var hwmenfirsttime=true;
function openMenu(mx,my,p){
  if (!HW_MenuBuild)
  {
//      return;
  }
  if (typeof p == "undefined")
    p={};
  if (typeof p.h == "undefined")
    p.h=true;

  var x=3;
  var y=3;
  var op;
  p.oname=p.oname||p.mname;
  if (p.mname)
  {
    helpm=eval(p.mname);
  }
  else
    helpm=hwbar;


  var xpo = helpm.xpos_;
  var ypo = helpm.ypos_;

  if (typeof xpo == "undefined")
  {
    var xpo=p.xp=p.xp||"l";
  }
  if (typeof ypo == "undefined")
  {
    var ypo=p.yp=p.yp||"t";
  }

  if (p.obj)
  {
    helpm.obj_="/"+p.obj;
  }
  if (p.attrobj)
  {
    helpm.attrobj_=p.attrobj;
  }
  if (helpm.cname_ && !p.cname)
  {
    p.cname=helpm.cname_;
  }
  if (helpm.container_)
  {
    if (!top.frames[helpm.container_]) { // if the frame does not yet exist do nothing
      return;
    }
    if (helpm.opTim_)
    {
      Menu_clearTimeout(helpm.opTim_);
      helpm.opTim_=null;
    }
    if (!top.frames[helpm.container_].HW_pageLoaded)
    {
      var functionString='openMenu(-1,-1,{';
      var commaneeded=false;
// <FIXXXXXME date="2001-03-22" author="jschipf">
// ###add part for pasing attrobj###
// </FIXXXXXME>
      if (p.oname)
      {
        if (commaneeded) functionString+=",";
        functionString+='oname:"'+p.oname+'"';
        commaneeded=true;
      }
      if (p.cname)
      {
        if (commaneeded) functionString+=",";
        functionString+='cname:"'+p.cname+'"';
        commaneeded=true;
      }
      if (p.mname)
      {
        if (commaneeded) functionString+=",";
        functionString+='mname:"'+p.mname+'"';
        commaneeded=true;
      }
      if (p.ma)
      {
        if (commaneeded) functionString+=",";
        functionString+='ma:"'+p.ma+'"';
        commaneeded=true;
      }
      functionString+='})';
      helpm.opTim_=Menu_setTimeout(functionString,200,window);
      return;
    }

    referto=eval("top.frames."+helpm.container_+".document");
  }
  else
  {
    referto=document;
  }

  if (p.oname) {
    op=referto.getElementById(p.oname);
  }
  else {
    op=referto.getElementById("opener");
  }
  
  // if the container for the menu doesn't exists
  // stop processing creating the menu
  if (op == null) {
    return;
  }

  if (typeof mx !="undefined" && mx!=-1)
  {
    x=mx;
    y=my;
    if (p.h)
      op.style.visibility=vishide;
  }
  else
  {
    x=computeOffsetLeft(op,"BODY");
    y=computeOffsetTop(op,"BODY");
    var xo=x;
    var yo=y;
    if (xpo=="r")x+=op.offsetWidth;
    if (ypo=="b")y+=op.offsetHeight;
    if (p.h)
      op.style.visibility=vishide;
  }

  if (p.cname)
  {
    var opleft=referto.getElementById(p.cname);
    var cleft=null;
    if(opleft) {
      cleft=computeOffsetLeft(opleft,"BODY");
    }
  }

  if (helpm.relright_)
  {
    // finally register the menu for resize handling
    registerMenuResize(helpm,p);
  }

  if (!helpm.parentItem_)
  {
    helpm.addHideLayer('top.HW_Mainframe.document.getElementById("HWHIDE1")');
  }

  if (helpm.items_.length>0) {

    if (p.element) {
      helpm.openerElement_ = p.element;
    }
    var h_ma = helpm.menualignment_;
    if (typeof h_ma == "undefined")
      h_ma = p.ma = p.ma || "r";
    helpm.showAt(x,y,{ma:h_ma,may:p.may,positionConstraints:{left:cleft}});
    helpm.saveStat();
    if (p.event && p.event.type=="keypress") {
      helpm.focus();
    }
  }
}
function closeMenu()
{
  hwbar.hide();
  document.getElementById("opener").style.visibility=visshow;
  return false;
}

//--------------------------------------------------------------------
/**
 * This function registers the passed menu parameter, to recall openMenu with,
 * when the browser window is resized
 * It furter registers the onresize Handler
 *
 * @param p: object used in openMenu()
 * @param menu: the menu which should be opened. it is used to check if the
 *     function was already called with for this menu.
 * @return: none
 */

function registerMenuResize(menu,p)
{
  if (typeof gMenuOnresizeSaved == "undefined")
  {
    gMenuOnresizeSaved=new Object();
    gMenuOnresizeSaved.sonresize=window.onresize;
    window.onresize=hw_menuOnresize;
  }

  if (typeof gRegisteredMenus == "undefined")
  {
    gRegisteredMenus=[];
  }
  for (menucount=0;menucount<gRegisteredMenus.length;menucount++)
  {
    if (gRegisteredMenus[menucount].menu==menu)
      return;
  }
  gRegisteredMenus[gRegisteredMenus.length] = {menu:menu,p:p};
}

//--------------------------------------------------------------------
/**
 * This function is called on resize of the browser window
 * It is registered in header_menu.html. as a result of this function
 * the menus are positioned correctly. Do to this, the function
 * openMenu() is reused.
 * This is only necessary for IE because for Netscape onresize the
 * the whole page is reloaded
 *
 * @param none
 * @return: none
 */
function hw_menuOnresize()
{
  // check if there are registered menus
  if (typeof gRegisteredMenus!="undefined" && gRegisteredMenus.length)
  { // go thru all registered menus
    for (var menucount=0;menucount<gRegisteredMenus.length;menucount++)
    { // and call open menu with the passed parameters
      openMenu(-1,-1,gRegisteredMenus[menucount].p)
    }
  }
  // call saved onresize
  if (typeof ms != "undefined" && typeof ms.sonresize == "function")
    ms.sonresize();
}


