var ActiveMenu=null
var ActiveMenu2=null
var lastMenuBarSel=null
var lastActiveMenuSel=null
var pMenuBar,pMenu
var gMenuBar=new clsMenuBar()
var gMenu
function addItem(newitem){this.cItems[this.cItems.length]=newitem}
function clsMenuItem(vDesc, vAction){
  this.pDesc=vDesc
  this.pAction=vAction
  this.pEnabled=(vAction==null)?false:true
}
function clsMenu(vDesc, vAction, vWidth){
  this.pDesc=vDesc
  this.pAction=vAction
  this.pWidth=(vWidth==null)?100:vWidth
  this.pEnabled=true // always true for now
  this.cItems=new Array()
  this.mAdd=addItem
}
function clsMenuBar(){
  this.cItems=new Array()
  this.mAdd=addItem
  this.mCreate=createMenuBar
  this.mDestroy=destroyMenuBar
}
function propMenuBar(vLeft, vTop, vHeight, vBorder, vSpacing, vPadding, vFColor, vBColor, vHiFColor, vHiBColor, vXFColor, vXBColor, vXHiFColor, vXHiBColor, vFont, vFontSz, vFontWt, vFontSty, vWrap){
  this.pLeft=(vLeft==null)?0:vLeft
  this.pTop=(vTop==null)?0:vTop
  this.pHeight=(vHeight==null)?27:vHeight
  this.pBorder=(vBorder==null)?0:vBorder
  this.pSpacing=(vSpacing==null)?0:vSpacing
  this.pPadding=(vPadding==null)?0:vPadding
  this.pFColor=(vFColor==null)?'black':vFColor
  this.pBColor=(vBColor==null)?'silver':vBColor
  this.pHiFColor=(vHiFColor==null)?'white':vHiFColor
  this.pHiBColor=(vHiBColor==null)?'navy':vHiBColor
  this.pXFColor=(vXFColor==null)?'white':vXFColor
  this.pXBColor=(vXBColor==null)?'navy':vXBColor
  this.pXHiFColor=(vXHiFColor==null)?'white':vXHiFColor
  this.pXHiBColor=(vXHiBColor==null)?'navy':vXHiBColor
  this.pFont=(vFont==null)?'Arial':vFont
  this.pFontSz=(vFontSz==null)?'10pt':vFontSz
  this.pFontWt=(vFontWt==null)?'normal':vFontWt
  this.pFontSty=(vFontSty==null)?'normal':vFontSty
  this.pWrap=(vWrap==null)?false:vWrap
}
function propMenu(vHeight, vBorder, vSpacing, vPadding, vFColor, vBColor, vHiFColor, vHiBColor, vXFColor, vXBColor, vXHiFColor, vXHiBColor, vFont, vFontSz, vFontWt, vFontSty){
  this.pHeight=(vHeight==null)?0:vHeight
  this.pBorder=(vBorder==null)?0:vBorder
  this.pSpacing=(vSpacing==null)?0:vSpacing
  this.pPadding=(vPadding==null)?0:vPadding
  this.pFColor=(vFColor==null)?'black':vFColor
  this.pBColor=(vBColor==null)?'silver':vBColor
  this.pHiFColor=(vHiFColor==null)?'white':vHiFColor
  this.pHiBColor=(vHiBColor==null)?'navy':vHiBColor
  this.pXFColor=(vXFColor==null)?'white':vXFColor
  this.pXBColor=(vXBColor==null)?'navy':vXBColor
  this.pXHiFColor=(vXHiFColor==null)?'white':vXHiFColor
  this.pXHiBColor=(vXHiBColor==null)?'navy':vXHiBColor
  this.pFont=(vFont==null)?'Arial':vFont
  this.pFontSz=(vFontSz==null)?'10pt':vFontSz
  this.pFontWt=(vFontWt==null)?'normal':vFontWt
  this.pFontSty=(vFontSty==null)?'normal':vFontSty
}
function createMenuAction(plink){
  if (plink==''||plink==null) return ''
  if (plink.indexOf('javascript:')>=0)
    return ' onClick="'+plink+'" style="cursor:hand;"'
  else
    return ' onClick="location=\''+plink+'\'" style="cursor:hand;"'
}
function createMBFontInfo(f){
  return " color:"+f.pFColor+"; font-family:"+f.pFont+"; font-size:"+f.pFontSz+"; font-weight:"+f.pFontWt+"; font-style:"+f.pFontSty+";"
}
function createMIFontInfo(f, enabled){
  if (enabled)
    return " color:"+f.pFColor+"; font-family:"+f.pFont+"; font-size:"+f.pFontSz+"; font-weight:"+f.pFontWt+"; font-style:"+f.pFontSty+";"
  else
    return " color:"+f.pXFColor+"; font-family:"+f.pFont+"; font-size:"+f.pFontSz+"; font-weight:"+f.pFontWt+"; font-style:"+f.pFontSty+";"
}
function createFColorInfo(mobj, enabled){
  if (enabled)
    return " color="+mobj.pFColor+" "
  else
    return " color="+mobj.pXFColor+" "
}
function createBColorInfo(mobj, enabled){
  if (enabled)
    return " bgcolor="+mobj.pBColor+" "
  else
    return " bgcolor="+mobj.pXBColor+" "
}
function createMenuBar(){
  var s='';var mid='';var mb=pMenuBar;var m=pMenu;var w=getPageWidth();var mbwidth=0;var fwidth=0;var action='';var hasmenu='';var mitem;var sep;var fstyle;var mwrap='';
  fstyle=createMBFontInfo(mb)
  if(mb.pWrap)mwrap=" nowrap "
  s="<div id=MenuBar onMouseOut='hideActiveMenu()' style='position:absolute; left:"+mb.pLeft+"px; top:"+mb.pTop+"px; width=760px; height:"+mb.pHeight+"; z-index:1; layer-background-color:"+mb.pBColor+"; cursor:default;'>\n"
  s+="<table width=100% height=100% border="+mb.pBorder+" cellspacing='"+mb.pSpacing+"' cellpadding='"+mb.pPadding+"' style='border-style:outset; border-width:1px; border-color:"+mb.pHiBColor+"; "+fstyle+"'>\n"
  s+="<tr bgcolor="+mb.pBColor+">\n"
  for(i=0;i<gMenuBar.cItems.length;i++){
    mid="Menu"+i
    mitem=gMenuBar.cItems[i]
    action=createMenuAction(mitem.pAction)
    fcolor=createFColorInfo(mb, mitem.pEnabled)
    bcolor=createBColorInfo(mb, mitem.pEnabled)
    sep=(mitem.pDesc==null||mitem.pDesc=='')?true:false
    hasmenu=(mitem.cItems.length>0)?"'showMenuX("+mid+",lyrXP"+mid+",tblXP"+mid+");'" : "'hideActiveMenu();selMnuBarItem("+mid+")' onMouseOut='normMnuBarItem()'"
    if (sep){s+="<td id="+mid+" width="+mitem.pWidth+" style='cursor:default;'>&nbsp;"}
    else{s+="<td align='center' id="+mid+" width="+mitem.pWidth+bcolor+mwrap+" onMouseOver="+hasmenu+action+">&nbsp;"+mitem.pDesc+"\n"}
    s+="</td>\n"
    mbwidth+=mitem.pWidth
  }
  fwidth=w-mbwidth
  s+="<td id=filler width="+fwidth+" onMouseOver=\"filler.style.cursor='default'\">&nbsp;</td>\n"
  s+="</tr>\n</table>\n</div>\n\n"
  s+="<iframe id='lyrFrame' frameborder='0' scrolling='no' style='position:absolute;left:0;top:0;z-index:50;visibility:hidden;'></iframe>\n\n"
  fstyle="";fstyle=createMBFontInfo(m)
  for(i=0;i<gMenuBar.cItems.length;i++){
    if (gMenuBar.cItems[i].cItems.length>0){
      mid="Menu"+i
      s+="<div id=lyrXP"+mid+" onMouseOut='hideActiveMenu()' style='position:absolute; left:0px; width:100px; z-index:100; border-style:outset; border-width:1px; border-color:"+m.pHiBColor+"; layer-background-color:"+m.pBColor+"; visibility:hidden; cursor:default;'>\n"
      s+="<table id=tblXP"+mid+" width=100% height=100% border="+m.pBorder+" cellspacing='"+m.pSpacing+"' cellpadding='"+m.pPadding+"'>\n"
      for(j=0;j<gMenuBar.cItems[i].cItems.length;j++){
        mitem=gMenuBar.cItems[i].cItems[j]
        action=createMenuAction(mitem.pAction)
        fcolor=createFColorInfo(m, mitem.pEnabled)
        bcolor=createBColorInfo(m, mitem.pEnabled)
        fstyle=createMIFontInfo(m, mitem.pEnabled)
        sep=(mitem.pDesc==null||mitem.pDesc=='')?true:false
        if (sep){
          s+="<tr height='1'><td id=iXP"+mid+"_"+j+" bgcolor="+m.pHiBColor+"></td>\n</tr>\n"
        }
        else{
          s+="<tr height="+m.pHeight+" onMouseOver='selMnuItem(iXP"+mid+"_"+j+","+mitem.pEnabled+")'>\n"
          s+="<td nowrap id=iXP"+mid+"_"+j+action+bcolor+" style='"+fstyle+"'>&nbsp;&nbsp;"+mitem.pDesc+"&nbsp;\n</td>\n</tr>\n"
        }
      }
      s+="</table>\n</div>\n\n"
    }
  }
  document.body.insertAdjacentHTML("afterBegin",s);
  s=''
}
function destroyMenuBar(){
  var imax
  var jmax
  imax=gMenuBar.cItems.length
  for(i=0;i<imax;i++){
    jmax=gMenuBar.cItems[i].cItems.length
    for(j=0;j<jmax;j++){gMenuBar.cItems[i].cItems[j]=null}
    gMenuBar.cItems[i]=null
  }
}
function showMenu(ref, menu){
  var objref=getObj(ref)
  var objmenu=getObj(menu)
  if (objref==null||objmenu==null) return
  var x=getPageLeft(objref)
  //var x=0
  var y=getPageTop(objref)+getHeight(objref)
  if (ActiveMenu!=null){
    if (ActiveMenu.Id!=objmenu.Id){
      hideLayer(ActiveMenu)
      ActiveMenu=null
    }
  }
  moveLayerTo(objmenu,x,y)
  selMnuBarItem(objref)
  showLayer(objmenu)
  ActiveMenu=objmenu
  return false
}
function showMenuX(ref, menu, tbl){
  var objref=getObj(ref)
  var objtbl=getObj(tbl)
  var objmenu=getObj(menu)
  if (objref==null||objmenu==null) return
  var x=getPageLeft(objref)
  var y=getPageTop(objref)+getHeight(objref)
  if (ActiveMenu!=null){
    if (ActiveMenu.Id!=objmenu.Id){
      hideLayer(ActiveMenu)
      ActiveMenu=null
    }
  }
  moveLayerTo(objmenu,x,y)
  selMnuBarItem(objref)
  showLayer(objmenu)
  ActiveMenu=objmenu

  var objframe=eval(document.all.lyrFrame)
  moveFrameTo(objframe,x,y)
  setFrameWH(objframe,getWidth(objtbl)+2,getHeight(objtbl)+2)
  showLayer(objframe)

  return false
}
function hideActiveMenu(){
  var srcObj=window.event.fromElement
  var tgtObj=window.event.toElement
  if (tgtObj!=null){
    if (srcObj==null) return
    if (srcObj.contains(tgtObj)) return
    var menuid=tgtObj.id
	if (menuid.indexOf('lyrXPXMenu')>=0) return
    if (menuid.indexOf('lyrXPMenu')>=0) return
    if (menuid.indexOf('tblXPMenu')>=0) return
    if (menuid.indexOf('iXPMenu')>=0) return
	
	if (menuid.indexOf('customerservice')>=0) return
	if (menuid.indexOf('reomanager')>=0) return
	if (menuid.indexOf('assetmanager')>=0) return
	if (menuid.indexOf('brokeragent')>=0) return
	if (menuid.indexOf('generaluser')>=0) return
  }
  var objmenu=getObj(ActiveMenu)
  if (objmenu==null) return
  normMnuBarItem()
  normMnuItem()
  hideLayer(objmenu)
  ActiveMenu=null

  var objframe=eval(document.all.lyrFrame)
  hideLayer(objframe)
  return false
}
function selMnuBarItem(menu){
  var obj=getObj(menu)
  if (obj==null) return
  normMnuBarItem()
  setColor(obj,pMenuBar.pHiFColor)
  setBgColor(obj,pMenuBar.pHiBColor)
  lastMenuBarSel=obj
  return false
}
function normMnuBarItem(){
  var obj=getObj(lastMenuBarSel)
  if (obj==null) return
  setColor(obj,pMenuBar.pFColor)
  setBgColor(obj,pMenuBar.pBColor)
  lastMenuBarSel=null
  return false
}
function selMnuItem(menu, enabled){
  var obj=getObj(menu)
  if (obj==null) return
  normMnuItem()
  lastMIFColor=getColor(obj)
  lastMBFColor=getBgColor(obj)
  if (enabled){
    setColor(obj,pMenu.pHiFColor)
    setBgColor(obj,pMenu.pHiBColor)
  }
  else{
    //setColor(obj,pMenu.pXHiFColor)
    //setBgColor(obj,pMenu.pXHiBColor)
  }
  lastActiveMenuSel=obj
  return false
}
function normMnuItem(){
  var obj=getObj(lastActiveMenuSel)
  if (obj==null) return
  setColor(obj,lastMIFColor)
  setBgColor(obj,lastMBFColor)
  lastActiveMenuSel=null
  return false
}
function gotoURL(url){
  location = url
}
function openNewWindow(url, wtitle, woptions){
  if (wtitle==null) wtitle="newWindow"
  if (woptions==null) woptions=""
  var w=window.open(url, wtitle, woptions);
}
