﻿// JScript File
// ------------------------------------------------------------------------------------------------------------------------------------

// Show/Hide Layers ( DIV ), if only one checkbox checked
function checkedChanged(CheckBoxList, CheckBoxLayers, ClickedCheckBoxID)
{
    var CurrIndex;
    var i; // Index For Loop
    var CheckedCheckBoxCnt = 0; // Count Checked Boxes Only
    var ArrCheckBoxList;   // Get All the Check Boxes Types
    var ArrCheckBoxLayers; // Get All the Check Boxes Layers
    var ArrTextBox; // Get All the Text Boxes of Layers Boxes Layers
    var ArrSelect; // Get All the Selects of Layers

    // Iterate Through Check Boxes, Get Count of Checked ones
    // CurrIndex, useful only when one check box is checked (Only One)
    ArrCheckBoxList = document.getElementById(CheckBoxList).getElementsByTagName("input");
    for(var i=0;i<ArrCheckBoxList.length;i++)    
        if (ArrCheckBoxList[i].checked) { CheckedCheckBoxCnt = CheckedCheckBoxCnt + 1; CurrIndex = i; }           
 
    // At least one Check Box should be checked,
    // Make the last clicked checkbox = true, and recall the function. 
    if (CheckedCheckBoxCnt == 0)  
        { 
        document.getElementById(ClickedCheckBoxID).checked = true;  
        checkedChanged(CheckBoxList, CheckBoxLayers, ClickedCheckBoxID);                       
        }
    // Only one checkbox is checked, so display the related layer, and hide all the other layers
    else if(CheckedCheckBoxCnt == 1) 
        { 
       ArrCheckBoxLayers = document.getElementById(CheckBoxLayers).getElementsByTagName("table");
        for(var i=0;i<ArrCheckBoxLayers.length;i++) 
            { // For Begin        
                if (i == CurrIndex) 
                { setDisplay(ArrCheckBoxLayers[i].id,""); }
                else
                { setDisplay(ArrCheckBoxLayers[i].id,"none"); }           
            } // For End                 
        }
    // More than one checkbox is selected, so all layers will be hidden
    else 
        { 

        ArrTextBox = document.getElementById(CheckBoxLayers).getElementsByTagName("input");
        ArrSelect = document.getElementById(CheckBoxLayers).getElementsByTagName("select");
        for(var i=0;i<ArrTextBox.length;i++) 
        { // For Begin                      
            ArrTextBox[i].value = ""; // Clean Text Boxes  
            ArrSelect[i].value = 1;
        } // For End    
                    
        ArrCheckBoxLayers = document.getElementById(CheckBoxLayers).getElementsByTagName("table"); // Get All the Check Boxes Layers
        for(var i=0;i<ArrCheckBoxLayers.length;i++) 
            { // For Begin        
                setDisplay(ArrCheckBoxLayers[i].id,"none");
            } // For End                 
        }
}

// ------------------------------------------------------------------------------------------------------------------------------------
// Show-Hide Layer 
function setDisplay(id,value) 
{
    var elm = document.getElementById(id);   
    elm.style.display = value;
}
