var arrPopups = ["toolbar_garments", "toolbar_designs", "toolbar_newGarment"];

var hSingleWin = null;
var popupCloseTimeout = null;

function OpenPopupWin(strURL, iWidth, iHeight)
{
  flLeft = (screen.availWidth  / 2) - (iWidth  / 2);
  flTop  = (screen.availHeight / 2) - (iHeight / 2);
  iScreenHeight = screen.availHeight;
  if (hSingleWin)
  {
    hSingleWin.close();
    hSingleWin = null;
  }
  hSingleWin = window.open(strURL, "singlePopup", "left=" + flLeft + ",top=" + flTop + ",width=" + iWidth + ",height=" + iHeight + ",scrollbars=yes,toolbar=no,resizable=yes");
  hSingleWin.focus();
}

function TogglePopupMenu(strName, fVisible, fNow)
{
  var elPopup = null;
  
  if (document.all)
    elPopup = document.all[strName];
  else if (document.getElementById)
    elPopup = document.getElementById(strName)
  else
    elPopup = null;
  
  if (elPopup)
    if (fVisible)
      elPopup.style.display = "inline";
    else
      if (fNow)
        elPopup.style.display = "none";
      else
        popupCloseTimeout = setTimeout("_hideMenu('" + strName + "')", 500);
}

function _hideMenu(strName)
{
  var elPopup = null;
  
  if (document.all)
    elPopup = document.all[strName];
  else if (document.getElementById)
    elPopup = document.getElementById(strName)
  else
    elPopup = null;
  
  if (elPopup)
    elPopup.style.display = "none";
}

function ShowPopupMenu(strName)
{
  clearTimeout(popupCloseTimeout);
  for (var n = 0; n < arrPopups.length; n++)
  {
    if (strName == "NONE")
      TogglePopupMenu(arrPopups[n], false, true);
    else
    {
      if (arrPopups[n] == strName)
        TogglePopupMenu(arrPopups[n], true, true);
      else
        TogglePopupMenu(arrPopups[n], false, true);
    }
  }
}
