﻿//Navigation Menu

currentMenuItem = "";
menuItemNormal = "";

pageLoaded = false;

if (window.addEventListener)
  window.addEventListener("load", pageLoad, false);
else if (window.attachEvent)
  window.attachEvent("onload", pageLoad);

function pageLoad() {
  pageLoaded = true;
}

function setCurrentMenuItem(item, normal) {
  if(currentMenuItem != MM_findObj(item)) {
    currentMenuItem.src = menuItemNormal;
    currentMenuItem = MM_findObj(item);
    menuItemNormal = normal;
  }
}

function toggleList(id) {
  list = document.getElementById(id);
  if (list.style.display == "none") {
    list.style.display = "";
  } else {
    list.style.display = "none";
  }
}


// Browser Detection
isIE = isIE4 = isIE5 = isIE6 = isIE7 = isNS = isNS4 = isNS6 = isNS7 = isNS8 = isGecko = isOpera = isBlazer = isFlash5 = isFlashMX = false;
if (navigator.userAgent.indexOf('Gecko') > 0) isGecko = true;
if (navigator.appName.indexOf('Netscape') == 0) isNS = true;
if (navigator.appName.indexOf('Microsoft') == 0) isIE = true;
if (navigator.appName.indexOf('Opera') == 0) isOpera = true;
if (navigator.appName.indexOf('Blazer') == 0) isBlazer = true;
isUNIX = (window.navigator.appVersion.indexOf("X11") != -1) ||
         (window.navigator.appVersion.indexOf("Linux") != -1) ||
         (window.navigator.appVersion.indexOf("SunOS") != -1) ||
         (window.navigator.appVersion.indexOf("IRIX") != -1) ||
         (window.navigator.appVersion.indexOf("HP-UX") != -1);
isMac = (window.navigator.appVersion.indexOf("Mac") != -1);
isWindows = navigator.userAgent.indexOf("Windows 95") != -1 ||
            navigator.userAgent.indexOf("Windows 98") != -1 ||
            navigator.userAgent.indexOf("Windows NT") != -1;
isMacIE = (isMac && isIE);

// Browser Versions
if (isNS) {
  v = parseInt(navigator.appVersion);
  if(v == 4) {
    isNS4 = true;
  } else if(v == 5) {
    p = navigator.userAgent.lastIndexOf('/');
    v = parseInt(navigator.userAgent.substr(p+1));
    eval("isNS" + v + " = true");
  }
}

if (isIE) {
  v = parseInt(navigator.appVersion.substr(navigator.appVersion.indexOf("MSIE")+5));
  eval("isIE" + v + " = true");
}

if (isOpera) {
  v = parseInt(navigator.appVersion);
}

// DHTML menu functions
var timeout;
var menus = Array();

function DOMBrowser() {
	return document.body && document.body.style && document.getElementById;
}
function getX(elem) {
  var x = 0;
  if (elem.offsetParent)
    x = getX(elem.offsetParent);
  return x + elem.offsetLeft;
}
function getY(elem) {
  var y = 0;
  if (elem.offsetParent)
    y = getY(elem.offsetParent);
  return y + elem.offsetTop;
}
var lastMenu;
function enterMenu(elem, below) {
  if (DOMBrowser()) {
    parentDiv = elem.offsetParent.id;
    hideMenus(parentDiv, elem);
    showSubmenu(elem, below);
    if (timeout)
      clearTimeout(timeout);
  }
  return true;
}
function leaveMenu(elem) {
  if (DOMBrowser()) {
    lastMenu = "";
    if (elem)
      lastMenu = elem.offsetParent.id;
    timeout = setTimeout("hideMenus()", 300);
  }
  return true;
}
function getXPos(elem, child, below) {
  child.visible = false;
  // Temporarily set the display to block so that we can calculate offsetWidth/Height
  child.style.display = "block";
  parentX = getX(elem);
  if (below)
    x = parentX + 0;
  else
    x = parentX + elem.offsetWidth - 5;
  if (x + child.offsetWidth > document.body.clientWidth + document.body.scrollLeft) { // If the menu would appear offscreen:
    if (parentX - child.offsetWidth - document.body.scrollLeft + 5 > 0) { // If there's room to the left of the parent menu:
      x = parentX - child.offsetWidth + document.body.scrollLeft + 5;
    } else { // Fit as much in as possible:
      availSpace = (document.body.clientWidth - elem.offsetWidth) / 2;
      x = document.body.clientWidth + document.body.scrollLeft - child.offsetWidth;
      if (parentX > availSpace)
        x = 0;
      //Don't overlap the parent:
      if (x == parentX) x -= 5;
    }
  }
  child.style.display = "none";
  return x;
}
function getYPos(elem, child, below) {
  child.visible = false;
  // Temporarily set the display to block so that we can calculate offsetWidth/Height
  child.style.display = "block";
  parentY = getY(elem);
  if (below)
    y = parentY + elem.offsetHeight - 0;
  else
    y = parentY + 5;
  if (y + child.offsetHeight > document.body.clientHeight + document.body.scrollTop) { // If the menu would appear offscreen:
    if (parentY - child.offsetHeight - document.body.scrollTop + 20 > 0) { // If there's room above the parent menu:
      y = parentY - child.offsetHeight + document.body.scrollTop + 20;
    } else { // Fit as much in as possible:
      y = document.body.clientHeight + document.body.scrollTop - child.offsetHeight - 5;
      if (y < 0) y = 0;
    }
  }
  child.style.display = "none";
  return y;
}
function showSubmenu(elem, below) {
  var id = elem.id + "_submenu";
  menu = document.getElementById(id);
  if (menu && lastMenu != id) {
    // Reset display so that browsers are not confused when we postion (Opera in particular)
    // No longer needed?  11/30/05 MO
    menu.style.display = "none";
    menu.style.top = getYPos(elem, menu, below);
    menu.style.left = getXPos(elem, menu, below);
    menu.style.zIndex = 1000;
    menu.style.display = "block";
    tab = document.getElementById(elem.id + "_img");
    if (tab)
      tab.src = tab.src.replace(/(.*)1\.(.*)/, "$12.$2");
    // Only create the iframe element if the page has been loaded.  Otherwise, 
    // "Operation aborted" messages appear and the page won't load.
    if (isIE && pageLoaded) {
      var ifr = document.createElement("IFRAME");
      if (ifr) {
        document.body.appendChild(ifr);
        ifr.style.position = "absolute";
        ifr.style.width = menu.offsetWidth;
        ifr.style.height = menu.offsetHeight;
        ifr.style.top = menu.style.top;
        ifr.style.left = menu.style.left;
        ifr.style.zIndex = menu.style.zIndex - 1;
        ifr.style.display = "block";
        menu.iframe = ifr;
      }
    }
    menus.push(menu);
  }
}
