﻿/// <reference path="jquery-1.4.2.min.js" />
function KeyDownHandlerct(event, btnId) {
    if (event.keyCode == 13) {
        event.returnValue = false;
        event.cancel = true;
        __doPostBack(btnId, '')
        return false;
    }
}

////////// ChartFunctions ////////////////////////

function CreateNAVChart(arr, DivId, Title, xTitle, yTitle, PlotType, Pcolor) {
    //    var arrX = new Array();
    //    var arrY = new Array();
    //    var arrZ = new Array();
    //    $.each(arr,function(itotal, valTotal){
    //    $.each(valTotal.List, function(i, val) {
    //        arrX[i] = val.x;
    //        arrY[i] = val.y;
    //        var temparray = new Array(2);
    //        temparray[0] = arrX[i];
    //        temparray[1] = arrY[i];
    //        arrZ[i] = temparray;
    //    });
    //    });
    var axesWidth = 0;
    if (PlotType == "spline") {
        axesWidth = 4;
        if ((DivId != "NAVChart") && (DivId != "FundBourseCompairSoFardiv") && (DivId != "FundBourseCompairWeeklydiv") && (DivId != "divFundBourseCompairseven")) {
            yTitle += " (به میلیون ریال) ";

        }
    }
    var option = {
        colors: [
	    '#058dc7',
	    '#50b432',
	    '#ed561b',
	    '#dddf00',
	    '#24cbe5',
	    '#64e572',
	    '#ff9655',
	    '#A47D7C',
	    '#B5CA92'
        ],
        chart: {
            borderWidth: 2,
            showAxes: true,
            margin: [40, 20, 90, 150],
            showAxes: true,
            renderTo: DivId
        },
        title: {
            text: Title
        },
        xAxis: {
            gridLineWidth: 1,
            lineWidth: axesWidth,
            type: 'string',
            //            rotation: -15,
            labels: {
                formatter: function () {
                    return this.name;
                },
                rotation: -45

            },
            title: {
                text: 'تاریخ'
            },
            showLastLabel: true,
            showFirstLable: true,
            style: 'bottom:18px'
        },
        yAxis: {
            gridLineWidth: 1,
            maxPadding: 0.5,
            lineWidth: axesWidth,
            title: {
                text: yTitle,
                margin: 70
            },
            labels: {
                formatter: function () {
                    if (DivId == "NAVChart")
                        return addcommas2(this.value);
                    else if (DivId == "khalesarzeshdiv")
                        return addcommas(this.value);
                    else
                        return (this.value);
                }

            },
            plotLines: [{
                value: 0,
                width: 1,
                color: '#808080'
            }]

        },
        plotOptions: {
            spline: {
                lineWidth: 4,
                color: Pcolor,
                marker: {
                    enabled: false
                },
                states: {
                    hover: {
                        marker: {
                            enabled: true,
                            symbol: 'circle',
                            radius: 3,
                            lineWidth: 1
                        }
                    }
                }
            }
        },
        series: []
    };
    $.each(arr, function (index, value) {
        var tseries = { name: String, type: String, data: [] };
        arrZ = new Array();
        $.each(value.List, function (i, val) {
            var temparray = new Array(2);
            temparray[0] = val.x;
            temparray[1] = val.y;
            arrZ[i] = temparray;
        });
        tseries.name = value.name;
        tseries.type = PlotType;
        tseries.data = arrZ;
        option.series.push(tseries);
    });
    var chart = new Highcharts.Chart(option);
}

function addcommas(sValue) {

    sValue /= 1000000;
    var sValue = sValue.toString();
    var sRegExp = new RegExp('(-?[0-9]+)([0-9]{3})');
    var commExp = new RegExp(',');
    while (commExp.test(sValue)) {
        sValue = sValue.replace(commExp, '');
    }
    while (sRegExp.test(sValue)) {
        sValue = sValue.replace(sRegExp, '$1,$2');
    }
    return sValue;
}

function addcommas2(sValue) {

    //sValue /= 1000000;
    var sValue = sValue.toString();
    var sRegExp = new RegExp('(-?[0-9]+)([0-9]{3})');
    var commExp = new RegExp(',');
    while (commExp.test(sValue)) {
        sValue = sValue.replace(commExp, '');
    }
    while (sRegExp.test(sValue)) {
        sValue = sValue.replace(sRegExp, '$1,$2');
    }
    return sValue;
}

function SetTableGraphic(tableClass) {
    $('.' + tableClass + ' tr:even').addClass('OddRow');
    $('.' + tableClass + ' tr:odd').addClass('EvenRow');
}
