/**** this block of code adds CSS Hover functionality to older browsers ****/
/**isIE = (document.all) ? true:false;

sfHover = function() { 
	var sfEls = document.getElementById("lsm").getElementsByTagName("li"); 
	for (var i=0; i<sfEls.length; i++) 
		{ 
			sfEls[i].onmouseover=function() { this.className+=" sfhover"; } 
			sfEls[i].onmouseout=function() { this.className=this.className.replace(new RegExp(" sfhover\\b"), ""); } 
		} 
	} 
	
if (window.attachEvent) window.attachEvent("onload", sfHover);**/
/*** end Hover hack code **************************************************/

function buildG3Menu()
  {
  prepareMenu();
  setPage();
  collapseMenu();
//  displayMenu();
/*addLoadEvent(hideMenu);
addLoadEvent(prepareMenu);
addLoadEvent(setPage); 
addLoadEvent(collapseMenu);
addLoadEvent(displayMenu); */
  }
function buildG3MenuUS()
{	
	setPage();
}
function displayMenu()
{
/* alert("displayMenu is called"); */
  if (!document.getElementById("lsm")) 
    return false;
  else
    document.getElementById("lsm").style.display = "";
}

function hideMenu()
{
/*alert("hideMenu is called"); */
  if (!document.getElementById("lsm")) 
    return false;
  else
    {
    document.getElementById("lsm").style.display = "none";
/*     hideTopLevels(); */
    }
}

function collapseMenu(node) {
  if (!document.getElementById) return false;
  if (!document.getElementById("lsm")) return false;
  if (!node) node = document.getElementById("lsm");

  if (node.childNodes.length > 0) {
    for (var i=0; i<node.childNodes.length; i++) {
      var child = node.childNodes[i];
      if (child.nodeName.toLowerCase() == "ul" && child.parentNode.id != "lsm" && child.parentNode.className != "current") {
  /* alert("collapseMenu is called"); */
        child.style.display = "none";        
      }
/*      if (child.nodeName.toLowerCase() == "ul")
      {
          node.className = "MenuContainer";
      }
      else if (node.id != "lsm" && node.className != "MenuContainer")
        node.className = "MenuItem";
*/
      collapseMenu(child);
    }
  }
}

function prepareMenu() 
{
 /* alert("prepareMenu is called"); */
  if (!document.getElementById || !document.getElementsByTagName) return false;
  if (!document.getElementById("lsm")) return false;
  
  var links = document.getElementById("lsm").getElementsByTagName("a");

  for (var i=0; i<links.length; i++) 
  {
    links[i].onclick = function() 
      {
      toggleMenu(this.parentNode.getElementsByTagName("ul")[0], this); // was this.href
      // return links[i].href; //false;
//      if (!this.parentNode.getElementsByTagName("ul")[0]) 
//      {
//        alert("pause!");
        // setActiveMenu(this);
//        }
      }
  }
}

function toggleMenu(node, link)
{
/* alert("toggleMenu is called"); */
  if (!document.getElementById) return false;
  if (!link) return false;
  if (!node) location.href = link.href;
	// Collapse all nodes, and only show clicked node (when clicking top level of menu)
//	alert (node.parentNode.parentNode.parentNode.id);
//  if (node.parentNode.parentNode.parentNode.nodeType == 1 && node.parentNode.parentNode.parentNode.id == "lsm") 
//      hideTopLevels();
//  if (!node)
//  {
//if (!node) alert("Node is NULL! Link is: " + link + "parentNode:");
if (!node) return;

    if (node.style.display == "")
      node.style.display = "none";
    else
      {
      node.style.display = "";
      setActiveMenu(node);
      }
      
if (!node) alert("still clicking!");      
//   }
//   else
//    alert("Node is NULL! Link is: " + link);
}

function addLoadEvent(func) 
{
  var oldonload = window.onload;
  
  if (typeof window.onload != 'function')
    window.onload = func;
  else 
  {
    window.onload = function() 
      {
      oldonload();
      func();
      }
  }
}

function hideTopLevels() 
{
/* alert("hideTopLevels is called!"); */
  if (!document.getElementById) return false;
  if (!(node = document.getElementById("lsm"))) return false;

  // there can be more than one top level UL in menu's DIV 
  var topNodes = document.getElementById("lsm").getElementsByTagName("ul");
  for (var k=0; k<topNodes.length; k++) 
  {
    if (topNodes[k].childNodes.length > 0) 
    {
      for (var i=0; i<topNodes[k].childNodes.length; i++) 
      {
        var child = topNodes[k].childNodes[i];

        for(var j=0; j<child.childNodes.length; j++) 
        {
          var grandchild = child.childNodes[j];
          if (grandchild.nodeName.toLowerCase() == "ul") 
          {
            if (grandchild.style.display == '') 
              grandchild.style.display = "none";
          }
        }
      }
    }
  }
}

// extract the file name from a URL 
//(if input is '/files/index.html', output is 'index')
function extractPageName(hrefString)
{
/* alert("extractPageName is called"); */
  var arr = hrefString.split('.');
  arr = arr[arr.length-2].split('/');
  return arr[arr.length-1].toLowerCase();		
}

// search through all the links in array, if one points to
// the same file, apply the class .current to it and to its 
// parent
function setActiveMenu(currentElement)
{
/* alert("setActiveMenu is called"); */
  if (!currentElement.parentNode || currentElement.parentNode.id == "lsm") return;
  currentElement.parentNode.className = 'current';
  setActiveMenu(currentElement.parentNode);
  //currentElement.parentNode.parentNode.parentNode.className = 'current';
}

// call this method from your page
function setPage()
{
/* alert("setPage is called");  */
  var strCurrentPageName;
  
  if(document.location.href) 
    strCurrentPageName = extractPageName(document.location.href);
  else
    strCurrentPageName = extractPageName(document.location);
    
//  if (strCurrentPageName.indexOf("#") == -1)
    
  if (document.getElementById('lsm')!=null)
  {
    // find the A (link) element which target matches current page name
    if (!document.getElementsByTagName)
      return null;

    var anchors = document.getElementsByTagName("a");
  
    for(var i=0; i < anchors.length ; i++)
    {
      var a = anchors[i];
     
      var href = a.href.toLowerCase();
      if ((href.indexOf("/" + strCurrentPageName + ".") != -1) && (href.indexOf("#") == -1))
      {
        setActiveMenu(a);
      }
//      else if (href.indexOf("#") != -1)
//        alert("Found #");
    }
  }
}

function popUp(URL) {
  day = new Date();
  id = day.getTime();
  eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=630,height=400');");
}

/*****************************************
  MENU AS OF LATE FRIDAY April 21, 2006
******************************************
addLoadEvent(setPage);
addLoadEvent(collapseMenu);
addLoadEvent(prepareMenu);

function collapseMenu(node) {
  if (!document.getElementById) return false;
  if (!document.getElementById("lsm")) return false;
  if (!node) node = document.getElementById("lsm");

  if (node.childNodes.length > 0) {
    for (var i=0; i<node.childNodes.length; i++) {
//alert ("in collapseMenu(node) inner loop");    
      var child = node.childNodes[i];
//      if (child.tagName.toString() == "") continue;
 //alert ("in collapseMenu(node) with child:" + child.nodeName);
      if (child.nodeName.toLowerCase() == "ul" && child.parentNode.id != "lsm" && child.parentNode.className != "current") {
//alert ("in collapseMenu(node) with child:" + child.tagName);
//alert("hide in collapseMenu: " + node.tagName);  
        child.style.display = "none";
      }
      collapseMenu(child);
    }
  }
}

function prepareMenu() {
//alert("exec prepareMenu()");
 if (!document.getElementById || !document.getElementsByTagName) return false;
 if (!document.getElementById("lsm")) return false;

 var links = document.getElementById("lsm").getElementsByTagName("a");
 for (var i=0; i<links.length; i++) {
  links[i].onclick = function() {
//alert("this.href: " + this.href);
//alert("this.parentNode.tagName: " + this.parentNode.tagName);
   toggleMenu(this.parentNode.getElementsByTagName("ul")[0], this); // was this.href
   return false;
  }
 }
}

function toggleMenu(node, link) {
//alert ("link: " + link.href);
 if (!document.getElementById) return false;
 if (!link) return false;
 if (!node) location.href = link.href;
//alert ("in toggleMenu");

//alert (node.tagName);
	// Collapse all nodes, and only show clicked node (when clicking top level of menu)
 if (node.parentNode.parentNode.parentNode.id == "lsm") {
   hideTopLevels();
  }
//alert ("past hideTopLevels");
 if (node.style.display == "") {
//alert("hide in toggleMenu: " + node.tagName);  
  node.style.display = "none";
 } else {
  node.style.display = "";
//alert("about to call setPage() from toggleMenu()");  
//  setPage();
 }
}

function addLoadEvent(func) {
 var oldonload = window.onload;
 if (typeof window.onload != 'function') {
  window.onload = func;
 } else {
  window.onload = function() {
   oldonload();
   func();
  }
 }
}

function hideTopLevels() {
//alert ("in hideTopLevels()");
 if (!document.getElementById) return false;
 if (!(node = document.getElementById("lsm"))) return false;
//alert("got past hideTopLevel() check");

  // there can be more than one top level UL in menu's DIV 
  var topNodes = document.getElementById("lsm").getElementsByTagName("ul");
  for (var k=0; k<topNodes.length; k++) 
  {
//alert("in big loop k: " + k + " out of total: " + topNodes.length);
    if (topNodes[k].childNodes.length > 0) 
    {
      for (var i=0; i<topNodes[k].childNodes.length; i++) 
      {
        var child = topNodes[k].childNodes[i];

        for(var j=0; j<child.childNodes.length; j++) 
        {
          var grandchild = child.childNodes[j];
//alert ("grandchild.nodeName.toLowerCase: " + grandchild.nodeName.toLowerCase());
          if (grandchild.nodeName.toLowerCase() == "ul") 
          {
//alert ("about to hide grandchild in hideTopLevels");          
            if (grandchild.style.display == '') 
            {
//alert("hide: grandchild." + grandchild.tagName);  
              grandchild.style.display = "none";
            }
          }
        }
      }
    }
  }

}


// extract the file name from a URL 
//(if input is '/files/index.html', output is 'index')
function extractPageName(hrefString)
{
  var arr = hrefString.split('.');
  arr = arr[arr.length-2].split('/');
  return arr[arr.length-1].toLowerCase();		
}

// search through all the links in array, if one points to
// the same file, apply the class .current to it and to its 
// parent
function setActiveMenu(currentElement)
{
  currentElement.parentNode.className = 'current';
  currentElement.parentNode.parentNode.parentNode.className = 'current';
}

// call this method from your page
function setPage()
{
//alert("entered setPage()");
  var strCurrentPageName;
  
  if(document.location.href) 
    strCurrentPageName = extractPageName(document.location.href);
  else
    strCurrentPageName = extractPageName(document.location);
    
  if (document.getElementById('lsm')!=null)
  {
    // find the A (link) element which target matches current page name
    if (!document.getElementsByTagName) {
      return null;
    }
    var anchors = document.getElementsByTagName("a");
//alert("about to start looking for matching link: " + strCurrentPageName + " in setPage()");
    
    for(var i=0; i < anchors.length; i++)
    {
      var a = anchors[i];
      var href = a.href.toLowerCase();
// alert("current link: " + href);      
      if ((href.indexOf(strCurrentPageName) != -1) && (href.indexOf("#") == -1))
      {
//alert("should set active link now!");
        setActiveMenu(a);
      }
    }

    // setActiveMenu(document.getElementById(extractPageName(hrefString)));
  }
}
*/

/***********************************************
* Switch Menu script- by Martial B of http://getElementById.com/
* Modified by Dynamic Drive for format & NS4/IE4 compatibility
* Visit http://www.dynamicdrive.com/ for full source code
* Modified by John Davenport Scheuer for nested sub menus
***********************************************/
/*
var persistmenu="yes" //"yes" or "no". Make sure each SPAN content contains an incrementing ID starting at 1 (id="sub1", id="sub2", etc)
var persisttype="sitewide" //enter "sitewide" for menu to persist across site, "local" for this page only
var lastactivated = false;

function SwitchMenu(obj)
  {
    if(document.getElementById){
	    var el = document.getElementById(obj);

	    if(el.style.display == "block"){ //DynamicDrive.com change
		    el.style.display = "none";
		    lastactivated = el.parentNode;
	    }else{
		    if (lastactivated) 
		      {CollapseMenu(lastactivated);}
		      
		    ExpandMenu(el);
		    lastactivated = el;
	    }
	    return false;
    }
  }

function ExpandMenu(obj) 
  {
  if (document.getElementById)
    {
	  var pl = obj;
	  var to=10;
	  var pid = pl.id;
	  
	  while (pid != "lsm" && to>0) 
	    {
		  to--;
		  
		  if (pid != "") 
		    {
		    pl.style.display = "block";
		    }
		  
		  pl = pl.parentNode;
		  pid = pl.id;
	    }
    }	
  }

function CollapseMenu(obj) 
  {
    if (document.getElementById)
      {
	    var pl = obj;
	    var to=10;
	    var pid = pl.id;

	    while (pid != "lsm" && to>0) 
	      {
		    to--;
	
		    if (pid != "") {pl.style.display = "none";}
  		    pl = pl.parentNode;
	
		    pid = pl.id;
	      }
      }
  }

function get_cookie(Name) 
  {
  var search = Name + "="
  var returnvalue = "";

  if (document.cookie.length > 0) 
    {
    offset = document.cookie.indexOf(search)
    
    if (offset != -1) { 
      offset += search.length
      end = document.cookie.indexOf(";", offset);
  
      if (end == -1) end = document.cookie.length;
        returnvalue=unescape(document.cookie.substring(offset, end))
      }
    }
    
  return returnvalue;
  }

function onloadfunction(){
  if (persistmenu=="yes"){
	  var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname;
	  var cookievalue=get_cookie(cookiename);
  // Debug probe
  //var str = "cookiename = "+ cookiename+"; cookievalue = "+cookievalue;
  //window.status = str;
  // Debug probe ends
	  if (cookievalue!="" && cookievalue!="undefined") {
		  var el = document.getElementById(cookievalue);
		  ExpandMenu(el);
		  lastactivated = el;
	  }
  }
}

function savemenustate()
{
	var blockid = lastactivated.id;
	var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
	var cookievalue=(persisttype=="sitewide")? blockid+";path=/" : blockid
	document.cookie=cookiename+"="+cookievalue
}
/*
if (window.addEventListener)
  window.addEventListener("load", onloadfunction, false)
else if (window.attachEvent)
  window.attachEvent("onload", onloadfunction)
else if (document.getElementById)
  window.onload=onloadfunction

if (persistmenu=="yes" && document.getElementById)
  window.onunload=savemenustate;
  
<script language="javascript"> setPage()</script>

  
  */
  