// 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

var activeObjList = new Array(null, null, null, null, null, null);
var activeObjPtr = 0;
var timerHandle = null;
var subIndicator = "<table border=0 cellspacing=0 cellpadding=0 align=right><tr valign='top'><td class='bodycopy'>&gt;</td></tr></table>";
var ieTransFilter = ""; //"duration=0.2";

function GetElement(elName) {
  if (document.all)
    return document.all[elName];
  else {
    if (document.getElementById(elName))
      return document.getElementById(elName);
    else
      return null;
  }
}

function SetVisibility(elObj, OnOff) {
  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.body.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, 1500);
}

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 - 1], 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) {
	var IE7 = (navigator.appVersion.indexOf("MSIE 7.")==-1) ? false : true;
	
  if (arData != null && arMeta != null) {
    var i;
    var x = arMeta[0];
    
    if (IE7 == true){
    	var y = arMeta[1] + 20;
    } else {
    	var y = arMeta[1];
    }
    
    var ih = arMeta[2];
    var w = arMeta[3];
    var mw = w;
    if (typeof w == 'object' && w.length > 0)
      mw = w[depth];
    var subhtml = '';
    var clHeight = screen.height;
    if (document.documentElement && document.documentElement.clientHeight)
	  clHeight = document.documentElement.clientHeight;
	else if (document.body && document.body.clientHeight)
	  clHeight = document.body.clientHeight;
	else
	  clHeight = 0;
    var mh = ih * arData.length + 34;
    if (mh + y > clHeight)
    	y = clHeight - mh - 1;
    if (y < 1)
    	y = 1;
    ix = 0;
    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) {
      	var obj = arData[i];
        if (obj[2] != null) {
          var subID = elID + '_' + i;
          var nxtdep = depth + 1;
          html += '<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><BR>\n';
          var metaSub = new Array(x + mw, y + (ih * i), ih, w);
          subhtml += ProcessElement(obj[2], metaSub, subID, '', nxtdep);
        }
        else {
          html += '<A HREF="' + obj[1] + '" CLASS="menu" ONMOUSEOVER="HideChildElements(' + depth + ')" ';
          html += 'STYLE="width:' + w + 'px; line-height:' + ih + 'px">' + obj[0] + '</A><BR>\n';
        }
      }
    }
    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);
    }
    window.document.writeln(html);
  }
  AllMenusOff();
}

onLoad = MenuInit();

