var TINY={};

function T$(i){return document.getElementById(i)}
function T$$(e,p){return p.getElementsByTagName(e)}

TINY.table=function(){
	function sorter(n){this.n=n; }
	sorter.prototype.init=function(e,f){
		var sortrec=document.getElementById('sortrec');
		var sortprice=document.getElementById('sortprice');
		
		var t=ge(e), i=0; this.e=e; this.l=t.r.length; t.a=[];
		t.h=T$$('thead',T$(e))[0].rows[0]; t.w=t.h.cells.length;

		for(i;i<t.w;i++){
			var c=t.h.cells[i];
		}
		for(i=0;i<this.l;i++){t.a[i]={}}
		if(f!=null){var a=new Function(this.n+'.wk('+f+')'); a()}
		
		sortprice.onclick=new Function(this.n+'.wk(this.cellIndex)');
		sortrec.onclick=new Function(this.n+'.wk(0)');
	};
	sorter.prototype.wk=function(y){
		var t=ge(this.e), x=t.h.cells[y], i=0;
		for(i;i<this.l;i++){
		  t.a[i].o=i; var v=t.r[i].cells[y]; t.r[i].style.display='';
		  while(v.hasChildNodes()){v=v.firstChild}
		  t.a[i].v=v.nodeValue?v.nodeValue:''
		}
		for(i=0;i<t.w;i++){var c=t.h.cells[i];}
		if(t.p==y){t.a.reverse(); t.d=t.d?0:1}
		else{t.p=y; t.a.sort(cp); t.d=0; }
		var n=document.createElement('tbody');
		for(i=0;i<this.l;i++){
			var r=t.r[t.a[i].o].cloneNode(true); n.appendChild(r);
			var cells=T$$('td',r);
			
		}
		t.replaceChild(n,t.b); 
	};
	function ge(e){var t=T$(e); t.b=T$$('tbody',t)[0]; t.r=t.b.rows; return t};
	function cp(f,c){
		var g,h; f=g=f.v.toLowerCase(), c=h=c.v.toLowerCase();
		var i=parseFloat(f.replace(/(r|\,|\<([^>]+)>)/g,'')), n=parseFloat(c.replace(/(r|\,|\<([^>]+)>)/g,''));
		
		if(!isNaN(i)&&!isNaN(n)){g=i,h=n}
		i=Date.parse(f); n=Date.parse(c);
		if(!isNaN(i)&&!isNaN(n)){g=i; h=n}
		return g>h?1:(g<h?-1:0)
	};
	return{sorter:sorter}
}();
