/*
 *
 *
 *	(c) Profitmaster Systems Ltd, 2003
 *
 *	Version 2.0.0
 *
 *
 */

var menus     = new Array();

/*
 *	Display menus
 */

function
showMenu(menuId, btnLink, dropdown)
{
  if (document.getElementById) {
    createMenuInfo(menuId, null)
    displayMenu(menuId, btnLink, dropdown)
  }
}

function
showSubMenu(menuId, menuLink, btnLink)
{
  if (document.getElementById) {
    createMenuInfo(menuId, menuLink);
    displayMenu(menuId, btnLink, false)
  }
}

/*
 *	Shows the menu and marks it.
 */

function
displayMenu(menuId, btnLink, dropdown)
{

  document.getElementById(menuId).style.display = "block";

  linkObj = document.getElementById(btnLink);

  if (dropdown) {
    document.getElementById(menuId).style.left   = getLeft(linkObj) - 8 + "px";
    document.getElementById(menuId).style.top  = getTop(linkObj) + getHeight(linkObj) + "px";
    // document.getElementById(menuId).style.top    = linkObj.offsetTop + linkObj.offsetHeight + "px";
  } else {
    document.getElementById(menuId).style.left = getLeft(linkObj) + getWidth(linkObj) + "px";
    document.getElementById(menuId).style.top  = getTop(linkObj) + "px";
  }

  overMenu(menuId);
}

/*
 *	
 */

function
createMenuInfo(id, menuLink)
{

  arrNum = 0;

  for (a = 1; a < menus.length; a++) {
    if ((menus[a][0] == id) && (menus[a][1] == menuLink)) {
      arrNum = a;
    }
  }

  if (arrNum == 0) {
    arrNum = menus.length;
    if (arrNum == 0) { arrNum++; }
    menus[arrNum] = new Array(id, menuLink , false, false);
  }

}

/*
 *	Mark menu and submenus as open
 */

function
overMenu(id)
{
  do {
    id = markMenu(id, true);
  } while (id != null)
}

function
markMenu(id, markAs)
{
  submenuId = null;

  for ( a = 1; a < menus.length; a++ )
  {
    if (menus[a][0] == id) {
      menus[a][2] = markAs;
      submenuId = menus[a][1];
      a = menus.length;
    }
  }

  timer      = setTimeout("checkMenus()", 60);

  return submenuId;
}

/*
 *	Mark all menus for closure. MouseOver events will re-open.
 */

function
leaveMenu(id)
{
  for ( a = 1; a < menus.length; a++ )
  {
    if (menus[a]) {
      menus[a][2] = false;
    }
  }

  timer      = setTimeout("checkMenus()", 60);
}

/*
 *	Runs though and closes menus
 */

function
checkMenus()
{
  for ( a = 1; a < menus.length; a++ )
  {
    if (menus[a]) {
      if (menus[a][2] == false) {
        document.getElementById(menus[a][0]).style.display = "none";
      }
    }
  }
}

/*
 *	Standard routines
 */

function getLeft(ll) {
  if (ll.offsetParent)
    return (ll.offsetLeft + getLeft(ll.offsetParent));
  else
    return (ll.offsetLeft);
}

function getTop(ll) {
  
  if (ll.offsetParent)
    return (ll.offsetTop + getTop(ll.offsetParent));
  else
    return (ll.offsetTop);
}

function getHeight(ll) {
  return (ll.offsetHeight);
}

function getWidth(ll) {
  return (ll.offsetWidth);
}

