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