﻿// JavaScript Document for www.tmsmetalizing.com, TMS Web Services
function enhanceMenu() {
  var strPath = location.pathname;
     var strPath = strPath.replace(/^.*tmsExpressions\\/, "/");  // for testing only
     var strPath = strPath.replace(/\\/g, "/");                  // for testing only
  var arrPathname = strPath.split("/");
  var numArrayLen = arrPathname.length;
  var strCurFileId = arrPathname[numArrayLen - 1].replace(/[.].*/, "");
  if ((strCurFileId == "index") || (strCurFileId == "")) {
    var bIndexFile = true;
  }
  if (arrPathname[2] == null) {
    if (bIndexFile) {
      strCurFileId = "home";
    } 
    highlight(strCurFileId);
    highlight(strCurFileId + "Hoz");                // highlight the footer - Done
    return; 
  } else {
    if ((bIndexFile) && (numArrayLen == "4")) {
      strCurFileId = arrPathname[numArrayLen - 2];
    }
    var strSubMenu1 = (arrPathname[1]);
    var strSubMenu2 = (arrPathname[2]);
//alert("strPath: " + strPath + "\narrPathname: " + arrPathname + "\nnumArrayLen = " + numArrayLen + "\narrPathname[0]: " + "\narrPathname[1]: " + arrPathname[1] + "\narrPathname[2]: " + arrPathname[2]  + "\narrPathname[3]: " + arrPathname[3] + "\nstrCurFileId: " + strCurFileId + "\nbIndexFile: " + bIndexFile );
    openMenu(strSubMenu1 + "SubMu", "mainMenuSub"); // open the 1st submenu
    highlight(strSubMenu1);
    highlight(strSubMenu1 + "Hoz");                // highlight the footer - Done
    if (numArrayLen >= "3") {                      // if there is a 2nd submenu, open it
      highlight(strCurFileId);
    }
  }
}

function highlight(strId) {
  var menuItem = document.getElementById(strId);
  if (menuItem != null) { // to catch an incorrect parameter so that it will not error
//alert("set highlight for: " + strId);                       
    menuItem.style.backgroundColor = "#800000";
    menuItem.style.color = "#FFFFFF";
  }
}

function openMenu(strId, strClass) {
  var menuItem = document.getElementById(strId);
//alert("open menu for: " + strId);                       
  if (menuItem != null) {                        // to catch an incorrect parameter so that it will not error
    menuItem.className = strClass;
  }
}
