/**
  This is preliminary code to process JS menus. It's intended
  to try to remove the menu ASAP instead of leaving it around
  like many other JS menus. It's still included in Tang forms by
  default.

  This code is for preliminary menu support and is not yet
  part of Tang proper. It is however used in the Straightup site
  and may find other uses.

    <span class="menutitle" onclick="showmenu(event, 'menu1')">Menu Title</span> <!-- onmouseover works too -->
    ..
    (elsewhere in the document)
    ..
    <div class="menubody" id="menu1" onmouseout="hidemenu(event, 'menu1')">
      <div class="menuitem"><a href="url1">menu item 1</a></div>
      <div class="menuitem"><a href="url2">menu item 2</a></div>
      <div class="menuitem"><a href="url3">menu item 3</a></div>
      <div class="menuitem"><a href="url4">menu item 4</a></div>
    </div>
*/

function showmenu(event, id)
{
  event = BrowserGetEvent(event);
  var source = BrowserGetTarget(event);
  
  var menu = document.getElementById(id);
  menu.style.top = source.offsetTop + "px";
  menu.style.left = source.offsetLeft + "px";
  menu.style.display = "block";
}

function hidemenu(event, id)
{
  var menu = document.getElementById(id);

  if (event == null)
    event = document.event;

  var target = event.relatedTarget;
  if (target == null) 
    target = event.toElement;

  // If the event came from any child of the menu
  // then ignore it. Only if the event came from
  // some external element should we hide the menu.
  while (target != null)
  {
    if (target == menu)
      break;
    target = target.parentNode;
  }

  if (target == null)
    menu.style.display = "none";
  else
    event.cancelBubble = true;
}
