﻿function CloseThis(id) {
    if (document.getElementById(id) != null)
        document.getElementById(id).style.display = 'none';
    return false;
}

function ToggleThis(id) {
    if (document.getElementById(id) != null) {
        var el = document.getElementById(id);
        if (el.style.display == 'none')
            el.style.display = 'block';
        else if (el.style.display == 'block')
            el.style.display = 'none';
    }
    return false;
}


function ClosePops() {
    if ($find('galleryModalPopupExtender') != null)
        $find('galleryModalPopupExtender').hide();

    if ($find('errorsModalPopupExtender') != null)
        $find('errorsModalPopupExtender').hide();

    if ($find('warningModalPopupExtender') != null)
        $find('warningModalPopupExtender').hide();

    if ($find('warningPopupExtender') != null)
        $find('warningPopupExtender').hide();

    if ($find('warningPopupExtender') != null)
        $find('warningPopupExtender').hide();

    if ($find('swapErrorExtender') != null)
        $find('swapErrorExtender').hide();
}



/*****************/

function Carousel(container, prev, next, step) {
    var container = document.getElementById(container);
    var prev = document.getElementById(prev);
    var next = document.getElementById(next);
    var step = step;

    this.Rightx = Rightx;
    this.Leftx = Leftx;
    this.ToLeft = ToLeft;
    this.ToRight = ToRight;
    this.Hide = Hide;
    this.Show = Show;
    this.Startx = Startx;
    this.ResetPosition = ResetPosition;
    var curPos = 0;

    function Startx(position) {
        container.scrollLeft = position;
        curPos = 0;
    }

    function ResetPosition() {
        container.scrollLeft = 0;
        curPos = 0;
    }

    function Leftx() {

        if (container.scrollLeft == (curPos - step)) {
            curPos = container.scrollLeft;
            clearInterval(timerx);
        }
        if (container.scrollLeft != (curPos - step)) {
            container.scrollLeft -= 10;

            if (container.scrollLeft == 0) {
                curPos = container.scrollLeft;
                prev.style.visibility = 'hidden';
                clearInterval(timerx);
            }
            else {
                prev.style.visibility = 'visible';
                next.style.visibility = 'visible';
            }
        }
        else {
            clearInterval(timerx);
        }
    }



    function Rightx() {

        if (container.scrollLeft != (curPos + step)) {

            var oldval = container.scrollLeft;

            container.scrollLeft += 10;


            var answer = container.scrollLeft % 10;
            if (answer != 0 /*oldval == container.scrollLeft*/) {
                container.scrollLeft -= answer;
                curPos = container.scrollLeft;
                next.style.visibility = 'hidden';
                clearInterval(timerx);
            }
            else {
                prev.style.visibility = 'visible';
                next.style.visibility = 'visible';
            }
        }
        else {
            clearInterval(timerx);
        }

        if (container.scrollLeft == (curPos + step)) {
            curPos = container.scrollLeft;
            clearInterval(timerx);
        }

    }

    var timerx;
    //this.timerx = timer;

    function ToLeft() {
        clearInterval(timerx);
        timerx = setInterval(Leftx, 5);
    }

    function ToRight() {
        clearInterval(timerx);
        timerx = setInterval(Rightx, 5);
    }



    function Hide() {
        var el = document.getElementById(container);
        el.style.display = 'none';
    }

    function Show() {
        alert(container.scrollLeft + "-C:" + curPos.toString());
    }
}


//var car = new Carousel("cscz", "fdsfds", "cs");
//car.Ri


/****************/



/***GOOGLE CHARTS***/

function GChart(idOfChartDiv, xArr, yArr, Cartwidth, Cartheight) {

    this.drawVisualization = drawVisualization;

    function drawVisualization() {
        var dataTable = new google.visualization.DataTable();

        dataTable.addColumn('string', 'Name');
        dataTable.addColumn('number', 'All TypesX');
        dataTable.addRows(xArr.length);

        //Set X Axis
        for (var i = 0; i < xArr.length; i++) {
            dataTable.setCell(i, 0, xArr[i]);
        }

        //Set Y Axis
        for (var i = 0; i < yArr.length; i++) {
            dataTable.setCell(i, 1, yArr[i]);
        }

        var dataView = new google.visualization.DataView(dataTable);
        dataView.setColumns([0, 1]);

        new google.visualization.ColumnChart(document.getElementById(idOfChartDiv))
        .draw(
        dataView, 
        { 
            title: "(Revenue Total by Source/Kaynağa göre Toplam Meblağ)",
            titleFontSize: 9,
            width: Cartwidth,
            height: Cartheight, 
            fontSize: 10,
            legend: "none", 
            is3D: true,
            hAxis: { title: "Source" }
        });
    }

    this.drawVisualization();
}

/*******************/


/********FILE UPLOAD FILTER***********/

function UploadFilter() {

    this.CheckForTestFile = CheckForTestFile;
    this.Trim = Trim;

    //Trim the input text
    function Trim(input) {
        var lre = /^\s*/;
        var rre = /\s*$/;
        input = input.replace(lre, "");
        input = input.replace(rre, "");
        return input;
    }

    // filter the files before Uploading for text file only
    function CheckForTestFile(id, arr) {
        var file = document.getElementById(id);
        var fileName = file.value;
        //Checking for file browsed or not 
        if (Trim(fileName) == '') {
            alert("Please select a file to upload!\nLütfen dosya seçiniz!");
            file.focus();
            return false;
        }

        //Setting the extension array for diff. type of text files 
        var extArray = arr;

        //getting the file name
        while (fileName.indexOf("\\") != -1)
            fileName = fileName.slice(fileName.indexOf("\\") + 1);

        //Getting the file extension                     
        var ext = fileName.slice(fileName.indexOf(".")).toLowerCase();

        //matching extension with our given extensions.
        for (var i = 0; i < extArray.length; i++) {
            if (extArray[i] == ext) {
                return true;
            }
        }

        alert("Allowed file extensions:  " + (extArray.join("  "))
        + "\n"
        + "İzin verilen dosya uzantıları:  " + (extArray.join("  ")));
        file.focus();

        return false;
    }
}
/**************************************/



/*****SCROLLL NEWS****/


// WebTicker by Mioplanet
// www.mioplanet.com

function NewScroller(idofticker) {

        var TICKER_CONTENT = document.getElementById(idofticker).innerHTML;
        var TICKER_RIGHTTOLEFT = false;
        var TICKER_SPEED = 2;
        var TICKER_STYLE = "font-family:Trebuchet MS,Arial, Verdana; font-size:13px; color:#444444";
        var TICKER_PAUSED = false;
        
        ticker_start();
        
        function ticker_start() {
            var tickerSupported = false;
            TICKER_WIDTH = document.getElementById(idofticker).style.width;
            var img = "<img src=ticker_space.gif width=" + TICKER_WIDTH + " height=0>";

            // Firefox
            if (navigator.userAgent.indexOf("Firefox") != -1 || navigator.userAgent.indexOf("Safari") != -1) {
                document.getElementById(idofticker).innerHTML = "<TABLE  cellspacing='0' cellpadding='0' width='100%'><TR><TD nowrap='nowrap'>" + img + "<SPAN style='" + TICKER_STYLE + "' ID='TICKER_BODY' width='100%'>&nbsp;</SPAN>" + img + "</TD></TR></TABLE>";
                tickerSupported = true;
            }
            // IE
            if (navigator.userAgent.indexOf("MSIE") != -1 && navigator.userAgent.indexOf("Opera") == -1) {
                document.getElementById(idofticker).innerHTML = "<DIV nowrap='nowrap' style='width:100%;'>" + img + "<SPAN style='" + TICKER_STYLE + "' ID='TICKER_BODY' width='100%'></SPAN>" + img + "</DIV>";
                tickerSupported = true;
            }
            if (!tickerSupported) document.getElementById(idofticker).outerHTML = ""; else {
                document.getElementById(idofticker).scrollLeft = TICKER_RIGHTTOLEFT ? document.getElementById(idofticker).scrollWidth - document.getElementById(idofticker).offsetWidth : 0;
                document.getElementById("TICKER_BODY").innerHTML = TICKER_CONTENT;
                document.getElementById(idofticker).style.display = "block";
                TICKER_tick();
            }
        }

        function TICKER_tick() {
            if (!TICKER_PAUSED) document.getElementById(idofticker).scrollLeft += TICKER_SPEED * (TICKER_RIGHTTOLEFT ? -1 : 1);
            if (TICKER_RIGHTTOLEFT && document.getElementById(idofticker).scrollLeft <= 0) document.getElementById(idofticker).scrollLeft = document.getElementById(idofticker).scrollWidth - document.getElementById(idofticker).offsetWidth;
            if (!TICKER_RIGHTTOLEFT && document.getElementById(idofticker).scrollLeft >= document.getElementById(idofticker).scrollWidth - document.getElementById(idofticker).offsetWidth) document.getElementById(idofticker).scrollLeft = 0;
            window.setTimeout("TICKER_tick()", 30);
        }



}



/*****SCROLL NEWS END*****/
