var comptecount=1;

function gojson( torsh ) 
  {
	 //document.getElementById("info").innerHTML  ='Loading ... ';
	document.getElementById("spinner").style.visibility="visible";
  // handle the json object here
  //alert(torsh.engine);  //<---------- works
  //$.each(torsh.torrents, function(i,torrent){
    //alert(torrent.title); //<---------- works
	tbody = document.getElementById("tbodytorrent");
	if (torsh.error=='no error')
	{

		for( var f in torsh.torrents ) 
		{
				
			trtemp = document.createElement("tr");
					
						td = document.createElement("td");
						td.appendChild(document.createTextNode(torsh.torrents[f].age));
						trtemp.appendChild(td);
					
					
						td = document.createElement("td");
						//<a href="/get/648266" class="dl" onclick="pageTracker._trackPageview('/get/id')"><img src="/images/down.gif" alt="[D]"></a>


						//-- creation du liens direct de download
						//a=document.createElement("a");
						//a.setAttribute('href','r?url='+ torsh.torrents[f].torrent);
						//a.setAttribute('class','dl');
						//img=document.createElement("img");
						//img.setAttribute('src','/images/down_mininova.gif');
						//img.setAttribute('width','9px');
						//img.setAttribute('heigh','9px');
						//a.appendChild(img);
						//td.appendChild(a);
						
						a=document.createElement("a");
						a.setAttribute("title", torsh.torrents[f].title);
						a.setAttribute('href','/download-torrent/' + globalquery + '/'+ torsh.torrents[f].link);
						if ( torsh.torrents[f].title.length>40)
						{
							a.appendChild(document.createTextNode(torsh.torrents[f].title.substring(0,40) + '...'));
						}
						else
						{
							a.appendChild(document.createTextNode(torsh.torrents[f].title));
						}
						td.appendChild(a);
						trtemp.appendChild(td);
					
						td = document.createElement("td");
						td.appendChild(document.createTextNode(torsh.torrents[f].category));
						trtemp.appendChild(td);
					
						/*
						td = document.createElement("td");
						td.appendChild(document.createTextNode(torsh.torrents[f].nbrfiles));
						trtemp.appendChild(td);
						*/
					
						td = document.createElement("td");
						td.appendChild(document.createTextNode(torsh.torrents[f].size));
						trtemp.appendChild(td);
					
						td = document.createElement("td");
						td.setAttribute('class','g');
						td.appendChild(document.createTextNode(torsh.torrents[f].seed));
						trtemp.appendChild(td);
					
						td = document.createElement("td");
						td.setAttribute('class','b');
						td.appendChild(document.createTextNode(torsh.torrents[f].leech));
						trtemp.appendChild(td);
					
						td = document.createElement("td");
						img = document.createElement("img");
						img.setAttribute('src','/images/engines/' + torsh.engine + '.png');
						img.setAttribute('alt',torsh.engine);
						td.appendChild(img)
						//td.appendChild(document.createTextNode(torsh.engine));
						trtemp.appendChild(td);
					
						var id=torsh.engine+'_'+torsh.page+'_'+f;
						tmptr = document.getElementById(id);
						trtemp.setAttribute("id", id);
						tbody.appendChild(trtemp);
		}
		//---succes
		document.getElementById("spinner_" + torsh.engine).setAttribute('class',"state_2");
		//$("table").tablesorter({widthFixed: true, headers: {3: {sorter:'size'}}});
		$("table").trigger("update"); 
		// set sorting column and direction, this will sort on the first and third column 
		 var sorting = [[4,1],[5,1]]; 
		// sort on the first column 
		$("table")
		.trigger("sorton",[sorting]);
		//.tablesorterPager({container: $("#pager"),size: 20}); 
	}
	else
	{
	//----------- error
	document.getElementById("spinner_" + torsh.engine).setAttribute('class',"state_3");
	}

				//-------------------debut modification de la progression ----------------------------
				comptecount=comptecount-1;
				//alert(comptecount);
				if (comptecount===0)
				{
					//document.getElementById("info").innerHTML  = "done";
					document.getElementById("spinner").style.visibility="hidden";

				}
				else
				{
					//document.getElementById("info").innerHTML = comptecount + ' Restants';
				}
				//-------------------fin modification de la progression ----------------------------

}