//******************************************************************************
// toggleMenu(menu)
// This function toggles the state of a collapsible menu.
//   menu    Reference to menu to toggle.
//******************************************************************************

function toggleMenu(menu)
{
  var div, img, re1, re2;
  var p;
  if(document.getElementById)
  {
    // Retrieve div tag for submenu
    if (menu.parentNode)
      p = menu.parentNode;
    while (p.nextSibling && p.nextSibling.tagName != "DIV")
      p = p.nextSibling;
    if(p.nextSibling && p.nextSibling.tagName == "DIV")
      div=p.nextSibling;
    else 
    	return false;
    // Retrieve image for expandable menu
    if(menu.firstChild && menu.firstChild.tagName == "IMG")
      img=menu.firstChild;
    else 
      return false;
    // Set up regular expressions for switching div classes
    re1 = /hidden/;
    re2 = /visible/;
    if (re1.test(div.className))
    {
      // Switch image
      img.src = "/images/menuMinus.gif";
      // Switch class
      div.className = div.className.replace(re1, "visible");
    }
    else if (re2.test(div.className))
    {
      // Switch image
      img.src = "/images/menuPlus.gif";
      // Switch class
      div.className = div.className.replace(re2, "hidden");
    }
  }
  return true;
}

//******************************************************************************
// activateButton(img)
// This function activates the image on a button when the mouse hovers over it.
//   img    Reference to image to activate.
//******************************************************************************

function activateButton(link)
{
  var img, re1, re2, matches
  // Retrieve image for button
  if(link.firstChild && link.firstChild.tagName == "IMG")
    img=link.firstChild;
  else 
    return false;
  re1 = /-on\./
  re2 = /\.[^\.]+$/
  if (document.getElementById)
  {
    if (!re1.test(img.src))
    {
      matches = re2.exec(img.src);
      img.src = img.src.replace(re2, "-on" + matches[0]);
    }
  }
}

//******************************************************************************
// restoreButton(img)
// This function restores the image on a button when the mouse leaves it.
//   img    Reference to image to restore.
//******************************************************************************

function restoreButton(link)
{
  var img, re1, re2, matches
  // Retrieve image for button
  if(link.firstChild && link.firstChild.tagName == "IMG")
    img=link.firstChild;
  else 
    return false;
  re1 = /-on\.[^.]+$/
  re2 = /\.[^\.]+$/
  if (document.getElementById)
  {
    if (re1.test(img.src))
    {
      matches = re2.exec(img.src);
      img.src = img.src.replace(re1, matches[0]);
    }
  }
}

//******************************************************************************
// Scripts from http://www.alistapart.com/stories/alternate/
// These scripts are for switching style sheets.  Only the needed scripts were
// copied to here.
//******************************************************************************
function setActiveStyleSheet(title) 
{
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) 
  {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) 
    {
      a.disabled = true;
      if(a.getAttribute("title") == title) 
        a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) 
  {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) 
      return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() 
{
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) 
  {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("rel").indexOf("alt") == -1 && a.getAttribute("title")) 
      return a.getAttribute("title");
  }
  return null;
}

