	 if (typeof (fixEvent)=="undefined")
	  function fixEvent(event)
     {
	    event = event || window.event
	      if (!event) return false;
	    if ( event.isFixed ) {
	      return event
	    }
	    event.isFixed = true
	   
	    event.preventDefault = event.preventDefault || function(){this.returnValue = false}
	    event.stopPropagation = event.stopPropagaton || function(){this.cancelBubble = true}
	     
	    if (!event.target) {
	        event.target = event.srcElement
	    }
	   
	    if (!event.relatedTarget && event.fromElement) {
	        event.relatedTarget = event.fromElement == event.target ? event.toElement : event.fromElement;
	    }
	   
	    if ( event.pageX == null && event.clientX != null ) {
	        var html = document.documentElement, body = document.body;
	        event.pageX = event.clientX + (html && html.scrollLeft || body && body.scrollLeft || 0) - (html.clientLeft || 0);
	        event.pageY = event.clientY + (html && html.scrollTop || body && body.scrollTop || 0) - (html.clientTop || 0);
	    }
	   
	    if ( !event.which && event.button ) {
	        event.which = (event.button & 1 ? 1 : ( event.button & 2 ? 3 : ( event.button & 4 ? 2 : 0 ) ));
	    }
	     
	    return event
	  }

if (typeof(GetAbsCoords)=="undefined" )
 function GetAbsCoords (_obj) 
  {
    var isMSIE = (navigator.appVersion.indexOf("MSIE") != -1);

    var _top=0;
    var _left=0;
    var _parent=_obj;

  if (_parent==null ) { alert("GetAbsCoords\r\nNot Found Object "+obj.id);  return [0,0]; }

      _top+=_parent.offsetTop;
      _top+=_parent.clientTop;

     _left+=_parent.offsetLeft;
     _left+=_parent.clientLeft;

//     alert(_parent.offsetParent);

     do {
          if (!_parent.offsetParent ) { alert("GetAbsCoords\r\nNot Found Parent Object "+_parent.id);  return [0,0]; }
         _parent=_parent.offsetParent;
         _top+=_parent.offsetTop;
         _top+=_parent.clientTop;
         _left+=_parent.offsetLeft;
         _left+=_parent.clientLeft;

       } 
      while (_parent!==document.body);
//+document.body.scrollTop
//+document.body.scrollLeft

   if (isMSIE) { _top-=2; _left-=2;}

       return [_left,_top];
  }

//-------------------------------------------------------------------------------------------------------------------------------------------

rclick_ev=Event.add(document,'click',function(event) {   event=fixEvent(event); 
                                      event.cancelBubble = true;
                                      if (( event.target.id.indexOf(tb_menu_create.tb_id)==-1) && tb_menu_create.tb_st && tb_menu_create.cl_st) 
                                      tb_menu_create.close_menu();
 
/*                                     if ( event.which==3 && event.target.onclick)
                                        { try { event.which=3;   }  catch(e) { }
                                           event.target.onclick(event);  
                                        }
*/ 

                                     if ( event.which==3 && event.target.oncontextmenu)
                                        { try { event.which=3;   }  catch(e) { }
                                           event.target.oncontextmenu(event);  
                                                                  }

                               } );



document.oncontextmenu=function(event) {
                                      event=fixEvent(event); 
                                             event.cancelBubble = true;
                                      if (event.target.onclick)
                                        {  
     var isMSIE = (navigator.appVersion.indexOf("MSIE") != -1);
                   if (isMSIE)  event.which=3;
             event.target.onclick(event);  
                                        }
       if ( event.target.oncontextmenu!=null  || event.target.onclick!=null)
        return false;
}


function test_child(obj,r_id,st_f,exp)
 {
    var result=[];
 
   if ((!st_f && obj.id==r_id) ) return true;

    if (st_f)
     { var res=st_f(obj,r_id);
        if (res!=false)
         result.push(res);
     }

     for ( var i = 0; i < obj.childNodes.length; i++ )
      {
         if  (!(!exp) && (obj.childNodes[i].id==exp || obj.childNodes[i]===exp ) ) continue;

          var res=test_child(obj.childNodes[i],r_id,st_f,exp);
           if ( res!=false )
            { result=result.concat(res);
            }
      }

    if (st_f)
     result= (result.length==0)? false: result ;
      else 
       result= (result.length==0)? false: true;

      return result;
  }

 function  set_obj (obj,st,val)
     {
        val=(!val) ?  {exp:true}:val;
       
     if (val['exp'] )
      {
        for (var key in st)
         {
            if (val['exp'] && val[key] ) continue;

           if (typeof(st[key])=="object" )
            {
              set_obj (obj[key],st[key]);

               continue;
            }
           try {
          obj[key]=st[key]; 

             }
            catch(e) {}
         }
           return;
      } 

       for (var key in val)
        {
         obj[key]=st[key] || val[key];
        }
     }

  tb_menu_create=
   {
   cl_st:true,
   tb_st:false,
   tb_id:"menu_tb",
   tb_style:{borderRight:" #5e5757 2px solid",borderLeft:" #DCDCDC 1px solid",borderTop:"#DCDCDC 1px solid",
                          borderBottom:"#5e5757 2px solid",color:"#00008B",backgroundColor:"#EEE9E9",borderCollapse:"collapse",zIndex:"100000",opacity:".85", filter:"alpha(opacity=85)"},

   row_style:{font:"bold 10px 'Comic Sans MS'", cursor:"pointer",color:"black"},
   row_over:{backgroundColor:"#AFEEEE"},
   row_out: {backgroundColor:"#EEE9E9"},
   source_arr:"",

  create_tb: function ()
   {
     var table=document.createElement("table");
      table.id=this.tb_id;
        set_obj(table.style,this.tb_style);

         document.getElementsByTagName('body')[0].appendChild(table);
          return table;
   },
  
   close_menu : function ()
    {
      var tb_menu=document.getElementById(this.tb_id);
       ((tb_menu) ? tb_menu.style.display="none" : "");
    },

   create_menu : function (act,x,y)
    {
       var exp={exp:true,src:1};
     this.out=false;  
      var oTable=document.getElementById(this.tb_id);    
       if (oTable==null)
        oTable=this.create_tb();
        this.tb_st=true;
         oTable.style.display="";
         oTable.style.position="absolute";
         oTable.style.left=x+"px";
          oTable.style.top=y+"px";

        while(oTable.rows.length>0)
         oTable.deleteRow(oTable.rows.length-1);

          this.source_arr=act;

         for (i=0; i<act.length; i++)
          { 
           var oRow = oTable.insertRow(-1);
            set_obj(oRow.style,this.row_style);
                      if ( typeof (act[i]['src'])!="undefined")
                       {

          var oCell=oRow.insertCell(-1);   
                        var img=document.createElement('img');
                                  img.src=act[i]['src'];
                                  img.style.height="16px";
                                  img.style.width="16px";  
                               oCell.appendChild(img);        
                         }
             var oCell=oRow.insertCell(-1);
                 oCell.align="left";

              oCell.id=this.tb_id+"_"+i;

                       if (typeof (act[i].innerHTML)=="object")
                       {
                          oCell.appendChild(act[i].innerHTML);
                              exp.innerHTML=1;
                        }
              set_obj(oCell,act[i],exp);
              oCell.innerHTML+="&nbsp;&nbsp;";
              oCell.onmouseover=function (e){ tb_menu_create.out=false;  e=fixEvent(e); set_obj(e.target.style,tb_menu_create.row_over );  };
              oCell.onmouseout=function (e){  e=fixEvent(e); set_obj(e.target.style,tb_menu_create.row_out );   };
           }
       } 
  }

 function item_tree(tree_arr,pobj,id,ed_mod,s_style)
  {
       var tobj=this;
    if (!pobj )
     tobj.pobj=document.getElementsByTagName("body")[0];
      else
       switch (typeof (pobj))
        {
          case "string": 
       tobj.pobj=document.getElementById(pobj);
        tobj.pobj_id=pobj;
           break;

          case "object": 
       tobj.pobj=pobj;
        tobj.pobj_id=pobj.id;
           break;
       }
 
    tobj.id=id;
     if (typeof(tree_arr.length)!="undefined" )
      {
        tobj.in_arr=tree_arr;
         tobj.node_obj=tobj.convert_in_obj(tree_arr,tobj.id);
       } else 
           {
              tobj.node_obj=tree_arr;
               tobj.in_arr=tobj.convert_out_arr(tree_arr,tobj.id);
            }
//          alert(toJSON(s_style)+" "+id);



       var style_cfg=function ()
         {

         }
      style_cfg.prototype={
    
    tb_style:{color:"#00008B",backgroundColor:"#EEE9E9",borderCollapse:"collapse",whiteSpace:"nowrap"},

     tb_text:{ font:"bold 10px tahoma", cursor:"pointer", backgroundColor:"#EEE9E9", color:"black", textDecoration:"none"},

       sel_bg:{backgroundColor:"#0000CD",color:"#FFFFFF"}
       
                  }
         tobj.style_cfg=new style_cfg();

      if (typeof(s_style)=="object")
      {
         set_obj(tobj.style_cfg,s_style); 
      }
      
        tobj.edit_mod=ed_mod;
        tobj.pobj.style.height="100%";
        tobj.pobj.style.width="500px";
        tobj.pobj.onclick=function (e) {tobj.main_table_menu(e);};
        tobj.style_cfg.tb_text.backgroundColor=tobj.style_cfg.tb_style.backgroundColor;
        tobj.init_tree();  
 }
  
   item_tree.prototype= {
    edit_mod:false,
    in_arr:[],
     pobj:null,
   //{name:"",path:"", target:"", par:"",id:""}
    node_obj: {},
    newitem_id:0,
    last_sel:false,
    multi_select:false,
    cur_act:"",  
    style_cfg:null,
    exp_img1:{ op: {src:"/WinInterface/jslib/winlib/cooltree/e.gif",height:"16px",width:"16px"},
                   cl:{src:"/WinInterface/jslib/winlib/cooltree/c.gif",height:"16px",width:"16px"},
                 nch:{src:"/WinInterface/jslib/winlib/cooltree/join.gif",height:"16px",width:"16px"}},

    exp_img2:{op:{src:"/WinInterface/jslib/winlib/cooltree/fe.gif",height:"16px",width:"16px"},
                    cl:{src:"/WinInterface/jslib/winlib/cooltree/fc.gif",height:"16px",width:"16px"},
                  nch:{src:"/WinInterface/jslib/winlib/cooltree/d.gif",height:"16px",width:"16px"}},


   convert_in_obj: function(arr,p_id)
    {
       var s_obj={};
        var id=0;

       for (var i=0; i<arr.length; i++ )
        { 
           id++;
            if ( typeof(arr[i].substr)=="undefined" &&  arr[i].length>3 )
             { 
                if (typeof(arr[i][0].substr)=="undefined" &&  arr[i][0].length>0 || 
                     typeof(arr[i][0].substr)=="undefined" &&  arr[i][0].length>0 || 
                      typeof(arr[i][0].substr)=="undefined" &&  arr[i][0].length>0 )
                  {
                    alert('ERROR IN IMPLEMENTATION!!'+arr[i]);
                     return;
                  }

                var node={name:arr[i][0],path:arr[i][1], target:arr[i][2], par:"",status:true};

                 var sl_arr=arr[i].slice(3);
                  //   alert(arr[i].length);
                   node.par=this.convert_in_obj(sl_arr,p_id+"_"+(id-1));
 
                    s_obj[p_id+"_"+(id-1)]=node;

                   continue;
             }
                if ( typeof(arr[i].substr)=="undefined" && arr[i].length==3)
                 {
                   s_obj[p_id+"_"+(id-1)]={name:arr[i][0],path:arr[i][1], target:arr[i][2], par:"",status:true};

                    continue;
                 }
            s_obj[p_id+"_"+(id-1)]={name:arr[i],path:arr[i+1], target:arr[i+2], par:"",status:true};

            i+=2;
              }
       
        return s_obj;

    },
    
    convert_out_arr: function(obj)
     {
      var arr=[];
       for (var key in obj)
        {  
             if (obj[key].par!=="")
              {
                var r_arr=this.convert_out_arr(obj[key].par);
                    r_arr.splice(0,0, obj[key].name,obj[key].path,obj[key].target);  	 
                arr.push(r_arr);
                 continue;
              }
           arr.push(obj[key].name);
           arr.push(obj[key].path);
            arr.push(obj[key].target);
        }

       return arr;
     },
 

  addEvent_m : function(obj, type, fn,method)
      {
        func=function(event) { fn[method](event,fn); };
         Event.add(obj, type, func);
      },

     delEvent_m: function (obj, type)
      {
         Event.remove(obj, type);
      },

  
  create_img: function (src)
   {
 //    var a=document.createElement("a");
     var img=document.createElement("img");
            set_obj(img.style,this.style_cfg.tb_text);

        if (!src || src=="") 
          img.style.display="none";
         else   
           img.src=src;

         return img;
   },

  delete_children: function(obj)
   {
     for ( var i = 0; i < obj.childNodes.length; i++ )
      {
  //      alert(obj.childNodes[i].toSource()+" "+obj.childNodes[i].id);
       (obj||body).removeChild(obj.childNodes[i]);
      }
   },

  init_tree: function ()
   {
    this.sel_arr=[]; 
    this.create_el_obj(this.node_obj,this.pobj);
     for (var i=0; i<this.sel_arr.length;i++)
      {
          this.select_el(this.sel_arr[i]);
       }
         this.sel_arr=[];
   },

   destroy_tree: function ()
    { 
      var tbobj=document.getElementById("ch_"+this.pobj_id);
        (tbobj.parentNode||body).removeChild(tbobj);
    },

 unselect_el: function (el)
  {
        var pos,cur_act;
          cur_act=el;
      
         if ( typeof(el)=='string' )
          cur_act=this.get_item_obj(el);
        
        if ( this.multi_select &&  cur_act[0].selected && this.cur_act.length && ( pos=this.cur_act.in_array(cur_act,function (comp,value) {  return comp[3]===value; }  ) ) !==false )
        {
           var unsel_el=$("a_"+this.cur_act[pos][3]);
                  this.cur_act[pos][0].selected=false;
           if ( unsel_el) set_obj(unsel_el.style,this.style_cfg.tb_text);
                   this.cur_act.splice(pos,1);
           return true;
        }

         if (!this.multi_select && this.last_sel) { set_obj(this.last_sel.style,this.style_cfg.tb_text);   this.cur_act[0].selected=false; this.cur_act=null; this.last_sel=null;  return true;}
              return false;
  },

  select_el: function (el)
   { 
      var pos;
        var cur_act=el;
         if ( typeof(el)=="string")
          cur_act=this.get_item_obj(el);
 
           var unsel_status=this.unselect_el(cur_act);
 
       if (  this.multi_select && unsel_status ) return;

      /*
        if ( this.multi_select &&  cur_act[0].selected && this.cur_act.length && ( pos=this.cur_act.in_array(el,function (comp,value) {  return comp[3]===value; }  ) ) !==false )
        {
           var unsel_el=$("a_"+this.cur_act[pos][3]);
                 this.cur_act[pos][0].selected=false;
           if ( unsel_el) set_obj(unsel_el.style,this.style_cfg.tb_text);
                   this.cur_act.splice(pos,1);
           return;
        }
          */
        var obj=$("a_"+cur_act[3]);
         if (obj==null) {return;}
 
         cur_act[0].selected=true;
 
         if (!this.multi_select)
          { 
     //         if (this.last_sel) set_obj(this.last_sel.style,this.tb_text);   
             this.cur_act=cur_act;
          }  else 
               {
                  if (!this.cur_act) this.cur_act=[];
                   this.cur_act.push(cur_act);
                }
         this.last_sel=obj; set_obj(this.last_sel.style,this.style_cfg.sel_bg);
    },

      refresh_node: function (el)
       {
        var cur_act=el;
         if ( typeof(el)=="string")
          cur_act=this.get_item_obj(el);

            if (!cur_act[0])
             {      
                    
               alert("cooltree:Not set Object for refresh"+toJSON(cur_act[0]));
                 return;
             }

            var  mod_node=$("a_"+cur_act[3]);
            if (!mod_node) { alert("obj_not found "+cur_act[3]); return;}

          //     mod_node.childNodes[0].firstChild.src= (op) ? this.exp_img1['op'] : this.exp_img1['cl'];
          
             (  (obj.src) ? mod_node.childNodes[1].firstChild.src=obj.src : "" ); 
   
              var a_obj=mod_node.childNodes[2].firstChild;

                     a_obj.href=(obj.path==null)? "javascript:" : obj.path;
                   a_obj.target=(obj.target==null)? "" : obj.target;
                a_obj.innerHTML= obj.name;
                    a_obj.title=(obj.title==null)? "" : obj.title;

                   set_obj(a_obj.style,(!obj.style)? this.style_cfg.tb_text : obj.style);   
        },

   set_icon_cell: function (img,cell)
    {
        set_obj(cell,{style:{background:"url('"+img.src+"') no-repeat"  ,padding:"0px",
         width:img.width,height:img.height,minWidth:img.width,minHeight:img.height,cursor:"pointer" }});
   //     cell.innerHTML='<img src="'+img.src+'">';
    
     },


  create_el_obj: function(obj,pobj)
   {
        var tobj=this;

         var oTable=document.createElement("table");
                
              set_obj(oTable,{id:"ch_"+pobj.id,className:"block", border:0,style:this.style_cfg.tb_style });

            pobj.onclick=function (e) {tobj.main_table_menu(e);};

       pobj.appendChild(oTable);



      var i=0;
          for(var key in obj)
           {
               var oRow = oTable.insertRow(-1);
                oRow.valign="top"; 
                 oRow.id=key;

             
              if (obj[key].par!="")
               {

    var oCell=oRow.insertCell(-1);
//          oCell.style.verticalAlign="top"; 
          oCell.id=key;
          
           this.set_icon_cell(this.exp_img1.op,oCell);
           this.delEvent_m(oCell,'click');
           this.addEvent_m(oCell,'click',this,"expand_node_ev");
  
         var oCell=oRow.insertCell(-1);
//              oCell.style.verticalAlign="top"; 
              oCell.id=key;

           this.set_icon_cell( {src: obj[key].src ||this.exp_img2.op.src, width:this.exp_img2.op.width,height:this.exp_img2.op.height } ,oCell);

            this.delEvent_m(oCell,'click');
             this.addEvent_m(oCell,'click',this,"expand_node_ev");
    
    var oCell=oRow.insertCell(-1);
         oCell.id=key;
          oCell.align="left";

          oCell.onclick=function (e) {tobj.main_table_menu(e);};

              var a=document.createElement("a");             
                   a.href=(obj[key].path==null)? "javascript:" : obj[key].path;
                   a.target=(obj[key].target==null)? "" : obj[key].target;
                   a.innerHTML= obj[key].name;
                   a.id="a_"+key;                  
                   a.title=(obj[key].title==null)? "" : obj[key].title;

                   set_obj(a.style,(!obj[key].style)? this.style_cfg.tb_text : obj[key].style);   
                   oCell.appendChild(a);

               a.onmousedown=function (e) {  
                                                          var cur_act=tobj.get_item_obj(this.id.replace(/a_/,"")); 
                                                            if (!cur_act[0].canselect) return;
                                                             tobj.select_el(cur_act);
                                                       };

               a.oncontextmenu=function (e) { tobj.open_edit_menu(e);  return false;};

              this.create_el_obj(obj[key].par,oCell);

                       if (obj[key].canselect && obj[key].selected) { obj[key].selected=false;
                                                                                     this.sel_arr.push(key);
                                                                                   }
                  continue;
               }

     var oCell=oRow.insertCell(-1);
           this.set_icon_cell( this.exp_img1.nch ,oCell);
     var oCell=oRow.insertCell(-1);
           this.set_icon_cell( {src: obj[key].src ||this.exp_img2.nch.src, width:this.exp_img2.op.width,height:this.exp_img2.op.height } ,oCell);

    var oCell=oRow.insertCell(-1);

        set_obj(oCell,{align:"left",onclick:function (e) {tobj.main_table_menu(e);} });

             var a=document.createElement("a");             
              set_obj(a,{href:(obj[key].path==null)? "javascript:" : obj[key].path,
                      target:(obj[key].target==null)? "" : obj[key].target,
                innerHTML: obj[key].name,
                           id:"a_"+key,
                           title:(obj[key].title==null)? "" : obj[key].title,
                           style:(!obj[key].style)? this.style_cfg.tb_text : obj[key].style}
              );   
                   oCell.appendChild(a);
                   
                   
                    a.onmousedown=function (e) {                                           
                                                           tobj.select_el(this.id.replace(/a_/,""));
                                                            };

                a.oncontextmenu=function (e) { tobj.open_edit_menu(e);   return false;};

                       if (obj[key].selected)
                        { obj[key].selected=false;                                                                 
                            this.sel_arr.push(key);
                        }
                        
              i++;          
         }

         return oTable;
   },
   
   get_item_obj: function (id,obj)
    {
      if (!obj) obj=this.node_obj;

      if (!id || id=="") return ['','','',''];

       var path=id.split('_');

        var str_path=path[0]+"_"+path[1];
    
         var item=obj[str_path];

          var acc_path='[\''+str_path+'\']';  
           var  par_path="";

         for (var i=2; i<path.length; i++ )
          {
              str_path+="_"+path[i];
             par_path=acc_path;
             acc_path+='.par[\''+str_path+'\']';
             
             var item=item.par[str_path];
          }
 
        return [item,acc_path,par_path,id];
    },

   refresh_tree: function ()
    {
         this.destroy_tree();
         this.init_tree();
         this.restore_expand_st();
    },

   del_item: function (id)
    { 
      var obj=id;
  
      if ( typeof(id)=="string")
        obj=this.get_item_obj(id);
   
           /*    if ( obj[0].selected)
               {
                     this.unselect_el(obj);
               }

           */
       eval ( 'delete this.node_obj'+obj[1]+'; var l=0; var p_path="'+obj[2]+'"; if (p_path!=""){for (var key in this.node_obj'+obj[2]+'.par) {l++;}'+
              'if (l==0) this.node_obj'+obj[2]+'.par="";}');
         this.destroy_tree();
         this.init_tree();
         this.restore_expand_st();
    }, 

   replace_key: function(id,s_obj)
   {
      var new_s_obj={};

             for(var key  in s_obj)
              { 

                new_s_obj[id+"_"+key]=s_obj[key];

                   if (new_s_obj[id+"_"+key].par!="")
                    {
                       new_s_obj.par[id+"_"+key].par=this.replace_key(id+"_"+key,new_s_obj[id+"_"+key].par);
                     }

               }
        return new_s_obj;
   },

  add_item_obj: function(p_obj,s_obj,ai_obj)
    {
//------------- looking for parent object if set by name
      if ( typeof(p_obj) == 'string')
       p_obj=this.get_item_obj(p_obj);
//----------------------------------------------------

           if (typeof(p_obj[3])=="undefined") { alert("Add Item not Possible!! Not Set Parent ELEMENT Path."); return;}
  
          var new_key=((p_obj[1]=="")? this.id : p_obj[3])  +"_ni"+this.newitem_id;
           this.newitem_id++;

           if (!s_obj) s_obj= {name:"New_Item",path:null,target:null,par:""};

            if (s_obj && s_obj.par!="")
             {
                s_obj.par=this.replace_key(new_key,s_obj.par);
              }
       
            if (typeof(ai_obj)!='undefined')
            {
                 // ai_obj=ai_obj[1];   
              var obj_arr=[];
              var w_obj;
              var el_pos=( typeof(ai_obj) === String) ? -1 : ai_obj;
                if  (p_obj[1]=="")
                 w_obj=this.node_obj;
                  else
                   eval('w_obj=this.node_obj'+p_obj[1]);

             var i=0;
              for (var key in w_obj)
               {
                  obj_arr.push({key: key,val: w_obj[key]});
                    if ( el_pos==-1 && ai_obj==key) el_pos=i;
                        i++; 
                }
                 w_obj={};

                if (el_pos==-1)
                 el_pos=obj_arr.length-1;

            obj_arr.splice(el_pos,0,{key: new_key, val:s_obj });

           for (var i=0; i<(obj_arr.length); i++)
            {
              w_obj[obj_arr[i].key]=obj_arr[i].val;
             }

               if  (p_obj[1]=="")
                this.node_obj=w_obj;
                 else
                  eval('this.node_obj'+p_obj[1]+'=w_obj;');

         return new_key;
       }

       if (p_obj[1]=="")
       {
           this.node_obj[new_key]=s_obj;
       } else 
      eval(' if ( !this.node_obj'+p_obj[1]+'.par || this.node_obj'+p_obj[1]+'.par== "")'+
           'this.node_obj'+p_obj[1]+'.par={};'+ 
           'this.node_obj'+p_obj[1]+'.par["'+new_key+'"]=s_obj;');

         return new_key;
    },


   add_item: function (id,s_obj,pos)
    {
      var new_key=this.add_item_obj(id,s_obj,pos);
         this.refresh_tree();
        return new_key;
    },


   rename_item_dialog: function(path,obj,xy)
     {
        var tobj=this;
                tb_menu_create.create_menu( [{innerHTML:'Name:&nbsp;&nbsp;'+ 
'<input id="in_'+tobj.id+'_n" style="height:15px;font:bold italic 10px tahoma;background-color:#FFFFFF" value="'+obj[0].name+'" type="text">'},
       {innerHTML:'URL:&nbsp;&nbsp;&nbsp;&nbsp;'+
'<input id="in_'+tobj.id+'_p" style="height:15px;font:bold italic 10px tahoma;background-color:#FFFFFF" value="'+( (obj[0].path==null)? "":obj[0].path) +
 '" type="text">'},
       {innerHTML:'<button style="height:15px;font-size:8px;" onclick="'+tobj.id+'.rename_item(\''+path+'\');">Save</button>'+
             '<button style="height:15px;font-size:8px;" onclick="tb_menu_create.close_menu()" >Close</button>'
       }],xy[0],xy[1]);

           }, 

    rename_item: function(path)
     {
         this.save_item(path);
     },
    save_item: function (id)
     {
       var n=document.getElementById("in_"+this.id+"_n").value;
        if (n=="") 
         {
           alert("Not set Item Name");
            return "";
         }
  
        var p=document.getElementById("in_"+this.id+"_p").value;
           
            p=p.replace(/["]/g,'\\"');         
 
           var obj=this.get_item_obj(id);
      eval('this.node_obj'+obj[1]+'.name="'+n+'";'+
            'this.node_obj'+obj[1]+'.path="'+p+'";'+
            'this.node_obj'+obj[1]+'.target="_self";');

         this.destroy_tree();
         this.init_tree();
          tb_menu_create.close_menu();
           this.restore_expand_st();
      },

  restore_expand_st : function (obj)
   {
     if (!obj) obj= this.node_obj; 
      for(var key in obj)
       {
          if (obj[key].par!="")
           {
             if ( typeof(obj[key].status)!="undefined" )
              this.expand_node(key,obj[key].status);
               this.restore_expand_st(obj[key].par);
           }

        }

   },

   expand_all: function (op,obj)
    {
      if (!obj) obj=this.node_obj;
      for (var key in obj)
       { 
         if  (obj[key].par!="" )
          {
            this.expand_node(key,op);      
             this.expand_all(op,obj[key].par);
          }
       }

    },
    
   init_main_table_menu: function (path,xy)
    {
      path="";
       this.init_edit_menu_button(path,xy,[1,2]);
    },

    main_table_menu : function (e)
     {
        e=fixEvent(e);

         if (!this.edit_mod) return false;
                    if (e.target.id!=tb_menu_create.tb_id && tb_menu_create.tb_st && tb_menu_create.cl_st) 
                                      tb_menu_create.close_menu();
                if  (e.which==3)
                  { 
                   this.init_main_table_menu("",[e.pageX,e.pageY]); 
                  return false;
                  }
        return false;
     },

     init_edit_menu_button: function (path,xy,act_it)
      {
        var tobj=this;

        var menu_arr=[{src:"/WinInterface/jslib/winlib/cooltree/b_insrow.png",innerHTML: "Add new&nbsp;", onclick: function () {  
                           tobj.add_item(path); 
                            tb_menu_create.close_menu();   }},
                                            {src:"/WinInterface/jslib/winlib/cooltree/b_drop.png",innerHTML: "Delete",onclick: function () { tobj.del_item(path); tb_menu_create.close_menu();    }},
                                            {src:"/WinInterface/jslib/winlib/cooltree/b_edit.png",innerHTML: "Rename", onclick: function () { 
                 var obj=tobj.get_item_obj(path);
          tb_menu_create.close_menu(); tb_menu_create.cl_st=false; 
               tobj.rename_item_dialog(path,obj,xy); }} ];


       if (act_it)
        {
          for (var i=0; i<act_it.length; i++)
           {
              menu_arr[act_it[i]].onclick=function () { return false;};
              menu_arr[act_it[i]].style={color:"#CFCFCF"};
           }
        }
       tb_menu_create.create_menu(menu_arr,xy[0],xy[1]);
      }, 

      open_edit_menu: function (event)
       { 
         if (!this.edit_mod) return false;
          event=fixEvent(event);

    var xy=GetAbsCoords (event.target);
                xy[0]+=event.target.offsetWidth+3;
                xy[1]+=event.target.offsetHeight/2;
                var path= event.target.id.split("_").slice(1);
                    path=path.join("_");
                      tb_menu_create.cl_st=true;
                      this.init_edit_menu_button(path,xy);
                          return false;  
           },

        expand_node_ev: function (e,obj)
         {
              e=fixEvent(e);
            var target=e.target.id;   
        
              if  (target=="") {alert("Not Set Node object"); return;}
              this.expand_node(target);
               e=null;
             return false;
         },


      expand_node: function (obj,op)
       {
         switch (typeof(obj) )
          {
            case "string":
            var mod_node=document.getElementById(obj);
              break;
             case "object":
              var mod_node=obj;
               obj=obj.id;
               break;
          }

            if (mod_node==null) { alert("obj_not found "+obj); return;}

         var oTable=document.getElementById("ch_"+obj);

             if (typeof (oTable.status) =="undefined") { oTable.status=true;}

               if (typeof(op)=="undefined") op=!oTable.status;
                oTable.status=op;

                if (oTable==null) { alert("ch_"+obj+" Not found!!");  return;}

            for(i=0;i<oTable.rows.length;i++)
             {
              oTable.rows.item(i).style.display=(op)? "":"none";
             }

            this.set_icon_cell( (op) ? this.exp_img1['op'] : this.exp_img1['cl'] ,mod_node.childNodes[0]);

            this.set_icon_cell( (op) ? this.exp_img2['op'] : this.exp_img2['cl'] ,mod_node.childNodes[1]);
                var obj=this.get_item_obj(obj);
                   eval('this.node_obj'+obj[1]+'.status='+oTable.status);
       }
           
  }
