(function(b){b(window).on("load",function(r){b("table#viewTable").treeExp()});b.fn.lvlctl=function(){return this.find(".lvlctl")};b.fn.getLvl2=function(){var r=this.lvlctl().attr("lvl");return parseInt(r||"-1",10)};b.fn.treeExp=function(r){var a={sFetching:"fetching",sFetched:"fetched",sCollapsed:"collapsed",sExpanded:"expanded",sNoSub:"nosub",sSTreeUrl:"",sSTreeUFn:"h_child_search_jsp",sTPlusImg:"",sTMinusImg:"",sTLeafImg:"",sTPlusFn:"h_img_collapsed",sTMinusFn:"h_img_expanded",sTLeafFn:"h_img_nosub"};
b.extend(a,b.hybs.defaults);var w=function(c,d){var l;var p=!0;var q={bForceExp:!1,bHeaderFix:!0};b.extend(q,d||{});a.sTPlusImg||(a.sTPlusImg=b.hybs.getHValue(a.sTPlusFn));a.sTMinusImg||(a.sTMinusImg=b.hybs.getHValue(a.sTMinusFn));a.sTLeafImg||(a.sTLeafImg=b.hybs.getHValue(a.sTLeafFn));var h=b.hybs.getHybsTr(c.parents("tr:first"));h.is("tr");var t=c.parents("table:first");if(!c.hasClass(a.sFetching)&&!c.hasClass(a.sNoSub))if(c.hasClass(a.sFetched)){if(d=c.hasClass(a.sExpanded),!d||!q.bForceExp){var g=
h.next();var x=h.getLvl2();for(nCloseLvl=l=Math.floor(Number.MAX_VALUE);g[0];){nRunLvl=g.getLvl2();if(x>=nRunLvl)break;d?g.hide():(g.lvlctl().hasClass(a.sCollapsed)?nCloseLvl>nRunLvl&&(nCloseLvl=nRunLvl):nCloseLvl>=nRunLvl&&(nCloseLvl=l),nCloseLvl>=nRunLvl&&g.show());var m=!0;g=g.next()}d?m&&(c.removeClass(a.sExpanded).addClass(a.sCollapsed),c.attr("src",a.sTPlusImg)):(c.removeClass(a.sCollapsed).addClass(a.sExpanded),c.attr("src",a.sTMinusImg));q.bHeaderFix&&t.resizeView()}}else if(m=a.sSTreeUrl,
!m&&a.sSTreeUFn&&(m=b.hybs.getHValue(a.sSTreeUFn)),m){var n={};if(d=c.attr("vals")){var u=(g=c.attr("keys"))?g.split(","):[];var y=u.length;b.each(d.split(","),function(e,f){n[e<y?u[e]:"key"+e]=f});d={};n[a.sHybsSel]||(d[a.sHybsSel]=h.attr(a.sHybsRid));n[a.sHybsCmd]||(d[a.sHybsCmd]="NEW");n[a.sNoTsKey]||(d[a.sNoTsKey]="true");b.extend(n,d)}b.ajax({url:m,data:n,type:"POST",async:!1,error:function(e,f,k){p=!1;b.hybs.ogLog(f+"\n"+e.responseText);b.hybs.ogAlert(f+"<br/>"+e.responseText)},success:function(e){var f;
e=/(<tbody[^>]*>[\S\s]*<\/tbody>)/m.exec(e);var k="";e&&(k=e[1].trim());if(k){e=h.next();c.removeClass(a.sFetching+" "+a.sCollapsed).addClass(a.sFetched+" "+a.sExpanded);h.after(k);c.attr("src",a.sTMinusImg);k=b.hybs.getNoColId(t);var v=["row_0","row_1","row_hilight"];var A=b.grep(v,function(z){return h.hasClass(z)})[0];for(f=h.next();f[0]&&f[0]!=e[0];)f.lvlctl().addClass(a.sCollapsed),f.removeClass(v.join(" ")).addClass(A),0<=k&&f.find("td:nth("+k+")").empty(),f=f.next()}else c.attr("src",a.sTLeafImg),
c.removeClass(a.sCollapsed).addClass(a.sFetched+" "+a.sExpanded+" "+a.sNoSub);q.bHeaderFix&&t.resizeView()}})}else b.hybs.ogAlert("URL is not sepcified!"),p=!1;return p};var B=function(c){var d;var l=b.hybs.getHybsTr(c.parents("tr:first"));var p=l.getLvl2();for(d=l;w(c,{bForceExp:!0,bHeaderFix:!1});){d=d.next();if(0==d.length)break;if(p>=d.getLvl2())break;c=d.lvlctl()}l.parents("table:first").resizeView()};return this.each(function(){b(this).on("click",function(c){var d=b(c.target);d.is(".lvlctl")&&
(c.shiftKey?B(d):w(d))})})}})(jQuery);
