﻿function Item(_id, _parameters, _isVisible, _icon, _text, _icons, _clicked,_public, _visible, _firstpage, _order, _template){
 this.id=_id;
 this.access=_public
 this.text=_text;
 this.template=_template;
 this.parameters=_parameters
 this.tr=null;
 this.childs=new Array();
 this.isVisible=_isVisible;
 this.div=null;
 this.order=_order;
 this.isCreated=false;
 this.onClick=_clicked;
 this.icon=_icon;
 this.icons=_icons;
 this.firstpage=_firstpage;
 this.visible=_visible
 this.textitem=null
 this.sign=htmlCreateImage(this.icons[4],"", "");
}
Item.prototype.onUpdate=function(){
    var res =updateNode(this.id)
    if (res==null) return
    this.text=res.text;
    this.access=res.cbpublic
    this.order=res.order;
    this.firstpage=res.cbfirst;
    this.visible=res.cbvis;
    this.template=res.template;
    this.textitem.innerHTML=this.text
    toggleProperties();
}
Item.prototype.SelectNode=function(){
    this.onClick(this)
     var elem=htmlGetId("buUpdate")
     if (elem !=null) elem.onclick=utilBind(this.onUpdate, this);
    if(selectedNode != null) {
        if(selectedNode.id !=this.id) {
            selectedNode.DeselectNode();
        }
    }
    if(selectedNode == null || selectedNode.id !=this.id){
        selectedNode=this;
        this.textitem.className="treeSelected";
    }
}
Item.prototype.DeselectNode=function(){
    this.textitem.className="treeNonSelected";
}
Item.prototype.Create=function(elem){
if(this.id != configRootNode){
    elem.className="treeItem";
    elem.style.left=parseInt(elem.parentElement.style.left)+10;
}else{
    
    elem.style.left=0;
}
 var thisObj=this;
 var table =htmlCreateElement("table", null, null)
  table.border=0
  table.cellspacing=0;
  table.cellpadding=0;
  table.id="tb"+this.id
 var tbody=htmlCreateElement("tbody", null, null);
 this.tr=htmlCreateElement("tr", null, null)
 this.tr.className="treeTr";
 this.tr.id=this.id+"tr";
 this.tr.border=0;
 this.tr.onmouseover=function(){
  if (selectedNode!=null){
    if (selectedNode.id!=thisObj.id)  thisObj.textitem.className="treeSelected";
    
   }else{
     thisObj.textitem.className="treeSelected";
   }
 }
  this.tr.onmouseleave=function(){
  if (selectedNode!=null){
    if (selectedNode.id!=thisObj.id) thisObj.textitem.className="treeNonSelected";
   
   }else{
         thisObj.textitem.className="treeNonSelected";
   }
    
 }
 var td=null;
 this.tr.onclick= utilBind(this.SelectNode, this);
         

 if (this.sign !=null){
    td=htmlCreateElement("td", this.sign, "treeTd")
    td.width=16;
    td.border=0
    if (this.childs==null){
        this.sign.src=this.icons[4];
    }else{
        (this.childs.length >0) ? this.sign.src=this.icons[3] : this.sign.src=this.icons[4];
    }
    this.tr.appendChild(td)
 }
  if (this.icon !=null){
    td=htmlCreateElement("td", this.icon, "treeTd")
    td.width=18;
    td.border=0
    this.icon.src=this.icons[0]
    this.tr.appendChild(td);
 }

 td=htmlCreateElement("td", this.text, "treeNonSelected")
 td.border=0
  this.textitem=td
 this.tr.appendChild(td)
 tbody.appendChild(this.tr)
 table.appendChild(tbody)

  table.cellspacing=0;
  table.cellpadding=0;
 elem.appendChild(table);

 this.div=htmlAddElement(elem,"div",null,null)
 this.div.id=this.id
 this.div.style.display = 'none';
 this.isCreated=true;
}

