
var numMenus = 0;   /* Defines the number of menus available */
var Menus = new Array();   /* Stores the menu contents */                               
var MenuText = new Array(); /* Stores the text of the menu */
var MenuLink = new Array(); /* Stores the links */

/******************************************************************************
    addMenuItem:
    
    parameters:
        menu --> a string with the id of the cell the menu is attached to
        linkText --> The text to appear in the sub menu
        link --> the url of the page to link to
 ******************************************************************************/
 
function addMenuItem (Menu, linkText, link) {
    numMenus = Menus.push(Menu);
    MenuText.push(linkText);
    MenuLink.push(link);
  }
  
/******************************************************************************
    move_box
    
    parameters:
        menu --> a string with the id of the cell the menu is attached to
        linkText --> The text to appear in the sub menu
        link --> the url of the page to link to
 ******************************************************************************/
 
function move_box(an, box) {
  var cleft = 0;
  var ctop = 0;
  var obj = an;
  
  /* Get the offset for the parent */
  while (obj.offsetParent) {           
    cleft += obj.offsetLeft;            /* Adds the left offsets for all parents of this object */
    ctop += obj.offsetTop;              /* Adds the top offsets for all parents of the object */
    obj = obj.offsetParent;
  }
  
  /* Adjust for the left margin */
  if (document.body.currentStyle && document.body.currentStyle['marginLeft']) {
    cleft += parseInt(document.body.currentStyle['marginLeft']);
  }
  
  if (navigator.appName == "Microsoft Internet Explorer") {
    cleft = cleft - 120;
  }
    
  box.style.left = cleft + 'px';
  
  /* Get the offset for the top of the parent */
  ctop += an.offsetHeight ;             /* Moves the submenu to the bottom of the cell */
  
  /* Adjust for the top margin */
  if (document.body.currentStyle && document.body.currentStyle['marginTop']) {
    ctop += parseInt(document.body.currentStyle['marginTop']);
  }  
  
  box.style.top = ctop + 'px';
}

/******************************************************************************
    show_menu:
    
    parameters:
        an --> a string with the id of the cell
 ******************************************************************************/
 
function show_menu(an) {
  var li = an;                              /* Get the id from the current object */
  var boxdiv = document.getElementById(li); /* Get a reference to the object */
  var an_pass = boxdiv;
  
  /* These lines attempt to find an existing submenu.  The submenu will exist
     after the first time a person hovers over the menu object */
     
  var id = li + 'subMenu';                  /* Get the name of the subment */
  var submenu = document.getElementById(id); /* Get a reference to the subment */
  
  hide_menu(li);
  
  /* If the submenu does not exist then build it */
  if (submenu == null ) {
     boxdiv = document.createElement('div');
     boxdiv.setAttribute ('id', id);
     boxdiv.style.display = 'block';
     boxdiv.style.position = 'absolute';
  
     var contents = document.createElement('table');
     contents.id = 'DDSubMenu';

     rowIdx = 0;
     for (var i=0; i<numMenus; ++i) {
        if (Menus[i] == li )  {
            var oRow = contents.insertRow(rowIdx);
            var oCell = oRow.insertCell(0);
            var aElem = document.createElement('a');    /* Create a hyperlink item */
            aElem.href = MenuLink[i];                   /* set the hyperlink */
            var aElemTN = document.createTextNode(MenuText[i]);   //Create a text node to hold the text of the <a>
            aElem.appendChild(aElemTN);  //Append the <a> text node to the <a> element
            oCell.appendChild(aElem);
            ++rowIdx;
        }
     }
     
     boxdiv.appendChild(contents); 
     document.body.appendChild(boxdiv);
     move_box(an_pass, boxdiv);
     
 /* if it does exist simply display it */
  } else {
     submenu.style.display = 'block';
  }

  return false;
}

/******************************************************************************
    hide_menu:
    
    parameters:
        an --> a string with the ID of the cell
 ******************************************************************************/
 
function hide_menu(an) {  
  var li = an;                              /* Get the id from the current object */
  var boxdiv = document.getElementById(li); /* Get a reference to the object */
  var ddTable = document.getElementById ('_mbaMaster_TopDD');
  if (ddTable != null ) {
    var oCells = ddTable.rows[0].cells;
  
    for (var i=0; i<oCells.length; ++i) {
     var srchID = oCells[i].id;
     if (srchID != li) {
            var id = srchID + 'subMenu';
            var submenu = document.getElementById(id); /* Get a reference to the submenu */
  
            if (submenu != null) {
                submenu.style.display='none';
            }
        }
     }
  }
}
