/*
* Mihai Oaida 
* 29.07.07
*/


function orderInit(){
	if(table=document.getElementById('tabelParticipanti')){
	  	
		poz=(table.childNodes.length == 3)?1:0;
		head=table.childNodes[poz].childNodes[0];//head-ul
		
		poz=(head.childNodes.length==7)?1:0;
		for(i=poz+1;i<=poz+4;i++){
			head.childNodes[i].style.cursor="pointer";
			
			if(poz==1)head.childNodes[i].id="head_"+(i-1);
			else head.childNodes[i].id="head_"+i;
			head.childNodes[i].innerHTML+="<span></span>";
			
			head.childNodes[i].onclick=function(){
				//code care face restul span-urilor vide
				table=document.getElementById('tabelParticipanti');
				head=table.childNodes[0].childNodes[0];
				poz=(head.childNodes.length==7)?1:0;
				
				for(j=poz+1;j<=poz+4;j++)
					if((j-(poz))!=this.id.substring(5))
						head.childNodes[j].childNodes[1].innerHTML='';
						
	    		if(this.ord=='asc'){this.ord='desc';this.childNodes[1].innerHTML="&#160;\\/";}
	    		else {this.ord='asc';this.childNodes[1].innerHTML="&#160;/\\";}
	    			

	    		orderTable(this.id.substring(5),this.ord);
				
			}
		}
		head.childNodes[poz+3].childNodes[1].innerHTML="&#160;/\\";
		head.childNodes[poz+3].style.width="90px";
		head.childNodes[poz+3].ord='asc';

	}
}


function loadTable(){
	if(table=document.getElementById('tabelParticipanti')){
		
		poz=(table.childNodes.length == 3)?1:0;

		body=document.getElementById('tabelParticipanti').childNodes[poz+1];
		
		rows=new Array();	
			
		for(i=0;i<body.childNodes.length;i++){
			rows[i]=new Array();
			
			for(j=0;j<body.childNodes[i].childNodes.length;j++){
				rows[i][j]=body.childNodes[i].childNodes[j].innerHTML;
			}
		}
		
		
		return rows;
	}else return  false;
}


function orderTable(id,order){

	
	rows=loadTable();
	
	sort=1;

	
	while(sort){
		sort=0;
		
		for(i=0;i<rows.length-1;i++){
			if(rows[i][id]<rows[i+1][id]&&order=="desc" || rows[i][id]>rows[i+1][id]&&order=="asc" ){
				aux=rows[i];
				rows[i]=rows[i+1];
				rows[i+1]=aux;
				sort=1;
			}
		}
	}
	

	

	
	
	table=document.getElementById('tabelParticipanti')
	poz=(table.childNodes.length == 3)?1:0;	
	body=table.childNodes[poz+1];
	
	for(i=0;i<body.childNodes.length;i++){
		for(j=0;j<body.childNodes[i].childNodes.length;j++){	
			body.childNodes[i].childNodes[j].innerHTML=rows[i][j];
			if(j==0){
				
				if(rows[i][3]=="Web")body.childNodes[i].childNodes[j].style.backgroundColor="#fff5ff";
				else if(rows[i][3]=="Soft")body.childNodes[i].childNodes[j].style.backgroundColor="#fffff5";
			}
		}
		body.childNodes[i].childNodes[0].innerHTML=(i+1);	
	}
	
	
	
	
	
}





