(function(t,g){var u={loading:'<img src="'+IMG_URL+'images/loading.gif"/>&nbsp;&nbsp;&nbsp;&#x6570;&#x636E;&#x8F7D;&#x5165;&#x4E2D;&#x3002;&#x3002;&#x3002;',noData:"&#x6682;&#x65E0;&#x6570;&#x636E;",prevPage:"&#x4E0A;&#x4E00;&#x9875;",nextPage:"&#x4E0B;&#x4E00;&#x9875;"},H=document.createElement("div"),A=g(document);t.table=function(m,i){m=g(m);var n=g(m[0].tBodies[0]);i||(i={});var I=i.rowIdPrefix||"row_",Q=i.rightMenuId||"right_menu",R=t.func(i.dblclickHandler||"dblclick_handler")||function(){},
B=t.func(i.rowCallback||"init_row_event")||function(){},S=t.func(i.jsonLoaded||"json_loaded")||function(){},T=g.trim(i.template||""),p=g("#"+(i.pagerId||"pagination")),U=i.pageVar||"page",J=i.pagesizeVar||"pagesize",q=i.pageSize||12,K=i.baseUrl||"",x=K+(p.length?"&"+J+"="+q:""),L={},M=[],l={},r=[],N=0,y=g(m[0].rows[0].cells).each(function(a){var c=g(this);if(c.hasClass("sorter"))c.removeClass("sorter");else{L[a]={sorter:false};N++;c.hasClass("ajaxer")&&(c.removeClass("sorter").addClass("header"),
M.push(c))}});N<y.length&&m.tablesorter({headers:L});var o=g('<tfoot><tr><td class="empty" colspan="'+y.length+'" align="center">'+u.loading+"</td></tr></tfoot>");n.after(o);var z=y.find("input:checkbox");z.click(function(){for(var a=z[0].checked?"check":"unCheck",c=0,d;d=r[c++];)d.trigger(a)});var v=null,C=function(a){var c=T;for(var d in a)c=c.replace(RegExp("{"+d+"}","gm"),a[d]);H.innerHTML="<table><tbody>"+c+"</tbody></table>";var b=g(H.firstChild.rows[0]),h=b[0].id.substr(I.length);l[h]=b;b.hover(function(){b.addClass("over")},
function(){b.removeClass("over")});var f=b.find("input:checkbox");if(f.length){b.bind("check",function(){b.addClass("row_chked");f[0].checked=true}).bind("unCheck",function(){b.removeClass("row_chked");f[0].checked=false});c=function(e){e.stopPropagation();A.click();var j=f[0].checked;e.target==f[0]&&(j=!j);b.trigger(j?"unCheck":"check")};f.click(c);b.click(c);r.push(f);b.bind("beforeRemove",function(){var e=r.indexOf(f);e!=-1&&r.splice(e,1);delete l[h]})}else b.click(function(){b.trigger("check")}).bind("check",
function(){if(v!=b){v&&v.trigger("unCheck");v=b;b.addClass("row_chked")}}).bind("unCheck",function(){b.removeClass("row_chked")}).bind("beforeRemove",function(){delete l[h]});b.dblclick(function(){R(h,b,a)});if(g.fn.contextMenu){b.bind("contextMenu",function(){for(var e in l)l[e].trigger("unCheck");b.trigger("check")});b.contextMenu("#"+(b.attr("right_menu_id")||Q),function(e){(e=t.func(e))&&e(h,b,a)})}return b};this.addRow=function(a,c){g("tr.empty").remove();var d=C(a);c?n.prepend(d):n.append(d);
B(d[0].id.substr(I.length),d);m.trigger("update");n.find(">tr").length&&o.hide();return d};this.updateRow=function(a,c){var d=l[a];d.trigger("beforeRemove");var b=C(c);d.replaceWith(b);b.trigger("check");B(a,b);m.trigger("update");return b};this.deleteRow=function(a){a==undefined?a=this.checkedIds():typeof a=="number"?a=[a]:!g.isArray(a)&&(a=(a+"").split(","));for(var c=0,d=a.length;c<d;c++){var b=l[a[c]];b&&(b.trigger("beforeRemove"),b.remove())}if(!n.find(">tr").length){a=u.noData;o.find("td").html(a);
o.show()}};this.checkedIds=function(){for(var a=[],c=0,d;d=r[c++];)d[0].checked&&a.push(d.val());return a};this.checkedRow=function(){return v};this.setPageSize=function(a){q=parseInt(a)||12;D.items_per_page=q;x=K+(p.length?"&"+J+"="+q:"")};this.getPageSize=function(){return q};var w="",D={callback:function(a){E(x+"&"+(U+"="+(a+1)),w)},items_per_page:q,num_display_entries:5,num_edge_entries:2,prev_text:u.prevPage,next_text:u.nextPage},O="GET",E=function(a,c,d,b){b&&(O=b);g.ajax({url:a,data:c,dataType:"json",
type:O,success:function(h){l={};r=[];n.empty();z.length&&(z[0].checked=false);S(h);for(var f=0,e;e=h.data[f++];){e=C(e);n.append(e)}m.trigger("update");for(var j in l)B(j,l[j]);if(n.find(">tr").length)o.hide();else{f=u.noData;o.find("td").html(f);o.show()}typeof d=="function"&&d(h.total)}})};this.load=function(a,c){a&&(w=a.jquery?a.serialize():a);E(x,w,function(d){p.length&&p.pagination(d,D)},c)};g.each(M,function(){var a=false,c=null,d=function(){c&&(clearTimeout(c),c=null)},b=null,h=function(){b&&
(clearTimeout(b),b=null)},f=this,e=function(){d();a&&b||(b=setTimeout(F,5E3))},j=f.find(">em").click(function(){a?F():V()}).hover(function(){h();a||c||(c=setTimeout(function(){j.click()},800))},e),G=j.attr("name"),s=g("#"+G).hover(h,e),P=function(k){s[0]==k.target||s.find(k.target.nodeName).index(k.target)!=-1||F();return true},F=function(){h();d();A.unbind("click",P);j.removeClass("more_pop_open");a=false;s.hide()},V=function(){h();d();j.addClass("more_pop_open");var k={top:j.offset().top+parseInt(j.outerHeight()),
left:0,display:"block"};k.width=s.css("width")=="auto"?f.width()-14:parseInt(s.css("width"));k.left=f.offset().left-k.width+f.width()-14;s.css(k);a=true;setTimeout(function(){A.bind("click",P)},0)};e=f.find(">div");(G=e.attr("name"))&&e.click(function(){var k=f.hasClass("headerSortDown")?"desc":"asc";w="orderby="+G+"%7C"+k;E(x,w,function(W){p.length&&p.pagination(W,D);y.removeClass("headerSortDown headerSortUp");f.addClass(k=="asc"?"headerSortDown":"headerSortUp")})})})}})(cmstop,jQuery);
