/**
* nlsmenuext_dyn.js v.1.0
* Copyright 2005-2007, addobject.com. All Rights Reserved
* Author Jack Hermanto, www.addobject.com
*/
NLSMENU.setItemVisible=function(key, v) {
  var it=this.getItemById(key);
  var oIt=NlsMenu.$GE(it.intKey);
  if(oIt) {
    if (this.orient=="V") { oIt=oIt.parentNode; }
    oIt.style.display=(v?"":"none");
  }
  nlsMenuMgr[this.mgrId].hideMenus();
  var it=this.getItemById(key);
  it.visible=v;
};

NLSMENU.setItemState=function(itId, s) {
  var it=this.items[itId], lit=null;
  if(it.group) {
    for (var l in this.items) {
      lit=this.items[l];
      if(lit.group==it.group && lit.state==2) {
        setMnStyle(NlsMenu.$GE(lit.intKey), (lit.enable ? "N" : "D"), NlsMenu.getPrf(lit, this));
        setMnIcon(this, lit, "N");
        lit.state=1;
      }
    }
  }
  var oIt=NlsMenu.$GE(itId);
  setMnStyle(oIt, (it.enable ? (s==1?"N":"S") : "D"), NlsMenu.getPrf(it, this));
  setMnIcon(this, it, "N");
  it.state=s;
};

NLSMENU.setSelection=function(itId, s) {
  var prf="";
  var it=this.items[this.rt.lastSel];
  if(it){
    prf=it.stlprf; if(prf=="")prf=this.stlprf;
    setMnStyle(NlsMenu.$GE(it.intKey), (it.enable ?"N":"D"), prf);
    setMnIcon(this, it, "N");
    it.selected=false;
  }

  it=this.items[itId];
  prf=it.stlprf; if(prf=="")prf=this.stlprf;
  setMnStyle(NlsMenu.$GE(itId), (it.enable ?"S":"D"), prf);
  setMnIcon(this, it, "O");
  this.rt.lastSel=itId;
  it.selected=true;
};

NlsMnMgr.savePath=function(vl) {
  NlsMenuManager.$setCookie(this.mgrId+"_path", String(vl));
};

NlsMnMgr.loadPath=function() {
  var p=NlsMenuManager.$getCookie(this.mgrId+"_path");
  if(p && p!="") {
    p=p.split("_");
    this.selectPath(p[0], p[1]);
  }

}

NlsMnMgr.selectPath=function(mId, id) {
  this.unselectPath();
  var mn=nlsMenu[mId], it=mn.items[mId+"_"+id],prf="",pr="";
  while(mn && it) {
    prf=it.stlprf; if(prf=="")prf=mn.stlprf;
    setMnStyle(NlsMenu.$GE(it.intKey), (it.enable ?"S":"D"), prf);
    setMnIcon(mn, it, "O");
    mn.rt.lastSel=it.intKey;
    it.selected=true;

    pr=mn.prIt;
    if(pr) {
      mn=nlsMenu[pr.split("_")[0]];
      it=mn.items[pr];
    } else {mn=null; it=null}
  }
};

NlsMnMgr.unselectPath=function() {
  var mgr=this,prf="",it=null, mns=[mgr.menubar];
  for(var i in mgr.menus) { mns[mns.length]=mgr.menus[i]; }
  for(var i=0;i<mns.length;i++) {
    for (var j in mns[i].items) {
      it=mns[i].items[j];
      if (it.selected) {
        prf=it.stlprf; if(prf=="")prf=mns[i].stlprf;
        setMnStyle(NlsMenu.$GE(it.intKey), (it.enable ?"N":"D"), prf);
        setMnIcon(mns[i], it, "N");
      }
    }
  }
};

NLSMENU.addToggleItem=function(key, grp, capt, url, ico, enb, xtra, title) {
  var it=this.addItem(key, capt, url, ico, enb, xtra, null, title);
  it.toggle=true;
  it.group=grp;
  return it;
};

NLSMENU.deleteItem = function(key) {
  var intKey = this.mId+"_"+key;
  if (!this.items[intKey]) return;

  if(this.lsItm) {
    var lsItm=this.items[this.lsItm.id];
    if(lsItm.id==key) {this.lsItm=null; }
  }

  this.items[intKey] = null;
  delete this.items[intKey];
  var ovr=-1;
  for (var i=0; i<this.srItems.length; i++) {
    if (this.srItems[i].id==key) { ovr=i; }
    if ( ovr!=-1 && i>=ovr && i<this.srItems.length) {
      this.srItems[i]=this.srItems[i+1];
    }
  }
  this.srItems.length--;
};

/*Cookie related*/
NlsMenuManager.$setCookie=function(key, value, expire) {
  if (value==null) return;
  var v = value;
  if (v!="") v=escape(v);
  document.cookie = escape(key)+"="+ v + (expire?"; expires="+expire:"");
};

NlsMenuManager.$getCookie=function(key) {
  if (document.cookie) {
    var cp=document.cookie.split(";");
    var c=null;
    for (var i=0; i<cp.length; i++) {
      c=cp[i].split("=");
      if (unescape(c[0].replace(/\s*/gi,""))==key) { return (c.length>1?unescape(c[1]):""); }
    }
  }
  return "";
};

NlsMenuManager.$removeCookie=function(key) {
  NlsMenuManager.$setCookie(key, "-1", "Fri, 31 Dec 1999 23:59:59 GMT;");
}



