// debug = open("", "debug", "width=400,height=300,screenX=50,screenY=50,top=50,left=50,scrollbars");

if (!window.path) {
  path = ".."
}
arw = new Object();
arw.on = new Image();
arw.on.src = path + "/images/arw_menu.gif";
arw.off = new Image();
arw.off.src = path + "/images/spacer.gif";

IE = (document.all) ? 1 : 0;
NS = (document.layers) ? 1 : 0;
leftEdge=100;
topEdge = !window.internalTopEdge ? 147 : window.internalTopEdge;
topLevelInterval = 19;
bgCol="#CFCFE5";
bgOverColor="#EEEEF8";
borCol="#712D08";
fontCol="#333333";
fontOverCol="#e5772e";
fontFam="Arial, Helvetica";
fontSiz="9pt";
fontWeight="bold";
menuWidth=120;

menuStyle='<style type="text/css">';
menuStyle+='.menu {';
menuStyle+='position:absolute;';
menuStyle+='}';
menuStyle+='.menuText {';
menuStyle+='font-family:'+fontFam+';';
menuStyle+='font-size:'+fontSiz+';';
menuStyle+='color:'+fontCol+';';
menuStyle+='width:'+menuWidth+';';
menuStyle+='}';
menuStyle+='.overText {';
menuStyle+='font-family:'+fontFam+';';
menuStyle+='font-size:'+fontSiz+';';
menuStyle+='font-weight:'+fontWeight+';';
menuStyle+='color:'+fontOverCol+';';
menuStyle+='width:'+menuWidth+';';
menuStyle+='border-width:1;';
menuStyle+='border-style:solid;';
menuStyle+='border-color:'+borCol+';';
if (IE) menuStyle+='padding:3;';
menuStyle+='}';
menuStyle+='</style>';
document.write(menuStyle);

function getX(obj) {
  var x=0;
  while (obj.offsetParent.tagName != "BODY") {
    x += obj.offsetLeft;
    obj = obj.offsetParent;
  }
  return x + obj.offsetLeft;
}


function getY(obj) {
  var y=0;
  while (obj.offsetParent.tagName != "BODY") {
    y += obj.offsetTop;
    obj = obj.offsetParent;
  }
  return y + obj.offsetTop;
}


var currentMenu=-1;
var noMenu=true;
var currentLayer=null;
function setBack(e) {
//  window.status = this.mLink;
  if (this.submenu > "") {
    eval("var submenu = " + this.submenu);
  }
  if (NS) {
    if (this.submenu > "") {
      show(submenu, e);
    }
    else {
      hideLevel(1*this.level + 1);
    }
    this.textLyr.bgColor=bgOverColor;
    this.textLyr.document.write('<div class="overText">'+this.text+'</div>');
    this.textLyr.document.close();
  }
  if (IE) {
    if (this.submenu > "") {
      show(submenu, event);
    }
    else {
      hideLevel(1*this.level + 1);
    }
    if (currentLayer) currentLayer.restoreBack();
    this.style.backgroundColor=bgOverColor;
    document.images["arrow_" + this.suffix].src = arw.on.src;
    this.style.color=fontOverCol;
    this.style.cursor="hand";
    currentLayer=this;
  }
}


function restoreBack() {
  if (NS) {
    this.textLyr.bgColor=bgCol;
    this.textLyr.document.write('<div class="menuText">'+this.text+'</div>');
    this.textLyr.document.close();
  }
  if (IE) {
    this.style.backgroundColor=bgCol;
    this.style.color=fontCol;
    document.images["arrow_" + this.suffix].src = arw.off.src;
  }
  noMenu=true;
}


function linkIt() {
  noMenu=false;  
  if (this.mLink.substr(0,7) == "newwin:") {
    var openLink = this.mLink.substr(7,this.mLink.length - 7);
    window.open(path + '/customers/' + openLink,'newWin','width=800,height=600,scrollbars=yes,toolbar=no');
  }
  else {
    location.href=this.mLink;
  }
}


function NSshow(e) {
  if (e.pageY-5 + this.menuHeight > window.innerHeight)
    this.top = window.innerHeight - this.menuHeight;
  else {
    this.top=this.topEdge;
    this.left=this.x;
  }
  this.visibility="show";
}


function IEshow() {
  if (event.clientY-5 + this.menuHeight > document.body.clientHeight)
    this.style.pixelTop=document.body.clientHeight - this.menuHeight;
  else {
    this.style.pixelTop=event.clientY - 5;
    this.style.pixelLeft=this.x;
  }
  this.style.visibility="visible";
}


function checkHide() {
  if (noMenu) {
    hideAll();
    currentMenu = null;
  }
}


function hideLevel(level) {
  for (i = 0; i < menus.length; i++) {
    if (menus[i].level == level) {
      hideMenu(menus[i]);
    }
  }
}

function hide() {
  for (i = 0; i < menus.length; i++) {
    if (menus[i].level == currentMenu.level && menus[i] != currentMenu) {
      hideMenu(menus[i]);
    }
  }
}

function hideAll() {
  for (i = 0; i < menus.length; i++) {
    if (IE) {
      menus[i].style.visibility="hidden";
    }
    if (NS) {
      menus[i].visibility="hide";
    }
  }
}

function hideMenu(menu) {
  if (IE) {
    menu.style.visibility="hidden";
  }
  if (NS) {
    menu.visibility="hide";
  }
  for (var i = 0; i < menu.childarray.length; i++) {
    hideMenu(menu.childarray[i]);
  }
  return;
}

linkActive = false;
function initShow(m, e) {
  linkActive = true;
  show(m, e);
}

function show(m,e) {
  currentMenu=m;
  hide();
  if (NS) {
    m.NSshow(e);
  }
  if (IE) {
    m.IEshow();
  }
  cancelHide();
}

hideTimer = null;
function cancelHide() {
  if (hideTimer) {
    clearTimeout(hideTimer);
    hideTimer = null;
  }
}

function initHideMenus() {
  linkActive = false;
  hideTimer = setTimeout("checkHide()", 1000);
}

menuActive = false;
function menuCheck(e) {
  var hit=false;
  var x=event.clientX;
  var y=event.clientY;
  var o=event.srcElement;
  while (o.tagName != "BODY" && !hit) {
    if (o.id.substring(0,8)=="menuOpt_") {
      hit=true;
    }
    o=o.offsetParent;
  }
  if (hit) {
    cancelHide();
    menuActive = true;
  }
  if (!hideTimer && menuActive && !linkActive && !hit) {
    initHideMenus();
  }
}


var menundx=0;
menucount = !window.menucount ? 6 : window.menucount;
function hierinit() {
  loaded=true;
  menus=new Array();
  createMenus(null, "menu", menucount);
  if (IE) document.onmousemove=menuCheck;
  if (NS) document.captureEvents(Event.CLICK);
  document.onclick=checkHide;
}


function createMenus(progenitor, menu, opts) {
  var levels;
  for (var i = 0; i < opts; i++) {
    childmenu = menu + "_" + i;
    levels = childmenu.split("_");
    if (eval("window." + childmenu)) {
      menus[menundx] = makeMenu(childmenu);
      eval("M_" + childmenu + " = menus[menundx];");
      currentmenu = menus[menundx++];
      if (progenitor) {
        progenitor.childarray[progenitor.childndx++] = currentmenu;
      }
      currentmenu.makeOptions(childmenu);
      currentmenu.progenitor = progenitor;
      currentmenu.x = leftEdge + (currentmenu.level - 1) * (menuWidth - 10);
      currentmenu.topEdge = progenitor ? currentmenu.progenitor.topEdge + currentmenu.progenitor.childTop[levels[levels.length-1]] : topEdge + levels[1] * topLevelInterval;
      createMenus(currentmenu, childmenu, currentmenu.optioncount);
    }
  }
  return;
}


function makeMenu(menu) {
  if (NS) {
    var thisMenu=new Layer(menuWidth,window);
    thisMenu.NSshow = NSshow;
    thisMenu.visibility="hide";
  } else {
    document.body.insertAdjacentHTML("BeforeEnd",'<div id="HM_'+menu+'" style="position:absolute; width='+menuWidth+';"></div>');
    var thisMenu=document.all["HM_"+menu];
    thisMenu.IEshow = IEshow;
    thisMenu.style.visibility="hidden";
  }
  var levels = menu.split("_");
  thisMenu.level = levels.length - 1;
  thisMenu.arrayname = menu;
  thisMenu.makeOptions=makeOptions;
  thisMenu.childarray = new Array();
  thisMenu.childndx = 0;
  thisMenu.childTop = new Array();
  thisMenu.childtopndx = 0;
  return thisMenu;
}


function makeOptions(menu) {
  var menuArray=eval(menu);
  var menuItems=menuArray.length/2;
  this.optioncount = menuItems;
  if (NS) {
    var h=0;
    for (var i=0; i<menuItems; ++i) {
      var mText = menuArray[i*2];
      var mLink = menuArray[i*2+1];
      if (mLink.substr(0,7) != "newwin:" && mLink.substr(0,4) != "http") {
        mLink = path + "/" + mLink;
      }
      var tempLyr=new Layer(menuWidth, this);
      tempLyr.textLyr=new Layer(menuWidth,tempLyr);
      var textLyr=tempLyr.textLyr;
      textLyr.document.write('<div class="menuText">'+mText+'</div>');
      textLyr.document.close();
      textLyr.visibility="inherit";
      textLyr.bgColor=bgCol;

      tempLyr.visibility="inherit";
      tempLyr.top=h;
      tempLyr.left=0;
      tempLyr.clip.bottom=textLyr.document.height;

      tempLyr.mask=new Layer(menuWidth, tempLyr);
      var mask=tempLyr.mask;
      mask.visibility="inherit";
      mask.clip.bottom=textLyr.document.height-1;
      mask.clip.right=menuWidth;
this.childTop[this.childtopndx++] = h + (textLyr.document.height-1) / 2;
      h+=textLyr.document.height-1;

      tempLyr.text=mText;
      tempLyr.captureEvents(Event.MOUSEOVER || Event.MOUSEOUT);
submenu = "";
if (eval("window." + menu + "_" + i)) {
  submenu = "M_" + menu + "_" + i;
}
      tempLyr.submenu = submenu;
      tempLyr.level = this.level;
      tempLyr.mLink = mLink;
      tempLyr.onmouseover=setBack;
      tempLyr.onmouseout=restoreBack;
      mask.mLink = mLink;
      mask.captureEvents(Event.MOUSEUP);
      mask.onmouseup=linkIt;
    }  
    this.clip.bottom=h+1;
  }
  if (IE) {
    for (var i=0; i<menuItems; ++i) {
      var mText = menuArray[i*2];
      var mLink = menuArray[i*2+1];
      if (mLink.substr(0,7) != "newwin:" && mLink.substr(0,4) != "http") {
        mLink = path + "/" + mLink;
      }
      var suffix=menu+"_"+i;
      var code = 
          "<table border='0' cellpadding='0' cellspacing='0'>" +
          "  <tr valign='top'>" +
          "    <td><img src='" + path + "/images/spacer.gif' height='4' width='1' border='0'><br><img src='" + path + "/images/spacer.gif' height='6' width='6' id='arrow_" + suffix + "' name='arrow_" + suffix + "' border='0'></td>" +
          "    <td><img src='" + path + "/images/spacer.gif' height='1' width='5' border='0'></td>" +
          "    <td class='menuText'>" + mText + "</td>" +
          "  </tr>" +
          "</table>";
      this.insertAdjacentHTML('BeforeEnd','<div id="menuOpt_'+suffix+'" style="position:absolute;">' + code + '</div>');
      var temp=document.all["menuOpt_"+suffix];
      temp.style.backgroundColor=bgCol;
      temp.style.fontFamily=fontFam;
      temp.style.fontSize=fontSiz;
      temp.style.fontWeight=fontWeight;
      temp.style.color=fontCol;
      temp.style.width=menuWidth;
      temp.style.borderWidth=1;
      temp.style.borderStyle="solid";
      temp.style.borderColor=borCol;
      temp.style.padding=3;
      temp.mLink = mLink;
    }
    var h=0;
    for (var i=0; i<this.children.length; ++i) {
      var suffix=menu+"_"+i;
      var temp=document.all["menuOpt_"+suffix];
      temp.style.cursor="hand";
      temp.style.pixelTop=h;
      temp.setBack=setBack;
      temp.restoreBack=restoreBack;
submenu = "";
if (eval("window." + menu + "_" + i)) {
  submenu = "M_" + menu + "_" + i;
}
      temp.submenu=submenu;
      temp.level = this.level;
      temp.onmouseover=setBack;
      temp.onmouseup=linkIt;
      temp.suffix = suffix;
this.childTop[this.childtopndx++] = h + (temp.offsetHeight-1) / 2;
      h+=(temp.offsetHeight-1);
    }
  }
  this.menuHeight=h+1;
}

