//Notes:
//1. For normal sidebar highlighting (more like bookmarking) of links, 
//   the divs must have unique names and look like:
//      <div id="test1" name="test1" class="miscSidebarNavOff">
//   and all divs must be set to the off class.
//   At the top of the page you must have this in a script section:
//      var onIdName=["test1","test3"];
//      var onClassName=["miscSidebarNavOn","miscSidebarNavOn"];
//   which saves which divs to turn on and to what class.
//   You must also have this function in the body's onLoad:
//      SidebarHighlight();
//
//2. For in-page section-switch highlighting,
//   the divs must have the same names and look like:
//      <div id="switchName" name="switchName" class="miscSidebarNavOn">
//   and the div to start on, should be already set to the on class.
//   The links must have unique names and look like this:
//      <a onclick="doSwitchHighlight(this);" id="navHosted" name="navHosted" href="#hosted">
//   The blocks containing the sections should start like this:
//      <blockquote id="navHosted"> 
//   At the top of the page you must have this in a script section:
//      var SwitchIdName=["switchName"];
//      var SwitchClassNameOn=["miscSidebarNavOn"];
//      var SwitchClassNameOff=["miscSidebarNavOff"];
//   which saves what the div grouping is called and what to turn them
//   on and off to.
//   You must also have this function in the body's onLoad:
//      fixLinks(); hideDivs('hosted'); startSwitchHighlight();
//   Note: you must also include the tab.js script.


function SidebarHighlight(){
  var id;
  id=0;
  while (window.onIdName[id] && window.onClassName[id])
  {
    var e=document.getElementsByName(onIdName[id]);
    for(var i=0;i<e.length;i++)
    {
       e[i].className = onClassName[id];
    }
    id++;
  }
}

//Called onLoad.  Checks for tab cookie.  If exists, turn on that tab.
function startSwitchHighlight(){
  var curElement;
  var i;

  var tabCookie;
  tabCookie = getCookie('switchTabName');
  //if cookie set, switch on that tab
  if (tabCookie != null) {
	  curElement = document.getElementById(tabCookie);
     doSwitchHighlight(curElement);
  }
}

//Called onClick of link.  Saves cookie with tab clicked (for refresh).
function doSwitchHighlight(curElement){
  var curSwitchIdName;
  var id;
  
  //set tab cookie with tab name
  setCookie('switchTabName', curElement.id);
  
  //curSwitchIdName = curElement.parentElement.id; //only works in IE
  curSwitchIdName = curElement.parentNode.id;
  id=0;
  //Loops thru all parent switch structures
  while (window.SwitchIdName[id] && window.SwitchClassNameOn[id] && window.SwitchClassNameOff[id])
  {
    //Finds current parent element structure
    if(curSwitchIdName == window.SwitchIdName[id]) {

      //Turn all switch elements of current (type) off
      var e=document.getElementsByName(SwitchIdName[id]);
      for(var i=0;i<e.length;i++)
      {
         e[i].className = SwitchClassNameOff[id];
      }
      
      //Turn current switch element on
      //curElement.parentElement.className = window.SwitchClassNameOn[id]; //only works in IE
      curElement.parentNode.className = window.SwitchClassNameOn[id];
    }
    id++;
  }
}


