﻿var firstDraw=true;
var canRefreshWebParts = false;
function addRefreshScript(id, script){
    if(refreshScript.indexOf(id)<0) refreshScript+=script;
}
function refreshWebParts(){
    if (refreshScript != '' && canRefreshWebParts) eval(refreshScript);
}
function drawGrid(WebPartID, Group, LayerID, negativeRedCell) {
    var layer = $get(LayerID);
    if (layer != null){
        layer.innerHTML = '<div style="text-align:center; width:100%"><img src="Images/BigLoading.gif" /></div>';
        BSC.Web.Services.DW.GetGrid(WebPartID, varIDCtlView, Group, '', '', negativeRedCell, function(result) { layer.innerHTML = result });
    }   
}
function drawChart(id){
    if (firstDraw) return;
    if (eval(id + "_origdata") == null)
        return;
    eval(id + "_data=String.format(" + id + "_origdata,'" + $get('hidYears').value + "','" + $get('hidMonths').value + "')");
    renderAndReloadChartDataURL(id);
}
function refreshLists() {
    for (var list = 0; list < 2; list++) {
        var cells = $get(list == 1 ? tblYears : tblMonths).getElementsByTagName('td');
        var hid = $get(list == 1 ? 'hidYears' : 'hidMonths');
        for (var pos = 0; pos < cells.length; pos++) {
            var value = cells[pos].attributes["value"].value;
            if (hid.value.indexOf(',' + value + ',', 0) < 0)
                cells[pos].className = '';
            else
                cells[pos].className = 'Selected';
        }
    }
}
function getGridExport(WebPartID, Format, IDCtlView, GroupField, NegativeCellRed, Title) {
    window.location.href = 'CtlExport.ashx?WebPartID=' + WebPartID + '&Format=' + Format + '&IDCtlView=' + IDCtlView + '&GroupField=' + GroupField + '&NegativeCellRed=' + NegativeCellRed + '&FileName=' + Title;
}
function downloadAttach(id){
    window.location.href = 'Download.ashx?Type=CA&ID=' + id;
}
function doFirstDraw() {
    firstDraw = true;
    canRefreshWebParts = true;
    refreshWebParts();
    firstDraw = false;
    setBackground();
}
function selectItem(cel, list) {
    var value = cel.attributes["value"].value;
    var hid = $get(list == 1 ? 'hidYears' : 'hidMonths');
    if (hid.value.indexOf(',' + value + ',', 0) < 0) {
        cel.className = 'Selected';
        hid.value += value + ',';
    } else {
        cel.className = '';
        hid.value = hid.value.replace(',' + value + ',', ',');
    }
    refreshWebParts();
}
function selectAll(list) {
    var values = '';
    var cells = $get(list == 1 ? tblYears : tblMonths).getElementsByTagName('td');
    for (var pos = 0; pos < cells.length; pos++) {
        cells[pos].className = 'Selected';
        values += cells[pos].attributes["value"].value + ',';
    }
    $get(list == 1 ? 'hidYears' : 'hidMonths').value = ',' + values;
    refreshWebParts();
}
function deselectAll(list) {
    var cells = $get(list == 1 ? tblYears : tblMonths).getElementsByTagName('td');
    for (var pos = 0; pos < cells.length; pos++)
        cells[pos].className = '';
    $get(list == 1 ? 'hidYears' : 'hidMonths').value = ',';
    refreshWebParts();
}
function cleanPeriod() {
    $get('hidYears').value = ',';
    $get('hidMonths').value = ',';
}
function setBackground() {
    var width = document.body.scrollWidth;
    if ($get('tblMenu').width > width)
        width = $get('tblMenu').offsetWidth;
    var div = $get('divBackground');
    if (div) {
        div.style.width = width;
        div.style.height = document.body.offsetHeight - 107;
        div.style.backgroundImage = 'url(download.ashx?Type=DB&w=' + width + '&ID=' + idCtlBoard + ')';
    }
}
window.onload = doFirstDraw;
window.onresize = setBackground;

if (typeof(Sys) !== 'undefined'){ Sys.Application.notifyScriptLoaded(); }
