﻿jQuery(function () {
    var $ = jQuery; // reclaim it. do it.
    var slider = $('#SwedegasSlider');
    if (slider) {
        slider.anythingSlider({
            buildNavigation: false,
            autoPlay: true,
            delay: 18000,
            animationTime: 1000
        }); // add any non-default options here
    }
    var flyout = $('.flyout');
    var flyoutArrow = $('.flyout-arrow');

    $('.top-menu-link').click(function () {
        var $t = $(this)
        $('.top-menu-link').parent().css({ 'z-index': '0' });
        flyout.hide();
        flyoutArrow.hide();
        $t.parent().css({ 'z-index': '1' });
        $t.siblings(flyout).show();
        $t.siblings(flyoutArrow).show();
        return false;
    });

    $(document).click(function () {
        flyout.hide();
        flyoutArrow.hide();
    });
    flyout.unbind('click').click(function (e) {
        e.stopPropagation();
    });
    flyoutArrow.unbind('click').click(function (e) {
        e.stopPropagation();
    });

    var boxes = $('.searchTextBox');
    if (document.location.href.indexOf('searchStr') == -1) {
        var defColor = $(boxes[0]).css('color');
        boxes.focus(function () {
            var t = $(this);
            if (t.val() == this.defaultValue)
                t.val('').css('color', '#000');
        }).blur(function () {
            var t = $(this);
            if (t.val() == '')
                t.val(this.defaultValue).css('color', defColor);
        });
    } else
        boxes.css('color', '#000');

    $(".arealogin .textbox").each(function (i) {
        $(this).val("");
    });

    $("legend").wrap('<span class="legend-wrapper">');

    //Event Menu-Poof
    if ($('.content-list')) {
        var EventListArrow = $('#list-point-arrow'), saveOfArrow = false, clist = $('.text-holder'), clistHight = clist.innerHeight();
        $('.nav-list ul li a').click(function () {
            var that = $(this), pos = that.position();
            if (that.hasClass('selected')) { return false; }
            $('.nav-list ul li a').removeClass('selected');
            clist.animate({ 'top': '-' + (that.data('C') * clistHight) + 'px' }, 400);
            EventListArrow.animate({ 'top': (pos.top + 4) + 'px' }, 400);
            that.addClass('selected');
            return false;
        }).each(function (index) {
            $(this).data('C', index);
        });
    };

    // show location in lightbox and csv file string 
    var locationGlobalStr = '';
    var unitGlobalStr = 'Nm3/h';
    var bookingGlobalBool = false;
    var decimalsGlobalInt = 0;
    //Gas-searchform
    var findQueryNrParam = -1; // need a default
    $(".select-criteria, #boking-MaxCapacityPerHour, #boking-CapacitySubscription").change(function () {
        var str = $("select option:selected").val();
        if (str == "Bookings") {
            $(".gas-flow-wrapper").hide();
            $(".gas-quality-wrapper").hide();
            $(".gas-transfer-wrapper").hide();
            $(".booking-wrapper").show();

            var flowStr = $('.booking-wrapper select option:selected').val();
            if ('' == flowStr)
                flowStr = -1
            findQueryNrParam = parseInt(flowStr);
            locationGlobalStr = $(".booking-wrapper select option:selected").text();
            unitGlobalStr = 'Nm3/h';
            bookingGlobalBool = true;
            decimalsGlobalInt = 0;
        }
        else if (str == "Flow") {
            $(".booking-wrapper").hide();
            $(".gas-quality-wrapper").hide();
            $(".gas-transfer-wrapper").hide();
            $(".gas-flow-wrapper").show();
            var flowStr = $('.gas-flow-wrapper select option:selected').val();
            if ('' == flowStr)
                flowStr = -1
            findQueryNrParam = parseInt(flowStr);
            locationGlobalStr = $(".gas-flow-wrapper select option:selected").text();
            bookingGlobalBool = false;
            decimalsGlobalInt = 0;
            if (DragorGCV == locationGlobalStr) {
                unitGlobalStr = 'kWh';
            }
            else {
                unitGlobalStr = 'Nm3/h';
            }
        }
        else if (str == "GasQuality") {
            $(".booking-wrapper").hide();
            $(".gas-flow-wrapper").hide();
            $(".gas-transfer-wrapper").hide();
            $(".gas-quality-wrapper").show();
            var flowStr = $('.gas-quality-wrapper select option:selected').val();
            if ('' == flowStr)
                flowStr = -1
            findQueryNrParam = parseInt(flowStr);
            locationGlobalStr = $(".gas-quality-wrapper select option:selected").text();
            bookingGlobalBool = false;
            unitGlobalStr = 'kWh/Nm3';
            decimalsGlobalInt = 3;
        }

        else if (str == "GasTransfer") {
            $(".booking-wrapper").hide();
            $(".gas-flow-wrapper").hide();
            $(".gas-quality-wrapper").hide();
            $(".gas-transfer-wrapper").show();
            var flowStr = $('.gas-transfer-wrapper select option:selected').val();
            if ('' == flowStr)
                flowStr = -1
            findQueryNrParam = parseInt(flowStr); ; //TODO: should this value be set here?... maybe not?
            locationGlobalStr = $(".gas-transfer-wrapper select option:selected").text(); //TODO: SET THIS 
            unitGlobalStr = 'Nm3/h';
            bookingGlobalBool = false;
            decimalsGlobalInt = 1;
        }

        if ($('.select-criteria').val() != 'none') {
            $('#noGasStartPoint').hide();
        }

        if ($('.select-criteria').val() == 'none') {
            $(".booking-wrapper").hide();
            $(".gas-flow-wrapper").hide();
            $(".gas-quality-wrapper").hide();
            $(".gas-transfer-wrapper").hide();
            findQueryNrParam = -1;
            locationGlobalStr = '';
            unitGlobalStr = 'Nm3/h';
            bookingGlobalBool = false;
            decimalsGlobalInt = 0;
        }

    }).trigger('change');


    $(".input-from,.input-to").datepicker({
        onSelect: function (dateText, inst) {
            if ($(".input-from").val() == '' || $(".input-to").val() == '') { return false; }
            //validate date
            var front = Date.today().addMonths(+18);
            var from = Date.parse($('.input-from').val());
            var to = Date.parse($('.input-to').val());
            var compareFront = Date.compare(front, to);

            $('.error-message-to').hide();

            if (compareFront == -1) {
                $('.error-message-to').show();
                $('.input-to').val("");
            }
            if (from != null) {
                var compareDates = Date.compare(from, to);
                if (compareDates == -1) {
                    var checkBetweenDates = Date.compare(from.addMonths(18), to);
                    if (checkBetweenDates == -1) {
                        $('#csvErrorMsg').show().html(errorMsgObj.onlyCsv);
                        $('.hideable').hide();
                    }
                    else {
                        $('#csvErrorMsg').hide();
                        $('.hideable').show();
                    }
                }
                else {
                    $('#dateErrorMsg').show().html(errorMsgObj.negativDate); //from erro msg obj
                    $('.input-to').val("");
                }
            }
        }
    });




    /* Swedish initialisation for the jQuery UI date picker plugin. */
    /* Written by Anders Ekdahl ( anders@nomadiz.se). */

    $.datepicker.regional['sv'] = {
        closeText: 'Stäng',
        prevText: '&laquo;Förra',
        nextText: 'Nästa&raquo;',
        currentText: 'Idag',
        monthNames: ['Januari', 'Februari', 'Mars', 'April', 'Maj', 'Juni',
            'Juli', 'Augusti', 'September', 'Oktober', 'November', 'December'],
        monthNamesShort: ['Jan', 'Feb', 'Mar', 'Apr', 'Maj', 'Jun',
            'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dec'],
        dayNamesShort: ['Sön', 'Mån', 'Tis', 'Ons', 'Tor', 'Fre', 'Lör'],
        dayNames: ['Söndag', 'Måndag', 'Tisdag', 'Onsdag', 'Torsdag', 'Fredag', 'Lördag'],
        dayNamesMin: ['Sö', 'Må', 'Ti', 'On', 'To', 'Fr', 'Lö'],
        weekHeader: 'Ve',
        dateFormat: 'yy-mm-dd',
        firstDay: 1,
        isRTL: false,
        showMonthAfterYear: false,
        yearSuffix: '',
        minDate: new Date(2006, 10 - 1, 01)
    };
    if ($(".gasformleftwrapper .Swedish").length != 0) {
        $.datepicker.setDefaults($.datepicker.regional["sv"]);
        $(".input-from").datepicker($.datepicker.regional["sv"]);
        $(".input-to").datepicker($.datepicker.regional["sv"]);
    }


    //check if radio btn i got a value
    $('.format input:radio').click(function () {
        if ($('.format input:checked').val() != undefined) {
            $('#csvErrorMsg').hide();
        }
    });


    //open-lightbox
    $('#fetch-data').click(function () {
        var gotError = false;

        globalStopAllLoading = false;
        //chek for error 
        if ($('.input-from').val() == '' || $('.input-to').val() == '') {
            $('#dateErrorMsg').show().html(errorMsgObj.emptyDateFeild);
            gotError = true;
        }
        if ($('.select-criteria').val() == 'none' || findQueryNrParam < 0) {
            $('#noGasStartPoint').show().html(errorMsgObj.noLocationSelected);
            gotError = true;
        }
        if ($('.format input:checked').val() == undefined) {
            $('#csvErrorMsg').show().html(errorMsgObj.presentationWayError);
            gotError = true;
        }

        //build table 
        var tableMaker = function (tableJson) {
            if (!tableJson || !tableJson.values) return;
            var tableJson = tableJson.values, loong = tableJson.length, i = 0, html = ['<table class="gas-flow-table"><tbody>'], closeStatusBar = false;

            while (i < loong) {
                if (i % 2 == 0) {
                    html.push('<tr>');
                } else {
                    html.push('<tr class="alt">');
                }

                html.push('<td>' + tableJson[i].from[0] + ' <img class="tableTimer" src="' + SGglobal.imageUrl + 'tableTimer.png" alt="clock icon" /> ' + tableJson[i].from[1] + '</td>\
                        <td>' + (tableJson[i].value[0] == undefined ? ' -' : formatNumberWatainStyle(tableJson[i].value[0])) + '</td>');
                if (bookingGlobalBool == false) {
                    html.push('<td>' + (tableJson[i].status[0] == undefined ? ' -' : tableJson[i].status[0]) + '</td>');
                }

                i++;
            }
            if (bookingGlobalBool == false) {
                $('#closeStatusBar').show();
            }
            else {
                $('#closeStatusBar').hide();
            }
            html.push('</tbody></table>');
            return html.join('');
        };


        if (gotError == false) {
            // what pressentation
            lightBoxGrafSwitch = false;
            if ($('#presentation-graf:checked').val() === 'on') {
                //Graph
                lightBoxGrafSwitch = true;
                popLightbox(true, true);
                //add to date some text from johan :)
                $('#gasflowTextArea').html(locationGlobalStr + ' <span>' + $('.input-from').val() + ' - ' + $('.input-to').val() + '</span>'); // ta bort hårkodad location text 
                SWEGAS.chart.init();
                if (!bookingGlobalBool) {
                    $('#explain-valu-graf').show();
                } else {
                    $('#explain-valu-graf').hide();
                }
            } else if ($('#presentation-tabell:checked').val() === 'on') {
                // Table
                popLightbox(true, true);
                $('#gasflowTextArea').html(locationGlobalStr + ' - ' + unitGlobalStr + '  <span>' + $('.input-from').val() + ' - ' + $('.input-to').val() + '</span>'); // ta bort hårkodad location text 
                $.post(SGglobal.seviceUrl + 'gasdata.asmx/' + CustomerQueryString + 'GasStatisticsTable',
                {
                    'fromDate': $('.input-from').val(),
                    'toDate': $('.input-to').val(),
                    'query': findQueryNrParam
                },
                function (data) {
                    if (globalStopAllLoading == true) { globalStopAllLoading = false; return; }
                    $('#tableDataWrap').show().html(tableMaker(data));
                    $('#stickyTableHeader').show();
                });
                $('#explain-valu-graf').hide();
            } else if ($('#presentation-csv:checked').val() === 'on') {
                //CSV file
                popLightbox(true, false, 'S');
                $.post(SGglobal.seviceUrl + 'gasdata.asmx/' + CustomerQueryString + 'NotEmptyFile', { 'fromDate': $('.input-from').val(), 'toDate': $('.input-to').val(), 'query': findQueryNrParam }, function (data) {
                    if (globalStopAllLoading == true) { globalStopAllLoading = false; return; }
                    $('#downloadCsvFile').show();
                    if ($.trim(data) == 'true') {
                        $('#downloadCsvFile a').show().attr('href', SGglobal.seviceUrl + 'gasdata.asmx/' + CustomerQueryString + 'GasStatisticsCsv' + '?fromDate=' + $('.input-from').val() + '&toDate=' + $('.input-to').val() + '&query=' + findQueryNrParam + '&fileName=' + locationGlobalStr + '_' + unitGlobalStr.replace('/', '//')).click(function () {
                            popLightbox(false, true);
                        });
                        $('#gasflowTextArea').html(locationGlobalStr + ' <span>' + $('.input-from').val() + ' - ' + $('.input-to').val() + '</span>'); // ta bort hårkodad location text 
                    } else {
                        $('#downloadCsvFile a').hide();
                        $('#csvErrorMsginLB').show().html(errorMsgObj.noFile);
                    }
                });
                $('#explain-valu-graf').hide();
            }
            $('.error-message').hide();
        }

        return false;
    });


    // open close light box function
    // True false ||  true/false ||  S,M,L L== default
    var popLightbox = function (showHide, printPage, size, selectedOutput) {
        size = size == undefined ? 'L' : $.trim(size);
        if (printPage == true || printPage == undefined) {
            $('#print-lightbox').show();
            $('#downloadCsvFile').hide();
            $('#stickyTableHeader').hide();
            $('#tableDataWrap').hide();
        } else {
            $('#print-lightbox').hide();
        }
        switch (size) {
            case 'L':
                $('#lightbox').attr('style', '');
                break;
            case 'M':
                // Medium
                break;
            case 'S':
                $('#lightbox').css({ 'width': '300px', 'height': '200px', 'min-height': '0', 'margin-top': '200px' });
                break;
            default:
                $('#lightbox').attr('style', '');
        }
        if (showHide) {
            $('#lightbox-shade').show();
        } else {
            $('#downloadCsvFile').hide();
            $('#drawChartCanvas').html('');
            $('#lightbox-shade').hide();
            $('#tableDataWrap').hide().html('');
            $('#stickyTableHeader').hide();

        }
    };





    //close-lightbox
    var globalStopAllLoading = false;
    $('#close-lightbox').click(function () {
        globalStopAllLoading = true;
        popLightbox(false, true);
        return false;
    });

    //Print content in lightbox ... respons to print btn.
    var win = null, lightBoxGrafSwitch = false;
    function printIt(printThis, graf) {
        bringJS = '';
        if ($.browser.msie && parseInt($.browser.version, 10) < 9 && lightBoxGrafSwitch) {
            bringJS = '<script type="text/javascript" src="' + SGglobal.siteUrl + 'raphael-min.js"></script>' +
                       '<script type="text/javascript" src="' + SGglobal.siteUrl + 'Common.js"></script>' +
                       '<script type="text/javascript">startRunGraf(' + globalGrafJson + ',false);</script>';
        }
        win = window.open();
        self.focus();
        win.document.open();
        // win.document.write('<link media="screen" type="text/css" rel="stylesheet" href="../Design/Styles/print.css" />');
        var style = '<style type="text/css"> body{ font-family:arial; }' +
                         '.gas-flow-table { font-size:12px; border-collapse:collapse; }' +
                         '.gas-flow-table th, td { padding:3px 20px; border-bottom:1px solid #ccc; }' +
                         '#stickyTableHeader div{float:left; padding:3px 20px;}' +
                         '#stickyTableHeader{height:30px;} #tableDataWrap{margin:0 0 0 20px;}' +
                         '.rowTime{margin-left:20px;} .rowVal{margin-left:77px;} .rowStat{padding-left:-8px;}' +
                         '</style>';
        win.document.write('<!DOCTYPE html><html><head>' + style + '</head><body>' + printThis + bringJS + '</body></html>');
        win.document.close();
        win.print();
        win.close();
    }

    //print button in the lightbox
    $('#print-lightbox').click(function () {
        printIt($('#print-area').html());
        return false;
    });


    //start chart ------------------------------


    var SWEGAS = (SWEGAS || {});
    SWEGAS.chart = function () {

        var PAPER_WIDTH = 1040;
        var PAPER_HEIGHT = 480;
        var PAPER_MARGIN = 20;
        var POPUP_HEIGHT = 70;
        var POPUP_WIDTH = 110;
        var COLOR_POPUP_BACKGROUND = '#eee';
        var COLOR_POPUP_STROKE = '#aaa';
        var COLOR_BAR_NORMAL = '#aaa';
        var COLOR_BAR_HOVER = '#345c8d';
        var COLOR_BAR_HOVER_GLOW = '#2a4b71';
        var COLOR_PRE_VALU_NORMAL = ''; // pre val
        var COLOR_PRE_VALU_HOVER = ''; // pre val hover
        var AXIS_VERTICAL_WIDTH = 64;
        var AXIS_HORIZONTAL_HEIGHT = 64;
        var SHAPE_POPUP = 'l 0,-20 l -' + (POPUP_WIDTH / 2 - 10) + ',0 l 0,-' + (POPUP_HEIGHT - 20) + ' l ' + POPUP_WIDTH + ',0 l 0,' + (POPUP_HEIGHT - 20) + ' l -' + (POPUP_WIDTH / 2) + ',0 z';
        var paper = null;
        var chartData = [];
        var chartUnit = '';
        var widthBar = 1;

        return {
            init: init
        };


        function init() {
            load();
        }
        var globalGurafJson = null;
        var startRunGraf = function (data) {
            if (data.error) {
                //error 
            } else {
                $('#drawChartCanvas').html('');
                loadedData = data;
                chartUnit = loadedData['unit'] || '';
                chartData = [];
                for (var i = 0; i < loadedData.values.length; i++) {
                    singleBar = loadedData['values'][i];
                    chartData[chartData.length] = {
                        fromDate: singleBar.from[0],
                        fromTime: singleBar.from[1],
                        toDate: singleBar.to[0],
                        toTime: singleBar.to[1],
                        popup: (singleBar.from[0] + ' ' + singleBar.from[1] + ' -\n' + singleBar.to[0] + ' ' + singleBar.to[1] + '   \n' + formatNumberWatainStyle(singleBar['value']) + ' ' + unitGlobalStr /*chartUnit*/),
                        value: fetchNumberWatainStyle(singleBar['value']),
                        status: singleBar.status[0]
                    };
                }
                paper = Raphael(document.getElementById('drawChartCanvas'), PAPER_WIDTH, PAPER_HEIGHT);
                paint();
            }
        };

        function load(date) {
            var singleBar = {};
            var loadedData;
            $.ajax({
                'type': 'POST',
                'url': SGglobal.seviceUrl + 'gasdata.asmx/' + CustomerQueryString + 'GasStatisticsJson',
                'data': { 'fromDate': $('.input-from').val(), 'toDate': $('.input-to').val(), 'returnFormat': 'json', 'query': findQueryNrParam }, //query var får jag området ifrån??
                'success': function (data) {
                    if (data.error) {
                        //error 
                    } else {
                        if (globalStopAllLoading == true) { globalStopAllLoading = false; return; }
                        globalGrafJson = data;
                        $('#drawChartCanvas').html('');
                        loadedData = data;
                        chartUnit = loadedData['unit'] || '';
                        chartData = [];
                        for (var i = 0; i < loadedData.values.length; i++) {
                            singleBar = loadedData['values'][i];
                            chartData[chartData.length] = {
                                fromDate: singleBar.from[0],
                                fromTime: singleBar.from[1],
                                toDate: singleBar.to[0],
                                toTime: singleBar.to[1],
                                popup: (singleBar.from[0] + ' ' + singleBar.from[1] + ' -\n' + singleBar.to[0] + ' ' + singleBar.to[1] + '   \n' + formatNumberWatainStyle(singleBar['value']) + ' ' + unitGlobalStr /*chartUnit*/),
                                value: fetchNumberWatainStyle(singleBar['value']),
                                status: singleBar.status[0]
                            };
                        }
                        paper = Raphael(document.getElementById('drawChartCanvas'), PAPER_WIDTH, PAPER_HEIGHT);
                        paint();
                    }
                },
                'error': function () { },
                'cache': false,
                'timeout': (20 * 1000)
            });
        }



        function paint() {
            var axis = {};
            var labels = {};
            var axisX1 = PAPER_MARGIN + AXIS_VERTICAL_WIDTH - 1;
            var axisX2 = PAPER_WIDTH - PAPER_MARGIN - POPUP_WIDTH / 2 + 1;
            var axisY1 = PAPER_MARGIN + POPUP_HEIGHT - 1;
            var axisY2 = PAPER_HEIGHT - (PAPER_MARGIN + AXIS_HORIZONTAL_HEIGHT) + 1;
            var bars = {};
            var values = [];
            var factor = 1;
            var scaledValue = 0;
            var widthTotal = 1;
            var i = 0;
            var labelDistance = 15;
            var valueMax = 0;
            var valueStep = 0;
            var valueStepCount = 10;

            paper.clear();

            for (i = 0; i < chartData.length; values[values.length] = chartData[i++].value);
            valueMax = Math.max.apply(Math, values);
            valueMax = Math.round(valueMax + 0.4999999);
            significant = parseInt(valueMax.toString().substring(0, 2));
            if (significant == 10) {
                significant = 10;
                valueStepCount = 10;
            } else if (significant <= 12) {
                significant = 12;
                valueStepCount = 6;
            } else if (significant <= 15) {
                significant = 15;
                valueStepCount = 6;
            } else if (significant <= 20) {
                significant = 20;
                valueStepCount = 8;
            } else if (significant <= 30) {
                significant = 30;
                valueStepCount = 6;
            } else if (significant <= 40) {
                significant = 40;
                valueStepCount = 8;
            } else if (significant <= 50) {
                significant = 50;
                valueStepCount = 5;
            } else if (significant <= 75) {
                significant = 75;
                valueStepCount = 7.5;
            } else {
                significant = 100;
                valueStepCount = 10;
            }
            valueMax = parseInt(significant + stringRepeat('0', valueMax.toString().length - 2));

            factor = (PAPER_HEIGHT - (2 * PAPER_MARGIN + AXIS_HORIZONTAL_HEIGHT + POPUP_HEIGHT)) / (valueMax + 1);
            widthTotal = (PAPER_WIDTH - (2 * PAPER_MARGIN + AXIS_VERTICAL_WIDTH + POPUP_WIDTH / 2)) / values.length;
            widthBar = widthTotal * 0.75;

            bars = paper.set();
            labels = paper.set();
            for (i = 0; i < chartData.length; i++) {
                scaledValue = chartData[i].value * factor;
                var isPreVal = $.trim(chartData[i].status);
                if (scaledValue == 0) {
                    // value is zero 
                    //console.log(axisY2)
                    var bar = paper.rect(PAPER_MARGIN + AXIS_VERTICAL_WIDTH + widthTotal * i, (PAPER_HEIGHT - axisY2) + 5, widthBar, (axisY2 - 89)).toFront().attr({ 'fill': '#fff', 'stroke': false });
                } else if (isPreVal == 'FINAL' && scaledValue != 0) {
                    var bar = paper.rect(PAPER_MARGIN + AXIS_VERTICAL_WIDTH + widthTotal * i, PAPER_HEIGHT - (PAPER_MARGIN + AXIS_HORIZONTAL_HEIGHT + scaledValue), widthBar, scaledValue).attr({ fill: COLOR_BAR_NORMAL, stroke: false });
                } else if (isPreVal == 'PRELIMINARY' && scaledValue != 0) {
                    var bar = paper.rect(PAPER_MARGIN + AXIS_VERTICAL_WIDTH + widthTotal * i, PAPER_HEIGHT - (PAPER_MARGIN + AXIS_HORIZONTAL_HEIGHT + scaledValue), widthBar, scaledValue).attr({ 'fill': '#fff', 'stroke': '#000' });
                } else {

                }

                bar.index = i;
                bars.push(bar);
                labelDistance += widthTotal;
                if (labelDistance >= 15) {
                    labels.push(paper.text(widthBar / 2 + PAPER_MARGIN + AXIS_VERTICAL_WIDTH + widthTotal * i, PAPER_HEIGHT - (PAPER_MARGIN + AXIS_HORIZONTAL_HEIGHT / 2), chartData[i].fromDate));
                    labelDistance = 0;
                }
            }
            //bars.attr({ fill: COLOR_BAR_NORMAL, stroke: false });
            bars.hover(barHoverIn, barHoverOut);
            labels.rotate(270);

            axis = paper.path('M' + axisX1 + ',' + axisY1 + ' L' + axisX1 + ',' + axisY2 + ' L' + axisX2 + ',' + axisY2);
            valueStep = valueMax / valueStepCount;
            for (i = 0; i <= valueStepCount; i++) {
                paper.path('M' + axisX1 + ',' + (axisY2 - i * valueStep * factor) + ' L' + (axisX1 - 10) + ',' + (axisY2 - i * valueStep * factor));
                // set value for y axel graf 
                paper.text(axisX1 - 20, axisY2 - i * valueStep * factor, Math.round(i * valueStep)).attr({ 'text-anchor': 'end' });
            }
            paper.text(60, 60, '[' + unitGlobalStr + ']').attr({ 'text-anchor': 'end' });

        }

        function barHoverIn() {
            if (chartData[this.index].value == 0 || chartData[this.index].status == 'PRELIMINARY') {

            } else {
                this.attr({ fill: COLOR_BAR_HOVER, stroke: COLOR_BAR_HOVER_GLOW });
            }
            this.popup = paper.path('M' + (this.attrs.x + widthBar / 2) + ',' + (this.attrs.y - 5) + SHAPE_POPUP);
            this.popup.attr({ 'stroke': COLOR_POPUP_STROKE, 'fill': COLOR_POPUP_BACKGROUND });
            this.popupText = paper.text(this.attrs.x + 10 + widthBar / 2, this.attrs.y - (POPUP_HEIGHT / 2 + 15), chartData[this.index].popup);
        }

        function barHoverOut() {
            if (chartData[this.index].value == 0 || chartData[this.index].status == 'PRELIMINARY') {

            } else {
                this.attr({ fill: COLOR_BAR_NORMAL, stroke: false });
            }
            this.popup.remove();
            this.popupText.remove();
        }

        function stringRepeat(string, times) {
            return new Array(times + 1).join(string);
        }

    } ();

    // end chart ----------------------
    var fetchNumberWatainStyle = function (number) {
        if (number.toString().indexOf(',') != -1) {
            number = number.toString().replace(',', '.');
        }
        return parseFloat(number);
    }

    var formatNumberWatainStyle = function (number) {
        var fnumber, lnumber;
        if (number.toString().indexOf(',') != -1) {
            var numbers = number.toString().split(',');
            fnumber = numbers[0];
            lnumber = decimalsGlobalInt > 0 ? ',' : '';
            lnumber += numbers[1].toString().substring(0, decimalsGlobalInt);
        }
        else {
            fnumber = number;
            lnumber = '';
        }
        fnumber = fnumber < 0 ? -fnumber : fnumber;
        return Math.max(0, fnumber).toFixed(0).replace(/(?=(?:\d{3})+$)(?!^)/g, ' ') + lnumber;
    }
});



