function SortableTable(c,d){var i;var l=this;this.SORTED='stSorted';this.SORTABLE='stSortable';this.SORTED_ASC='stAsc';this.SORTED_DESC='stDesc';this.TYPE_NUMBER='stTypeNumber';this.TYPE_FLOAT='stTypeFloat';this.TYPE_MONEY='stTypeMoney';this.SortedColumnIndex=(d==null)?-1:d;this.table=document.getElementById(c);this.head=this.table.getElementsByTagName('thead')[0];this.theadCells=this.head.getElementsByTagName('td');if(this.head){for(i=0;i<this.theadCells.length;i++){if(this.getSelector(this.theadCells[i],this.SORTABLE)){this.theadCells[i].stIndex=i;if(this.getSelector(this.theadCells[i],this.TYPE_NUMBER)){this.theadCells[i].stSortkeyType=this.TYPE_NUMBER;}else{if(this.getSelector(this.theadCells[i],this.TYPE_FLOAT)){this.theadCells[i].stSortkeyType=this.TYPE_FLOAT;}else{if(this.getSelector(this.theadCells[i],this.TYPE_MONEY)){this.theadCells[i].stSortkeyType=this.TYPE_MONEY;}}}if(this.theadCells[i].attachEvent){this.theadCells[i].attachEvent('onclick',function(){l.sort();});}else{if(this.theadCells[i].addEventListener){this.theadCells[i].addEventListener('click',function(e){l.sort(e);},false);}}}}}this.Tbody=this.table.getElementsByTagName('tbody')[0];this.Rows=this.Tbody.getElementsByTagName('tr');this.rowsCount=this.Rows.length;this.cache=new Array();var m=this.Tbody.getElementsByTagName('td');var n=m.length;var o;for(i=0;i<n;i++){o=m[i].getAttribute('abbr');this.setCellSortkey(m[i],(o!=null&&o!='')?o:m[i].firstChild.nodeValue);}for(i=0;i<this.rowsCount;i++){this.cache[i]=this.Rows[i].cloneNode(true);}return this;}SortableTable.prototype.sort=function(e){var l=this;var k=window.event?window.event.srcElement:e.currentTarget;if(this.OnSortBegin){this.OnSortBegin(window.event?window.event:e);}this.applyCssSelectors(k);if(k.stIndex==this.SortedColumnIndex){this.cache.reverse(k);}else{this.SortedColumnIndex=k.stIndex;switch(k.stSortkeyType){case this.TYPE_NUMBER:this.cache.sort(function(a,b){var p=parseInt(l.getCellSortkey(a.getElementsByTagName('td')[l.SortedColumnIndex]),10);var q=parseInt(l.getCellSortkey(b.getElementsByTagName('td')[l.SortedColumnIndex]),10);if(isNaN(p))p=0;if(isNaN(q))q=0;return-1*(p-q);});break;case this.TYPE_FLOAT:this.cache.sort(function(a,b){var p=parseFloat(l.getCellSortkey(a.getElementsByTagName('td')[l.SortedColumnIndex]),10);var q=parseFloat(l.getCellSortkey(b.getElementsByTagName('td')[l.SortedColumnIndex]),10);if(isNaN(p))p=0;if(isNaN(q))q=0;return-1*(p-q);});break;case this.TYPE_MONEY:this.cache.sort(function(a,b){var p=parseFloat(l.getCellSortkey(a.getElementsByTagName('td')[l.SortedColumnIndex].firstChild.nodeValue).substr(1));var q=parseFloat(l.getCellSortkey(b.getElementsByTagName('td')[l.SortedColumnIndex].firstChild.nodeValue).substr(1));if(isNaN(p))p=0;if(isNaN(q))q=0;return(p-q);});break;default:this.cache.sort(function(a,b){var p=l.getCellSortkey(a.getElementsByTagName('td')[l.SortedColumnIndex]);var q=l.getCellSortkey(b.getElementsByTagName('td')[l.SortedColumnIndex]);return(p==q?0:(p>q?1:-1));});break;}}var r=document.createElement('tbody');for(var i=0;i<this.rowsCount;i++){r.appendChild(this.cache[i]);}this.table.replaceChild(r,this.Tbody);this.Tbody=r;if(this.OnSortEnd){this.OnSortEnd(window.event?window.event:e);}};SortableTable.prototype.getCellSortkey=function(f){if(f){return f.getAttribute('sortKey');}};SortableTable.prototype.setCellSortkey=function(f,g){f.setAttribute('sortKey',g);};SortableTable.prototype.getSelector=function(h,j){return(h&&h.className.indexOf(j)!=-1);};SortableTable.prototype.setSelector=function(h,j){for(var i=1;i<arguments.length;i++){h.className+=' '+arguments[i];}};SortableTable.prototype.deleteSelector=function(h,j){for(var i=1;i<arguments.length;i++){h.className=h.className.replace(new RegExp(arguments[i],'g'),'');}};SortableTable.prototype.applyCssSelectors=function(k){for(var i=0;i<this.theadCells.length;i++){if(k.stIndex==this.theadCells[i].stIndex){this.setSelector(this.theadCells[i],this.SORTED);if(this.getSelector(this.theadCells[i],this.SORTED_ASC)){this.deleteSelector(this.theadCells[i],this.SORTED_ASC);this.setSelector(this.theadCells[i],this.SORTED_DESC);}else{this.deleteSelector(this.theadCells[i],this.SORTED_DESC);this.setSelector(this.theadCells[i],this.SORTED_ASC);}}else{this.deleteSelector(this.theadCells[i],this.SORTED,this.SORTED_ASC,this.SORTED_DESC);}}};