(function(h){function g(a){var b=h.data(a,"combotree").options;var c=h.data(a,"combotree").tree;h(a).addClass("combotree-f");h(a).combo(b);var d=h(a).combo("panel");if(!c){c=h("<ul></ul>").appendTo(d);h.data(a,"combotree").tree=c}c.tree(h.extend({},b,{checkbox:b.multiple,onLoadSuccess:function(i,p){var q=h(a).combotree("getValues");if(b.multiple){var r=c.tree("getChecked");for(var t=0;t<r.length;t++){var s=r[t].id;(function(){for(var j=0;j<q.length;j++){if(s==q[j]){return}}q.push(s)})()}}h(a).combotree("setValues",q);b.onLoadSuccess.call(this,i,p)},onClick:function(j){f(a);h(a).combo("hidePanel");b.onClick.call(this,j)},onCheck:function(k,l){f(a);b.onCheck.call(this,k,l)}}))}function f(p){var a=h.data(p,"combotree").options;var b=h.data(p,"combotree").tree;var i=[],n=[];if(a.multiple){var c=b.tree("getChecked");for(var o=0;o<c.length;o++){i.push(c[o].id);n.push(c[o].text)}}else{var d=b.tree("getSelected");if(d){i.push(d.id);n.push(d.text)}}h(p).combo("setValues",i).combo("setText",n.join(a.separator))}function e(p,q){var r=h.data(p,"combotree").options;var s=h.data(p,"combotree").tree;s.find("span.tree-checkbox").addClass("tree-checkbox0").removeClass("tree-checkbox1 tree-checkbox2");var d=[],a=[];for(var i=0;i<q.length;i++){var c=q[i];var b=c;var t=s.tree("find",c);if(t){b=t.text;s.tree("check",t.target);s.tree("select",t.target)}d.push(c);a.push(b)}h(p).combo("setValues",d).combo("setText",a.join(r.separator))}h.fn.combotree=function(c,a){if(typeof c=="string"){var b=h.fn.combotree.methods[c];if(b){return b(this,a)}else{return this.combo(c,a)}}c=c||{};return this.each(function(){var d=h.data(this,"combotree");if(d){h.extend(d.options,c)}else{h.data(this,"combotree",{options:h.extend({},h.fn.combotree.defaults,h.fn.combotree.parseOptions(this),c)})}g(this)})};h.fn.combotree.methods={options:function(a){return h.data(a[0],"combotree").options},tree:function(a){return h.data(a[0],"combotree").tree},loadData:function(a,b){return a.each(function(){var c=h.data(this,"combotree").options;c.data=b;var d=h.data(this,"combotree").tree;d.tree("loadData",b)})},reload:function(a,b){return a.each(function(){var c=h.data(this,"combotree").options;var d=h.data(this,"combotree").tree;if(b){c.url=b}d.tree({url:c.url})})},setValues:function(a,b){return a.each(function(){e(this,b)})},setValue:function(a,b){return a.each(function(){e(this,[b])})},clear:function(a){return a.each(function(){var b=h.data(this,"combotree").tree;b.find("div.tree-node-selected").removeClass("tree-node-selected");h(this).combo("clear")})}};h.fn.combotree.parseOptions=function(a){return h.extend({},h.fn.combo.parseOptions(a),h.fn.tree.parseOptions(a))};h.fn.combotree.defaults=h.extend({},h.fn.combo.defaults,h.fn.tree.defaults,{editable:false})})(jQuery);