var TreeList=new Class({options:{showStep:3,container:"",checkboxName:false,nodeClass:{clazz:"node",handle:"node-handle",first:"first-node",last:"last-node",close:"node-close",open:"node-open",hasc:"node-hasc",nl:"node-line",icon:"node-icon",name:"node-name",loading:"node-loading",cbox:"node-child-box"},remoteURL:"",remoteParamKey:"p[0]",dataMap:{PID:"parent_id",NID:"cat_id",CNAME:"cat_name",HASC:"isleaf"}},initialize:function(a){$extend(this.options,a);this.container=$(this.options.container);if(!this.container){return}this.initTree()},createNode:function(d){var j=this.options;var c=j.nodeClass;var a=new Element("span",{"class":c.handle}).set({pid:d.PID,nid:d.NID,hasc:d.HASC}).setHTML("&nbsp;");var g=new Element("span",{"class":c.nl}).setHTML("&nbsp;");var i=new Element("input",{type:"checkbox",name:j.checkboxName,value:d.NID,pid:d.PID});var e=new Element("span",{"class":c.icon}).setHTML("&nbsp;");var h=new Element("span",{"class":c.name}).setText(d.CNAME);var b=new Element("span",{"class":c.clazz}).adopt([a,g,i,e,h]);if(!!d.HASC.toInt()){var f=this;a.addClass(c.close);i.set("value",i.get("value")+"|close");a.addEvent("click",function(m){var l=this.getParent("."+c.clazz);if(this.hasClass(c.close)){if(!l.getNext()||l.getNext().getTag()!=="div"){var k=new Element("div",{"class":c.cbox}).injectAfter(l);f.loadNodes(this.get("nid"),k);this.addClass(c.loading);i.set("value",i.get("value").toInt())}else{if(l.getNext()&&l.getNext().getTag()=="div"){l.getNext().show()}}this.removeClass(c.close)}else{if(l.getNext()&&l.getNext().getTag()=="div"){l.getNext().hide();this.addClass(c.close)}}});i.addEvent("click",function(){var l=this.getParent("."+c.clazz);var k=l.getNext();if(k&&k.getTag()=="div"){$ES("input[type=checkbox]",k).set("checked",this.checked==true?true:false)}})}if($E("input[value="+i.get("pid")+"]",this.container)){if($E("input[value="+i.get("pid")+"]",this.container).checked){i.set("checked",true)}}return b},initTree:function(){this.loadNodes(0)},loadNodes:function(b,g){var a;var e=this.options;var f=e.dataMap;new Request.JSON({onRequest:function(){},onSuccess:function(h){var c=this.options;var d=$H(c.dataMap);if($E("span[nid="+b+"]",this.container)){$E("span[nid="+b+"]",this.container).removeClass(c.nodeClass.loading)}h.each(function(k,i){var l={};d.each(function(n,m){l[m]=k[n]});var j=this.createNode(l);if(i==0){j.addClass(c.nodeClass.first)}if(h.length==i+1){j.addClass(c.nodeClass.last)}if(l.HASC.toInt()){j.addClass(c.nodeClass.hasc)}this.addNode(j,g)}.bind(this))}.bind(this)}).get(this.options.remoteURL.substitute({param:this.options.remoteParamKey,value:b})+"&v="+$time())},addNode:function(c,a){if(!a){$(c).inject(this.container)}else{$(c).inject(a)}var b=c.getElement("input[type=checkbox]");if(b&&b.retrieve("check")){b.set("checked",true)}switch(this.options.showStep){case 1:return;case 2:if(!a){$E("."+this.options.nodeClass.handle,c).fireEvent("click")}return;case 3:if(!a||(a&&!a.getParent().hasClass(this.options.nodeClass.cbox))){$E("."+this.options.nodeClass.handle,c).fireEvent("click")}return;case 4:return $E("."+this.options.nodeClass.handle,c).fireEvent("click")}},removeNode:function(){}});var GoodsCatNavTreeList=new Class({Extends:TreeList,createNode:function(e){var c=this.options;c.navURL=c.navURL||"#";var h=c.nodeClass;var g=new Element("span",{"class":h.handle}).set({pid:e.PID,nid:e.NID,hasc:e.HASC}).setHTML("&nbsp;");var b=c.navURL.substitute({cname:e.CNAME,cid:e.NID,cnamelth:e.CNAME.getLength()});b=b.split("filter=");b=b[0]+"filter="+encodeURIComponent(b[1]);var a=new Element("a",{"class":h.name,href:b}).setText(e.CNAME);var d=new Element("span",{"class":h.clazz}).adopt([g,a]);if(e.NID==0){a.setStyle("color","red")}if(!!e.HASC.toInt()){var f=this;g.addClass(h.close);g.addEvent("click",function(k){var j=this.getParent("."+h.clazz);if(this.hasClass(h.close)){if(!j.getNext()||j.getNext().getTag()!=="div"){var i=new Element("div",{"class":h.cbox}).injectAfter(j);f.loadNodes(this.get("nid"),i);this.addClass(h.loading)}else{if(j.getNext()&&j.getNext().getTag()=="div"){j.getNext().show()}}this.removeClass(h.close)}else{if(j.getNext()&&j.getNext().getTag()=="div"){j.getNext().hide();this.addClass(h.close)}}})}return d}});