var visibleMenuBody = null;

function doOnLoad() {
  if(document.all) {
    document.attachEvent("onclick", evlHideVisibleMenuBody);
  }
}

function evlHideVisibleMenuBody(event) {
  var toElem = event.toElement;
  while((toElem!=null)&&(toElem.className!="mhead")&&(toElem.className!="mbody")) {
    toElem = toElem.parentNode;
  }
  if(toElem!=null) {
    event.cancelBubble = true;
    return false;
  }
  if(visibleMenuBody!=null) {
    visibleMenuBody.style.display = "none";
    fnUnHighlightMenuHead(visibleMenuBody.parentNode);
  }
}

function showMenuBody(event) {
  if(!document.all) {
    return false;
  }
  if(visibleMenuBody!=null) {
    visibleMenuBody.style.display = "none";
    fnUnHighlightMenuHead(visibleMenuBody.parentNode);
  }
  var currentTarget = event.srcElement;
  while(currentTarget.className!="mhead") {
    currentTarget = currentTarget.parentNode;
  }
  currentTarget.attachEvent("onmouseout", evlHideVisibleMenuBody);
  var menuBody = currentTarget.firstChild.nextSibling;
  if (menuBody !== null) {
    while(menuBody.className!="mbody") {
      menuBody = menuBody.nextSibling;
    }
    if(menuBody.getAttribute("done")==null) {
      menuBody.setAttribute("done", "true");
      menuBody.attachEvent("onmouseover", evlCancelEvent);
      menuBody.attachEvent("onmouseout", evlHideVisibleMenuBody);
      var entries = menuBody.childNodes;
      var i=0;
      for(i=0;i<entries.length;i++) {
        var menuEntry = entries[i];
        if(menuEntry.tagName=="A") {
          menuEntry.attachEvent("onmouseover", evlHighlightMenuEntry);
          menuEntry.attachEvent("onmouseout", evlUnHighlightMenuEntry);
          setMenuEntryStyles(currentTarget, menuEntry);
        }
      }
    }
    visibleMenuBody = menuBody;
    menuBody.style.display = "block";
    var boundingBox = currentTarget.getBoundingClientRect();
    menuBody.style.left = (boundingBox.left-3) + "px";
    menuBody.style.top = (boundingBox.bottom-3) + "px";
  }
  fnHighlightMenuHead(currentTarget);
  return true;
}

function showMenuBodyFrame(event) {
  if(!document.all) {
    return false;
  }
  if(visibleMenuBody!=null) {
    visibleMenuBody.style.display = "none";
    fnUnHighlightMenuHead(visibleMenuBody.parentNode);
  }
  var currentTarget = event.srcElement;
  while(currentTarget.className!="mhead") {
    currentTarget = currentTarget.parentNode;
  }
  currentTarget.attachEvent("onmouseout", evlHideVisibleMenuBody);
  var menuBody = currentTarget.firstChild.nextSibling;
  if (menuBody !== null) {
    while(menuBody.className!="mbody") {
      menuBody = menuBody.nextSibling;
    }
    if(menuBody.getAttribute("done")==null) {
      menuBody.setAttribute("done", "true");
      menuBody.attachEvent("onmouseover", evlCancelEvent);
      menuBody.attachEvent("onmouseout", evlHideVisibleMenuBody);
      var entries = menuBody.childNodes;
      var i=0;
      for(i=0;i<entries.length;i++) {
        var menuEntry = entries[i];
        if(menuEntry.tagName=="A") {
          menuEntry.attachEvent("onmouseover", evlHighlightMenuEntry);
          menuEntry.attachEvent("onmouseout", evlUnHighlightMenuEntry);
          setMenuEntryStyles(currentTarget, menuEntry);
        }
      }
    }
    visibleMenuBody = menuBody;
    // don't show menuBody in frame version
    menuBody.style.display = "none";
    var boundingBox = currentTarget.getBoundingClientRect();
    menuBody.style.left = (boundingBox.left-2) + "px";
    menuBody.style.top = (boundingBox.bottom-2) + "px";
  }
  fnHighlightMenuHead(currentTarget);
  return true;
}

function setMenuEntryStyles(menuHead, menuEntry) {
  var ebs = findAttribute(menuHead, "ebs");
  var ebc = findAttribute(menuHead, "ebc");
  var ebw = findAttribute(menuHead, "ebw");
  var ep = findAttribute(menuHead, "ep");
  var ebgcol = findAttribute(menuHead, "ebgcol");
  var ecol = findAttribute(menuHead, "ecol");
  var etd = findAttribute(menuHead, "etd");
  var etdw = findAttribute(menuHead, "etdw");
  menuEntry.style.textDecoration = etd;
  menuEntry.style.backgroundColor = ebgcol;
  menuEntry.style.color = ecol;
  menuEntry.style.whiteSpace = "nowrap";
  //menuEntry.style.width = "100%";
  menuEntry.style.width = "174px";
  menuEntry.style.borderStyle = "none";
  menuEntry.style.borderBottomStyle = ebs;
  menuEntry.style.borderBottomColor = ebc;
  menuEntry.style.borderBottomWidth = ebw;
  menuEntry.style.padding = ep;
}

function setHighlightedMenuEntryStyles(menuHead, menuEntry) {
  var ebs = findAttribute(menuHead, "hebs");
  var ebc = findAttribute(menuHead, "hebc");
  var ebw = findAttribute(menuHead, "hebw");
  var ep = findAttribute(menuHead, "hep");
  var ebgcol = findAttribute(menuHead, "hebgcol");
  var ecol = findAttribute(menuHead, "hecol");
  var etd = findAttribute(menuHead, "hetd");
  menuEntry.style.textDecoration = etd;
  menuEntry.style.backgroundColor = ebgcol;
  menuEntry.style.color = ecol;
  menuEntry.style.whiteSpace = "nowrap";
  //menuEntry.style.width = "100%";
  menuEntry.style.width = "174px";
  menuEntry.style.borderStyle = "none";
  menuEntry.style.borderBottomStyle = ebs;
  menuEntry.style.borderBottomColor = ebc;
  menuEntry.style.borderBottomWidth = ebw;
  menuEntry.style.padding = ep;
}


function findAttribute(menuHead, attributeName) {
  var att = menuHead.getAttribute(attributeName);
  if(att==null) {
    att = document.getElementById(menuHead.getAttribute("tmpl")).getAttribute(attributeName);
  }
  return att;
}

function evlCancelEvent(event) {
  event.cancelBubble = true;
}

function fnHighlightMenuHead(menuHead) {
  var bgcol = menuHead.getAttribute("hhbgcol");
  if(bgcol==null) {
    bgcol = document.getElementById(menuHead.getAttribute("tmpl")).getAttribute("hhbgcol");
  }
  var col = menuHead.getAttribute("hhcol");
  if(col==null) {
    col = document.getElementById(menuHead.getAttribute("tmpl")).getAttribute("hhcol");
  }
  var firstChild = menuHead.firstChild;
  menuHead.style.backgroundColor = bgcol;
  menuHead.style.color = col;
  if(firstChild.style) {
    firstChild.style.color = col;
    firstChild.style.backgroundColor = bgcol;
  }
}

function evlUnHighlightMenuHeader(event) {
  if(!document.all) {
    return false;
  }
  if(event.srcElement.className!="mhead") {
    return false;
  }
  var menuBody = event.srcElement.firstChild.nextSibling;
  if (menuBody !== null) {
    while(menuBody.className!="mbody") {
      menuBody = menuBody.nextSibling;
    }
    if (menuBody.style.display=="none") {
      fnUnHighlightMenuHead(event.srcElement);
    }
  } else {
    fnUnHighlightMenuHead(event.srcElement);
  }
  return true;
}

function fnUnHighlightMenuHead(menuHead) {
  var bgcol = menuHead.getAttribute("hbgcol");
  if(bgcol==null) {
    bgcol = document.getElementById(menuHead.getAttribute("tmpl")).getAttribute("hbgcol");
  }
  var col = menuHead.getAttribute("hcol");
  if(col==null) {
    col = document.getElementById(menuHead.getAttribute("tmpl")).getAttribute("hcol");
  }
  var firstChild = menuHead.firstChild;
  menuHead.style.backgroundColor = bgcol;
  menuHead.style.color = col;
  if(firstChild.style) {
    firstChild.style.color = col;
    firstChild.style.backgroundColor = bgcol;
  }
}

function evlHighlightMenuEntry(event) {
  var currentTarget = event.srcElement;
  /*
  while(currentTarget.tagName!="DIV") {
    currentTarget = currentTarget.parentNode;
  }
  */
  var menuHead = currentTarget.parentNode.parentNode;
  setHighlightedMenuEntryStyles(menuHead, currentTarget);
  event.cancelBubble = true;
}

function evlUnHighlightMenuEntry(event) {
  var currentTarget = event.srcElement;
  var menuHead = currentTarget.parentNode.parentNode;
  setMenuEntryStyles(menuHead, currentTarget);
  event.cancelBubble = true;

  var toElem = event.toElement;
  while((toElem!=null)&&(toElem.className!="mhead")&&(toElem.className!="mbody")) {
    toElem = toElem.parentNode;
  }
  if(toElem==null) {
    evlHideVisibleMenuBody(event);
  }
}

ns4 = (document.layers) ? true : false;
ie4 = (document.all) ? true : false;
