/*******************************************************************************
  Code for the popup menu on the document pages.
*******************************************************************************/

// Display the div that normally is invisible.
function showmenu() {
	document.getElementById('dropbox').style.visibility = 'visible';
}

// Search the DOM to see if the element is contained within another.
function containsDOM (container, containee) {
  var isParent = false;
  do {
    if ((isParent = container == containee))
      break;
    containee = containee.parentNode;
  }
  while (containee != null);
  return isParent;
}


// Determine if the onmouseout event pertains to actually leaving the element's bounds.
function checkLeave(element, event) {
	if (event.relatedTarget) {
		return !containsDOM(element, event.relatedTarget);
	} else if (element.contains && event.toElement) {
		return !element.contains(event.toElement);
	}
}


// Hide the menu if we have left the bounds.
function hidemenu(element, event) {
	if (checkLeave(element, event)) {
		document.getElementById('dropbox').style.visibility = 'hidden';
	}
}