﻿

//--------Event Handlers-----------------------------------------------
function DFRCallout_link_click(event){
    if (document.getElementById('DFRCallout_callout').className!='ExPTCalloutWrapperDFR'){
        DisplayCGDFRList(document.getElementById("ctl00_ctl00_ExPTContent___EXPT_Peers__").value);
    }
    toggleCallout(document.getElementById('DFRCallout_link'),document.getElementById('DFRCallout_callout'), 'ExPTCalloutWrapperDFR');
    
}
function SaveCallout_link_click(event){
    toggleCallout(document.getElementById('SaveCallout_link'),document.getElementById('Save_callout'), 'ExPTCalloutWrapperSave');
    
    try{
        if (document.getElementById("Save_callout").className=='ExPTCalloutWrapperSave'){
            document.getElementById("email").value="";
            document.getElementById("ctl00_ctl00_ExPTContent_ExPT_Header_SaveCallout_tbFilename").value=document.getElementById("ctl00_ctl00_ExPTContent_ExPT_Header_SaveCallout_defaultFilename").value;
        }
    }catch (ex){
    
    }
    
    var peers;
    if (document.getElementById("ctl00_ctl00_ExPTContent___EXPT_Peers__").value!=""){
        if (document.getElementById("ctl00_ctl00_ExPTContent___EXPT_Peers__").value.indexOf(',')>0){
            peers = document.getElementById("ctl00_ctl00_ExPTContent___EXPT_Peers__").value.split(",");
            document.getElementById("InstCount").innerHTML = peers.length + " ";
        }else{
        
            peers = document.getElementById("ctl00_ctl00_ExPTContent___EXPT_Peers__").value.split(",");
            document.getElementById("InstCount").innerHTML = "1 ";
        }
    }else{
        document.getElementById("InstCount").innerHTML = "0 ";
    }
}

function InstInfo_link_click(event, unitid){
    toggleCallout(document.getElementById('InstInfoCallout_link_' + unitid),document.getElementById('InstInfoCallout_callout_' + unitid), 'InstInfoCallout');
}
function InstInfo_link_moused(event, unitid){
    toggleCallout(document.getElementById('InstInfoCallout_link_' + unitid),document.getElementById('InstInfoCallout_callout_' + unitid), 'InstInfoCallout');
}

function AddByNameInstInfo_link_click(event, unitid){
    toggleCallout(document.getElementById('AddByNameInstInfoCallout_link_' + unitid),document.getElementById('AddByNameInstInfoCallout_' + unitid), 'InstInfoCallout');
}
function FocusInstInfo_link_click(event, unitid){
    toggleCallout(document.getElementById('FocusInstInfoCallout_link_' + unitid),document.getElementById('FocusInstInfoCallout_' + unitid), 'InstInfoCallout');
}
function ReportCallout1_link_click(event){
    closeAllCalloutsOnPage(null,'div','Report1_callout');
    toggleCallout(document.getElementById('ReportCallout1_link'),document.getElementById('Report1_callout'), 'reportCallout1');
}
function ReportCallout2_link_click(event){
    closeAllCalloutsOnPage(null,'div','Report2_callout');
    toggleCallout(document.getElementById('ReportCallout2_link'),document.getElementById('Report2_callout'), 'reportCallout2');
}
function ChartInfo1Callout_link_click(event, chartid){
    closeAllCalloutsOnPage(null,'div','ChartInfo1Callout_' + chartid);
    toggleCallout(document.getElementById('ChartInfo1Callout_link_' + chartid),document.getElementById('ChartInfo1Callout_' + chartid), 'ChartInfoCallout');
}
function ChartInfo2Callout_link_click(event,chartid){
    closeAllCalloutsOnPage(null,'div','ChartInfo2Callout_' + chartid);
    toggleCallout(document.getElementById('ChartInfo2Callout_link_' + chartid),document.getElementById('ChartInfo2Callout_' + chartid), 'ChartInfoCallout');
}

function DataFile_link_click(event){
    toggleCallout(document.getElementById('DataFile_link'),document.getElementById('DataFile_callout'), 'DataFileInfo');
}

function Map_link_click(event){
    toggleCallout(null,document.getElementById('maplayer'), 'maplayer2');
    if (document.getElementById('maplayer').className=='maplayer2'){
        RebuildMapSelections();
    }
}

//--------Base Functions-----------------------------------------------
function toggleCallout(opener, callout, cssClass){
    if(callout.className!=cssClass){
        callout.className=cssClass;
    }else{
        callout.className='none';
    }   
}

function closeAllCalloutsOnPage(container,tagname,exception){
    if (container!=null){
        var oElements = document.getElementById(container).getElementsByTagName("div")
    }else{
        var oElements = document.getElementsByTagName("div")
    }
    for (var x=0; x<=oElements.length-1; x++){
        if(oElements[x].id.indexOf("allout")>0 && oElements[x].id!=exception){
            oElements[x].className="none";
        }
    }
}


function DisplayCGDFRList(comparisongroup){
    if(comparisongroup.length>0){
        var request = false;
        
        try {
         request = new XMLHttpRequest();
        } catch (trymicrosoft) {
         try {
           request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (othermicrosoft) {
           try {
             request = new ActiveXObject("Microsoft.XMLHTTP");
           } catch (failed) {
             request = false;
           }  
         }
        }

        if (!request)
         alert("Error initializing XMLHttpRequest!");


        var url = "workerDownloadDFRPeerList.aspx?cg=" + escape(comparisongroup);
        request.open("GET", url, true);
        openRequest = request;
        request.onreadystatechange = updatePeerDFRDisplay;
        request.send(null);
    }else{
        document.getElementById("ctl00_ctl00_ExPTContent_ExPT_Header_DFRCallout_panelNoCG").className = "";
        document.getElementById("ctl00_ctl00_ExPTContent_ExPT_Header_DFRCallout_panelCG").className="none";
    
    }
    
    
}
function updatePeerDFRDisplay() {
    if (openRequest.readyState == 4) {
        if (openRequest.status == 200) {
            if (openRequest.responseText!=""){    
                document.getElementById("ctl00_ctl00_ExPTContent_ExPT_Header_DFRCallout_panelNoCG").className = "none";
                document.getElementById("ctl00_ctl00_ExPTContent_ExPT_Header_DFRCallout_panelCG").className="";
                document.getElementById("cgDFRList").innerHTML=openRequest.responseText;
            }
        }
    }

}
