﻿function loadbody()
{
    _dom=document.all?3:(document.getElementById?1:(document.layers?2:0));
    //document.getElementById("ctl00_txtCompanysuggest").focus();
   // loadAllGraphs();
    
   // ddaccordion.collapseall('submenuheader');
    setTheMenuBgColor();
    strPrefix = 'ctl00_';
    changeGraphContainerWidth();
    changeGraphContainerHeight();
}

function setTheMenuBgColor()
{
    var idmenu = document.getElementById("leftnav_revisiontrend");
    var image = "url(App_Themes/images/navigation_button_submenu_over.gif)";
    if((idmenu != null) && (image != null))
    {
        //Replace the image to highlight
        idmenu.style.backgroundImage = image;
        idmenu.style.color = "#154f71";
    }
}


function loadPageControls()
{
    if(_dom==3)
    {
        location = document.getElementById('ctl00_ContentPlaceHolder1_startApp').href;       
    }
    else
    {
        location = document.getElementById('ctl00_ContentPlaceHolder1_startApp').href;        
    }

}


function loadGraph(dataFieldId, renderingItemID, width, height)
{
    var varGraph = document.getElementById(renderingItemID);
    varGraph.style.display = "none";
    varGraph.style.visbility = "hidden";
    
    var graphText = null;
    var element = document.getElementById(dataFieldId);

    // The element is null or undefined. hide the corresponding div and simply return.
    if(typeof(element) == "undefined" || element == null || typeof(element.value) == "undefined" 
        || typeof(element.value.length) == "undefined" || element.value.length == 0)
    {
        //alert("graph text is null");
        // Remove the element.
        // document.removeChild(varGraph);
        return;
    }
    
    // alert(graphText);
    
    graphText = element.value;

    if(graphText.length <= 0)
    {
        return;        
    }
    
    var vChart = new Visifire("Visifire.xap", width, height);


    
    vChart.setDataXml(graphText);    
    vChart.render(renderingItemID);
    
    varGraph.style.display = "block";
    varGraph.style.visbility = "show";
}

function loadAllGraphs()
{

    // Remove all the graphs before redrawing them.
    removeAllTheGraphs();
    
    loadGraph("LineGraphSales1", "SalesGraph1", 190, 200);
    loadGraph("LineGraphSales2", "SalesGraph2", 190, 200);
    loadGraph("LineGraphSales3", "SalesGraph3", 190, 200);
    loadGraph("LineGraphSales4", "SalesGraph4", 190, 200);
    loadGraph("LineGraphSales5", "SalesGraph5", 290, 200);
    loadGraph("LineGraphNonGAAP1", "NonGAAPGraph1", 190, 200);
    loadGraph("LineGraphNonGAAP2", "NonGAAPGraph2", 190, 200);
    loadGraph("LineGraphNonGAAP3", "NonGAAPGraph3", 190, 200);
    loadGraph("LineGraphNonGAAP4", "NonGAAPGraph4", 190, 200);
    loadGraph("LineGraphNonGAAP5", "NonGAAPGraph5", 290, 200);
    loadGraph("LineGraphGAAP1", "GAAPGraph1", 190, 200);
    loadGraph("LineGraphGAAP2", "GAAPGraph2", 190, 200);
    loadGraph("LineGraphGAAP3", "GAAPGraph3", 190, 200);
    loadGraph("LineGraphGAAP4", "GAAPGraph4", 190, 200);
    loadGraph("LineGraphGAAP5", "GAAPGraph5", 290, 200);

    
    
}

function removeAllTheGraphs()
{
    for(var i = 1; i <= 5; i++)
    {   var graphDivID = "SalesGraph" + i
        var varGraph = document.getElementById(graphDivID);
        varGraph.style.display = "none";
        varGraph.style.visbility = "hidden";
    }
}

function changeGraphContainerWidth() {

    var divListView = document.getElementById('GraphDiv');
    divListView.style.width = getElementWidth('gen_details');


}

function changeGraphContainerHeight() {
    var divListView = document.getElementById('GraphDiv');
    divListView.style.height = getElementHeight('GraphDiv') + 25;
}

function OnItemSelected() {

    var varSearch = document.getElementById("ctl00_ContentPlaceHolder1_linkSearch");
    if (varSearch != null) {
        //This causes the graph loading in the update panel
        location = varSearch.href;
    }
}
