// Javascript DHTML driver file
// Copyright (c)2002 Kelly Akins
// Support for DOM-compliant and MSIE 4+ browsers only
// Netscape 4.x has now become archaic and unsupported

activeObjList = new Array(null, null, null, null, null, null);
activeObjPtr = 0;
timerHandle = null;
subIndicator = "<table border=0 cellspacing=0 cellpadding=0 align=right><tr><td>&gt;</td></tr></table>";
ieTransFilter = "";

function GetElement(elName) {
  if (document.layers)
    return null;
  else if (document.all)
    return document.all[elName];
  else {
    if (document.getElementById(elName))
      return document.getElementById(elName);
    else
      return null;
  }
}

function SetVisibility(elObj, OnOff) {
  if (document.layers)
    return;
  if (elObj && elObj.style) {
    if (document.all && ieTransFilter != "") {
      elObj.style.filter = "blendTrans("+ieTransFilter+")";
      elObj.filters.blendTrans.Apply();
    }
    elObj.style.visibility = OnOff ? "visible" : "hidden";
    if (document.all && ieTransFilter != "")
      elObj.filters.blendTrans.Play();
  }
}

function ShowForms(OnOff)
{
  if (document.layers)
    return;

  var elObjList, i, vstate;
  if (OnOff)
    vstate = "visible";
  else
    vstate = "hidden";

  if (document.all)
  	elObjList = document.all.tags("select");
  else
    elObjList = document.getElementsByTagName("select");

  if (elObjList != null) {
    for (i = 0; i < elObjList.length; i++)
      elObjList[i].style.visibility = vstate;
  }
}
	
function ClearTimer() {
  if (timerHandle != null) {
    window.clearTimeout(timerHandle);
    timerHandle = null;
  }
}

function ResetTimer(callBack) {
  ClearTimer();
  timerHandle = window.setTimeout(callBack, 200);
}

function HideElement(elName) {
  var elObj = GetElement(elName);
  if (elObj) {
    SetVisibility(elObj, 0);
    ShowForms(1);
  }
}

function HideChildElements(depth) {
  for (i = 5; i > depth; i--) {
  	if (typeof activeObjList[i] == 'object') {
  	  SetVisibility(activeObjList[i], 0);
  	  activeObjList[i] = null;
  	}
  }
}

function TopMenuOn(elName) {
  if (document.layers)
    return;
  AllMenusOff();
  var elObj = GetElement(elName);
  if (elObj) {
    ClearTimer();
    SetVisibility(elObj, 1);
    activeObjList[0] = elObj;
    activeObjPtr++;
    ShowForms(0);
  }
  else
    activeObjList[0] = null;
}

function TopMenuOff(elName) {
  if (document.layers)
    return;
  if (activeObjPtr == 1)
    ResetTimer("HideElement('" + elName + "')");
}

function SubMenuOn(elName, depth) {
  if (document.layers)
    return;
  var elObj = GetElement(elName);
  HideChildElements(depth - 1);
  if (elObj && activeObjPtr > 0 && activeObjPtr < 5) {
  	ClearTimer();
    if (activeObjPtr > depth && depth > 0) {
      SetVisibility(activeObjList[activeObjPtr], 0);
      activeObjPtr--;
    }
    activeObjList[activeObjPtr] = elObj;
    SetVisibility(elObj, 1);
    activeObjPtr++;
  }
}

function AllMenusOff() {
  if (document.layers)
    return;
  var i;
  for (i = 5; i >= 0; i--) {
    if (typeof activeObjList[i] == 'object') {
      SetVisibility(activeObjList[i], 0);
      activeObjList[i] = null;
    }
  }
  activeObjPtr = 0;
  ShowForms(1);
}

function ProcessElement(arData, arMeta, elID, html, depth) {
  // Internet Explorer 4+ and DOM-compliant browser code
  if (arData != null && arMeta != null && !document.layers) {
    var i;
    var x = arMeta[0];
    var y = arMeta[1];
    var ih = arMeta[2];
    var w = arMeta[3];
    var mw = w;
    var obj = null;

    if (typeof w == 'object' && w.length > 0)
      mw = w[depth];
    var subhtml = '';
    if (arData.length > 25)	y = 1;

    html += '<DIV CLASS="menuContainer" ID="' + elID + '" STYLE="left:' + x + 'px; top:' + y;
    html += 'px; width:' + mw + 'px; visibility:hidden; z-index:1; position:absolute" ';
    html += 'ONMOUSEOVER="ClearTimer()" ONMOUSEOUT="ResetTimer(\'AllMenusOff()\')">\n';

    for (i = 0; i < arData.length; i++) {
      if (arData[i] != null) {
      	obj = arData[i];
        if (obj[2] == null || obj[2].length == 0) {
          html += '<DIV CLASS="menuCell" onmouseover="this.className=\'menuCellOver\'" onmouseout="this.className=\'menuCell\'" onmousedown="window.location=\''+obj[1]+'\'" style="cursor: pointer"><A HREF="' + obj[1] + '" CLASS="menu" ONMOUSEOVER="HideChildElements(' + depth + ')" ';
          html += 'STYLE="width:' + w + 'px; line-height:' + ih + 'px">' + obj[0] + '</A></DIV>\n';
        }
        else {        
          var subID = elID + '_' + i;
          var nxtdep = depth + 1;
          html += '<DIV CLASS="menuCell" onmouseover="this.className=\'menuCellOver\'" onmouseout="this.className=\'menuCell\'" onmousedown="window.location=\''+obj[1]+'\'" style="cursor: pointer"><A HREF="' + obj[1] + '" CLASS="menu" STYLE="width:' + mw + 'px; line-height:' + ih + 'px" ';
          html += 'ONMOUSEOVER="SubMenuOn(\'' + subID + '\',' + nxtdep + ')" ONMOUSEOUT="ResetTimer(\'AllMenusOff()\')"';
          html += '>' + subIndicator + obj[0] + '</A></DIV>\n';
          var metaSub = new Array(x + mw, y + (ih * i), ih, w);
          subhtml += ProcessElement(obj[2], metaSub, subID, '', nxtdep);
        }

        obj = null;
      }
    }
    
    html += '</DIV>\n' + subhtml;
  }
 
  return html;
}

function MenuInit() {
  if (menuItems != null && menuMeta != null && !document.layers) {
    html = '';
    for (n = 0; n < menuItems.length; n++) {
      arData = menuItems[n];
      arMeta = menuMeta[n];
      if (arData != null && arMeta != null)
        html += ProcessElement(arData, arMeta, 'menu_' + n.toString(), '', 0);
    }
    document.writeln(html);
  }
  AllMenusOff();
}

onLoad = MenuInit();
