var iTableNo = 0;
var iDefaultIconColumns = 5;
var iIconRows = 2;
var iMenuNo = 0;
var iDefaultTabHeight = 20;
var iIconHeight = 30;
var iDefaultIconHeight = 62;
var iDefaultPathHeight = 20;
var strHand = "hand";
var trLastHLMenu = null;
var divTabs = null;
var iIconColumns = iDefaultIconColumns;

var iStartTab = 0;

var topFrames = window.parent.frames;
var topWindow = window.parent;
if (topFrames.length < 5) {
  topFrames = window.parent.parent.frames;
  topWindow = window.parent.parent;
}

function GetFrameHeight(iFrameNo) {
  var iFrameHeight = 0;
  if (topFrames[iFrameNo].document != null) {
    iFrameHeight = topFrames[iFrameNo].document.body.getBoundingClientRect().bottom - 
                   topFrames[iFrameNo].document.body.getBoundingClientRect().top;
  }
  return iFrameHeight;
}

function GetFrameWidth(iFrameNo) {
  var iFrameWidth = 0;
  if (topFrames[iFrameNo].document != null) {
    iFrameWidth = topFrames[iFrameNo].document.body.getBoundingClientRect().right - 
                  topFrames[iFrameNo].document.body.getBoundingClientRect().left;
  }
  return iFrameWidth;
}

var bExplorer = (navigator.appName.indexOf("Explorer") >= 0);

function GetRowFromID(strMenuItemId) {
  var strMenu = topFrames[0].document.getElementById("TP").innerHTML;
  if (strMenu.indexOf("menuid=\"" + strMenuItemId + "\"") > 0) {
    strMenu = strMenu.substring(strMenu.indexOf("menuid=\"" + strMenuItemId + "\"") + 7);
    strMenu = strMenu.substring(strMenu.indexOf("id="));
    strMenu = GetValueOf(strMenu, "id");
  }
  else {
    strMenu = "";
  }
  return strMenu;
}

function ClickMenuFromID(strMenuItemId) {
  var strMenu = GetRowFromID(strMenuItemId);
  if (!StringEmpty(strMenu)) {
    ClickMenu("trMenu" + strMenu.substring(2, strMenu.length - 1));
  }
}

function ShowMenuFromID(strMenuItemId) {
  var strMenu = GetRowFromID(strMenuItemId);
  if (!StringEmpty(strMenu)) {
    SetPath(topFrames[0].document.getElementById("trMenu" + strMenu.substring(2, strMenu.length - 1)));
  }
}

function ResetLastMenu() {
  var trLastHLMenu = topFrames[0].document.getElementById("edLastHLMenuID").value;
  if (!StringEmpty(trLastHLMenu)) {
    trLastHLMenu = topFrames[0].document.getElementById(trLastHLMenu);
    if ((trLastHLMenu != null) &&
        (trLastHLMenu.className.substring(trLastHLMenu.className.length - 1) == "H")) {
      trLastHLMenu.className = trLastHLMenu.className.substring(0, trLastHLMenu.className.length - 1);
    }
  }
}

function CloseAllMenus() {
  var trMain = topFrames[0].document.getElementById("tblMenu1");
  for (iSubMenu = 0; iSubMenu < trMain.childNodes[0].childNodes.length; iSubMenu++) {
    if (trMain.childNodes[0].childNodes[iSubMenu].id.substring(0, 5) == "trTbl") {
      trMain.childNodes[0].childNodes[iSubMenu].style.display = "none";
    }
  }
}

function ClickMenu(strMenuItemId) {
  var strCurrentMenuID = strMenuItemId;
  if (StringEmpty(strCurrentMenuID)) {
    iIconColumns = 9;
//    iStartTab = 1;
    window.parent.document.getElementById("topframe").rows = "70,0,*";
    var trTbl = TblFromMenu(topFrames[0].document.getElementById(GetRowFromID("HOME")).parentNode);

    ShowTabs(topFrames[0].document.getElementById(GetRowFromID("HOME")).parentNode,
             trTbl, true);
    iIconColumns = iDefaultIconColumns;
    iStartTab = 0;
    topFrames[2].document.getElementById("divLocation").style.display = "none";
    window.parent.document.getElementById("topframe").rows = "70," + (iDefaultIconHeight) + ",*";
    ResetLastMenu();
    CloseAllMenus();
    if (topFrames[3].document.URL.indexOf("home.htm") < 0) {
      //alert("load home");
      LoadPage("home.htm", "main");
    }

    /*
    if (topFrames[2].document.getElementById("divLocation") != null) {
      topFrames[2].document.getElementById("divLocation").innerHTML = "";
      if (topFrames[0].document.getElementById("edLastHLMenuID") != null) {
        var trLastHLMenu = window.parent.frames[0].document.getElementById("edLastHLMenuID").value;
        if (!StringEmpty(trLastHLMenu)) {
          trLastHLMenu = topFrames[0].document.getElementById(trLastHLMenu);
          if ((trLastHLMenu != null) &&
              (trLastHLMenu.className.substring(trLastHLMenu.className.length - 1) == "H")) {
            trLastHLMenu.className = trLastHLMenu.className.substring(0, trLastHLMenu.className.length - 1);
          }
        }
      }
    }
    */
  }
  else {
    topFrames[0].document.getElementById(strCurrentMenuID).childNodes[0].click();
  }
}

function StringEmpty(strString) {
  return (("+" + strString + "+" == "++") ||
          ("+" + strString + "+" == "+undefined+"));
}

function ShowSinglePath(strPathName, strPathIcon, strPathURL) {
  try {
    window.parent.document.getElementById("topframe").rows = "70," + iDefaultTabHeight + ",*";
    var strPathHTML = "<table width=\"100%\" cellspacing=0 cellpadding=0 style=\"font-size:100%\"><tr bgcolor=#F0F7F9><td>";
    strPathHTML += "<table cellspacing=0 cellpadding=0 style=\"font-size:10\"><tr bgcolor=#F0F7F9>";
    strPathHTML += "<td><img height=" + (iDefaultPathHeight - 2) + " src=\"" + strPathIcon + "\"></td>";
    strPathHTML += "<td nowrap><a href=\"" + strPathURL + "\" target=\"main\"><b>&nbsp;" + strPathName + "</b></a></td>";
    strPathHTML += "</tr></table></td></tr></table>";
    topFrames[2].document.getElementById("divLocation").style.display = "";
    topFrames[2].document.getElementById("divLocation").innerHTML = strPathHTML;
    topFrames[2].document.getElementById("divTabs").style.display = "none";
  }
  catch (e) {
  }
}

function ShowPath(strShowPath) {
  slShowPath = strShowPath.split("++");
  var strPathHTML = "<table width=\"100%\" cellspacing=0 cellpadding=0 style=\"font-size:100%\"><tr bgcolor=#F0F7F9><td>";
  strPathHTML += "<table cellspacing=0 cellpadding=0 style=\"font-size:10\"><tr bgcolor=#F0F7F9>";
  var slShowPathLine;
  for (iShowPath = 0; iShowPath < slShowPath.length; iShowPath++) {
    if (iShowPath > 0) {
      strPathHTML += "<td nowrap>&nbsp;->&nbsp;</td>";
    }
    strPathHTML += "<td nowrap";
    slShowPathLine = slShowPath[iShowPath].split("==");
    if ((slShowPathLine.length > 3) &&
        (!StringEmpty(slShowPathLine[3]))) {
      strPathHTML += " onclick=\"ClickMenu('" + slShowPathLine[3] + "')\"";
      strPathHTML += " style=\"cursor:hand\"";
      if ((iShowPath < slShowPath.length - 1) &&
          (topFrames[0].document.getElementById(slShowPathLine[4]).style.display == "none")) {
        ExpandMenu(topFrames[0].document.getElementById(slShowPathLine[3]),
                   topFrames[0].document.getElementById(slShowPathLine[4]),
                   false);
      }
    }
    strPathHTML += ">";
    strPathHTML += "<img height=" + (iDefaultPathHeight - 2) + " src=\"" + slShowPathLine[2] + "\"></td>";
    strPathHTML += "<td nowrap ";
    if ((slShowPathLine.length > 3) &&
        (!StringEmpty(slShowPathLine[3]))) {
      strPathHTML += "style=\"cursor:hand\" onclick=\"ClickMenu('" + slShowPathLine[3] + "')\"";
    }
    strPathHTML += ">&nbsp;<b>" + slShowPathLine[0] + "</b></td>";
  }
  strPathHTML += "</tr></table>";
  strPathHTML += "</td></tr></table>";
  var strRows = window.parent.document.getElementById("topframe").rows;
  var slRows = strRows.split(",");
  if (slRows[1] == "0") {
    slRows[1] = iDefaultPathHeight;
    window.parent.document.getElementById("topframe").rows = slRows.join(",");
  }
  else {
    if (slRows[1] == iDefaultIconHeight) {
      slRows[1] = (iDefaultIconHeight + iDefaultPathHeight);
      window.parent.document.getElementById("topframe").rows = slRows.join(",");
    }
  }
  topFrames[2].document.getElementById("divLocation").style.display = "";
  topFrames[2].document.getElementById("divLocation").innerHTML = strPathHTML;
}

function GetValueOf(strHTML, strID) {
  var strResult = "";
  strResult = strHTML.substring(strHTML.toLowerCase().indexOf(strID.toLowerCase() + "="));
  if (strResult.toLowerCase().substring(0, strID.length + 1) == strID.toLowerCase() + "=") {
    strResult = strResult.substring(strID.length + 1);
    if (strResult.substring(0, 1) == "\"") {
      strResult = strResult.substring(1);
      strResult = strResult.substring(0, strResult.indexOf("\""));
    }
    else {
      if (strResult.substring(0, 1) == "'") {
        strResult = strResult.substring(1);
        strResult = strResult.substring(0, strResult.indexOf("'"));
      }
      else {
        if (strResult.indexOf(" ") < strResult.indexOf(">")) {
          strResult = strResult.substring(0, strResult.indexOf(" "));
        }
        else {
          strResult = strResult.substring(0, strResult.indexOf(">"));
        }
      }
    }
  }
  else {
    strResult = "";
  }
  //alert(strID + ":" + strHTML + ":" + strResult);
  return strResult;
}

function GetOuterHTML(trHTMLElement) {
  if (bExplorer) {
    return trHTMLElement.outerHTML;
  }
  else {
    try {
      var trTemp = trHTMLElement.cloneNode(true);
      var divTemp = document.getElementById("divTemp");
      divTemp.innerHTML = "";
      divTemp.appendChild(trTemp);
      return divTemp.innerHTML;
    }
    catch (e) {
      //alert("GetOuterHTML:" + e.message);
      return "";
    }
  }
}

function TblFromMenu(trFromMenu) {
  var strTblID = GetOuterHTML(trFromMenu);
  strTblID = strTblID.substring(strTblID.indexOf("trTbl"));
  strTblID = strTblID.substring(0, strTblID.indexOf("\""));
  return (topFrames[0].document.getElementById(strTblID));
}

function SetPath(trMenu) {
  var strParentMenu = GetOuterHTML(trMenu);
  if (trMenu.childNodes.length > 0) {
    var trTbl = TblFromMenu(trMenu);
    var strPath = trMenu.childNodes[0].innerHTML + "==0==" + GetValueOf(strParentMenu, "iconimg") + "==" + trMenu.id + "==" + trTbl.id;
    var iParentMenuNo;
    docMenu = window.parent.frames[0].document;
    do {
      iParentMenuNo = GetValueOf(strParentMenu, "parentid");
      if (iParentMenuNo > 0) {
        trTbl = TblFromMenu(docMenu.getElementById("trMenu" + iParentMenuNo));
        strParentMenu = GetOuterHTML(docMenu.getElementById("trMenu" + iParentMenuNo));
        strIconImage = GetValueOf(strParentMenu, "iconimg");
        if (strPath != "") {
          strPath = "++" + strPath;
        }
        strPath = docMenu.getElementById("trMenu" + iParentMenuNo).childNodes[0].innerHTML + "==" +
                  iParentMenuNo + "==" + strIconImage + "==trMenu" + iParentMenuNo + "==" + trTbl.id + strPath;
      }
    } while (iParentMenuNo > 0);
    if (strPath != "") {
      ShowPath(strPath);
    }
  }
}

function ShowTabs(trParentMenu, trTabsTable, bUseIcons) {
  var strTabHTML = "";
  try {
    divTabs = window.parent.frames[2].document.getElementById("divTabs");
    divTabs.innerHTML = "";
  }
  catch (e) {
  }
  if ((trTabsTable.childNodes[0].childNodes[0].innerHTML + "").substring(0, 15).toUpperCase().indexOf("<TR") >= 0) {
    if (divTabs != null) {
      strTabHTML = "";
      slTabs = new Array();
      if (!bUseIcons) {
        slTabs[0] = trParentMenu.childNodes[0].innerHTML;
      }
      strMainURL = GetOuterHTML(trParentMenu).substring(GetOuterHTML(trParentMenu).indexOf("LoadPage(") + 9);
      strMainURL = strMainURL.substring(0, strMainURL.indexOf(")"));
      slTabURLs = new Array();
      if (!bUseIcons) {
        slTabURLs[0] = strMainURL;
      }
      var strIconHeight = GetOuterHTML(trParentMenu);
      strIconHeight = GetValueOf(strIconHeight, "iconheight");
      try {
        strIconHeight *= 1;
        if (strIconHeight < iDefaultIconHeight) {
          strIconHeight = iDefaultIconHeight;
        }
      }
      catch (e) {
        strIconHeight = iDefaultIconHeight;
      }
      slIconIMG = new Array();
      if (!bUseIcons) {
        slIconIMG[0] = GetValueOf(GetOuterHTML(trParentMenu), "iconimg");
      }
      for (iTab = 0; iTab < trTabsTable.childNodes[0].childNodes[0].childNodes[0].childNodes.length; iTab += 2) {
        slTabs[slTabs.length] = trTabsTable.childNodes[0].childNodes[0].childNodes[0].childNodes[iTab].childNodes[0].innerHTML;
        slTabURLs[slTabURLs.length] = GetOuterHTML(trTabsTable.childNodes[0].childNodes[0].childNodes[0].childNodes[iTab]);
        if (bUseIcons) {
          slTabURLs[slTabURLs.length - 1] = slTabURLs[slTabURLs.length - 1].substring(slTabURLs[slTabURLs.length - 1].indexOf("trMenu"));
          slTabURLs[slTabURLs.length - 1] = slTabURLs[slTabURLs.length - 1].substring(0, slTabURLs[slTabURLs.length - 1].indexOf(" "));
          slIconIMG[slIconIMG.length] = GetValueOf(GetOuterHTML(trTabsTable.childNodes[0].childNodes[0].childNodes[0].childNodes[iTab]), "iconimg");
        }
        else {
          slTabURLs[slTabURLs.length - 1] = slTabURLs[slTabURLs.length - 1].substring(slTabURLs[slTabURLs.length - 1].indexOf("LoadPage(") + 9);
          slTabURLs[slTabURLs.length - 1] = slTabURLs[slTabURLs.length - 1].substring(0, slTabURLs[slTabURLs.length - 1].indexOf(")"));
          slIconIMG[slIconIMG.length] = GetValueOf(GetOuterHTML(trTabsTable.childNodes[0].childNodes[0].childNodes[0].childNodes[iTab]), "iconimg");
        }
      }
      if (bUseIcons) {
        strTabHTML += "<table width=\"100%\" style=\"font-size:100%\" cellspacing=0 cellpadding=0>";
        strTabHTML += "<tr height=" + (iDefaultIconHeight / iIconRows) + ">";
        iNextRow = iIconColumns;
        for (iTab = iStartTab; iTab < slTabs.length; iTab++) {
          strTabHTML += "<td width=\"" + (20 / iIconColumns) + "%\"><img src=\"" + slIconIMG[iTab] + "\" height=" + iIconHeight + " style=\"cursor:hand\" ";
          strTabHTML += "onclick=\"JavaScript:window.parent.frames[0].document.getElementById('" + slTabURLs[iTab] + "').click()\">";
          strTabHTML += "</td><td width=\"" + (80 / iIconColumns) + "%\" style=\"cursor:hand\" ";
          strTabHTML += "onclick=\"JavaScript:window.parent.frames[0].document.getElementById('" + slTabURLs[iTab] + "').click()\">";
          strTabHTML += "<b>" + slTabs[iTab] + "</b></td>";
          iNextRow--;
          if ((iTab < slTabs.length - 1) &&
              (iNextRow == 0)) {
            strTabHTML += "</tr><tr height=" + (iDefaultIconHeight / iIconRows) + ">";
            iNextRow = iIconColumns;
          }
        }
        while (iNextRow > 0) {
          strTabHTML += "<td width=\"" + (20 / iIconColumns) + "%\"></td>";
          strTabHTML += "<td width=\"" + (80 / iIconColumns) + "%\"></td>";
          iNextRow--;
        }
        strTabHTML += "</tr></table>";
        if (slTabs.length - iStartTab > (iIconColumns * iIconRows)) {
          window.parent.frames[2].document.getElementById("tdScrolUp").style.display = "";
          window.parent.frames[2].document.getElementById("tdScrolDown").style.display = "";
        }
        else {
          window.parent.frames[2].document.getElementById("tdScrolUp").style.display = "none";
          window.parent.frames[2].document.getElementById("tdScrolDown").style.display = "none";
        }
        //alert(strTabHTML);
      }
      else {
        strTabHTML += "<table cellpadding=0 cellspacing=0 style=\"font-size:100%\" border=0>";
        strTabHTML += "<tr height=" + (iDefaultPathHeight - 3) + ">";
        for (iTab = 0; iTab < slTabs.length; iTab++) {
          if (iTab == 0) {
            //strTabHTML += "<td width=1> </td>";
          }
          strTabHTML += "<td style=\"margin-top:1; margin-left:3";
          if (iTab == 0) {
            strTabHTML += "; margin-right:3; background-image:url(images/tableft" + ((iTab == 0)?"h":"") + ".jpg)\"";
          }
          else {
             strTabHTML += "\" bgcolor=#2080C0 width=\"1\"";
          }
          strTabHTML += " sonclick='JavaScript:SetPage(this, " + slTabURLs[iTab] + ")'>" +
                        "<table cellpadding=0 cellspacing=0><tr heigth=1>" +
                        "<td colspan=3> </td></tr><tr><td width=1> </td><td>";
          if (iTab == 0) {
            strTabHTML += "<img border=0 height=15  src=\"" + slIconIMG[iTab] + "\">";
          }
          strTabHTML += "</td></tr></table></td>";
          strTabHTML += "<td style=\"cursor:hand; font-size:10 \" bgcolor=";
          if (iTab == 0) {
            strTabHTML += "#224593";
          }
          else {
            strTabHTML += "#81B7E2";
          }
          //strTabHTML += "background-image:url(images/tabright" + ((iTab == 0)?"h":"") + ".jpg)\" " +
          strTabHTML += " onclick='JavaScript:SetPage(this, " + slTabURLs[iTab] + ")'>";
          strTabHTML += "<table cellpadding=0 cellspacing=0 style=\"font-size:100%; sfont-weight:bold; color:";
          if (iTab == 0) {
            strTabHTML += "#A8FFC8";
          }
          else {
            strTabHTML += "#FFFFFF";
          }
          strTabHTML += "\" border=0>";
          strTabHTML += "<tr height=1><td></td></tr>";
//          strTabHTML += "<tr><td nowrap>" + slTabs[iTab] + "</td></tr>";
          strTabHTML += "<tr><td nowrap>&nbsp;" + slTabs[iTab] + "&nbsp;</td></tr>";
//          strTabHTML += "\">" + slTabs[iTab] + "</b>&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>";
          strTabHTML += "</table></td>";
        }
        strTabHTML += "</td></tr></table>";
      }
      if (bUseIcons) {
        divTabs.innerHTML = strTabHTML;
        divTabs.style.display = "";
        if (slTabs.length - iStartTab > iIconColumns) {
          iHeight = iDefaultIconHeight;
        }
        else {
          iHeight = iDefaultIconHeight / iIconRows;
        }
        window.parent.document.getElementById("topframe").rows = "70," + (iHeight + iDefaultPathHeight) + ",*";
        divTabs.style.height = iHeight;
        if (GetFrameHeight(2) < iHeight + iDefaultPathHeight) {
          divTabs.style.fontSize = "60%";
        }
        if (GetFrameWidth(2) < divTabs.clientWidth) {
          divTabs.style.fontSize = "60%";
          divTabs.innerHTML = strTabHTML.replace(/height=30/g, "height=23");
        }
      }
      else {
        if (GetValueOf(GetOuterHTML(trParentMenu), "hidekiddies") != "yes") {
          divTabs.style.height = iDefaultTabHeight;
          window.parent.document.getElementById("topframe").rows = "70," + (iDefaultTabHeight + iDefaultPathHeight) + ",*";
          divTabs.innerHTML = strTabHTML;
          divTabs.style.display = "";
        }
      }
      slTabs = null;
      slTabURLS = null;
      slIconIMG = null;
      //divTabs.scrollTop = 0;
    }
  }
  else {
    window.parent.document.getElementById("topframe").rows = "70," + iDefaultPathHeight + ",*";
    trTabsTable.style.display = "";
  }
}

function ExpandMenu(trMenu, trTable, bSetPath) {
  var bIcons = false;
  var bTabs= false;
  var bMultiLevel = (trMenu.parentNode.parentNode.parentNode.parentNode.style.display == "none");

  if (bMultiLevel) {
    //alert(trMenu.id);
    //alert(trMenu.outerHTML);
  }

  if (GetValueOf(GetOuterHTML(trMenu), "icons") == "yes") {
    //alert("icons:" + trMenu.id + ":" + trTable.id);
    bIcons = true;
    window.parent.frames[2].document.getElementById("tdScrolUp").style.display = "";
    window.parent.frames[2].document.getElementById("tdScrolDown").style.display = "";
  }
  else {
    //alert("tabs:" + trMenu.id + ":" + trTable.id);
    window.parent.frames[2].document.getElementById("tdScrolUp").style.display = "none";
    window.parent.frames[2].document.getElementById("tdScrolDown").style.display = "none";
  }

  if (((trMenu.className == "MenuItem") ||
       (trMenu.className == "MenuItemH")) &&
      (trTable.childNodes[0].childNodes[0].childNodes[0].childNodes.length > 0)) {
    bTabs = true;
  }
  ResetLastMenu();
  window.parent.document.getElementById("topframe").rows = "70," + iDefaultPathHeight + ",*";
  if ((trTable.style.display == "") &&
      (bSetPath)) {
    trTable.style.display = "none";
  }
  else {
    if ((!bIcons) &&
        (!bTabs) &&
        (GetValueOf(GetOuterHTML(trMenu), "hidekiddies") != "yes") &&
        (trTable.innerHTML.indexOf("<TR") >= 0)) {
      trTable.style.display = "";
    }
  }
  {
    if (trTable.parentNode.childNodes != null) {
      for (iChild = 0; iChild < trTable.parentNode.childNodes.length; iChild++) {
        if ((trTable.parentNode.childNodes[iChild] != trTable) &&
            (trTable.parentNode.childNodes[iChild] != trMenu) &&
            (trTable.parentNode.childNodes[iChild].id != "")) {
          if ((trTable.parentNode.childNodes[iChild].id + "").substring(0, 5) == "trTbl") {
            trTable.parentNode.childNodes[iChild].style.display = "none";
          }
        }
      }
    }
    if (bSetPath) {
      SetPath(trMenu);
    }
    if (bTabs == true) {
      ShowTabs(trMenu, trTable, bIcons);
    }
  }
  if ((trMenu.className + "").substring((trMenu.className + "").length - 1) != "H") {
    if (!bMultiLevel) {
      trMenu.className += "H";
      trLastHLMenu = trMenu;
      window.parent.frames[0].document.getElementById("edLastHLMenuID").value = trMenu.id;
    }
  }
  CheckScroll();
}

function SetMenuBG(strTdMenuH, strTdMenuN) {
  document.getElementById(strTdMenuH).style.display = "none";
  document.getElementById(strTdMenuN).style.display = "";
}

function ShowMsg(strMsg) {
  window.status = strMsg;
}

function LoadPage(strURL, strTarget) {
  if (strURL != "") {
    window.open(strURL, strTarget);
  }
}

var iMenuMax;

function CheckScroll() {
  iMenuMax = document.body.clientHeight - 160;
  window.parent.frames[0].document.getElementById("TP").style.height = ((window.parent.frames[0].document.getElementById("TP").scrollHeight < iMenuMax)?window.parent.frames[0].document.getElementById("TP").scrollHeight:iMenuMax);
  if (window.parent.frames[0].document.getElementById("TP").scrollHeight >= iMenuMax) {
    window.parent.frames[0].document.getElementById("trScrollUp").style.display = "";
    window.parent.frames[0].document.getElementById("trScrollDown").style.display = "";
  }
  else {
    window.parent.frames[0].document.getElementById("trScrollUp").style.display = "none";
    window.parent.frames[0].document.getElementById("trScrollDown").style.display = "none";
  }
}

function GetMenus(nodeParent, iLevel, bParentListKiddies) {
  var iParentMenu = iMenuNo;
  var nodeCurrent = nodeParent;
  var strResult = "";
  var iSubMenu;
  iTableNo++;
  strResult += "<table class=tblBack id=tblMenu" + iTableNo + " width='148' border=0 cellpadding=0 cellspacing=0";
  if (iLevel == 0) {
//    strResult += " onresize='JavaScript:TP.style.height = TP.scrollHeight; alert(TP.style.height + \":\" + TP.scrollHeight)'";
//    strResult += " onresize='JavaScript:alert(TP.style.height);TP.style.height = ((TP.scrollHeight < 400)?TP.scrollHeight:400);alert(TP.style.height);'";
    strResult += " onresize='JavaScript:CheckScroll()'";
  }
  var bMainChildren = false;
  for (iChild = 0; iChild < nodeCurrent.childNodes.length; iChild++) {
    if ((nodeCurrent.childNodes[iChild].attributes != null) &&
        (nodeCurrent.childNodes[iChild].attributes.getNamedItem("TITLE") != null) &&
        (nodeCurrent.childNodes[iChild].attributes.getNamedItem("TITLE").value != "")) {
      bMainChildren = true;
      break;
    }
  }
  if (bMainChildren == true) {
    iMenuNo++;
  }
  strResult += ">\n";
  var iSubMenuUsed = 0;
  var bTabKiddies;
  var bListKiddies;
  for (iSubMenu = 0; iSubMenu < nodeCurrent.childNodes.length; iSubMenu++) {
    if (nodeCurrent.childNodes[iSubMenu].tagName == "") {
      continue;
    }
    if ((nodeCurrent.childNodes[iSubMenu].attributes == null) ||
        (nodeCurrent.childNodes[iSubMenu].attributes.getNamedItem("TITLE") == null) ||
        (nodeCurrent.childNodes[iSubMenu].attributes.getNamedItem("TITLE").value == "")) {
      continue;
    }
    bTabKiddies = ((nodeCurrent.childNodes[iSubMenu].attributes != null) &&
                   (nodeCurrent.childNodes[iSubMenu].attributes.getNamedItem("SUBITEMSTYLE") != null) &&
                   (nodeCurrent.childNodes[iSubMenu].attributes.getNamedItem("SUBITEMSTYLE").value == "TABS"));
    bListKiddies = ((bParentListKiddies) ||
                    ((nodeCurrent.childNodes[iSubMenu].attributes != null) &&
                     (nodeCurrent.childNodes[iSubMenu].attributes.getNamedItem("SUBITEMSTYLE") != null) &&
                     (nodeCurrent.childNodes[iSubMenu].attributes.getNamedItem("SUBITEMSTYLE").value == "ICONS")));
    bHideKiddies = ((nodeCurrent.childNodes[iSubMenu].attributes != null) &&
                    (nodeCurrent.childNodes[iSubMenu].attributes.getNamedItem("SUBITEMSTYLE") != null) &&
                    (nodeCurrent.childNodes[iSubMenu].attributes.getNamedItem("SUBITEMSTYLE").value == "HIDE"));
    iMenuNo++;
    strMenuType = "";
    var strClick = "";
    var bChildren = false;
    for (iChild = 0; iChild < nodeCurrent.childNodes[iSubMenu].childNodes.length; iChild++) {
      if ((nodeCurrent.childNodes[iSubMenu].childNodes[iChild].attributes != null) &&
          (nodeCurrent.childNodes[iSubMenu].childNodes[iChild].attributes.getNamedItem("TITLE") != null) &&
          (nodeCurrent.childNodes[iSubMenu].childNodes[iChild].attributes.getNamedItem("TITLE").value != "")) {
        bChildren = true;
        break;
      }
    }
    if ((bChildren == true) && (!bTabKiddies) && (!bListKiddies) && (!bHideKiddies)){
      strMenuType = "P";
    }
    else {
      if (!bChildren) {
        bListKiddies = false;
      }
    }
    strResult += "<tr class=MenuItem" + strMenuType;
    if ((nodeCurrent.childNodes[iSubMenu].attributes != null) &&
        (nodeCurrent.childNodes[iSubMenu].attributes.getNamedItem("ID") != null)) {
      strResult += " menuid=\"" + nodeCurrent.childNodes[iSubMenu].attributes.getNamedItem("ID").value + "\" ";
    }
    if (bHideKiddies) {
      strResult += " hidekiddies=\"yes\" ";
    }
    strResult += " parentid=\"" + iParentMenu + "\" ";
    if ((bListKiddies) &&
        (!bTabKiddies)) {
      strResult += " icons=\"yes\" ";
      if ((nodeCurrent.childNodes[iSubMenu].childNodes[iChild].attributes != null) &&
          (nodeCurrent.childNodes[iSubMenu].childNodes[iChild].attributes.getNamedItem("ICONHEIGHT") != null) &&
          (nodeCurrent.childNodes[iSubMenu].childNodes[iChild].attributes.getNamedItem("ICONHEIGHT").value != "")) {
        strResult += " iconheight=\"" + nodeCurrent.childNodes[iSubMenu].childNodes[iChild].attributes.getNamedItem("ICONHEIGHT").value + "\" ";
      }
      else {
        strResult += " iconheight=\"" + iDefaultIconHeight + "\" ";
      }
    }
    if ((nodeCurrent.childNodes[iSubMenu].attributes != null) &&
        (nodeCurrent.childNodes[iSubMenu].attributes.getNamedItem("IMG") != null) &&
        (nodeCurrent.childNodes[iSubMenu].attributes.getNamedItem("IMG").value != "")) {
      strResult += " iconimg=\"" + nodeCurrent.childNodes[iSubMenu].attributes.getNamedItem("IMG").value + "\" ";
    }
    else {
      strResult += " iconimg=\"images/nopic.gif\" ";
    }
    strClick = "ExpandMenu(this, document.getElementById(\"trTbl" + iTableNo + "\"), true);";
    if (iLevel > 0) {
      //strResult += " style='display:none'";
    }
    strResult += " id=trMenu" + iMenuNo;
    strResult += " onmouseover=\"JavaScript:";
    if ((nodeCurrent.childNodes[iSubMenu].attributes != null) &&
        (nodeCurrent.childNodes[iSubMenu].attributes.getNamedItem("MSG") != null) &&
        (nodeCurrent.childNodes[iSubMenu].attributes.getNamedItem("MSG").value != "")) {
      strResult += " ShowMsg(\'" + nodeCurrent.childNodes[iSubMenu].attributes.getNamedItem("MSG").value + "\');";
    }
    strResult += " SetMenuBG('td" + iMenuNo + "n', 'td" + iMenuNo + "h')\"";
    strResult += " onmouseout='JavaScript:";
    if ((nodeCurrent.childNodes[iSubMenu].attributes != null) &&
        (nodeCurrent.childNodes[iSubMenu].attributes.getNamedItem("MSG") != null) &&
        (nodeCurrent.childNodes[iSubMenu].attributes.getNamedItem("MSG").value != "")) {
      strResult += " ShowMsg(\"\");";
    }
    strResult += " SetMenuBG(\"td" + iMenuNo + "h\", \"td" + iMenuNo + "n\")'";
    if ((nodeCurrent.childNodes[iSubMenu].attributes != null) &&
        (nodeCurrent.childNodes[iSubMenu].attributes.getNamedItem("URL") != null) &&
        (nodeCurrent.childNodes[iSubMenu].attributes.getNamedItem("URL").value != "")) {
      strClick += "LoadPage(\"";
//      if (!bListKiddies) {
        strClick += nodeCurrent.childNodes[iSubMenu].attributes.getNamedItem("URL").value;
//      }
      strClick += "\",\"";
      if ((nodeCurrent.childNodes[iSubMenu].attributes != null) &&
          (nodeCurrent.childNodes[iSubMenu].attributes.getNamedItem("TARGET") != null) &&
          (nodeCurrent.childNodes[iSubMenu].attributes.getNamedItem("TARGET").value != "")) {
        strClick += nodeCurrent.childNodes[iSubMenu].attributes.getNamedItem("TARGET").value;
      }
      else {
        strClick += "main";
      }
      strClick += "\")";
    }
    if (strClick != "") {
      strResult += " onclick='JavaScript:" + strClick + "'";
    }
    strResult += ">\n";
    strResult += "<td id=td" + iMenuNo + "n height=15px width='100%' style='padding-left:" + (5 + (10 * iLevel)) + "px;cursor:" + strHand + "; ";
    strResult += " background-image: url(\"../images/menu_background" + ((iSubMenuUsed == 0)?"F":"") + strBGNumber + strMenuType + (iLevel + 1) + ".jpg\")'>";
    if ((nodeCurrent.childNodes[iSubMenu].attributes != null) &&
        (nodeCurrent.childNodes[iSubMenu].attributes.getNamedItem("TITLE") != null)) {
      strResult += nodeCurrent.childNodes[iSubMenu].attributes.getNamedItem("TITLE").value;
    }
    strResult += "</td>";
    strResult += "<td id=td" + iMenuNo + "h height=15px width='100%' style='padding-left:" + (5 + (10 * iLevel)) + "px;cursor:" + strHand + "; ";
    strResult += " display:none; background-image: url(\"../images/menu_background" + ((iSubMenuUsed == 0)?"F":"") + strBGNumber + strMenuType + "HL" + (iLevel + 1) + ".jpg\")'>";
    if ((nodeCurrent.childNodes[iSubMenu].attributes != null) &&
        (nodeCurrent.childNodes[iSubMenu].attributes.getNamedItem("TITLE") != null)) {
      strResult += nodeCurrent.childNodes[iSubMenu].attributes.getNamedItem("TITLE").value;
    }
    strResult += "</td>";
    strResult += "</tr>\n<tr style='";
    strResult += "display:none' id=trTbl" + iTableNo + "><td height=15px>";
    strResult += GetMenus(nodeCurrent.childNodes[iSubMenu], iLevel + 1, bListKiddies);

    strResult += "</td>";
    strResult += "</tr>\n";
    iSubMenuUsed++;
  }
  if (bMainChildren == true) {
    if (iLevel == 0) {
      strResult += "<tr class=MenuBottom><td></td></tr>\n";
    }
  }
  strResult += "</table>\n";

  return strResult;
}

function ShowMenu(strMenuXML) {
  if (bExplorer) {
    xmlMenu = new ActiveXObject("Microsoft.XMLDOM");
  }
  else {
    xmlMenu = document.implementation.createDocument("text/xml","",null);
    strHand = "pointer";
  }
  xmlMenu.async = false;
  try {
    xmlMenu.load(strMenuXML);
  }
  catch (e) {
    //alert("ShowMenu(xmlLoad):" + e.message);
  }
  strMenuHTML = GetMenus(xmlMenu.documentElement, 0, false);
  try {
    document.getElementById("TP").innerHTML = strMenuHTML;
//    document.getElementById("EDED").value = strMenuHTML;
    ClickMenu("");
  }
  catch (e) {
    //alert(e);
//    alert("ShowMenu(MenuLoad):" + e.message + ":" + document.URL);
  }
}
