(function(c){c.extend({tablesorter:new function(){function a(b,a){l(b+","+((new Date).getTime()-a.getTime())+"ms")}function l(b){"undefined"!=typeof console&&"undefined"!=typeof console.debug?console.log(b):alert(b)}function q(b,a){if(b.config.debug)var d="";if(0!=b.tBodies.length){var g=b.tBodies[0].rows;if(g[0])for(var f=[],h=g[0].cells.length,j=0;j<h;j++){var e=!1;c.metadata&&c(a[j]).metadata()&&c(a[j]).metadata().sorter?e=i(c(a[j]).metadata().sorter):b.config.headers[j]&&b.config.headers[j].sorter&&
(e=i(b.config.headers[j].sorter));if(!e)a:{for(var e=b,m=g,n=-1,q=j,r=p.length,x=!1,s=!1,t=!0;""==s&&t;)n++,m[n]?(x=m[n].cells[q],s=c.trim(A(e.config,x)),e.config.debug&&l("Checking if value was empty on row:"+n)):t=!1;for(m=1;m<r;m++)if(p[m].is(s,e,x)){e=p[m];break a}e=p[0]}b.config.debug&&(d+="column:"+j+" parser:"+e.id+"\n");f.push(e)}b.config.debug&&l(d);return f}}function i(b){for(var a=p.length,d=0;d<a;d++)if(p[d].id.toLowerCase()==b.toLowerCase())return p[d];return!1}function r(b){if(b.config.debug)var k=
new Date;for(var d=b.tBodies[0]&&b.tBodies[0].rows.length||0,g=b.tBodies[0].rows[0]&&b.tBodies[0].rows[0].cells.length||0,f=b.config.parsers,h={row:[],normalized:[]},j=0;j<d;++j){var e=c(b.tBodies[0].rows[j]),m=[];if(e.hasClass(b.config.cssChildRow))h.row[h.row.length-1]=h.row[h.row.length-1].add(e);else{h.row.push(e);for(var n=0;n<g;++n)m.push(f[n].format(A(b.config,e[0].cells[n]),b,e[0].cells[n]));m.push(h.normalized.length);h.normalized.push(m)}}b.config.debug&&a("Building cache for "+d+" rows:",
k);return h}function A(b,a){var d="";if(!a)return"";b.supportsTextContent||(b.supportsTextContent=a.textContent||!1);return d="simple"==b.textExtraction?b.supportsTextContent?a.textContent:a.childNodes[0]&&a.childNodes[0].hasChildNodes()?a.childNodes[0].innerHTML:a.innerHTML:"function"==typeof b.textExtraction?b.textExtraction(a):c(a).text()}function B(b,k){if(b.config.debug)var d=new Date;for(var g=k.row,f=k.normalized,h=f.length,j=f[0].length-1,e=c(b.tBodies[0]),m=[],n=0;n<h;n++){var l=f[n][j];
m.push(g[l]);if(!b.config.appender)for(var q=g[l].length,i=0;i<q;i++)e[0].appendChild(g[l][i])}b.config.appender&&b.config.appender(b,m);m=null;b.config.debug&&a("Rebuilt table:",d);C(b);setTimeout(function(){c(b).trigger("sortEnd")},0)}function E(b,a){return b.config.headers[a]&&b.config.headers[a].lockedOrder?b.config.headers[a].lockedOrder:!1}function C(a){for(var c=a.config.widgets,d=c.length,g=0;g<d;g++)F(c[g]).format(a)}function F(a){for(var c=w.length,d=0;d<c;d++)if(w[d].id.toLowerCase()==
a.toLowerCase())return w[d]}function G(a,k,d,g){k.removeClass(g[0]).removeClass(g[1]);var f=[];k.each(function(){this.sortDisabled||(f[this.column]=c(this))});a=d.length;for(k=0;k<a;k++)f[d[k][0]].addClass(g[d[k][1]])}function H(b,c,d){if(b.config.debug)var g=new Date;for(var f="var sortWrapper = function(a,b) {",h=c.length,j=0;j<h;j++)var e=c[j][0],m=c[j][1],e="text"==b.config.parsers[e].type?0==m?y("text","asc",e):y("text","desc",e):0==m?y("numeric","asc",e):y("numeric","desc",e),l="e"+j,f=f+("var "+
l+" = "+e),f=f+("if("+l+") { return "+l+"; } "),f=f+"else { ";j=d.normalized[0].length-1;f+="return a["+j+"]-b["+j+"];";for(j=0;j<h;j++)f+="}; ";f+="return 0; }; ";b.config.debug&&a("Evaling expression:"+f,new Date);eval(f);d.normalized.sort(sortWrapper);b.config.debug&&a("Sorting on "+c.toString()+" and dir "+m+" time:",g);return d}function y(a,c,d){var g="a["+d+"]",d="b["+d+"]";if("text"==a&&"asc"==c)return"("+g+" == "+d+" ? 0 : ("+g+" === null ? Number.POSITIVE_INFINITY : ("+d+" === null ? Number.NEGATIVE_INFINITY : ("+
g+" < "+d+") ? -1 : 1 )));";if("text"==a&&"desc"==c)return"("+g+" == "+d+" ? 0 : ("+g+" === null ? Number.POSITIVE_INFINITY : ("+d+" === null ? Number.NEGATIVE_INFINITY : ("+d+" < "+g+") ? -1 : 1 )));";if("numeric"==a&&"asc"==c)return"("+g+" === null && "+d+" === null) ? 0 :("+g+" === null ? Number.POSITIVE_INFINITY : ("+d+" === null ? Number.NEGATIVE_INFINITY : "+g+" - "+d+"));";if("numeric"==a&&"desc"==c)return"("+g+" === null && "+d+" === null) ? 0 :("+g+" === null ? Number.POSITIVE_INFINITY : ("+
d+" === null ? Number.NEGATIVE_INFINITY : "+d+" - "+g+"));"}var p=[],w=[];this.defaults={cssHeader:"header",cssAsc:"headerSortUp",cssDesc:"headerSortDown",cssChildRow:"expand-child",sortInitialOrder:"asc",sortMultiSortKey:"shiftKey",sortForce:null,sortAppend:null,sortLocaleCompare:!0,textExtraction:"simple",parsers:{},widgets:[],widgetZebra:{css:["even","odd"]},headers:{},widthFixed:!1,cancelSelection:!0,sortList:[],headerList:[],dateFormat:"us",decimal:"/.|,/g",onRenderHeader:null,selectorHeaders:"thead th",
debug:!1};this.benchmark=a;this.construct=function(b){return this.each(function(){if(this.tHead&&this.tBodies){var k,d,g,f;this.config={};f=c.extend(this.config,c.tablesorter.defaults,b);k=c(this);c.data(this,"tablesorter",f);var h=this;if(h.config.debug)var j=new Date;for(var e=[],m={},i=h.getElementsByTagName("THEAD")[0].getElementsByTagName("TR"),p=0;p<i.length;p++)for(var v=i[p].cells,x=0;x<v.length;x++){var s=v[x],t=s.parentNode.rowIndex,w=t+"-"+s.cellIndex,y=s.rowSpan||1,s=s.colSpan||1,z;"undefined"==
typeof e[t]&&(e[t]=[]);for(var u=0;u<e[t].length+1;u++)if("undefined"==typeof e[t][u]){z=u;break}m[w]=z;for(u=t;u<t+y;u++){"undefined"==typeof e[u]&&(e[u]=[]);for(var w=e[u],D=z;D<z+s;D++)w[D]="x"}}$tableHeaders=c(h.config.selectorHeaders,h).each(function(a){this.column=m[this.parentNode.rowIndex+"-"+this.cellIndex];this.count=this.order="Number"!=typeof h.config.sortInitialOrder?"desc"==h.config.sortInitialOrder.toLowerCase()?1:0:1==h.config.sortInitialOrder?1:0;if(c.metadata&&!1===c(this).metadata().sorter||
h.config.headers[a]&&!1===h.config.headers[a].sorter)this.sortDisabled=!0;E(h,a)&&(this.order=this.lockedOrder=E(h,a));if(!this.sortDisabled){var b=c(this).addClass(h.config.cssHeader);h.config.onRenderHeader&&h.config.onRenderHeader.apply(b)}h.config.headerList[a]=this});h.config.debug&&(a("Built headers:",j),l($tableHeaders));d=$tableHeaders;this.config.parsers=q(this,d);g=r(this);var I=[f.cssDesc,f.cssAsc];if(this.config.widthFixed){var J=c("<colgroup>");c("tr:first td",this.tBodies[0]).each(function(){J.append(c("<col>").css("width",
c(this).width()))});c(this).prepend(J)}d.click(function(a){var b=k[0].tBodies[0]&&k[0].tBodies[0].rows.length||0;if(!this.sortDisabled&&0<b){k.trigger("sortStart");c(this);b=this.column;this.order=this.count++%2;this.lockedOrder&&(this.order=this.lockedOrder);if(a[f.sortMultiSortKey]){a:{for(var a=f.sortList,e=a.length,h=0;h<e;h++)if(a[h][0]==b){a=!0;break a}a=!1}if(a)for(a=0;a<f.sortList.length;a++)e=f.sortList[a],h=f.headerList[e[0]],e[0]==b&&(h.count=e[1],h.count++,e[1]=h.count%2);else f.sortList.push([b,
this.order])}else{f.sortList=[];if(null!=f.sortForce){e=f.sortForce;for(a=0;a<e.length;a++)e[a][0]!=b&&f.sortList.push(e[a])}f.sortList.push([b,this.order])}setTimeout(function(){G(k[0],d,f.sortList,I);B(k[0],H(k[0],f.sortList,g))},1);return!1}}).mousedown(function(){if(f.cancelSelection)return this.onselectstart=function(){return!1},!1});k.bind("update",function(){var a=this;setTimeout(function(){a.config.parsers=q(a,d);g=r(a)},1)}).bind("updateCell",function(a,b){var c=this.config,d=[b.parentNode.rowIndex-
1,b.cellIndex];g.normalized[d[0]][d[1]]=c.parsers[d[1]].format(A(c,b),b)}).bind("sorton",function(a,b){c(this).trigger("sortStart");f.sortList=b;for(var e=f.sortList,h=this.config,j=e.length,l=0;l<j;l++){var k=e[l],m=h.headerList[k[0]];m.count=k[1];m.count++}G(this,d,e,I);B(this,H(this,e,g))}).bind("appendCache",function(){B(this,g)}).bind("applyWidgetId",function(a,b){F(b).format(this)}).bind("applyWidgets",function(){C(this)});c.metadata&&(c(this).metadata()&&c(this).metadata().sortlist)&&(f.sortList=
c(this).metadata().sortlist);0<f.sortList.length&&k.trigger("sorton",[f.sortList]);C(this)}})};this.addParser=function(a){for(var c=p.length,d=!0,g=0;g<c;g++)p[g].id.toLowerCase()==a.id.toLowerCase()&&(d=!1);d&&p.push(a)};this.addWidget=function(a){w.push(a)};this.formatFloat=function(a){a=parseFloat(a);return isNaN(a)?0:a};this.formatInt=function(a){a=parseInt(a);return isNaN(a)?0:a};this.isDigit=function(a){return/^[-+]?\d*$/.test(c.trim(a.replace(/[,.']/g,"")))};this.clearTableBody=function(a){c.browser.msie?
function(){for(;this.firstChild;)this.removeChild(this.firstChild)}.apply(a.tBodies[0]):a.tBodies[0].innerHTML=""}}});c.fn.extend({tablesorter:c.tablesorter.construct});var i=c.tablesorter;i.addParser({id:"text",is:function(){return!0},format:function(a){return c.trim(a.toLocaleLowerCase())},type:"text"});i.addParser({id:"digit",is:function(a,l){return c.tablesorter.isDigit(a,l.config)},format:function(a){return c.tablesorter.formatFloat(a)},type:"numeric"});i.addParser({id:"currency",is:function(a){return/^[\u00c2\u00a3$\u00e2\u201a\u00ac?.]/.test(a)},
format:function(a){return c.tablesorter.formatFloat(a.replace(RegExp(/[\u00c2\u00a3$\u00e2\u201a\u00ac]/g),""))},type:"numeric"});i.addParser({id:"ipAddress",is:function(a){return/^\d{2,3}[\.]\d{2,3}[\.]\d{2,3}[\.]\d{2,3}$/.test(a)},format:function(a){for(var a=a.split("."),l="",i=a.length,v=0;v<i;v++)var r=a[v],l=2==r.length?l+("0"+r):l+r;return c.tablesorter.formatFloat(l)},type:"numeric"});i.addParser({id:"url",is:function(a){return/^(https?|ftp|file):\/\/$/.test(a)},format:function(a){return jQuery.trim(a.replace(RegExp(/(https?|ftp|file):\/\//),
""))},type:"text"});i.addParser({id:"isoDate",is:function(a){return/^\d{4}[\/-]\d{1,2}[\/-]\d{1,2}$/.test(a)},format:function(a){return c.tablesorter.formatFloat(""!=a?(new Date(a.replace(RegExp(/-/g),"/"))).getTime():"0")},type:"numeric"});i.addParser({id:"percent",is:function(a){return/\%$/.test(c.trim(a))},format:function(a){return c.tablesorter.formatFloat(a.replace(RegExp(/%/g),""))},type:"numeric"});i.addParser({id:"usLongDate",is:function(a){return a.match(RegExp(/^[A-Za-z]{3,10}\.? [0-9]{1,2}, ([0-9]{4}|'?[0-9]{2}) (([0-2]?[0-9]:[0-5][0-9])|([0-1]?[0-9]:[0-5][0-9]\s(AM|PM)))$/))},
format:function(a){return c.tablesorter.formatFloat((new Date(a)).getTime())},type:"numeric"});i.addParser({id:"shortDate",is:function(a){return/\d{1,2}[\/\-]\d{1,2}[\/\-]\d{2,4}/.test(a)},format:function(a,l){var i=l.config,a=a.replace(/\-/g,"/");if("us"==i.dateFormat)a=a.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/,"$3/$1/$2");else if("uk"==i.dateFormat)a=a.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/,"$3/$2/$1");else if("dd/mm/yy"==i.dateFormat||"dd-mm-yy"==i.dateFormat)a=a.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{2})/,
"$1/$2/$3");return c.tablesorter.formatFloat((new Date(a)).getTime())},type:"numeric"});i.addParser({id:"time",is:function(a){return/^(([0-2]?[0-9]:[0-5][0-9])|([0-1]?[0-9]:[0-5][0-9]\s(am|pm)))$/.test(a)},format:function(a){return c.tablesorter.formatFloat((new Date("2000/01/01 "+a)).getTime())},type:"numeric"});i.addParser({id:"metadata",is:function(){return!1},format:function(a,i,q){a=i.config;a=!a.parserMetadataName?"sortValue":a.parserMetadataName;return c(q).metadata()[a]},type:"numeric"});
i.addWidget({id:"zebra",format:function(a){if(a.config.debug)var i=new Date;var q,v=-1,r;c("tr:visible",a.tBodies[0]).each(function(){q=c(this);q.hasClass(a.config.cssChildRow)||v++;r=0==v%2;q.removeClass(a.config.widgetZebra.css[r?0:1]).addClass(a.config.widgetZebra.css[r?1:0])});a.config.debug&&c.tablesorter.benchmark("Applying Zebra widget",i)}})})(jQuery);