/*
 * JQuery zTree 2.3
 * http://code.google.com/p/jquerytree/
 *
 * Copyright (c) 2010 Hunter.z
 *
 * Date: 2011-01-04
 *
 */
(function(e){function kb(a,b){b.unbind(ka);b.bind(ka,function(c,d,f){typeof a.callback.click=="function"&&a.callback.click(c,d,f)});b.unbind(la);b.bind(la,function(c,d,f){typeof a.callback.change=="function"&&a.callback.change(c,d,f)});b.unbind(ma);b.bind(ma,function(c,d,f){typeof a.callback.rename=="function"&&a.callback.rename(c,d,f)});b.unbind(na);b.bind(na,function(c,d,f){typeof a.callback.remove=="function"&&a.callback.remove(c,d,f)});b.unbind(oa);b.bind(oa,function(c,d,f){typeof a.callback.drag==
"function"&&a.callback.drag(c,d,f)});b.unbind(Z);b.bind(Z,function(c,d,f,g,i){typeof a.callback.drop=="function"&&a.callback.drop(c,d,f,g,i)});b.unbind(pa);b.bind(pa,function(c,d,f){typeof a.callback.expand=="function"&&a.callback.expand(c,d,f)});b.unbind(qa);b.bind(qa,function(c,d,f){typeof a.callback.collapse=="function"&&a.callback.collapse(c,d,f)});b.unbind(ra);b.bind(ra,function(c,d,f,g){typeof a.callback.asyncSuccess=="function"&&a.callback.asyncSuccess(c,d,f,g)});b.unbind(sa);b.bind(sa,function(c,
d,f,g,i,l){typeof a.callback.asyncError=="function"&&a.callback.asyncError(c,d,f,g,i,l)});e("#"+a.treeObjId).bind("contextmenu",function(c){var d=e(c.target);d=ta(a,d);var f=true;if(typeof a.callback.beforeRightClick=="function")f=a.callback.beforeRightClick(a.treeObjId,d);if(f&&typeof a.callback.rightClick=="function"){a.callback.rightClick(c,a.treeObjId,d);return false}return typeof a.callback.rightClick!="function"});e("#"+a.treeObjId).bind("mouseup",function(c){var d=e(c.target);d=ta(a,d);var f=
true;if(typeof a.callback.beforeMouseUp=="function")f=a.callback.beforeMouseUp(a.treeObjId,d);f&&typeof a.callback.mouseUp=="function"&&a.callback.mouseUp(c,a.treeObjId,d);return true});e("#"+a.treeObjId).bind("mousedown",function(c){var d=e(c.target);d=ta(a,d);var f=true;if(typeof a.callback.beforeMouseDown=="function")f=a.callback.beforeMouseDown(a.treeObjId,d);f&&typeof a.callback.mouseDown=="function"&&a.callback.mouseDown(c,a.treeObjId,d);return true})}function ta(a,b){var c;c=e(b);if(c.attr("id")==
a.treeObjId)c=null;else{for(;!c.is("li")&&c.attr("id")!=a.treeObjId;)c=c.parent();c=c.attr("id");c=$(a,c)}return c}function S(a,b,c,d){if(c)for(var f=0;f<c.length;f++){var g=c[f];g.level=b;g.tId=a.treeObjId+"_"+ ++ua;g.parentNode=d;g[a.checkedCol]=g[a.checkedCol]==true;g.checkedOld=g[a.checkedCol];g.check_Focus=false;g.check_True_Full=true;g.check_False_Full=true;g.editNameStatus=false;g.isFirstNode=(d?d:a.root)[a.nodesCol].length==c.length&&f==0;g.isLastNode=f==c.length-1;if(g[a.nodesCol]&&g[a.nodesCol].length>
0){g.open=g.open?true:false;g.isParent=true;Qa(a,g);S(a,b+1,g[a.nodesCol],g)}else{g.isParent=g.isParent?true:false;Qa(a,g);a.checkable&&f==c.length-1&&aa(a,g)}}}function Qa(a,b){var c=b.parentNode;c=c?e("#"+b.parentNode.tId+u):e("#"+a.treeObjId);c.append("<li id='"+b.tId+"' class='tree-node'><button type=\"button\" id='"+b.tId+w+"' title='' onfocus='this.blur();'></button><a id='"+b.tId+o+"' onclick=\""+(b.click||"")+'" ><button type="button" id=\''+b.tId+r+"' title='' onfocus='this.blur();'></button><span id='"+
b.tId+K+"'></span></a><ul id='"+b.tId+u+"'></ul></li>");c=e("#"+b.tId+w);var d=e("#"+b.tId+o);e("#"+b.tId+K);var f=e("#"+b.tId+u),g=e("#"+b.tId+r);Ra(a,b);H(a,b);f.css({display:b.open?"block":"none"});if(b.isParent){c.bind("click",{treeObjId:a.treeObjId,treeNode:b},ba);d.bind("dblclick",{treeObjId:a.treeObjId,treeNode:b},ba)}d.bind("click",function(){var l=true;if(typeof a.callback.beforeClick=="function")l=a.callback.beforeClick(a.treeObjId,b);if(l!=false){window.getSelection?window.getSelection().removeAllRanges():
document.selection.empty();O(a,b);e("#"+a.treeObjId).trigger(ka,[a.treeObjId,b])}});g.bind("mousedown",function(){b.editNameStatus=false});if(a.checkable){c.after("<BUTTON type='BUTTON' ID='"+b.tId+I+"' onfocus='this.blur();' ></BUTTON>");var i=e("#"+b.tId+I);if(a.checkStyle==P&&a.checkRadioType==va&&b[a.checkedCol])a.checkRadioCheckedList=a.checkRadioCheckedList.concat([b]);A(a,i,b);i.bind("click",function(){var l=true;if(typeof a.callback.beforeChange=="function")l=a.callback.beforeChange(a.treeObjId,
b);if(l!=false){b[a.checkedCol]=!b[a.checkedCol];Sa(a,b);A(a,i,b);T(a,b);e("#"+a.treeObjId).trigger(la,[a.treeObjId,b])}});i.bind("mouseover",function(){b.checkboxFocus=true;A(a,i,b)});i.bind("mouseout",function(){b.checkboxFocus=false;A(a,i,b)})}Ta(b);Ua(a,b);d.hover(function(){Va(a,b)},function(){a.curTreeNode!=b&&ca(a,b)});d.bind("mousedown",function(l){if(!(l.button==2||!a.editable)){var q=document,p,m,j,s=false,h=a,Q=null,L=null,t=null,v=x,lb=l.clientX,mb=l.clientY,Wa=(new Date).getTime();e(q).mousemove(function(k){if(b.editNameStatus)return true;
window.getSelection?window.getSelection().removeAllRanges():document.selection.empty();if(a.dragStatus==0&&Math.abs(lb-k.clientX)<Xa&&Math.abs(mb-k.clientY)<Xa)return true;e("body").css("cursor","pointer");e("#"+b.tId+w);if(a.dragStatus==0&&b.isParent&&b.open){B(a,b,!b.open);a.dragNodeShowBefore=true}if(a.dragStatus==0){a.dragStatus=-1;var n=true;if(typeof a.callback.beforeDrag=="function")n=a.callback.beforeDrag(a.treeObjId,b);if(n==false)return;a.dragStatus=1;Ya(true);O(a,b);ca(a,b);n=e("#"+b.tId).clone();
n.attr("id",b.tId+"_tmp");n.css("padding","0");n.children("#"+b.tId+o).removeClass(wa);n.children("#"+b.tId+u).css("display","none");p=e("<ul class='zTreeDragUL'></ul>").append(n);p.attr("id",b.tId+u+"_tmp");p.addClass(e("#"+a.treeObjId).attr("class"));p.appendTo("body");m=e("<button class='tmpzTreeMove_arrow'></button>");m.attr("id","zTreeMove_arrow_tmp");m.appendTo("body");e("#"+a.treeObjId).trigger(oa,[a.treeObjId,b])}if(a.dragStatus==1&&m.attr("id")!=k.target.id){if(j){j.removeClass(xa);t&&e("#"+
t+o,j).removeClass(ya)}t=j=null;s=false;h=a;for(var C in G)if(G[C].editable&&G[C].treeObjId!=a.treeObjId&&(k.target.id==G[C].treeObjId||e(k.target).parents("#"+G[C].treeObjId).length>0)){s=true;h=G[C]}C=e(q).scrollTop();n=e(q).scrollLeft();var D=h.treeObj.offset(),za=h.treeObj.get(0).scrollHeight,E=h.treeObj.get(0).scrollWidth,y=k.clientY+C-D.top,U=h.treeObj.height()+D.top-k.clientY-C,V=k.clientX+n-D.left;D=h.treeObj.width()+D.left-k.clientX-n;y=y<10&&y>-5;U=U<10&&U>-5;V=V<10&&V>-5;D=D<10&&D>-5;var nb=
y&&h.treeObj.scrollTop()<=0;za=U&&h.treeObj.scrollTop()+h.treeObj.height()+10>=za;var ob=V&&h.treeObj.scrollLeft()<=0;E=D&&h.treeObj.scrollLeft()+h.treeObj.width()+10>=E;if(k.target.id&&h.treeObj.find("#"+k.target.id).length>0){for(var z=e("#"+k.target.id);!z.is("li")&&z.attr("id")!=h.treeObjId;)z=z.parent();var Aa=false;if(b.parentNode&&z.attr("id")!=b.tId&&e("#"+b.tId).find("#"+z.attr("id")).length==0)Aa=true;else if(b.parentNode==null&&z.attr("id")!=b.tId&&e("#"+b.tId).find("#"+z.attr("id")).length==
0)Aa=true;if(Aa)if(k.target.id&&(k.target.id==z.attr("id")+o||e(k.target).parents("#"+z.attr("id")+o).length>0)){j=z;t=z.attr("id");e("#"+t+o,j).addClass(ya)}}if(k.target.id==h.treeObjId||e(k.target).parents("#"+h.treeObjId).length>0){if(!j&&(nb||za||ob||E)&&(s||!s&&b.parentNode!=null)){j=h.treeObj;j.addClass(xa)}if(y)h.treeObj.scrollTop(h.treeObj.scrollTop()-10);else U&&h.treeObj.scrollTop(h.treeObj.scrollTop()+10);if(V)h.treeObj.scrollLeft(h.treeObj.scrollLeft()-10);else D&&h.treeObj.scrollLeft(h.treeObj.scrollLeft()+
10);j&&j!=h.treeObj&&j.offset().left<h.treeObj.offset().left&&h.treeObj.scrollLeft(h.treeObj.scrollLeft()+j.offset().left-h.treeObj.offset().left)}p.css({top:k.clientY+C+3+"px",left:k.clientX+n+3+"px"});E=y=0;if(j&&j.attr("id")!=h.treeObjId){y=e("#"+b.tId).prev().attr("id")==j.attr("id");E=e("#"+b.tId).next().attr("id")==j.attr("id");n=e("#"+t+o,j);k=(k.clientY+C-n.offset().top)/n.height();if(k<0.25&&k>=-0.2&&!E){y=1-m.width();E=0-m.height()/2;v=W}else if(k>0.75&&k<=1.2&&!y){y=1-m.width();E=n.height()-
m.height()/2;v=da}else{y=5-m.width();E=0;v=x}m.css({display:"block",top:n.offset().top+E+"px",left:n.offset().left+y+"px"});if(Q!=t||L!=v)Wa=(new Date).getTime();if(v==x)window.moveTimer=setTimeout(function(){if(v==x){var ea=$(h,t);ea&&ea.isParent&&!ea.open&&(new Date).getTime()-Wa>500&&Ba(h,ea)}},600)}else{v=x;m.css({display:"none"});window.moveTimer&&clearTimeout(window.moveTimer)}Q=t;L=v}return false});e(q).mouseup(function(){this.moveTimer&&clearTimeout(this.moveTimer);L=Q=null;e(q).unbind("mousemove");
e(q).unbind("mouseup");e("body").css("cursor","auto");if(j){j.removeClass(xa);t&&e("#"+t+o,j).removeClass(ya)}Ya(false);if(a.dragStatus!=0){a.dragStatus=0;if(b.isParent&&a.dragNodeShowBefore&&!b.open){B(a,b,!b.open);a.dragNodeShowBefore=false}p&&p.remove();m&&m.remove();if(j&&t&&b.parentNode&&t==b.parentNode.tId&&v==x)j=null;if(j){var k=t==null?null:$(h,t),n=true;if(typeof h.callback.beforeDrop=="function")n=h.callback.beforeDrop(h.treeObjId,b,k,v);if(n!=false){if(s){Ca(a,b);fa(h,null,[b],false);
Da(h,k,b,v);O(h,b)}else Da(h,k,b,v);e("#"+b.tId+r).focus().blur();e("#"+a.treeObjId).trigger(Z,[h.treeObjId,b,k,v])}}else e("#"+a.treeObjId).trigger(Z,[a.treeObjId,null,null,null])}});l.preventDefault&&l.preventDefault()}});typeof a.addDiyDom=="function"&&a.addDiyDom(a.treeObjId,b)}function pb(a,b){if(a.setSelectionRange){a.focus();a.setSelectionRange(b,b)}else if(a.createTextRange){var c=a.createTextRange();c.collapse(true);c.moveEnd("character",b);c.moveStart("character",b);c.select()}}function Ya(a){for(;ga.length>
0;){ga[0].remove();ga.shift()}if(a){a=e("iframe");for(var b=0;b<a.length;b++){var c=a.get(b),d;d=Array(2);oRect=c.getBoundingClientRect();d[0]=oRect.left;d[1]=oRect.top;d=d;c=e("<div id='zTreeMask_"+b+"' class='zTreeMask' style='top:"+d[1]+"px; left:"+d[0]+"px; width:"+c.offsetWidth+"px; height:"+c.offsetHeight+"px;'></div>");c.appendTo("body");ga.push(c)}}}function Ra(a,b){e("#"+b.tId+K).text(b[a.nameCol])}function Ta(a){e("#"+a.tId+o).attr("target",a.target||"_blank")}function Ua(a,b){var c=e("#"+
b.tId+o);b.url&&!a.editable?c.attr("href",b.url):c.removeAttr("href")}function H(a,b){if(b){var c=e("#"+b.tId+w);e("#"+b.tId+o);var d=e("#"+b.tId+u),f=e("#"+b.tId+r);c.attr("class","switch");if(a.showLine){if(b.level==0&&b.isFirstNode&&b.isLastNode)c.attr("class","switch_"+Ea);else if(b.level==0&&b.isFirstNode)c.attr("class","switch_"+Fa);else b.isLastNode?c.attr("class","switch_"+ha):c.attr("class","switch_"+Za);b.isLastNode?d.removeClass(Ga):d.addClass(Ga)}else c.attr("class","switch_"+$a);f.attr("class",
b.iconSkin?b.iconSkin:"");if(b.isParent){d=b.open?"_"+M:"_"+N;c.attr("class",c.attr("class")+d);f.addClass("ico"+d)}else{c.attr("class",c.attr("class")+"_"+J);f.addClass("ico_"+J)}b.icon?f.attr("style","background:url("+b.icon+") 0 0 no-repeat;"):f.attr("style","")}}function F(a,b){if(a){var c=a.attr("class");if(c!=undefined){c=c.split("_");switch(b){case Ea:case Fa:case Za:case ha:case $a:c[1]=b;break;case M:case N:case J:c[2]=b}a.attr("class",c.join("_"))}}}function R(a,b){if(a){var c=a.attr("class");
if(c!=undefined){c=c.split("_");switch(b){case M:case N:case J:c[1]=b}a.attr("class",c.join("_"))}}}function Va(a,b){if(a.dragStatus==0){b.isHover=true;if(a.editable){qb(a,b);rb(a,b)}typeof a.addHoverDom=="function"&&a.addHoverDom(a.treeObjId,b)}}function ca(a,b){b.isHover=false;e("#"+b.tId+ia).unbind().remove();e("#"+b.tId+X).unbind().remove();typeof a.removeHoverDom=="function"&&a.removeHoverDom(a.treeObjId,b)}function qb(a,b){if(!(b.editNameStatus||e("#"+b.tId+ia).length>0)){var c=a.edit_renameBtn;
if(typeof a.edit_renameBtn=="function")c=a.edit_renameBtn(b);if(c){e("#"+b.tId+o);e("#"+b.tId+K).after("<button type='button' class='edit' id='"+b.tId+ia+"' title='' onfocus='this.blur();' style='display:none;'></button>");e("#"+b.tId+ia).bind("click",function(){var d=true;if(typeof a.callback.beforeRename=="function")d=a.callback.beforeRename(a.treeObjId,b);if(d!=false){ca(a,b);b.editNameStatus=true;O(a,b);return false}}).bind("mousedown",function(){return true}).show()}}}function rb(a,b){if(!(!a.edit_removeBtn||
e("#"+b.tId+X).length>0)){var c=a.edit_removeBtn;if(typeof a.edit_removeBtn=="function")c=a.edit_removeBtn(b);if(c){e("#"+b.tId+o).append("<button type='button' class='remove' id='"+b.tId+X+"' title='' onfocus='this.blur();' style='display:none;'></button>");e("#"+b.tId+X);e("#"+b.tId+X).bind("click",function(){var d=true;if(typeof a.callback.beforeRemove=="function")d=a.callback.beforeRemove(a.treeObjId,b);if(d!=false){Ca(a,b);e("#"+a.treeObjId).trigger(na,[a.treeObjId,b]);return false}}).bind("mousedown",
function(){return true}).show()}}}function Sa(a,b){if(a.checkStyle==P)if(b[a.checkedCol])if(a.checkRadioType==va){for(var c=a.checkRadioCheckedList.length-1;c>=0;c--){var d=a.checkRadioCheckedList[c];d[a.checkedCol]=false;a.checkRadioCheckedList.splice(c,1);A(a,e("#"+d.tId+I),d);d.parentNode!=b.parentNode&&T(a,d)}a.checkRadioCheckedList=a.checkRadioCheckedList.concat([b])}else{c=b.parentNode?b.parentNode:a.root;for(var f=0;f<c[a.nodesCol].length;f++){d=c[a.nodesCol][f];if(d[a.checkedCol]&&d!=b){d[a.checkedCol]=
false;A(a,e("#"+d.tId+I),d)}}}else{if(a.checkRadioType==va)for(c=0;c<a.checkRadioCheckedList.length;c++)if(b==a.checkRadioCheckedList[c]){a.checkRadioCheckedList.splice(c,1);break}}else{if(b[a.checkedCol]&&a.checkType.Y.indexOf("s")>-1){ja(a,b,true);Ha(a,b)}b[a.checkedCol]&&a.checkType.Y.indexOf("p")>-1&&Ia(a,b,true);if(!b[a.checkedCol]&&a.checkType.N.indexOf("s")>-1){ja(a,b,false);Ha(a,b)}!b[a.checkedCol]&&a.checkType.N.indexOf("p")>-1&&Ia(a,b,false)}}function A(a,b,c){if(b){b.removeClass();a=a.checkStyle+
"_"+(c[a.checkedCol]?sb:tb)+"_"+(c[a.checkedCol]||a.checkStyle==P?c.check_True_Full?ab:bb:c.check_False_Full?ab:bb);a=c.checkboxFocus?a+"_"+ub:a;b.addClass(vb);b.addClass(a)}}function aa(a,b){if(b&&b.parentNode){Ja(a,b.parentNode);aa(a,b.parentNode)}}function T(a,b){b[a.nodesCol]&&b[a.nodesCol].length>0?aa(a,b[a.nodesCol][0]):aa(a,b)}function Ha(a,b){if(b&&b[a.nodesCol]){for(var c=0;c<b[a.nodesCol].length;c++)b[a.nodesCol][c][a.nodesCol]&&Ha(a,b[a.nodesCol][c]);Ja(a,b)}}function Ja(a,b){if(b){var c=
true,d=true;if(b[a.nodesCol])for(var f=0;f<b[a.nodesCol].length;f++){if(a.checkStyle==P&&(b[a.nodesCol][f][a.checkedCol]||!b[a.nodesCol][f].check_True_Full))c=false;else if(a.checkStyle!=P&&b[a.checkedCol]&&(!b[a.nodesCol][f][a.checkedCol]||!b[a.nodesCol][f].check_True_Full))c=false;else if(a.checkStyle!=P&&!b[a.checkedCol]&&(b[a.nodesCol][f][a.checkedCol]||!b[a.nodesCol][f].check_False_Full))d=false;if(!c||!d)break}b.check_True_Full=c;b.check_False_Full=d;c=e("#"+b.tId+I);A(a,c,b)}}function ba(a){var b=
G[a.data.treeObjId];a=a.data.treeNode;b.expandTriggerFlag=true;if(a.open){var c=true;if(typeof b.callback.beforeCollapse=="function")c=b.callback.beforeCollapse(b.treeObjId,a);if(c==false){b.expandTriggerFlag=false;return}}else{c=true;if(typeof b.callback.beforeExpand=="function")c=b.callback.beforeExpand(b.treeObjId,a);if(c==false){b.expandTriggerFlag=false;return}}Ba(b,a)}function Ba(a,b){if(b.open||b&&b[a.nodesCol]&&b[a.nodesCol].length>0)B(a,b,!b.open);else if(a.async&&!a.editable)Ka(a,b);else b&&
B(a,b,!b.open)}function Ka(a,b){if(!(b&&(b.isAjaxing||!b.isParent))){if(b){b.isAjaxing=true;e("#"+b.tId+r).attr("class","ico_loading")}for(var c="",d=0;b&&d<a.asyncParam.length;d++)c+=(c.length>0?"&":"")+a.asyncParam[d]+"="+b[a.asyncParam[d]];for(d=0;d<a.asyncParamOther.length;d+=2)c+=(c.length>0?"&":"")+a.asyncParamOther[d]+"="+a.asyncParamOther[d+1];d=a.asyncUrl;if(typeof a.asyncUrl=="function")d=a.asyncUrl(b);e.ajax({type:"POST",url:d,data:c,success:function(f){if(!(!f||f.length==0)){var g="";
try{g=typeof f=="string"?eval("("+f+")"):f}catch(i){}H(a,b);g&&g!=""?fa(a,b,g,false):fa(a,b,[],false);if(b)b.isAjaxing=undefined;e("#"+a.treeObjId).trigger(ra,[a.treeObjId,b,f])}},error:function(f,g,i){a.expandTriggerFlag=false;H(a,b);if(b)b.isAjaxing=undefined;e("#"+a.treeObjId).trigger(sa,[a.treeObjId,b,f,g,i])}})}}function B(a,b,c,d,f){if(!b||b.open==c)typeof f=="function"&&f();else{if(a.expandTriggerFlag){f=function(){b.open?e("#"+a.treeObjId).trigger(pa,[a.treeObjId,b]):e("#"+a.treeObjId).trigger(qa,
[a.treeObjId,b])};a.expandTriggerFlag=false}c=e("#"+b.tId+w);var g=e("#"+b.tId+r),i=e("#"+b.tId+u);if(b.isParent)if(b.open){F(c,N);R(g,N);b.open=false;if(d==false){i.hide();typeof f=="function"&&f()}else i.hide(a.expandSpeed,f)}else{F(c,M);R(g,M);b.open=true;if(d==false){i.show();typeof f=="function"&&f()}else if(b[a.nodesCol]&&b[a.nodesCol].length>0)i.show(a.expandSpeed,f);else typeof f=="function"&&f()}else typeof f=="function"&&f()}}function La(a,b,c,d,f){var g=b?b[a.nodesCol]:a.root[a.nodesCol],
i=b?false:d;if(g)for(var l=0;l<g.length;l++)g[l]&&La(a,g[l],c,i);B(a,b,c,d,f)}function Y(a,b,c,d,f){if(b)if(b.parentNode){B(a,b,c,d);b.parentNode&&Y(a,b.parentNode,c,d,f)}else B(a,b,c,d,f)}function Ia(a,b,c){var d=e("#"+b.tId+I);b[a.checkedCol]=c;A(a,d,b);if(b.parentNode){d=true;if(!c)for(var f=0;f<b.parentNode[a.nodesCol].length;f++)if(b.parentNode[a.nodesCol][f][a.checkedCol]){d=false;break}d&&Ia(a,b.parentNode,c)}}function ja(a,b,c){if(b){var d=e("#"+b.tId+I);if(b!=a.root){b[a.checkedCol]=c;A(a,
d,b)}if(b[a.nodesCol])for(d=0;d<b[a.nodesCol].length;d++)b[a.nodesCol][d]&&ja(a,b[a.nodesCol][d],c)}}function cb(a,b,c){if(c){c.level=b?b.level+1:0;if(c[a.nodesCol])for(b=0;b<c[a.nodesCol].length;b++)c[a.nodesCol][b]&&cb(a,c,c[a.nodesCol][b])}}function fa(a,b,c,d){if(a.isSimpleData)c=Ma(a,c);if(b){if(e("#"+a.treeObjId).find("#"+b.tId).length!=0){target_switchObj=e("#"+b.tId+w);target_icoObj=e("#"+b.tId+r);target_aObj=e("#"+b.tId+o);target_ulObj=e("#"+b.tId+u);if(!b.open){F(target_switchObj,N);R(target_icoObj,
N);b.open=false;target_ulObj.css({display:"none"})}if(!b.isParent){target_switchObj.unbind("click");target_switchObj.bind("click",function(){B(a,b,!b.open)});target_aObj.unbind("dblclick");target_aObj.bind("dblclick",{treeObjId:a.treeObjId,treeNode:b},ba)}db(a,b,c);S(a,b.level+1,c,b);d||Y(a,b,true)}}else{db(a,a.root,c);S(a,0,c,null)}}function db(a,b,c){b[a.nodesCol]||(b[a.nodesCol]=[]);if(b[a.nodesCol].length>0){b[a.nodesCol][b[a.nodesCol].length-1].isLastNode=false;H(a,b[a.nodesCol][b[a.nodesCol].length-
1])}b.isParent=true;b[a.nodesCol]=b[a.nodesCol].concat(c)}function Da(a,b,c,d,f){if(b!=c){var g=c.parentNode==null?a.root:c.parentNode,i=b===null||b==a.root;if(i&&b===null)b=a.root;if(i)d=x;var l=b.parentNode?b.parentNode:a.root;if(d!=W&&d!=da)d=x;var q=-1,p=0,m=null,j=null;if(c.isFirstNode){q=0;if(g[a.nodesCol].length>1){m=g[a.nodesCol][1];m.isFirstNode=true}}else if(c.isLastNode){q=g[a.nodesCol].length-1;m=g[a.nodesCol][q-1];m.isLastNode=true}else for(var s=0;s<g[a.nodesCol].length;s++)if(g[a.nodesCol][s].tId==
c.tId)q=s;q>=0&&g[a.nodesCol].splice(q,1);if(d!=x)for(s=0;s<l[a.nodesCol].length;s++)if(l[a.nodesCol][s].tId==b.tId)p=s;q=false;if(d==x){if(i)c.parentNode=null;else{q=!b.isParent;b.isParent=true;c.parentNode=b}b[a.nodesCol]||(b[a.nodesCol]=[]);if(b[a.nodesCol].length>0){j=b[a.nodesCol][b[a.nodesCol].length-1];j.isLastNode=false}b[a.nodesCol].splice(b[a.nodesCol].length,0,c);c.isLastNode=true;c.isFirstNode=b[a.nodesCol].length==1}else if(b.isFirstNode&&d==W){l[a.nodesCol].splice(p,0,c);j=b;j.isFirstNode=
false;c.parentNode=b.parentNode;c.isFirstNode=true;c.isLastNode=false}else if(b.isLastNode&&d==da){l[a.nodesCol].splice(p+1,0,c);j=b;j.isLastNode=false;c.parentNode=b.parentNode;c.isFirstNode=false;c.isLastNode=true}else{d==W?l[a.nodesCol].splice(p,0,c):l[a.nodesCol].splice(p+1,0,c);c.parentNode=b.parentNode;c.isFirstNode=false;c.isLastNode=false}cb(a,c.parentNode,c);e("#"+c.tId+w);e("#"+c.tId+u);var h,Q,L;if(i)p=l=e("#"+a.treeObjId);else{l=e("#"+b.tId);h=e("#"+b.tId+w);Q=e("#"+b.tId+r);L=e("#"+b.tId+
o);p=e("#"+b.tId+u)}if(d==x){F(h,M);R(Q,M);b.open=true;p.css({display:"block"});if(q&&!i){h.unbind("click");h.bind("click",function(){B(a,b,!b.open)});L.unbind("dblclick");L.bind("dblclick",{treeObjId:a.treeObjId,treeNode:b},ba)}p.append(e("#"+c.tId).detach())}else if(d==W)l.before(e("#"+c.tId).detach());else d==da&&l.after(e("#"+c.tId).detach());H(a,c);if(g[a.nodesCol].length<1){g.isParent=false;d=e("#"+g.tId+u);i=e("#"+g.tId+w);m=e("#"+g.tId+r);F(i,J);R(m,J);d.css("display","none")}else m&&H(a,
m);j&&H(a,j);if(a.checkable){Ja(a,g);T(a,g);g!=c.parent&&T(a,c)}Y(a,c.parentNode,true,f)}}function Ca(a,b){var c=b.parentNode==null?a.root:b.parentNode;if(a.curTreeNode===b)a.curTreeNode=null;if(a.curEditTreeNode===b)a.curEditTreeNode=null;e("#"+b.tId).remove();for(var d=-1,f=0;f<c[a.nodesCol].length;f++)if(c[a.nodesCol][f].tId==b.tId)d=f;d>=0&&c[a.nodesCol].splice(d,1);if(c[a.nodesCol].length<1){c.isParent=false;c.open=false;d=e("#"+c.tId+u);f=e("#"+c.tId+w);c=e("#"+c.tId+r);F(f,J);R(c,J);d.css("display",
"none")}else if(a.showLine){c[a.nodesCol][c[a.nodesCol].length-1].isLastNode=true;c[a.nodesCol][c[a.nodesCol].length-1].isFirstNode=c[a.nodesCol].length==1;d=e("#"+c[a.nodesCol][c[a.nodesCol].length-1].tId+u);f=e("#"+c[a.nodesCol][c[a.nodesCol].length-1].tId+w);e("#"+c[a.nodesCol][c[a.nodesCol].length-1].tId+r);if(c==a.root)if(c[a.nodesCol].length==1)F(f,Ea);else{c=e("#"+c[a.nodesCol][0].tId+w);F(c,Fa);F(f,ha)}else F(f,ha);d.removeClass(Ga)}}function $(a,b){return Na(a,a.root[a.nodesCol],"tId",b)}
function Na(a,b,c,d){if(!b||!c)return null;for(var f=0;f<b.length;f++){if(b[f][c]==d)return b[f];var g=Na(a,b[f][a.nodesCol],c,d);if(g)return g}return null}function eb(a,b,c,d){if(!b||!c)return[];for(var f=[],g=0;g<b.length;g++){b[g][c]==d&&f.push(b[g]);f=f.concat(eb(a,b[g][a.nodesCol],c,d))}return f}function fb(a){if(a.curTreeNode){e("#"+a.curTreeNode.tId+o).removeClass(wa);e("#"+a.curTreeNode.tId+K).text(a.curTreeNode[a.nameCol]);ca(a,a.curTreeNode);a.curTreeNode=null}}function wb(a){if(a.curEditTreeNode){e("#"+
a.curEditTreeNode.tId+o).removeClass(gb);e("#"+a.curEditTreeNode.tId+Oa).unbind();e("#"+a.curEditTreeNode.tId+K).text(a.curEditTreeNode[a.nameCol]);a.curEditTreeNode.editNameStatus=false;a.curEditTreeNode=null}}function O(a,b){if(!(a.curTreeNode==b&&!b.editNameStatus)){fb(a);wb(a);if(a.editable&&b.editNameStatus){e("#"+b.tId+K).html("<input type=text class='rename' id='"+b.tId+Oa+"'>");var c=e("#"+b.tId+Oa);c.attr("value",b[a.nameCol]);c.focus();pb(c.get(0),b[a.nameCol].length);c.bind("blur",function(){hb(this.value,
a,b)}).bind("keypress",function(d){d.keyCode=="13"&&hb(this.value,a,b)}).bind("click",function(){return false}).bind("dblclick",function(){return false});e("#"+b.tId+o).addClass(gb);a.curEditTreeNode=b}else e("#"+b.tId+o).addClass(wa);Va(a,b);a.curTreeNode=b}}function hb(a,b,c){c[b.nameCol]=a;e("#"+b.treeObjId).trigger(ma,[b.treeObjId,c]);O(b,c)}function ib(a,b,c){if(!b)return[];for(var d=[],f=0;f<b.length;f++){if(b[f][a.checkedCol]==c)d=d.concat([b[f]]);var g=ib(a,b[f][a.nodesCol],c);if(g.length>
0)d=d.concat(g)}return d}function jb(a,b){if(!b)return[];for(var c=[],d=0;d<b.length;d++){if(b[d][a.checkedCol]!=b[d].checkedOld)c=c.concat([b[d]]);var f=jb(a,b[d][a.nodesCol]);if(f.length>0)c=c.concat(f)}return c}function Ma(a,b){var c=a.treeNodeKey,d=a.treeNodeParentKey;if(!c||c==""||!b)return[];if(Object.prototype.toString.apply(b)==="[object Array]"){for(var f=[],g=[],i=0;i<b.length;i++)g[b[i][c]]=b[i];for(i=0;i<b.length;i++)if(b[i][d]&&g[b[i][d]]){g[b[i][d]][a.nodesCol]||(g[b[i][d]][a.nodesCol]=
[]);g[b[i][d]][a.nodesCol].push(b[i])}else f.push(b[i]);return f}else return[b]}function Pa(a,b){if(!b)return[];var c=[];if(Object.prototype.toString.apply(b)==="[object Array]")for(var d=0;d<b.length;d++){c.push(b[d]);if(b[d][a.nodesCol])c=c.concat(Pa(a,b[d][a.nodesCol]))}else{c.push(b);if(b[a.nodesCol])c=c.concat(Pa(a,b[a.nodesCol]))}return c}function xb(){return{container:null,setting:null,init:function(a){this.container=a;this.setting=G[a.attr("id")];return this},refresh:function(){e("#"+this.setting.treeObjId).empty();
this.setting.curTreeNode=null;this.setting.curEditTreeNode=null;this.setting.dragStatus=0;this.setting.dragNodeShowBefore=false;this.setting.checkRadioCheckedList=[];ua=0;S(this.setting,0,this.setting.root[this.setting.nodesCol])},setEditable:function(a){this.setting.editable=a;return this.refresh()},transformTozTreeNodes:function(a){return Ma(this.setting,a)},transformToArray:function(a){return Pa(this.setting,a)},getNodes:function(){return this.setting.root[this.setting.nodesCol]},getSelectedNode:function(){return this.setting.curTreeNode},
getCheckedNodes:function(a){a=a!=false;return ib(this.setting,this.setting.root[this.setting.nodesCol],a)},getChangeCheckedNodes:function(){return jb(this.setting,this.setting.root[this.setting.nodesCol])},getNodeByTId:function(a){if(a)return $(this.setting,a)},getNodeByParam:function(a,b){if(a)return Na(this.setting,this.setting.root[this.setting.nodesCol],a,b)},getNodesByParam:function(a,b){if(a)return eb(this.setting,this.setting.root[this.setting.nodesCol],a,b)},getNodeIndex:function(a){if(a){for(var b=
a.parentNode==null?this.setting.root:a.parentNode,c=0;c<b[this.setting.nodesCol].length;c++)if(b[this.setting.nodesCol][c]==a)return c;return-1}},getSetting:function(){var a=this.setting,b={checkType:{},callback:{}},c=a.checkType;a.checkType=undefined;var d=a.callback;a.callback=undefined;var f=a.root;a.root=undefined;e.extend(b,a);a.checkType=c;a.callback=d;a.root=f;e.extend(true,b.checkType,c);e.extend(b.callback,d);return b},updateSetting:function(a){if(a){var b=this.setting,c=b.treeObjId,d=a.checkType;
a.checkType=undefined;var f=a.callback;a.callback=undefined;var g=a.root;a.root=undefined;e.extend(b,a);a.checkType=d;a.callback=f;a.root=g;e.extend(true,b.checkType,d);e.extend(b.callback,f);b.treeObjId=c;b.treeObj=this.container}},expandAll:function(a){La(this.setting,null,a,true)},expandNode:function(a,b,c){if(a){if(b){a.parentNode&&Y(this.setting,a.parentNode,b,false);B(this.setting,a,b,true)}if(c)La(this.setting,a,b,false,function(){e("#"+a.tId+r).focus().blur()});else if(a.open!=b){Ba(this.setting,
a);e("#"+a.tId+r).focus().blur()}}},selectNode:function(a){if(a){O(this.setting,a);a.parentNode?Y(this.setting,a.parentNode,true,false,function(){e("#"+a.tId+r).focus().blur()}):e("#"+a.tId+r).focus().blur()}},cancleSelectedNode:function(){this.cancelSelectedNode()},cancelSelectedNode:function(){fb(this.setting)},checkAllNodes:function(a){this.setting.checkable&&ja(this.setting,this.setting.root,a==true)},reAsyncChildNodes:function(a,b){if(this.setting.async){var c=!a;if(c)a=this.setting.root;if(b==
"refresh"){a[this.setting.nodesCol]=[];c?this.setting.treeObj.empty():e("#"+a.tId+u).empty()}Ka(this.setting,c?null:a)}},addNodes:function(a,b,c){if(b){a||(a=null);fa(this.setting,a,b,c==true)}},updateNode:function(a,b){if(a){var c=e("#"+a.tId+I);if(this.setting.checkable){b==true&&Sa(this.setting,a);A(this.setting,c,a);T(this.setting,a)}Ra(this.setting,a);Ta(a);Ua(this.setting,a);H(this.setting,a)}},moveNode:function(a,b,c){if(b)if(!(a&&(b.parentNode==a&&c==x||e("#"+b.tId).find("#"+a.tId).length>
0))){a||(a=null);Da(this.setting,a,b,c,false)}},removeNode:function(a){a&&Ca(this.setting,a)}}}var ka="ZTREE_CLICK",la="ZTREE_CHANGE",ma="ZTREE_RENAME",na="ZTREE_REMOVE",oa="ZTREE_DRAG",Z="ZTREE_DROP",pa="ZTREE_EXPAND",qa="ZTREE_COLLAPSE",ra="ZTREE_ASYNC_SUCCESS",sa="ZTREE_ASYNC_ERROR",w="_switch",r="_ico",K="_span",Oa="_input",I="_check",ia="_edit",X="_remove",u="_ul",o="_a",Ea="root",Fa="roots",Za="center",ha="bottom",$a="noLine",Ga="line",M="open",N="close",J="docu",wa="curSelectedNode",gb="curSelectedNode_Edit",
xa="tmpTargetTree",ya="tmpTargetNode",P="radio",vb="chk",tb="false",sb="true",ab="full",bb="part",ub="focus",va="all",x="inner",W="before",da="after",Xa="5",G=[],ua=0;e.fn.zTree=function(a,b){var c={treeObjId:"",checkable:false,editable:false,edit_renameBtn:true,edit_removeBtn:true,showLine:true,curTreeNode:null,curEditTreeNode:null,dragStatus:0,dragNodeShowBefore:false,checkStyle:"checkbox",checkType:{Y:"ps",N:"ps"},checkRadioType:"level",checkRadioCheckedList:[],async:false,asyncUrl:"",asyncParam:[],
asyncParamOther:[],isSimpleData:false,treeNodeKey:"",treeNodeParentKey:"",nameCol:"name",nodesCol:"nodes",checkedCol:"checked",expandSpeed:"fast",expandTriggerFlag:false,addHoverDom:null,removeHoverDom:null,addDiyDom:null,root:{isRoot:true,nodes:[]},callback:{beforeClick:null,beforeRightClick:null,beforeMouseDown:null,beforeMouseUp:null,beforeChange:null,beforeDrag:null,beforeDrop:null,beforeRename:null,beforeRemove:null,beforeExpand:null,beforeCollapse:null,click:null,rightClick:null,mouseDown:null,
mouseUp:null,change:null,drag:null,drop:null,rename:null,remove:null,expand:null,collapse:null,asyncSuccess:null,asyncError:null}};if(a){var d=a.checkType;a.checkType=undefined;var f=a.callback;a.callback=undefined;var g=a.root;a.root=undefined;e.extend(c,a);a.checkType=d;e.extend(true,c.checkType,d);a.callback=f;e.extend(c.callback,f);a.root=g;e.extend(c.root,g)}c.treeObjId=this.attr("id");c.treeObj=this;c.root.tId=-1;c.root.name="ZTREE ROOT";c.root.isRoot=true;c.checkRadioCheckedList=[];c.curTreeNode=
null;c.curEditTreeNode=null;c.dragNodeShowBefore=false;c.dragStatus=0;c.expandTriggerFlag=false;c.root[c.nodesCol]||(c.root[c.nodesCol]=[]);ua=0;if(b)c.root[c.nodesCol]=b;if(c.isSimpleData)c.root[c.nodesCol]=Ma(c,c.root[c.nodesCol]);G[c.treeObjId]=c;e("#"+c.treeObjId).empty();kb(c,this);if(c.root[c.nodesCol]&&c.root[c.nodesCol].length>0)S(c,0,c.root[c.nodesCol]);else c.async&&c.asyncUrl&&c.asyncUrl.length>0&&Ka(c);return(new xb).init(this)};var ga=[]})(jQuery);
