var isDOM = (document.getElementById ? true : false); 
var isIE6 = (document.getElementById && document.all);
var isIE4 = ((document.all && !isDOM) ? true : false);
var isNS4 = (document.layers ? true : false);

if (!isNS4)
  document.write("<link type='text/css' rel='stylesheet' href='" + ieMozNS7_StyleSheet + "' title='ieMozNS7_MenuLook'>");
else
  document.write("<link type='text/css' rel='stylesheet' href='" + NS4_StyleSheet + "' title='NS4_MenuLook'>");
  
function getRefById(objId) {
  if (isNS4) return getRefByIdNS4(objId);
  if (isIE4) return document.all[objId];
  if (isDOM) return document.getElementById(objId);
}

function getRefByIdNS4(objId,doc) {
  var objRef = null;
  if (!doc)
    doc = document;
  if (doc.layers[objId])
    return doc.layers[objId];
  for (var i = 0; i < doc.layers.length; i++)
    {
    objRef = getRefByIdNS4(objId,doc.layers[i].document);
    if (objRef)
      return objRef;
    }
  return objRef;
}

function gotoUrl(aTagId) {
  document.location = getRefById(aTagId).href;
}
/* This function was created so that top-level menu items could have URLs for
 * Netscape 4.79 and screen readers since they cannot expand/collapse the menu
 * with Javascript.
 * In other browsers, it will follow the link depending on the value of 
 * bFollowLink which must be declared in your menu include.
 */
function followLink() {
  if (isNS4) return true;
  return bFollowLink;
}
function max(first,second)
{
  return first > second ? first : second;
}
function screenHeight()
{
  if (typeof(window.innerWidth) == 'number')
    return innerHeight;
  else if (document.documentElement
       && (document.documentElement.clientWidth || document.documentElement.clientHeight))
    return document.documentElement.clientHeight;
  else if (document.body
       && (document.body.clientWidth || document.body.clientHeight))
    return document.body.clientHeight;
  return 0;
}
function screenWidth()
{
  if (typeof(window.innerWidth) == 'number')
    return innerWidth;
  else if (document.documentElement
       && (document.documentElement.clientWidth || document.documentElement.clientHeight))
    return document.documentElement.clientWidth;
  else if (document.body
       && (document.body.clientWidth || document.body.clientHeight))
    return document.body.clientWidth;
  return 0;
}
function setHeights(menuId,contentId,containerId)
{
  if (isNS4)
    return;
  var menu       = getRefById(menuId)
  var menuHeight = menu.offsetHeight;
  var cont       = getRefById(contentId);
  var contHeight = cont.offsetHeight;
  var container  = getRefById(containerId);
  var maxHeight  = max(menuHeight,max(contHeight,screenHeight()));
  menu.style.height = maxHeight;
  cont.style.height = maxHeight;
  container.style.height = maxHeight;
}
function initSubMenus(menu)
{
  var theMenu = getRefById(menu.MenuDivID);
  var theULs  = theMenu.getElementsByTagName('ul');
  for (var iCtr = 0; iCtr < theULs.length; iCtr++)
  {
    if (theULs[iCtr].className == menu.SubMenuClass
    &&  menu.AlwaysExpandedMenus
    &&  menu.AlwaysExpandedMenus.indexOf(theULs[iCtr].id) != -1)
    {
      theULs[iCtr].className = theULs[iCtr].id;
      var theLI = getRefById('M' + theULs[iCtr].id);
      theLI.className = theLI.id;
      menuClick(menu,theULs[iCtr].id);
    }
  }
}
function collapseSubMenus(menu)
{
  var theMenu = getRefById(menu.MenuDivID);
  var theULs  = theMenu.getElementsByTagName('ul');
  for (var iCtr = 0; iCtr < theULs.length; iCtr++)
  {
    if (theULs[iCtr].className == menu.SubMenuClass
    && (!menu.AlwaysExpandedMenus
     || (menu.AlwaysExpandedMenus 
     &&  menu.AlwaysExpandedMenus.indexOf(theULs[iCtr].id) == -1)))
    {
      theULs[iCtr].style.display = 'none';
      var theLI = getRefById('M' + theULs[iCtr].id);
      theLI.className = menu.MenuItemWSubClass;
    }
  }
}
function menuClick(menu,subMenuId)
{
  if (isNS4)
    return;

  var subMenu = getRefById(subMenuId);
  var displayType = subMenu.style.display;

  if (menu.Initialized && !menu.ExpandMultipleMenues)
    collapseSubMenus(menu);

  if (displayType == 'block'
  && (!menu.AlwaysExpandedMenus
  ||  (menu.AlwaysExpandedMenus &&  menu.AlwaysExpandedMenus.indexOf(subMenuId) == -1)))
  {
    subMenu.style.display = 'none';
    var theLI = getRefById('M' + subMenuId);
    if (subMenu.className == menu.SubMenuClass)
      theLI.className = menu.MenuItemWSubSelectedClass;
  }
  else
  {
    subMenu.style.display = 'block';
    var theLI = getRefById('M' + subMenuId);
    if (subMenu.className == menu.SubMenuClass)
      theLI.className = menu.MenuItemWSubClickedSelectedClass;
  }
  /*setHeights(menu.MenuContainerID,menu.ContentDivID,menu.FullPageDivID,menu.BottomBorderColor);*/
}
function selectItem(menu,menuObj)
{
  
  if (menu.menuItemSelected)
    unselectItem(menu.menuItemSelected);
  var theLI = menuObj;
  var theClass = theLI.className;

  // Main menu item w/o submenu
       if (theClass == menu.MenuItemClass)
    theLI.className  = menu.MenuItemSelectedClass;
  // Main menu item with submenu
  else if (theClass == menu.MenuItemWSubClass)
    theLI.className  = menu.MenuItemWSubSelectedClass;
  else if (theClass == menu.MenuItemWSubClickedClass)
    theLI.className  = menu.MenuItemWSubClickedSelectedClass;
  // Submenu item
  else if (theClass == menu.SubItemClass)
    theLI.className  = menu.SubItemSelectedClass;
  else if (theClass == theLI.id)
    {
    theLI.className = theLI.id + '_Selected';
    //alert("selectItem(" + theLI.className + ")");
    }
  menu.menuItemSelected = menuObj;
  return;
}

function unselectItem(menu,menuObj)
{
  var theLI = menuObj;
  var theClass = theLI.className;

       if (theClass == menu.MenuItemSelectedClass)
    theLI.className  = menu.MenuItemClass;
  // Main menu item with submenu
  else if (theClass == menu.MenuItemWSubSelectedClass)
    theLI.className  = menu.MenuItemWSubClass;
  else if (theClass == menu.MenuItemWSubClickedSelectedClass)
    theLI.className  = menu.MenuItemWSubClickedClass;
  // Submenu item
  else if (theClass == menu.SubItemSelectedClass)
    theLI.className  = menu.SubItemClass;
  else if (theClass.indexOf(theLI.id) != -1)
    {
    theLI.className  = theLI.id;
    //alert("unselectItem(" + theLI.className + ")");
    }
  menu.menuItemSelected = null;
  return;
}

function cssMenu(menuId)
{
  this.MenuDivID                        = menuId;
  this.MenuItemClass                    = "";
  this.MenuItemSelectedClass            = "";
  this.MenuItemWSubClass                = "";
  this.MenuItemWSubSelectedClass        = "";
  this.MenuItemWSubClickedClass         = "";
  this.MenuItemWSubClickedSelectedClass = "";
  this.SubItemClass                     = "";
  this.SubItemSelectedClass             = "";
  this.SubMenuClass                     = "";
  this.ExpandMultipleMenus              = false;
  this.AlwaysExpandedMenus              = null;
  this.menuItemSelected                 = null;
  this.Initialized                      = false;
}

