/*
controlId = Control which fires the event
guidArray = Array of Guids for which controls are set to visible
controlArray = Array of control IDs to show/hide
validationControlArray = Array of control IDs to show/hide and enable/disable
*/
function OnSelectedIndexChanged(controlId, guidArray, controlArray, validationControlArray)  
{
  // Get the control which fires the event
  var control = document.getElementById(controlId); 

  if(control != null)    
  { 
    var foundMatch = false;
    
    // Loop through each guids and see if a match is found for control's selected value
    for(var i = 0; i < guidArray.length; i++)
    {
      if(control.value == guidArray[i])
      {
        foundMatch = true;
      }
    }

    // Found matching selected value
    if(foundMatch == true)    
    {  
      // Visible all controls in controlArray and validationControlArray
      // AND
      // Enable all validationControlArray
      ToggleDisplay('inline', controlArray, validationControlArray);    
    }    
    else    
    {      
      // Hide all controls in controlArray and validationControlArray
      // AND
      // Disable all validationControlArray
      ToggleDisplay('none', controlArray, validationControlArray);    
    }  
  }
}

function ToggleDisplay(isVisible, controlArray, validationControlArray)  
{
  if(controlArray != null)
  {
    // Loop through each control IDs in controlArray, find the control in document and set visibility
    for (var i = 0; i < controlArray.length; i++)
    {
      document.getElementById(controlArray[i]).style.display = isVisible;
    }
  }
  
  if(validationControlArray != null)
  {
      // Loop throuh each validation control IDs in array to enable/disable property
      for (var i = 0; i < validationControlArray.length; i++)
      {
        if(isVisible == 'inline')
        {
          ValidatorEnable(document.getElementById(validationControlArray[i]), true);
        }
        else
        {
          ValidatorEnable(document.getElementById(validationControlArray[i]), false);
        }
      }
  }
}