(function(d){d.extend({tablesorter:new (function(){function b(a,c){n(a+","+((new Date).getTime()-c.getTime())+"ms")}function n(a){typeof console!="undefined"&&typeof console.debug!="undefined"?console.log(a):alert(a)}function p(a,c){if(a.config.debug)var f="";var h=a.tBodies[0].rows;if(a.tBodies[0].rows[0]){var e=[];h=h[0].cells;for(var m=h.length,g=0;g<m;g++){var j=false;if(d.metadata&&d(c[g]).metadata()&&d(c[g]).metadata().sorter)j=s(d(c[g]).metadata().sorter);else if(a.config.headers[g]&&a.config.headers[g].sorter)j=
s(a.config.headers[g].sorter);if(!j)a:{j=a;for(var k=h[g],l=q.length,r=1;r<l;r++)if(q[r].is(d.trim(z(j.config,k)),j,k)){j=q[r];break a}j=q[0]}if(a.config.debug)f+="column:"+g+" parser:"+j.id+"\n";e.push(j)}}a.config.debug&&n(f);return e}function s(a){for(var c=q.length,f=0;f<c;f++)if(q[f].id.toLowerCase()==a.toLowerCase())return q[f];return false}function t(a){if(a.config.debug)var c=new Date;for(var f=a.tBodies[0]&&a.tBodies[0].rows.length||0,h=a.tBodies[0].rows[0]&&a.tBodies[0].rows[0].cells.length||
0,e=a.config.parsers,m={row:[],normalized:[]},g=0;g<f;++g){var j=a.tBodies[0].rows[g],k=[];m.row.push(d(j));for(var l=0;l<h;++l)k.push(e[l].format(z(a.config,j.cells[l]),a,j.cells[l]));k.push(g);m.normalized.push(k)}a.config.debug&&b("Building cache for "+f+" rows:",c);return m}function z(a,c){if(!c)return"";var f="";return f=a.textExtraction=="simple"?c.childNodes[0]&&c.childNodes[0].hasChildNodes()?c.childNodes[0].innerHTML:c.innerHTML:typeof a.textExtraction=="function"?a.textExtraction(c):d(c).text()}
function x(a,c){if(a.config.debug)var f=new Date;for(var h=c.row,e=c.normalized,m=e.length,g=e[0].length-1,j=d(a.tBodies[0]),k=[],l=0;l<m;l++){k.push(h[e[l][g]]);if(!a.config.appender)for(var r=h[e[l][g]],v=r.length,u=0;u<v;u++)j[0].appendChild(r[u])}a.config.appender&&a.config.appender(a,k);k=null;a.config.debug&&b("Rebuilt table:",f);y(a);setTimeout(function(){d(a).trigger("sortEnd")},0)}function E(a){if(a.config.debug)var c=new Date;for(var f=[],h=0;h<a.tHead.rows.length;h++)f[h]=0;$tableHeaders=
d("thead th",a);$tableHeaders.each(function(e){this.count=0;this.column=e;var m=a.config.sortInitialOrder;this.order=i=typeof m!="Number"?m.toLowerCase()=="desc"?1:0:m==1?m:0;if(!(m=d.metadata&&d(this).metadata().sorter===false?true:false))m=a.config.headers[e]&&a.config.headers[e].sorter===false?true:false;if(m)this.sortDisabled=true;this.sortDisabled||d(this).addClass(a.config.cssHeader);a.config.headerList[e]=this});if(a.config.debug){b("Built headers:",c);n($tableHeaders)}return $tableHeaders}
function y(a){for(var c=a.config.widgets,f=c.length,h=0;h<f;h++)A(c[h]).format(a)}function A(a){for(var c=w.length,f=0;f<c;f++)if(w[f].id.toLowerCase()==a.toLowerCase())return w[f]}function F(a,c){for(var f=c.length,h=0;h<f;h++)if(c[h][0]==a)return true;return false}function B(a,c,f,h){c.removeClass(h[0]).removeClass(h[1]);var e=[];c.each(function(){this.sortDisabled||(e[this.column]=d(this))});a=f.length;for(c=0;c<a;c++)e[f[c][0]].addClass(h[f[c][1]])}function G(a){if(a.config.widthFixed){var c=
d("<colgroup>");d("tr:first td",a.tBodies[0]).each(function(){c.append(d("<col>").css("width",d(this).width()))});d(a).prepend(c)}}function C(a,c,f){if(a.config.debug)var h=new Date;for(var e="var sortWrapper = function(a,b) {",m=c.length,g=0;g<m;g++){var j=c[g][0],k=c[g][1],l="e"+g;e+="var "+l+" = "+(a.config.parsers[j].type=="text"?k==0?"sortText":"sortTextDesc":k==0?"sortNumeric":"sortNumericDesc")+"(a["+j+"],b["+j+"]); ";e+="if("+l+") { return "+l+"; } ";e+="else { "}g=f.normalized[0].length-
1;e+="return a["+g+"]-b["+g+"];";for(g=0;g<m;g++)e+="}; ";e+="return 0; ";e+="}; ";eval(e);f.normalized.sort(sortWrapper);a.config.debug&&b("Sorting on "+c.toString()+" and dir "+k+" time:",h);return f}var q=[],w=[];this.defaults={cssHeader:"header",cssAsc:"headerSortUp",cssDesc:"headerSortDown",sortInitialOrder:"asc",sortMultiSortKey:"shiftKey",sortForce:null,sortAppend:null,textExtraction:"simple",parsers:{},widgets:[],widgetZebra:{css:["even","odd"]},headers:{},widthFixed:false,cancelSelection:true,
sortList:[],headerList:[],dateFormat:"us",decimal:".",debug:false};this.benchmark=b;this.construct=function(a){return this.each(function(){if(this.tHead&&this.tBodies){var c,f,h,e;this.config={};e=d.extend(this.config,d.tablesorter.defaults,a);c=d(this);f=E(this);this.config.parsers=p(this,f);h=t(this);var m=[e.cssDesc,e.cssAsc];G(this);f.click(function(g){c.trigger("sortStart");var j=c[0].tBodies[0]&&c[0].tBodies[0].rows.length||0;if(!this.sortDisabled&&j>0){d(this);j=this.column;this.order=this.count++%
2;if(g[e.sortMultiSortKey])if(F(j,e.sortList))for(g=0;g<e.sortList.length;g++){var k=e.sortList[g],l=e.headerList[k[0]];if(k[0]==j){l.count=k[1];l.count++;k[1]=l.count%2}}else e.sortList.push([j,this.order]);else{e.sortList=[];if(e.sortForce!=null){k=e.sortForce;for(g=0;g<k.length;g++)k[g][0]!=j&&e.sortList.push(k[g])}e.sortList.push([j,this.order])}setTimeout(function(){B(c[0],f,e.sortList,m);x(c[0],C(c[0],e.sortList,h))},1)}});c.bind("update",function(){this.config.parsers=p(this,f);h=t(this)}).bind("sorton",
function(g,j){d(this).trigger("sortStart");e.sortList=j;for(var k=e.sortList,l=this.config,r=k.length,v=0;v<r;v++){var u=k[v],D=l.headerList[u[0]];D.count=u[1];D.count++}B(this,f,k,m);x(this,C(this,k,h))}).bind("appendCache",function(){x(this,h)}).bind("applyWidgetId",function(g,j){A(j).format(this)}).bind("applyWidgets",function(){y(this)});if(d.metadata&&d(this).metadata()&&d(this).metadata().sortlist)e.sortList=d(this).metadata().sortlist;e.sortList.length>0&&c.trigger("sorton",[e.sortList]);y(this)}})};
this.addParser=function(a){for(var c=q.length,f=true,h=0;h<c;h++)if(q[h].id.toLowerCase()==a.id.toLowerCase())f=false;f&&q.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,c){var f="\\"+c.decimal;return RegExp("/(^[+]?0("+f+"0+)?$)|(^([-+]?[1-9][0-9]*)$)|(^([-+]?((0?|[1-9][0-9]*)"+f+"(0*[1-9][0-9]*)))$)|(^[-+]?[1-9]+[0-9]*"+f+"0+$)/").test(d.trim(a))};
this.clearTableBody=function(a){if(d.browser.msie)(function(){for(;this.firstChild;)this.removeChild(this.firstChild)}).apply(a.tBodies[0]);else a.tBodies[0].innerHTML=""}})});d.fn.extend({tablesorter:d.tablesorter.construct});var o=d.tablesorter;o.addParser({id:"text",is:function(){return true},format:function(b){return d.trim(b.toLowerCase())},type:"text"});o.addParser({id:"digit",is:function(b,n){return d.tablesorter.isDigit(b,n.config)},format:function(b){return d.tablesorter.formatFloat(b)},
type:"numeric"});o.addParser({id:"currency",is:function(b){return/^[\uffe1$\u20ac?.]/.test(b)},format:function(b){return d.tablesorter.formatFloat(b.replace(RegExp(/[^0-9.]/g),""))},type:"numeric"});o.addParser({id:"ipAddress",is:function(b){return/^\d{2,3}[\.]\d{2,3}[\.]\d{2,3}[\.]\d{2,3}$/.test(b)},format:function(b){b=b.split(".");for(var n="",p=b.length,s=0;s<p;s++){var t=b[s];n+=t.length==2?"0"+t:t}return d.tablesorter.formatFloat(n)},type:"numeric"});o.addParser({id:"url",is:function(b){return/^(https?|ftp|file):\/\/$/.test(b)},
format:function(b){return jQuery.trim(b.replace(RegExp(/(https?|ftp|file):\/\//),""))},type:"text"});o.addParser({id:"isoDate",is:function(b){return/^\d{4}[\/-]\d{1,2}[\/-]\d{1,2}$/.test(b)},format:function(b){return d.tablesorter.formatFloat(b!=""?(new Date(b.replace(RegExp(/-/g),"/"))).getTime():"0")},type:"numeric"});o.addParser({id:"percent",is:function(b){return/\%$/.test(d.trim(b))},format:function(b){return d.tablesorter.formatFloat(b.replace(RegExp(/%/g),""))},type:"numeric"});o.addParser({id:"usLongDate",
is:function(b){return b.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(b){return d.tablesorter.formatFloat((new Date(b)).getTime())},type:"numeric"});o.addParser({id:"shortDate",is:function(b){return/\d{1,2}[\/\-]\d{1,2}[\/\-]\d{2,4}/.test(b)},format:function(b,n){var p=n.config;b=b.replace(/\-/g,"/");if(p.dateFormat=="us")b=b.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/,"$3/$1/$2");else if(p.dateFormat==
"uk")b=b.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/,"$3/$2/$1");else if(p.dateFormat=="dd/mm/yy"||p.dateFormat=="dd-mm-yy")b=b.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{2})/,"$1/$2/$3");return d.tablesorter.formatFloat((new Date(b)).getTime())},type:"numeric"});o.addParser({id:"time",is:function(b){return/^(([0-2]?[0-9]:[0-5][0-9])|([0-1]?[0-9]:[0-5][0-9]\s(am|pm)))$/.test(b)},format:function(b){return d.tablesorter.formatFloat((new Date("2000/01/01 "+b)).getTime())},type:"numeric"});o.addParser({id:"metadata",
is:function(){return false},format:function(b,n,p){b=n.config;b=!b.parserMetadataName?"sortValue":b.parserMetadataName;return d(p).metadata()[b]},type:"numeric"});o.addWidget({id:"zebra",format:function(b){if(b.config.debug)var n=new Date;d("tr:visible",b.tBodies[0]).filter(":even").removeClass(b.config.widgetZebra.css[1]).addClass(b.config.widgetZebra.css[0]).end().filter(":odd").removeClass(b.config.widgetZebra.css[0]).addClass(b.config.widgetZebra.css[1]);b.config.debug&&d.tablesorter.benchmark("Applying Zebra widget",
n)}})})(jQuery);
