NS4   = (document.layers);
NS6   =  ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 5))
IE4   = (document.all);
ver4  = (NS4 || IE4);
MAC45 = (navigator.appVersion.indexOf("MSIE 4.5") != -1)
isMac = (navigator.appVersion.indexOf("Mac") != -1);

// routing 'constants'...
bMenusAreOpen = false;
activeMenuLayer = null;
currentpopup = null;
currentParent = null;
activeItem = null;
activepopup = null;
activeParent = null;
overcheck = null;
overmenu = 0;
menuWasOpen = 0;
textChildPopup = null;
textParentPopup = null;
var pageId = "0";
var IMG_ON = "on";
var IMG_OFF = "off";

// Default values...
var imgLangPreSufix     = "images/";
var imgLangPostSufixOn  = "1";
var imgLangPostSufixOff = "";
var bParentMenuOver     = false;
var comboPageId         = "";
var checkXComboP400_401_402 = "Main1";

function popupJSP(popJSP) {
  showMenu(popJSP);
  if (activeParent != null) {
     switchImage(activeParent,IMG_ON);
  }

  if (activeItem != null) {
     switchImage(activeItem,IMG_ON);
  }
}

function showMenu(strMenu) { // Show Menu Layer
  if ((strMenu == null) || (strMenu == 'none')) {
     return;
  }

  if (NS6) {
     menu = document.getElementById(strMenu);
  } else if (NS4) {
     menu = eval("document.layers."+strMenu);
  } else {
     menu = eval(strMenu);
  }

  if ((menu != null) && (strMenu != 'none')) {
     if (NS4) {
        menu.visibility = "show";
     } else {
         menu.style.visibility = "visible";
     }
  }
  disposeComboBox(false,strMenu);
}

function hideMenu() { // Hide Menu Layer
  if ((currentpopup == null) || (currentpopup == 'none')) {
     return;
  }

  if (currentpopup != null) {
     if (NS6) {
        menu = document.getElementById(currentpopup);
     } else if (NS4) {
        menu = eval("document.layers."+currentpopup);
     } else {
        menu = eval(currentpopup);
     }

     if ((menu != null) && (menu != 'none')) {
        if (NS4) {
           menu.visibility = "hide";
        } else {
           menu.style.visibility = "hidden";
        }
     }
  }
  disposeComboBox(true,currentpopup);
}

function checkmenu (currentpopup,check) { // Check to see if menu is open but not used, if so it is closed
  if ((currentpopup == null) || (currentpopup == 'none') || (menuWasOpen > 0)) {
     return;
  }

  if ((overmenu == 0) && (check == overcheck) && (currentpopup != null) && (currentpopup != activepopup)) {
     if (NS6) {
        menu = document.getElementById(currentpopup);
     } else if (NS4) {
        menu = eval("document.layers."+currentpopup);
     } else {
        menu = eval(currentpopup);
     }

     if (NS4) {
        menu.visibility = "hide";
     } else {
        menu.style.visibility = "hidden";
     }

     window.status = activepopup;
     showMenu(activepopup);

     if (currentParent != null) {
        switchImage(currentParent,IMG_OFF);
     }

     if (activeParent != null) {
        switchImage(activeParent,IMG_ON);
     }

     if (activeItem != null) {
        switchImage(activeItem,IMG_ON);
     }
  }

  if (textParentPopup != currentpopup) {
     hideTextMenu(textParentPopup);
     textParentPopup = null;
  }

  hideTextMenu(textChildPopup);
  textChildPopup = null;
}

function menutimeout(strMenu) { // Set a .5 second timeout when the menu is not being used to close
  //return;
  overcheck = overcheck+1;
  setTimeout("checkmenu(currentpopup,"+overcheck+")",750);
}

function tocItem (name,nMenuParent,strMenuLayer,popupMenu,fileExtension,imgRealName,noAddPrefix) {
  this.menuParent = nMenuParent;
  this.parentLayer = strMenuLayer;
  this.popupChild = popupMenu;
  this.on = new Image();
  this.off = new Image();

  if (noAddPrefix == null) {
     this.on.src = imgLangPreSufix + imgRealName + imgLangPostSufixOn + fileExtension;
     this.off.src = imgLangPreSufix + imgRealName + imgLangPostSufixOff + fileExtension;
  } else {
     this.on.src = imgLangPreSufix + imgRealName + "1" + fileExtension;
     this.off.src = imgLangPreSufix + imgRealName + "" + fileExtension;
  }
  //alert(this.on.src);
}

function toc_new (name,nMenuParent,strMenuLayer,popupMenu,fileExtension,imgRealName,noAddPrefix) {
  tocItem[name] = new tocItem(name,nMenuParent,strMenuLayer,popupMenu,fileExtension,imgRealName,noAddPrefix);
}

function checkMenuMO(strMenu) {
  bParentMenuOver = true;
  mouseUp(null);

  if ((tocItem[strMenu].popupChild == null) && (currentpopup != null)) {
     hideMenu();
  }

  if (textParentPopup != tocItem[strMenu].popupChild) {
     hideTextMenu(textParentPopup);
  }

  activeMenuLayer = tocItem[strMenu].parentLayer;
  overmenu = tocItem[strMenu].menuParent;

  if (tocItem[strMenu].popupChild != null) {
     if (currentParent != null) {
        switchImage(currentParent,IMG_OFF);
     }

     currentParent = strMenu;
     switchImage(strMenu,IMG_ON);

     if ( activeParent != strMenu) {
        switchImage(activeParent,IMG_OFF);
     }

     hideMenu();
     showMenu(tocItem[strMenu].popupChild);
     currentpopup = tocItem[strMenu].popupChild;

  } else {
     switchImage(strMenu,IMG_ON);
  }

  textParentPopup = tocItem[strMenu].popupChild;
}

function checkMenuMOUT(strMenu) {
  bParentMenuOver = false;

  if (currentParent != strMenu) {
     switchImage(strMenu,IMG_OFF);
  }

  if (currentParent == activeParent) {
     switchImage(activeItem,IMG_ON);
  }

  overmenu = 0;

  if ((tocItem[strMenu].parentLayer != null) && (tocItem[strMenu].parentLayer != activepopup)) {
     menutimeout(tocItem[strMenu].parentLayer);
  } else {
     menutimeout(currentpopup);
  }
}

function switchImage(imgName,imgState) {
  if (document.images) {
     if (imgName != null) {
        if ((tocItem[imgName].parentLayer == null) || (IE4) || (NS6)) {
           document[imgName].src = eval("tocItem[imgName]."+imgState+".src");
        } else {
           image = eval("document.layers."+tocItem[imgName].parentLayer+".document.images['"+imgName+"']");
           eval("image.src = tocItem[imgName]."+imgState+".src");
        }
     }
  }
}

function openPopup(menuId,itemId,hLiteColor,childPopup,obj) {
  setOverMenu(menuId,1);

  if (!NS4 && !NS6) {
     eItemNew = eval("document.all('" + itemId + "')");
     eParent = eItemNew.parentElement;

     if (eParent == null) {
        return;
     }

     if (!(hLiteColor == null)) {
        eParent.style.background = hLiteColor;
     }
  }

  if ((textChildPopup != null) && (menuId != textChildPopup)) {
     hideTextMenu(textChildPopup);
     textChildPopup = null;
  }


  if (childPopup != null) {
     showTextMenu(childPopup);
     textChildPopup = childPopup;
     textParentPopup = menuId;
  }

  if ((childPopup == null ) && (textParentPopup==null)) {
     textParentPopup = menuId;
  }
}

function closePopup(menuId,itemId,bgColor,childPopup) {
  setOverMenu(menuId,0);

  if (!NS4 && !NS6) {
     eItemNew = eval("document.all('" + itemId + "')");
     eParent = eItemNew.parentElement;

     if (eParent == null) {
        return;
     }

     if (!(bgColor == null)) {
        eParent.style.background = bgColor;
     }
  }
}

function hideTextMenu(strMenu) {
  if ((strMenu != null) && (strMenu != "none")) {
     if (NS4) {
        menu = eval("document.layers."+strMenu);
     } else if (NS6) {
        menu = document.getElementById(strMenu);
     } else {
        menu = eval(strMenu);
     }

     if (!NS4) {
        menu.style.visibility = "hidden";
     } else {
        menu.visibility = "hidden";
     }
  }
}

function setOverMenu(strMenu,state) {
  menuWasOpen = state;
  currentpopup = strMenu;

  if (state == 0) {
     menutimeout(currentpopup);
  }
}

function init() {
  if (NS4) {
    document.captureEvents(Event.MOUSEUP);
  }

  document.onmouseup = mouseUp;
}

// mouseDown(e) humm !!! super function
function mouseDown(e) {
  if ((!NS4) && (event.button != 1)) return true;
  return true;
}

// mouseMove(e) ben coudon !!!
function mouseMove(e) {
  return true;
}

// mouseUp(e)
function mouseUp(e) {
  bMenusAreOpen = !bMenusAreOpen;
  COAllMenus(true);
  return true;
}

function doscroll(){
//  xScrolled = (NS4)? e.pageX : event.x+document.body.scrollLeft;
//  yScrolled = (NS4)? e.pageY : event.y+document.body.scrollTop;
}

// showTextMenu(strMenu)
function showTextMenu(strMenu) {
  if (strMenu != null) {
    if (NS4) {
      menu = eval("document.layers."+strMenu);
    } else if (NS6) {
      menu = document.getElementById(strMenu);
    } else {
      menu = eval(strMenu);
    }

    if (!NS4) {
      menu.style.visibility = "visible";
    } else {
      menu.visibility = "visible";
    }
  }
}

// COAllMenus(bForceClose)
function COAllMenus(bForceClose) {
  if (bForceClose) {
    closeAllMenus();
    bForceClose = false;
    return;
  }
  if (!bMenusAreOpen) {
    openAllMenus();
  } else {
     closeAllMenus();
  }
  bForceClose = false;
}

// closeAllMenus()
function closeAllMenus() {
  strMenuStatus = "hidden";
  if (NS4) {
    if ((textChildPopup != null) && (textChildPopup!="none")) {
      menu = eval("document.layers." + textChildPopup);
      menu.visibility = strMenuStatus;
    }
    if ((textParentPopup != null) && (textParentPopup != "none")) {
      menu = eval("document.layers." + textParentPopup);
      menu.visibility = strMenuStatus;
    }
  } else {
    if ((textChildPopup != null) && (textChildPopup != "none")) {
      menu = document.getElementById(textChildPopup);
      menu.style.visibility = strMenuStatus;
    }
    if ((textParentPopup != null) && (textParentPopup != "none")){
      menu = document.getElementById(textParentPopup);
      menu.style.visibility = strMenuStatus;
    }
  }
  disposeComboBox(true,currentpopup);
}

// openAllMenus()
function openAllMenus() {
  strMenuStatus = "visible";
  if (NS4) {
    if (textChildPopup != null) {
      menu = eval("document.layers." + textChildPopup);
      menu.visibility = strMenuStatus;
    }
    if (textParentPopup != null) {
      menu = eval("document.layers." + textParentPopup);
      menu.visibility = strMenuStatus;
    }
  } else {
    if (textChildPopup != null) {
      menu = document.getElementById(textChildPopup);
      menu.style.visibility = strMenuStatus;
    }
    if (textParentPopup != null) {
      menu = document.getElementById(textParentPopup);
      menu.style.visibility = strMenuStatus;
    }
  }
}

function disposeComboBox(bOnOff,xMenu) {
  strToEval = null;
  strHref   = top.location.href;
  if (strHref.indexOf(comboPageId) == -1) {
    return;
  }

  if ((strHref.indexOf(".400.") > -1) || (strHref.indexOf(".401.") > -1) || (strHref.indexOf(".402.") > -1)) {
    strToCheck = checkXComboP400_401_402;
    if (strToCheck.indexOf(xMenu) > -1) {
      if (NS4) {
        strToEval = "document.layers.topClothing";
      }
      else {
        strToEval = "topClothing";
      }
    }
  }

  if (strToEval != null) {
    if (NS6) {
      itemCombo = document.getElementById(strToEval);
      if (itemCombo == null) {
        return;
      }
      itemCombo.style.visibility = bOnOff ? "visible" : "hidden";
    }
    else {
      if (NS4) {
        itemCombo = eval(strToEval);
        if (itemCombo == null) {
          return;
        }
        itemCombo.visibility = bOnOff ? "visible" : "hide";
      }
      else {
        itemCombo = eval(strToEval);
        if (itemCombo == null) {
          return;
        }
        itemCombo.style.visibility = bOnOff ? "visible" : "hidden";
      }
    }
  }
}

function getNewURL(strPage) {
  strNewPageId = strPage;
  
  top.location.href = strNewPageId;
}

