/* Mootools table sorting script by Leo Feyer, Copyright 2007 (LGPL) */
var SORT_INDEX;var TableSort=new Class({initialize:function(B,J){var H=$(B);if(H==null){return false}if(!H.rows||H.rows.length<1||!H.tHead||H.tHead.rows.length<1){return false}var A=null;var F=Cookie.get("TS_"+B.toUpperCase());if(F!==false){var A=F.split("|")}var I=H.tHead.rows[H.tHead.rows.length-1];for(var E=0;E<I.cells.length;E++){if(I.cells[E].className.indexOf("unsortable")!=-1){continue}var C=I.cells[E];
var D=C.innerHTML;var G=new Element("a").addClass("pointer");G.innerHTML=D;C.innerHTML="";G.addEvent("click",function(K,L){this.resort(K,L)}.pass([E,C],this));G.injectInside(C);if(A!==null&&A[0]==E){C.addClass((A[1]=="desc")?"asc":"desc");this.resort(A[0],C)}}},resort:function(H,B){var D=$(B);if(D==null){return false}var A=D.getParent();var J=A.getParent().getParent();if(J==null||J.tBodies[0].rows.length<2){return false
}SORT_INDEX=H;var E=0;var C="";while(C==""&&J.tBodies[0].rows[E]){C=J.tBodies[0].rows[E].cells[H].innerHTML.replace(/<[^>]+>/i).clean();E++}var F=new Array();for(var E=0;E<J.tBodies[0].rows.length;E++){F[E]=J.tBodies[0].rows[E]}if(B.className.indexOf("date")!=-1||C.match(/^\d{1,4}[\/\. -]\d{1,2}[\/\. -]\d{1,4}$/)){F.sort(this.sortDate)}else{if(B.className.indexOf("currency")!=-1||C.match(/^[£$€Û¢´]/)||C.match(/^-?[\d\.,]+[£$€]$/)){F.sort(this.sortNumeric)
}else{if(B.className.indexOf("numeric")!=-1||C.match(/^-?[\d\.,]+(E[-+][\d]+)?$/)||C.match(/^-?[\d\.,]+%?$/)){F.sort(this.sortNumeric)}else{F.sort(this.sortCaseInsensitive)}}}if(B.className.indexOf("asc")==-1){var G=A.getChildren();for(var E=0;E<G.length;E++){G[E].removeClass("asc");G[E].removeClass("desc")}B.addClass("asc");Cookie.set("TS_"+J.id.toUpperCase(),H+"|asc",{path:"/"})}else{var G=A.getChildren();
for(var E=0;E<G.length;E++){G[E].removeClass("asc");G[E].removeClass("desc")}B.addClass("desc");Cookie.set("TS_"+J.id.toUpperCase(),H+"|desc",{path:"/"});F.reverse()}for(E=0;E<F.length;E++){var I=F[E].className;I=I.replace(/row_\d+/,"").replace(/odd|even|row_first|row_last/g,"").clean();I+=" row_"+E;if(E==0){I+=" row_first"}if(E>=(F.length-1)){I+=" row_last"}I+=(E%2==0)?" odd":" even";F[E].className=I.trim();
for(j=0;j<F[E].cells.length;j++){var I=F[E].cells[j].className;I=I.replace(/col_\d+/,"").replace(/odd|even|col_first|col_last/g,"").clean();I+=" col_"+j;if(j==0){I+=" col_first"}if(j>=(F[E].cells.length-1)){I+=" col_last"}F[E].cells[j].className=I.trim()}J.tBodies[0].appendChild(F[E])}},sortDate:function(B,A){aa=B.cells[SORT_INDEX].innerHTML.replace(/<[^>]+>/i).clean();bb=A.cells[SORT_INDEX].innerHTML.replace(/<[^>]+>/i).clean();
var C=aa.replace(/[\/\.-]/g," ").split(" ");var E=bb.replace(/[\/\.-]/g," ").split(" ");if(aa.match(/^\d{1,2}[\/\. -]\d{1,2}[\/\. -]\d{2,4}$/)){var D=((C[2].length==4)?C[2]:"19"+C[2])+((C[1].length==2)?C[1]:"0"+C[1])+((C[0].length==2)?C[0]:"0"+C[0]);var F=((E[2].length==4)?E[2]:"19"+E[2])+((E[1].length==2)?E[1]:"0"+E[1])+((E[0].length==2)?E[0]:"0"+E[0])}if(aa.match(/^\d{2,4}[\/\. -]\d{1,2}[\/\. -]\d{1,2}$/)){var D=((C[0].length==4)?C[0]:"19"+C[0])+((C[1].length==2)?C[1]:"0"+C[1])+((C[2].length==2)?C[2]:"0"+C[2]);
var F=((E[0].length==4)?E[0]:"19"+E[0])+((E[1].length==2)?E[1]:"0"+E[1])+((E[2].length==2)?E[2]:"0"+E[2])}if(D==F){return 0}if(D<F){return -1}return 1},sortNumeric:function(B,A){aa=B.cells[SORT_INDEX].innerHTML.replace(/<[^>]+>/i).replace(/[^0-9\.]/g,"").clean();bb=A.cells[SORT_INDEX].innerHTML.replace(/<[^>]+>/i).replace(/[^0-9\.]/g,"").clean();aa=parseFloat(aa);aa=(isNaN(aa)?0:aa);bb=parseFloat(bb);
bb=(isNaN(bb)?0:bb);return aa-bb},sortCaseInsensitive:function(B,A){aa=B.cells[SORT_INDEX].innerHTML.replace(/<[^>]+>/i).clean().toLowerCase();bb=A.cells[SORT_INDEX].innerHTML.replace(/<[^>]+>/i).clean().toLowerCase();if(aa==bb){return 0}if(aa<bb){return -1}return 1}});