/************************************************************
*  javascript.js                                            *
*    Contains additional javascript for pdnchildrens.org    *
*                                                           *
*  Version 001 -- Original Version.                         *
*                 1333293 -- Jim Currey                     *
*                 12/28/2009 -- Jose Rosado                 *
************************************************************/
/************************************************************
*  toggleView( strGroup, strItem )                          *
*    If passed group item is visible, hides the item.       *
*    If passed group item is not visible,                   *
*      hides all the groups items and makes the passed group*
*      item visible.                                        *
*                                                           *
*  strGroup - The name of the group of div's whose display  *
*             will be changed                               *
*  strItem  - The group item that who's display will be     *
*             toggled between visible and not visible       *
*************************************************************
*  NOTE: The IDs of the group items need to be in the format*
*       "groupname itemname". Items with the same group     *
*       name will be made to only have one item visible at  *
*       a time.                                             *
************************************************************/
function toggleView( strGroup, strItem )
{
  var elmItem;   // Group item who's view will be changed
  var lstDiv;    // List of div elements on page
  var intLength; // Used for string length
  var i;
  
  // Get item to toggle
  elmItem = document.getElementById( strGroup + " " + strItem );
  // If item not found, return to avoid javascript errors
  if( elmItem === null )
  {
    return;
  }
  
  // If item is not hidden
  if( elmItem.style.display !== "none" )
  {
    // Hide item
    elmItem.style.display = "none";
    
    // Return as all other items in group should already be hidden
    return;
  }
  
  // Get string length of group name
  intLength = strGroup.length;
  
  // Get list of all div's on page			
  lstDiv = document.getElementsByTagName( "div" );
  
  // Iterate through list of div's, hiding div's that belong to group
  for( i = 0; i < lstDiv.length; i++ )
  {
    // Get first part of the div's ID,
    //   if it matches the passed group name, hide div
    if( lstDiv[ i ].id.substring( 0, intLength ) === strGroup )
    {
      // Hide div
      lstDiv[ i ].style.display = "none";
    }
  }
  // All divs that are part of the passed group are now hidden
  
  // Display group item that was passed
  elmItem.style.display = "";
} // toggleView()
