//------------------------------------------------------------------------------
// DomAPI Menu Component
// D. Kadrioski 7/30/2001
// (c) Nebiru Software 2001
//------------------------------------------------------------------------------
var menuCascadeChevron = "&gt;";
function Menu(parent,theme){
  var elm   = createElm(parent,null,null,150,null,null,null,"UL");
  elm.theme = theme?theme:defaultTheme;
  with(elm.style){
    cursor      = "default";
    margin      = "0px";
    padding     = "0px";
    fontFamily  = '"MS Sans Serif",Geneva,sans-serif';
    fontSize    = "8pt";
    padding     = "0px";
    overflow    = "visible";
    listStyle   = "none";
    height      = "auto";
  }
  if (isNS){
    elm.style.marginRight = "10px";
    elm.style.padding     = "0px";
  }
  elm.addItem       = MenuAdditem;
  elm.addSeparator  = MenuAddseparator;
  elm.onmouseover   = MenuOnmouseover;
  elm.onmouseout    = MenuOnmouseout;
  elm.timer         = null;
  elm.reDraw=function(){
    with(this.style){
      backgroundColor = this.theme.ctrlBgColor;
      color           = this.theme.ctrlFgColor;
      borderStyle     = this.theme.bdrOutset;
      borderWidth     = this.theme.bdrWidth;
      borderColor     = this.theme.bdrColor;
    }
    for(var b=0;b<this.childNodes.length;b++){
      with(this.childNodes[b].style){
        font            = this.theme.ctrlFont;
        backgroundColor = this.theme.ctrlBgColor;
        color           = this.theme.ctrlFgColor;
      }
      if(this.childNodes[b].dropDown){
        this.childNodes[b].dropDown.theme=this.theme;
        this.childNodes[b].dropDown.reDraw();
      }
    }
  };
  //-----
  elm.onselect=function(item){};
  elm.hide();
  elm.reDraw();
  elm.domAPIObjType="MENU";
  return elm;
};
//------------------------------------------------------------------------------
function MenuAdditem(caption,fn){
  this.appendChild(new MenuItem(this,caption,fn));
};
//------------------------
function MenuAddseparator(){
  this.appendChild(document.createElement("HR"));
};
//------------------------
MenuOnmouseover=function(e){
  if(this.timer)clearTimeout(this.timer);
  var temp=findTarget(e,"LI"); if(!temp)return;
  var root=temp.parentNode;
  if(isIE)event.cancelBubble = true; else e.preventDefault(); // stop bubble
  if((!temp) || (temp.nodeName!= "LI") || temp.selected)return;
  temp.style.color           = root.theme.selFgColor;
  temp.style.backgroundColor = root.theme.selBgColor;
  temp.style.font            = root.theme.selFont;
  if(temp.cascadeIcon){
    temp.cascadeIcon.style.color           = root.theme.selFgColor;
    temp.cascadeIcon.style.backgroundColor = root.theme.selBgColor;
  }
  if(temp.dropDown){
    temp.parentNode.isOpen         = true;
    temp.dropDown.style.left       = parseInt(temp.offsetWidth)+"px";
    temp.dropDown.style.top        = parseInt(temp.offsetTop  )+"px";
    temp.dropDown.style.visibility = "visible";
    temp.dropDown.style.font       = root.theme.ctrlFont;
  }
  var tds=temp.getElementsByTagName("TD");
  for(var b in tds)
    if(tds[b].style)
      with(tds[b].style){
        color           = root.theme.selFgColor;
        backgroundColor = root.theme.selBgColor;
      }
};
//------------------------
MenuOnmouseout=function(e){
  var temp=findTarget(e,"LI"); if(!temp)return;
  var root=temp.parentNode;
  if(isIE)event.cancelBubble = true; else e.preventDefault(); // stop bubble
  if((!temp) || (temp.nodeName!= "LI") || temp.selected)return;
  temp.style.color           = root.theme.ctrlFgColor;
  temp.style.backgroundColor = root.theme.ctrlBgColor;
  temp.style.font            = root.theme.ctrlFont;
  if(temp.cascadeIcon){
    temp.cascadeIcon.style.color           = root.theme.ctrlFgColor;
    temp.cascadeIcon.style.backgroundColor = root.theme.ctrlBgColor;
  }
  if(temp.dropDown){
    if(temp.dropDown.timer)clearTimeout(temp.dropDown.timer);
    temp.dropDown.timer=setTimeout("domAPIElms["+temp.dropDown.domAPIIndex+"].style.visibility='hidden'",400);
  }
};

//------------------------------------------------------------------------------
// MenuItem
//------------------------------------------------------------------------------

function MenuItem(parent,caption,fn){
  var elm=document.createElement(parent.domAPIObjType=="MENUBAR"?"SPAN":"LI");
  elm.innerHTML     = caption;
  elm.fn            = fn;
  elm.dropDown      = null; 
  elm.onclick       = menuItemOnclick;
  elm.addItem       = MenuItemAdditem;
  elm.addSeparator  = MenuItemAddseparator;
  with(elm.style){
    padding         = "3px";
    paddingLeft     = "5px";
    cursor          = "default";
    if(isIE && parent.domAPIObjType!="MENUBAR") width = "100%";
  }
  elm.domAPIObjType = "MENUITEM";
  return elm;
};
//------------------------------------------------------------------------------
function menuItemOnclick(e){
  if(this.dropDown)this.dropDown.hide();
  var temp=this.parentNode;
  while(temp){
    if(temp.domAPIObjType)
      if(temp.domAPIObjType=="MENU"){
        temp.hide();
        temp.onselect(this);
        break; 
      }
    temp=temp.parentNode;
  }
  if(this.fn!="undefined")eval(this.fn);
};
//------------------------
function MenuItemAdditem(caption,fn){
  if(!this.dropDown){
    if(findParent(this,"MENU")){ // only add cascade icon to non top level menus
      this.cascadeIcon                = document.createElement("SPAN");
      this.cascadeIcon.innerHTML      = menuCascadeChevron;
      this.cascadeIcon.style.position = "absolute";
      this.cascadeIcon.style.left     = "86px";
      this.cascadeIcon.style.top      = parseInt(this.offsetTop)+2+"px";
      this.appendChild(this.cascadeIcon);
    }
    this.dropDown=new Menu(this,this.parentNode.theme);
    this.dropDown.hide();
  }
  this.dropDown.appendChild(new MenuItem(this.dropDown,caption,fn));
};
//------------------------
function MenuItemAddseparator(){
  if(!this.dropDown){
    this.dropDown=new Menu(this,this.parentNode.theme);
    this.dropDown.hide();
  }
  this.dropDown.appendChild(document.createElement("HR"));
};
//------------------------