function loadLlistaPilots(){
	$("#detallPilotDiv").hide();
	$("#llistaPilots").show();
	$('#llistaPilots div').remove();
	$.ajax({
			type: "POST",
			data:"AJaccio=llista&categoria="+$("#pilotsCategoria").val(),
			url:"AJ_pilotos.php",			
			success:function(response){
				var llista = response.firstChild;
				
				$('#llistaPilots table tr').remove();
				var numm = 0;
				$(llista).children().each(function(){//50cc
						numm++;
						$('#llistaPilots table').append('<tr class="dorsal pointer" onclick="loadPilotDades(\''+$(this).find('dni').text()+'\')"><td class="pilot">'+$(this).find('nombre').text()+' '+$(this).find('apellidos').text()+'</td></tr>');																  
				});
				
				if(numm==0){
					$('#llistaPilots').append("<div style=\"clear:both;margin-top:15px\">No hay pilotos inscritos en esta categoria</div>")	
				}
			}
	});
}

function veureLlistaPilots(){
	$("#detallPilotDiv").hide();
	$("#llistaPilots").show();
	$("#back").hide();
}

function loadPilotDades(idPilot){
	$("#llistaPilots").hide();
	$("#back").show();
	
		$.ajax({
			type: "POST",
			data:"AJaccio=veure&idp="+idPilot,
			url:"AJ_pilotos.php",			
			success:function(response){
				
				$('#dPFotoCarnet').empty();
				$('#dPFotoMoto').empty();
				$('#dPFotoCarrera').empty();
				$("#detallPilotDiv").show();
				var llista = response.firstChild;
				
				$("#dPPilotDadesNom").html($(llista).find("nombre").text()+" "+$(llista).find("apellido1").text()+" "+$(llista).find("apellido2").text());
				$("#dPPilotDadesDatan").html($(llista).find("fechan").text());
				$("#dPPilotDadesResidencia").html($(llista).find("ciudad").text()+"("+$(llista).find("pais").text()+")");
				//$("#dPPilotDadesCategoria").html($(llista).find("categoria").text());
				$("#dPPilotDadesEquip").html($(llista).find("equipo").text());
				$("#dPPilotDadesMoto").html($(llista).find("mmodelo").text());
				if($(llista).find("publicaremail").text() == "1"){
					$("#dPPilotDadesContacte").html($(llista).find("email").text());
				}else{
					$("#dPPilotDadesContacte").html("-");
				}//$("#dPPilotDadesWeb").html($(llista).find("web").text());
				//$("#dPPilotDadesCurriculum").html($(llista).find("curriculum").text());
				
				loadPilotImage($(llista).find("dni").text(),"Carnet");
				//loadPilotImage($(llista).find("id").text(),"Moto");
				//loadPilotImage($(llista).find("id").text(),"Carrera");
			}
		});	
}

function loadPilotImage(id,foto){
	$(function () {
	  var img = new Image();
	  
	  // wrap our new image in jQuery, then:
	  $(img)
		// once the image has loaded, execute this code
		.load(function () {
		  // set the image hidden by default    
		  $(this).hide();
		
		  // with the holding div #loader, apply:
		  $('#dPFoto'+foto)
			// then insert our image
			.append(this);
		
		  // fade our image in to create a nice effect
		  $(this).fadeIn();
		})
		// *finally*, set the src attribute of the new image to our image
		
		.attr('src', WROOT+'webconf/getImage.php?t=inscripciones_fotos&c=foto&idpilot='+id);
	});	
}