
// 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 valign=top><td class=text><font color=black>&gt;</font></td></tr></table>";

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)
    elObj.style.visibility = OnOff ? 'visible' : 'hidden';
}

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, 100);
}

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 bh = ih;
    var mw = w;
    var obj = null;
    if (typeof w == 'object' && w.length > 0)
      mw = w[depth];
    var subhtml = '';
    if (arData.length > 25)	y = 1;

    // Find the height attributes of the "A.menu:link" style selector
    if (document.styleSheets && document.styleSheets[0].rules) {
      var found = false;      
      for (z = 0; z < document.styleSheets[0].rules.length && !found; z++)
        found = (document.styleSheets[0].rules[z].selectorText.toLowerCase() == "a.menu:link");
      if (found) {
      	var m = document.styleSheets[0].rules[z].style;
      	bh = parseInt(m.lineHeight);
      	if (m.padding != "")
      	  bh += parseInt(m.padding);
      	else {
      	  if (m.paddingTop != "")
      	    bh += parseInt(m.paddingTop);
      	  if (m.paddingBottom != "")
      	    bh += parseInt(m.paddingBottom);
      	}
      }
    }

    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];
        html += '<A HREF="' + obj[1] + '" CLASS="menu" ONMOUSEOVER="HideChildElements(' + depth + ')" ';          
        html += 'STYLE="width:' + w + 'px; line-height:' + ih + 'px">' + obj[0] + '</A><BR>\n';
        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();
  if (typeof(spMenuInit) == "object" || typeof(spMenuInit) == "function")
  	spMenuInit();
}

onLoad = MenuInit();
