(function(q,f){var w=document.createElement("div");f.fn.getDescendants=function(){for(var g=this,h=parseInt(g.attr("level"))||0,j=[];(g=g.next()).length&&parseInt(g.attr("level"))>h;)j.push(g[0]);return f(j)};f.fn.getChildren=function(){for(var g=this,h=parseInt(g.attr("level"))||0,j=h+1,n,r=[];(g=g.next()).length&&(n=parseInt(g.attr("level")))>h;)j==n&&r.push(g[0]);return f(r)};var A=function(g){for(var h=g,j=parseInt(g.attr("level"))||0;(g=g.next()).length&&parseInt(g.attr("level"))>j;)h=g;return h},
e={hover:"over",focused:"row_chked",collapsed:"collapsed",parent:"parent",hitarea:"hitarea",treeTable:"treeTable"},B={loading:'<img src="'+IMG_URL+'images/loading.gif"/>&nbsp;&nbsp;&nbsp;&#x6570;&#x636E;&#x8F7D;&#x5165;&#x4E2D;&#x3002;&#x3002;&#x3002;',noData:"&#x6682;&#x65E0;&#x6570;&#x636E;"};q.treeTable=function(g,h){g=f(g).addClass(e.treeTable);h||(h={});var j=f(g[0].tBodies[0]),n=f.trim(h.template||""),r=h.baseUrl||"",o=h.rowIdPrefix||"row_",C=h.treeCellIndex||0,D=h.idField||"id",u=h.parentField||
"parentid",E=!!h.collapsed,F=q.func(h.jsonLoaded)||function(){},G=q.func(h.rowReady)||function(){},H=q.func(h.rowsPrepared)||function(){},l=null,x=f('<tfoot><tr><td class="empty" colspan="'+f(n).find(">td").length+'" align="center">'+B.loading+"</td></tr></tfoot>");j.after(x);var y=function(b,c,d){var i=0,a=null,k=0;if(c&&c.jquery){a=c;i=c[0].id.substr(o.length)}else(i=parseInt(c)||0)&&(a=f("#"+o+i)).length||(a=null);a&&a.addClass(e.parent);k=a?parseInt(a.attr("level")):-1;c=k+1;b.attr("level",c).attr("parentid",
i);b.data("parentTr",a);b.data("indent").css("padding","0 "+10*c+"px");a&&a.hasClass(e.collapsed)&&b.hide();if(d&&d.jquery){if(d.hasClass(e.parent)){b.addClass(e.parent);d.hasClass(e.collapsed)&&b.addClass(e.collapsed);d.getChildren().data("parentTr",b)}d.hasClass(e.focused)&&setTimeout(function(){b.click()},0);d.replaceWith(b)}else a?A(a).after(b):j.append(b)},z=function(b){var c=b.next();if(!c.length||parseInt(c.attr("level"))<=parseInt(b.attr("level")))b.removeClass(e.parent+" "+e.collapsed)},
t=function(b,c){var d=n;for(var i in b)d=d.replace(RegExp("{"+i+"}","gm"),b[i]);w.innerHTML="<table><tbody>"+d+"</tbody></table>";d=w.firstChild.rows[0];var a=f(d);i=f(d.cells[C]);var k=f('<span class="'+e.hitarea+'"></span>').click(function(){if(a.hasClass(e.parent))if(a.hasClass(e.collapsed)){a.removeClass(e.collapsed);a.getChildren().each(function(){f.data(this,"show")()})}else{a.getDescendants().hide();a.addClass(e.collapsed)}}).dblclick(function(){return false}),s=f(document.createElement("q"));
E&&a.addClass(e.collapsed);a.data("indent",s);i.prepend(k).prepend(s);y(a,b[u],c);d=d.id.substr(o.length);a.hover(function(){a.addClass(e.hover)},function(){a.removeClass(e.hover)}).click(function(){if(l!=a){l&&l.removeClass(e.focused);l=a;a.addClass(e.focused)}}).data("show",function(){a.show();a.hasClass(e.parent)&&!a.hasClass(e.collapsed)&&a.getChildren().each(function(){f.data(this,"show")()})}).data("_delete_",function(){a.hasClass(e.parent)&&a.getChildren().each(function(){f.data(this,"_delete_")()});
l==a&&(l=null);a.remove()}).data("_setParent_",function(m){var p=a.hasClass(e.parent)?a.getChildren():null;y(a,m);p&&p.each(function(){f.data(this,"_setParent_")(a)})});G(d,a,b);return a};this.addRow=function(b){return t(b)};this.updateRow=function(b,c){var d=f("#"+o+b);if(parseInt(c[u])==parseInt(d.attr("parentid")))return t(c,d);var i=d.hasClass(e.parent)?d.getChildren():null,a=t(c);if(i){d.hasClass(e.collapsed)&&a.addClass(e.collapsed);i.each(function(){f.data(this,"_setParent_")(a)})}d.hasClass(e.focused)&&
a.click();i=d.data("parentTr");d.remove();i&&z(i);return a};this.deleteRow=function(b){b=f("#"+o+b);var c=b.data("parentTr");b.data("_delete_")();c&&z(c)};var I=function(b){var c;if(f.isArray(b)){c={};for(var d=0,i;i=b[d++];)c[i[D]]=i}else c=f.extend({},b);var a={},k=function(m){var p=c[m],v=p[u];if(!(m in a)){v in a||v in c&&k(v);t(p);delete c[m];a[m]=1}};for(var s in c)k(s)};this.load=function(b){var c=r;b&&(c+="&"+b);f.getJSON(c,function(d){F(d);x.hide();j.empty();I(d);H(j)})}}})(cmstop,jQuery);
