switch (jIdioma) {
	case "esp":
		tParticipant="Participante";
		tNom="Nombre*";
		tCognoms="Apellido*";
		tDataneix="Fecha de Nacimiento*";
		tDia="Día";
		tMes="Mes";
		tAny="Año";
		tSexe="Sexo";
		tHome="Hombre";
		tDona="Mujer";
		tNIF="NIF";
		tPoblacio="Población";
		tTelefon="Teléfono";
		tMail="Email";
		tTitulCondiMenor="Condiciones antes de formalizar la inscripción de un menor:";
		tCondiMenor="Declaro que soy padre/madre o tutor legal del menor y acepto que se halla bajo mi responsabilidad y que realizaremos la actividad conjuntamente. Acepto asimismo las condiciones y normativas y declaro que, mediante reconocimiento médico, conozco mi estado físico y el del menor y que nos hallamos en condiciones para realizar la actividad.";
		tCondiAccept="Acepto las condiciones";
		tError1="Se han de rellenar todos los campos obligatorios.";
		tError2="Se han de aceptar las condiciones de uso.";
		tError3="Se han de aceptar las condiciones de uso del menor.";
		tError4="El DNI no es valido.";
		tError5="El telèfono no es valid";
		tError6="Direccióo de correu electronico incorrecto.";
		tError8="La fecha de la cursa no es valida, el inicio de la prueba es el 14/07/2010";
		tErrorDef="Los datos no son correctos.";
		tErrorEdatM="La edad es incorrecta, ha de ser menor de edat.";
		tErrorEdatA="La edad es incorrecta, ha de tener mas de 18años.";
		tErrorDataFormat="Fecha de nacimiento incorrecta, tiene que ser con el formato dd mm aaaa.";
		break;
	case "eng":
		alert("idioma eng");
		break;
	case "fra":
		alert("idioma fra");
		break;
	default: //case "cat":
		tParticipant="Participant";
		tNom="Nom*";
		tCognoms="Cognoms*";
		tDataneix="Data de naixement*";
		tDia="Dia";
		tMes="Mes";
		tAny="Any";
		tSexe="Sexe";
		tHome="Home";
		tDona="Dona";
		tNIF="NIF";
		tPoblacio="Població";
		tTelefon="Telèfon";
		tMail="Email";
		tTitulCondiMenor="Condicions abans de formalitzar la inscripció d'un menor:";
		tCondiMenor="Declaro que sóc pare/mare o tutor legal del menor, que accepto que corre sota la meva responsabilitat i que farem l'activitat conjuntament. Accepto les condicions i normatives i declaro que, mitjançant reconeixement mèdic, conec el meu estat físic i el del menor i que ens trobem en condicions per fer l'activitat.";
		tCondiAccept="Accepto les condicions";
		tError1="S'han d'emplenar tots els camps obligatoris.";
		tError2="S'han d'acceptar les condicions d'us.";
		tError3="S'han d'acceptar les condicios d'us per menors.";
		tError4="El DNI no es vàlid.";
		tError5="El telèfon no es valid";
		tError6="Direcció de correu electronic incorrecte.";
		tError8="La data de la cursa no es vàlida, el inici de la proba es el 14/07/2010";
		tErrorDef="Les dades no son correctes.";
		tErrorEdatM="L'edat es incorrecte, ha de ser menor d'edat.";
		tErrorEdatA="L'edat es incorrecte, ha de tenir mes de 18 anys.";
		tErrorDataFormat="Data naixement incorrecte, ha d'estar amb el format dd mm aaaa"
		break;
}

function showModal(id){
	$('.tapa').show();
	$('#'+id).show();
	/*$('#rutaGran').animate(
		{ 
			width: "571px",
			height: "548px",
			display: "block",
			left: "48px",
			top: "26px"
		}, 500 
	);*/
}

function hideModal(id){
	$('#'+id).hide();
 	$('.tapa').hide();
	/*$('#rutaGran').animate(
		{ 
			width: "219px",
			height: "205px",
			display: "none",
			top: "313px",
			left: "359px"
		}, 200 ,function() {
   			$('.tapa').hide();
  		}
	);*/
}
function deleteForm(id){
	$('#'+id).hide('200',function(){
		$('#'+id).remove();
	});
	$('#numparticipant').val(parseInt($('#numparticipant').val())-1);
	showPrice();
}

function changeOpacity(id,value){
	if($.browser.msie){
		$(id).css('filter', 'alpha(opacity = '+value+')');
	}else{
		$(id).css('opacity',value/100);
	}
}

function addForm(type,id){
	innerHTML='<div id="form'+id+'" class="formscursa" style="display:none;">';
	innerHTML+='<div class="barrapetita"></div>';
	innerHTML+='<div class="tancarpetit" onclick="javascript:deleteForm(\'form'+id+'\');"></div>';
	innerHTML+=htmlForm(id,type);
	
	switch(type){
		case 'adult':
			innerHTML+= htmlAdultForm(id);
			break;
		case 'menor':
			innerHTML+= htmlMenorForm(id);
			break;
	}
	
	innerHTML+='</div>';
	$('#formscontent').append(innerHTML);
	$('#numparticipant').val(parseInt($('#numparticipant').val())+1);
	textboxbehavior();
	$('#form'+id).show('200',function(){
			$('.footer').html($('.footer').html());
			//document.body.innerHTML=document.body.innerHTML;
		}
	);
	
	showPrice();
	
}
function htmlForm(id,type){
	innerHTML='<div id="numpar'+id+'" class="titulformparti"> '+tParticipant+' ('+type+')</div>\n';
	innerHTML+='<input id="tipus'+id+'" type="hidden" name="tipus'+id+'" value="'+type+'"/>\n';
	innerHTML+='<input id="edat'+id+'" class="edatpar" type="hidden" name="edat'+id+'" value="18"/>\n';
	innerHTML+='<input type="text" value="'+tNom+'" name="nom'+id+'" id="nom'+id+'" class="textinputform"/><br/>\n';
	innerHTML+='<input type="text" value="'+tCognoms+'" name="cognom'+id+'" id="cognom'+id+'" class="textinputform"/><br/>\n';
	innerHTML+= tDataneix+' <input type="text" value="'+tDia+'" name="dia'+id+'" id="dia'+id+'" class="textdatainputform" style="margin-left: 17px;" onchange="javascript:checkEdat('+id+');"/><input type="text" value="'+tMes+'" name="mes'+id+'" id="mes'+id+'" class="textdatainputform" onchange="javascript:checkEdat('+id+');"/><input type="text" value="'+tAny+'" name="any'+id+'" id="any'+id+'" class="textdatainputform" onchange="javascript:checkEdat('+id+');"/><br/>\n';
	innerHTML+='<div style="height: 11px;width: 320px;">\n';
	innerHTML+='<div style="float:left;margin-right:24px;">'+tSexe+'</div>\n';
	innerHTML+='<div style="float:left;margin-right:5px;">'+tHome+'</div>\n';
	innerHTML+='<div style="float:left;margin-right:10px;"><input type="radio" name="sexe'+id+'" value="1" checked="checked"></div>\n';
	innerHTML+='<div style="float:left;;margin-right:5px;">'+tDona+'</div>\n';
	innerHTML+='<div style="float:left;margin-right:10px;"><input type="radio" name="sexe'+id+'" value="2"></div>\n';
	innerHTML+='</div><br/>\n';
	if (type == 'adult') {
		innerHTML += '<input type="text" value="'+tNIF+'*" name="nif' + id + '" id="nif' + id + '" class="textinputform"/><br/>\n';
	}else{
		innerHTML += '<input type="text" value="'+tNIF+'" name="nif' + id + '" id="nif' + id + '" class="textinputform"/><br/>\n';
	}
	
	innerHTML+='<input type="text" value="'+tPoblacio+'" name="poblacio'+id+'" id="poblacio'+id+'" class="textinputform"/><br/>\n';
	innerHTML+='<input type="text" value="'+tTelefon+'" name="tel'+id+'" id="tel'+id+'" class="textinputform"/><br/>\n';
	innerHTML+='<input type="text" value="'+tMail+'" name="mail'+id+'" id="mail'+id+'" class="textinputform"/><br/>\n';
								
	return(innerHTML);
}
function htmlAdultForm(id){
	return '';
}
function htmlMenorForm(id){
	text='';
	text+='<div id="condicionsmenor" class="condicionscursa condicionsmenor">\n';
	text+='<b>'+tTitulCondiMenor+'</b><br/>\n';
	text+= tCondiMenor+"\n";
	text+='<div class="acceptamenor acceptarCondicions">'+tCondiAccept+' <input id="condiciomenor'+id+'" type="checkbox" name="condicionMenor'+id+'" style="position: relative;top: 2px;"></div>';
	text+='</div>';
	return(text);
}

function numeral(num){
	text=''+num;
	switch(num){
		case 1:
			text+='er';
			break;
		case 2:
			text+='on';
			break;
		case 3:
			text+='er';
			break;
		case 4:
			text+='art';
			break;
		default:
			text+='è';
			break;
	}
	return(text);
}
function validarTot(){
	error={'error':false,'type':1};
	$('.formscursa').each(function(){
		if(!error.error)error=checkEdat(parseInt(this.id.substring(4)));
		if(!error.error)error=validarForm(this.id);
		if(!error.error)error=validarDNI(this.id);
		if(!error.error)error=validarTel(this.id);
		if(!error.error)error=validarMail(this.id);
		if(!error.error)error=validarDates();
	});
	
	
	if(!$('#condicionstotal').is(':checked')){
		error={'error':true,'type':2};		
	}  

	if (error.error) {
		switch (error.type) {
			case 1: 
				sError=tError1;
				break;
			case 2:
				sError=tError2;
				break;
			case 3: 
				sError=tError3;
				break;
			case 4: 
				sError=tError4;
				break;
			case 5: 
				sError=tError5;
				break;
			case 6: 
				sError=tError6;
				break;
			case 8:
				sError=tError8;
				break;
			default:
				sError=tErrorDef;
				break;
		}
		if (error.type != 7) {
			alert("ERROR: " + sError)
		}
		//mostrarError();
	}else{
		$('#participant').submit();
	}
}
function validarTel(id){
	numform=id.substring(4);
	error={'error':false,'type':1};
	sTel=$('#tel'+numform)[0].value;
	if ($('#tel' + numform)[0].defaultValue.indexOf("*") != -1) {
		if (sTel != $('#tel' + numform)[0].defaultValue) {
			if (sTel.length != 9 || isNaN(parseInt(sTel))) {
				error = {
					'error': true,
					'type': 5
				};
				return error;
			}
		}
	}
	return error;
}
function validarDNI(id){
	numform=id.substring(4);
	
	sDNI=$('#nif'+numform)[0].value;
	sDNI=sDNI.replace("-","")
	if ($('#nif' + numform)[0].defaultValue.indexOf("*")!=-1) {
		if (sDNI != $('#nif' + numform)[0].defaultValue) {
			if (sDNI.length != 9) {
				error = {
					'error': true,
					'type': 4
				};
				return error;
			}
		}
	}
	return error;
}
function validarMail(id){
	numform=id.substring(4);
	error={'error':false,'type':1};
	if ($('#mail' + numform)[0].defaultValue.indexOf("*") != -1) {
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		var address = sDNI=$('#mail'+numform)[0].value;
		if (reg.test(address) == false) {
			error = {
				'error': true,
				'type': 6
			};
			
		}
	}
	return error;
}
function ferPagament(){ //deprecated
	alert("deprecated")
	/*error={'error':false,'type':1};
	$('.formscursa').each(function(){
		error=validarForm(this.id);
	});
	if (error.error) {
		alert("HI HA UN ERROR"+" errorType:"+error.type)
		//mostrarError();
	}else{
		$('#envioTPV').submit();
	}*/
	$('#envioTPV').submit();
}
function validarForm(id){
	numform=id.substring(4);
	error={'error':false,'type':1};
	if($('#tipus'+numform)[0].value=='menor' && !$('#condiciomenor'+numform).is(':checked')){
		error={'error':true,'type':3};
		return error;
	}
	$('#'+id+' :input').each(function(){
		if(this.id!="" && this.id!="datepicker"){
			if(this.defaultValue==this.value && (this.defaultValue.indexOf("*")!=-1||this.id=='dia'+numform||this.id=='mes'+numform||this.id=='any'+numform)){
				error={'error':true,'type':'1'};
				return error;
			}		
			if(this.defaultValue==this.value){
				this.value='';
			}	
		}
	});
	return error;
}

function seguentParticipants(index,filter,any){
	var url = "cursa_ranking.asp?filter="+filter+"&index="+index+"&any="+any;    
	$(location).attr('href',url);
}
function diploma(id){
	var url = "cursa_diploma.asp?index="+id;    
	$(location).attr('href',url);
}

function imprimir(){
        var container = $('#areaImpresio');
        /*var WindowObject = window.open('', "Diploma", 
                              "width=1000,height=723,toolbars=no,scrollbars=yes,status=no,resizable=no");*/
		var WindowObject = window.open('', "Diploma","width=1000,height=723,,top=250,left=345");							 
		innerHTML=crearHTMLtoPrint(container.html());
        WindowObject.document.writeln(innerHTML);
        WindowObject.document.close();
        WindowObject.focus();
		setTimeout(function(){
			WindowObject.print();
       		WindowObject.close();	
		},1000);
        
}

function crearHTMLtoPrint(text){
	html='<html><head><link rel="stylesheet" type="text/css" href="../media/css/cursa/estilosCursa.css" /><style>.diplomacancel{width:0px;height:0px;}.diplomaimprimirhover{width:0px;height:0px;}</style></head><body>';
	html+='<div id="areaImpresio" class="diploma">';
	html+=text;
	html+='</div>';
	//html+='<div style="left: 24px;position: absolute;top: 47px;z-index:-1"><img src="imagenes/cursa/diploma.png"/></div>';
	html+='<div style="left: -22px;position: absolute;top: 11px;z-index:-1"><img src="imagenes/cursa/diploma.png"/></div>';
	html+='</body></html>';
	return html;
}

function showPrice(){
	$('#numCalculPreu').html(calculPreu()+'&euro;');
}
function calculPreu(){
	preu=18;
	adult=calcularAdults();
	menor=calcularMenors();
	switch(opcio){
		case 1:
			preu=opcio1Adult*adult+opcio1Menor*menor;
			break;
		case 2:
			preu=opcio2Adult*adult+opcio2Menor*menor;
			break;
		case 3:
			preu=opcio3Adult*adult+opcio3Menor*menor;
			break;
	}
	return preu;
}

function calcularAdults(){
	count=0;
	for(i=0;i<$('#numparticipant').val();i++){
		if($('#edat'+(i+1)).val()>14){
			count++;
		}
	}
	return count;
}

function calcularMenors(){
	count=0;
	for(i=0;i<$('#numparticipant').val();i++){
		if($('#edat'+(i+1)).val()<=14){
			count++;
		}
	}
	return count;
}

function changeOpcio(num){
	opcio=num;
	showPrice();
}

function checkEdat(num){
	if($('#dia'+num).val()!='Dia' && $('#mes'+num).val()!='Mes' && $('#any'+num).val()!='Any'){
		datePar=getDataNaix(num);
		if (datePar.error) return {'error':true,'type':7};
		edat=calcularEdat(datePar);
		$('#edat'+num).val(edat);
		if($('#edat'+num).val()>=18 && $('#tipus'+num).val()=="menor"){
			alert(tErrorEdatM);
			return {'error':true,'type':7};
		}
		if($('#edat'+num).val()<18 && $('#tipus'+num).val()=="adult"){
			alert(tErrorEdatA);
			return {'error':true,'type':7};
		}
		showPrice();
	}
	return {'error':false,'type':7};
}
function getDataNaix(num){
		dia=$('#dia'+num).val();
		mes=$('#mes'+num).val()-1;
		any=parseInt($('#any'+num).val(),10);
		error=false;
		if(dia<1 || dia>31){
			error=true;
		}
		if(mes<0 || mes>11){
			error=true;
		}
		if(any==0){
			error=true;
		}
		if(error){
			alert(tErrorDataFormat);
			return {'error':true,'type':7};
		}
		data=new Date(any,mes,dia);
		return data;
}
function calcularEdat(diaN){
 	now = new Date();
   	years = Math.floor((now.getTime() - diaN.getTime()) / (365.25 * 24 * 60 * 60 * 1000));
	return years;
}

function validarDates(){
	var expr = /([0-9]{2})\/([0-9]{2})\/([0-9]{4})/;
	var matches = document.getElementById("datepicker").value.match(expr);
	var Data = new Date(matches[3],matches[2]-1,matches[1]);
	
	var minData = new Date(2010,06,14);
	var minDataValue = "14/07/2010";
	/*
	var maxData = new Date(2010,10,01);
	var maxDataValue = "01/11/2010"; 
	*/
	if (Data < minData){
		document.getElementById("datepicker").value = minDataValue;
		return {'error':true,'type':8};
	}
	/*
	if (Data > maxData){
		document.getElementById("datepicker").value = maxDataValue;
		return {'error':true,'type':8};
	}
	*/
	return {'error':false,'type':8};
}

