/*********************************************************************************
'** This Module Contains Routines Used To Display Menus Using DIVs and HREF links
'** that contain specific classnames. Any sub-menus need 2 SPANS in the parent.
'** Revisions include fixes to hover widths and active menu/deactivation gleened from BrainJar.com.
'**
'** Current Revision Date  : 11/21/2004
'********************************************************************************/
var bolShowSubMenu; var objMenuActive = null; var objMenuTimer;

// Find Location Of HTML Object On The Page
function getLocation(objHTML)
 {var intX = 0; var intY = 0;
  while (objHTML) {intY += objHTML.offsetTop; intX += objHTML.offsetLeft; objHTML = objHTML.offsetParent; }
  return [intX, intY]; }

// Find Parent Object With Given Tag/Class
function findParentClass(objChild, strTag, strClass)
 {var bolWild = false;
  if (strClass.substring(strClass.length-1,strClass.length) == "%")
   {bolWild = true; strClass = strClass.substring(0,strClass.length-1); };
  while (objChild)
    {if (objChild.tagName && (objChild.tagName == strTag))
      {if (objChild.className == strClass || ((bolWild == true) && (objChild.className.substring(0,strClass.length) == strClass))) return objChild;}
     objChild = objChild.parentNode; }
  return objChild; }

// Main Routine For Showing Menu When Menu Is Clicked
function menuClick(objButton, strMenu, lngPlace)
 {if (objMenuTimer) clearTimeout(objMenuTimer);
  if (!objButton.objMenu)
   {if (strMenu.length > 0) objButton.objMenu = document.getElementById(strMenu);
    if (!objButton.objMenu) {menubarReset(objMenuActive); objMenuActive = null; return false; };
    if (!objButton.objMenu.bolMenufix)  menuFix(objButton.objMenu,""); }
  if (objMenuActive) menubarReset(objMenuActive);
//  if (objButton != objMenuActive)
//   {menubarShow(objButton, lngPlace); objMenuActive = objButton;  }
//   else
//   {objMenuActive = null; };
  menubarShow(objButton, lngPlace); objMenuActive = objButton;
  objButton.blur();
  return false; }

// If any other menubar item is active, switch to this one.
function menubarSelect(objButton, strMenu, lngPlace)
 {if (objMenuActive && objMenuActive != objButton) menuClick(objButton, strMenu, lngPlace);}

// Close sub menus when main/sub menu is selected
function menuSelect(objMenu)
 {if (bolShowSubMenu == true) {bolShowSubMenu = null; return; };
  if (objMenu.activeItem) submenuClose(objMenu); }

// Show sub menu when menu item is active
function submenuSelect(objItem, strSub) {
  var strVar1 = "";
  var objMenu = findParentClass(objItem, "DIV", "menu%");
  if (objMenu.activeItem) submenuClose(objMenu);
  objMenu.activeItem = objItem;
  if (objItem.className.substring(objItem.className.length-1,objItem.className.length) != "A") objItem.className = objItem.className + "A";
  if (!objItem.objSubmenu) objItem.objSubmenu = document.getElementById(strSub);
  if (objMenu.userVal1) {strVar1 = String(objMenu.userVal1); objItem.objSubmenu.userVal1 = strVar1; };
  if (!objItem.objSubmenu.bolMenufix || strVar1.length > 0) menuFix(objItem.objSubmenu, strVar1);
  var intLoc = getLocation(objItem);
  intLoc[0] += objItem.offsetWidth;
  objItem.objSubmenu.style.left = intLoc[0] + "px";
  objItem.objSubmenu.style.top  = intLoc[1] + "px";
  objItem.objSubmenu.style.display = "";
  bolShowSubMenu = true; }

// Close All Submenus - Recursively
function submenuClose(objMenu) {
  if (!objMenu || !objMenu.activeItem) return;
  if (objMenu.activeItem.objSubmenu)
   {submenuClose(objMenu.activeItem.objSubmenu);
    objMenu.activeItem.objSubmenu.style.display = "none";
    objMenu.activeItem.objSubmenu = null;  }
  if (objMenu.activeItem.className.substring(objMenu.activeItem.className.length-1,objMenu.activeItem.className.length) == "A")
   {objMenu.activeItem.className = objMenu.activeItem.className.substring(0,objMenu.activeItem.className.length-1); };
  objMenu.activeItem = null;}

// Show menu under the menubar
function menubarShow(objButton, lngPlace)
 {if (objButton.className.substring(objButton.className.length-1,objButton.className.length) != "A") objButton.className = objButton.className + "A";
  var intLoc = getLocation(objButton);
  objButton.objMenu.style.display = "";
  switch (lngPlace)        //Where To Show Menu - 1: Underneath object 2: Right of Object 3: Underneath Right Aligned
   {case 2 :
     intLoc[0] += objButton.offsetWidth; break;
    case 3 :
     intLoc[1] += objButton.offsetHeight;
     intLoc[0] += objButton.offsetWidth + 2;
     intLoc[0] -= objButton.objMenu.offsetWidth; break;
    default :
     intLoc[1] += objButton.offsetHeight; };
  objButton.objMenu.style.left = intLoc[0] + "px";
  objButton.objMenu.style.top  = intLoc[1] + "px"; }

// Hide menu under the active menubar
function menubarReset(objButton)
 {if (!objButton) return false;
  if (objButton.className.substring(objButton.className.length-1,objButton.className.length) != "A")
   {if (objButton.activeItem) submenuClose(objButton);
    objButton.style.display = "none"; }
   else
   {objButton.className = objButton.className.substring(0,objButton.className.length-1);
    if (objButton.objMenu)
     {submenuClose(objButton.objMenu); objButton.objMenu.style.display = "none";  }; }; }

// Used To Reset Menu On Mouseout If Not Moving To New Menu Item
function checkReset(objEvent)
 {var objClick;
  if (!objEvent) var objEvent = window.event;
  if (objEvent.toElement) objClick = objEvent.toElement; else if (objEvent.relatedTarget) objClick = objEvent.relatedTarget;
  if (objClick && objClick.nodeType == 3) objClick = objClick.parentNode;
  if (!findParentClass(objClick, "DIV", "menu%"))
   {objMenuTimer = setTimeout("menubarReset(objMenuActive); objMenuActive = null;",400); }; }

// Show context menu from a right click
function menuContext(objEvent, strMenu, lngPlace, strVar1)
 {var objClick, bolContext;
  if (!objEvent) var objEvent = window.event;
  if (objEvent.target) objClick = objEvent.target; else if (objEvent.srcElement) objClick = objEvent.srcElement;
  if (objClick.nodeType == 3) objClick = objClick.parentNode;
  if (objEvent.which) {bolContext = (objEvent.which == 3); } else if (objEvent.button) {bolContext = (objEvent.button == 2); };
  if (bolContext == true)
   {if (objMenuActive) {menubarReset(objMenuActive); objMenuActive = null; };
    objClick.blur();
    var objMenu = document.getElementById(strMenu);
    if (objMenu)
     {objMenu.userVal1 = strVar1;
      menuFix(objMenu, strVar1);
      switch (lngPlace)        //Where To Show Menu - 1: Mousepoint 2: Underneath object 3: Right of Object
       {case 2 :
         var intLoc = getLocation(objClick);
         intLoc[1] += objClick.offsetHeight; break;
        case 3 :
         var intLoc = getLocation(objClick);
         intLoc[0] += objClick.offsetWidth; break;
        default :
         var intLoc = [];
         if (objEvent.pageX || objEvent.pageY)
          {intLoc[0] = objEvent.pageX; intLoc[1] = objEvent.pageY; }
          else if (objEvent.clientX || objEvent.clientY)
          {intLoc[0] = objEvent.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
           intLoc[1] = objEvent.clientY + document.body.scrollTop + document.documentElement.scrollTop;  }; };
      objMenu.style.left = intLoc[0] + "px";
      objMenu.style.top  = intLoc[1] + "px";
      objMenu.style.display = "";
      objMenuActive = objMenu; };
    return false; }
    else
    {return true; }; }

// Hide active menu / submenu if not pagewide mousedown event's target
function menuCheck(objEvent)
 {var objClick, bolContext;
  if (!objEvent) var objEvent = window.event;
  if (objEvent.target) objClick = objEvent.target; else if (objEvent.srcElement) objClick = objEvent.srcElement;
  if (objClick.nodeType == 3) objClick = objClick.parentNode;
  if (objEvent.which) {bolContext = (objEvent.which == 3); } else if (objEvent.button) {bolContext = (objEvent.button == 2); };
  if (bolContext == true)
   {if (objMenuActive) {menubarReset(objMenuActive); objMenuActive = null; }; return false; }
   else
   {if (!objMenuActive) return;
    if (objClick == objMenuActive) return;
    if (!findParentClass(objClick, "DIV", "menu%"))
     {menubarReset(objMenuActive); objMenuActive = null;  }; };
  return true; }

// Fix links and menu widths
function menuFix(objMenu, strVar1)
 {var strLink;
  var objListA, objListS;
  var intMWidth, intLoop1;
  objListA = objMenu.getElementsByTagName("A");
  if (!objListA || objListA.length < 1) return;
  intMWidth = objListA[0].offsetWidth;
  for (intLoop1 = 0; intLoop1 < objListA.length; intLoop1++)
    {if (objListA[intLoop1].realLink)
      {strLink = objListA[intLoop1].realLink;
       objListA[intLoop1].href = strLink.replace("%1",strVar1); }
      else if (objListA[intLoop1].href.indexOf("%1") > 0)
      {strLink = objListA[intLoop1].href;
       objListA[intLoop1].realLink = strLink;
       objListA[intLoop1].href = strLink.replace("%1",strVar1); };
     objListS = objListA[intLoop1].getElementsByTagName("SPAN");
     if (objListS && objListS.length == 2)
      {if ((objListS[0].offsetWidth + objListS[1].offsetWidth) != intMWidth) objListS[0].style.paddingRight = (intMWidth - (objListS[0].offsetWidth + objListS[1].offsetWidth)) + "px"; }; };
  var sType; sType = navigator.userAgent; if (sType.indexOf("MSIE") >= 0) objListA[0].style.width = intMWidth + "px";  //IE Width Fix
  objMenu.bolMenufix = true; }

// Fix Size Of Empty Div To Active Menu Item
function menuFixB(strMenu)
 {var objMenu = document.getElementById(strMenu);
  if (!objMenu) return false;
  var objListDiv = objMenu.getElementsByTagName("DIV");
  if (!objListDiv || objListDiv.length < 1) return;
  objListDiv[0].style.width = ((objMenuActive.offsetWidth - objListDiv[0].offsetWidth) + objListDiv[0].offsetWidth - 2) + "px";
  var objListDiv = objMenu.getElementsByTagName("TABLE");
  if (!objListDiv || objListDiv.length < 1) return;
  objMenu.style.width = objListDiv[0].offsetWidth + "px";//  alert(objListDiv[0].offsetWidth);
  }
