﻿//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 options = {
//        colors: [
//	'#4572A7',
//	'#89A54E',
//	'#AA4643',
//	'#80699B',
//	'#3D96AE',
//	'#DB843D',
//	'#92A8CD',
//	'#A47D7C',
//	'#B5CA92'
//],
//        chart: {
//            margin: [50, 20, 90, 150],
//            renderTo: DivId
//        },
//        title: {
//            text: Title
//        },
//        xAxis: {
//            type: 'string',
//            //rotation: -15,
//            labels: {
//                formatter: function() {

//                    return this.name;
//                }
//                //rotation: -15
//            },
//            title: {
//                text: xTitle
//            },
//            showLastLabel: true,
//            showFirstLable: true,
//            style: 'bottom:18px'
//        },
//        yAxis: {
//            title: {
//                text: yTitle
//            },
//            labels: {
//                formatter: function() {
//                    return addcommas(this.value);
//                }
//            }

//        },
//        tooltip: {
//            formatter: function() {
//                if (PlotType == 'spline') {
//                    return '<b>' + this.series.data[this.x].name + '</b><br/>' +
//            this.x + ' : ' + addcommas(this.y) + '';
//                }
//                else {
//                    return '<b>' + this.series.data[0].name + '</b><br />' + this.y;
//                }
//            }
//        },
//        plotOptions: {
//            pie: {
//                borderColor: "#FFFFFF",
//                borderWidth: 2
//            },
//            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 = { 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.data[i] = val.y;
//    //            //options.xAxis.categories.push(val.x);
//    //            arrZ[i] = val.x;
//    //        });
//    //        tseries.type = PlotType;
//    //        //tseries.data = arrZ;
//    //        options.series.push(tseries);
//    //        options.xAxis.categories = arrZ;
//    //    });
//    $.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;
//        options.series.push(tseries);
//    });
//    var chart = new Highcharts.Chart(options);
//}
//function addcommas(sValue) {

//    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 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;
    }
