var imagenCargando = new Image();
imagenCargando.src = "img/loadingAnimation.gif";

var paginaActual = 1;
var direccion = 1;
var ordenActual = 2;

function cambiarHoja(hoja, idioma){
	paginaActual = hoja;
	var contenido = '<img style="margin: 30px;" src="img/loadingAnimation.gif" />';
	$('#comentarios').html(contenido);
	var ruta = 'ajax/ordenarComentarios.php?hoja='+hoja+'&idi='+idioma+'&ordenacion='+ordenActual+'&direccion='+direccion;
	$.get(ruta, function(data) {
		$('#comentarios').html(data);
	});
}

function ordenarComentarios(ordenacion, idioma){
	ordenActual = ordenacion;
	// Direccion actual es DESC por fecha
	if (direccion == 1){
		direccion = 3;
	}else{
		direccion = 1;
	}
	var contenido = '<img style="margin: 30px;" src="img/loadingAnimation.gif" />';
	$('#comentarios').html(contenido);
	var ruta = 'ajax/ordenarComentarios.php?hoja='+paginaActual+'&idi='+idioma+'&ordenacion='+ordenacion+'&direccion='+direccion;
	//alert (ruta);
	$.get(ruta, function(data) {
		$('#comentarios').html(data);
	});
}

function enviarComentario(formulario, idioma){
	var comprobacion = new comprobador();
	if (!comprobacion.vacio(formulario.texto)){
		if (idioma == 1){
			alert ('Debe introducir el comentario');
		}else{
			alert ('You must enter comment');
		}
		return false;
	}
	if (!comprobacion.vacio(formulario.mail)){
		if (idioma == 1){
			alert ('Debe introducir su e-Mail');
		}else{
			alert ('You must enter your e-Mail');
		}
		return false;
	}
	if (!comprobacion.validarMail(formulario.mail)){
		if (idioma == 1){
			alert ('El e-Mail introducido no es valido');
		}else{
			alert ('The e-Mail entered is not valid');
		}
		return false;
	}
	var contenido = '<p>Enviando...</p>';
	$('#envioDeComentario').html(contenido);
	$.post('ajax/nuevoComentario.php', $('#frmComentarios').serialize(), function(data){
		$('#envioDeComentario').html(data);
	});
	return false;
}

function cambiarMesEventos(mes, ano, idioma){
	// Quito la seleccion del mes y del año
	$('.selec').removeClass('selec');
	// Coloco la clase en el mes
	var mes_completo = '#mes_'+mes+'_'+ano;
	$(mes_completo).addClass('selec');
	// ... y ahora en el año
	var ano_completo = '#ano_'+ano;
	$(ano_completo).addClass('selec');
	/*lugar = document.getElementById(mes_completo);
	alert (lugar);*/
	var ruta = 'ajax/cambiarMesEventos.php?m='+mes+'&a='+ano+'&i='+idioma;
	var contenido = '<img style="margin: 30px;" src="img/loadingAnimation.gif" />';
	$('#calendarioEventos').html(contenido);
	$.get(ruta, function(data) {
		$('#calendarioEventos').html(data);
	});
}

function validar_inscripcion(formulario, idioma){
	// Validación y envio de la inscripción
	var comprobacion = new comprobador();
	for(i=0; i < formulario.acompanado.length; i++){
	   if(formulario.acompanado[i].checked){
		   valorSeleccionado = formulario.acompanado[i].value;
	   }
	}
	// Validacion los acompañantes
	if (valorSeleccionado == 1){
		// Solo se valida si dice que viaja acompañado
		// Primer acompañante
		var total = formulario.nombreacompanante1.value.length + formulario.apellido1acompanante1.value.length + formulario.apellido2acompanante1.value.length;
		if (total > 0){
			// Si uno de los tres campos tiene algo
			if (!comprobacion.vacio(formulario.nombreacompanante1)){
				if (idioma == 1){
					jAlert ('Debe indicar el nombre del primer acompa\u00f1ante', 'Faltan datos');
				}else{
					jAlert ('Must indicate the name of the first passenger', 'Missing data');
				}
				return false;
			}
			if (!comprobacion.vacio(formulario.apellido1acompanante1)){
				if (idioma == 1){
					jAlert ('Debe indicar el apellido del primer acompa\u00f1ante', 'Faltan datos');
				}else{
					jAlert ('Must indicate the surname of the first passenger', 'Missing data');
				}
				return false;
			}
			if (!comprobacion.vacio(formulario.apellido2acompanante1)){
				if (idioma == 1){
					jAlert ('Debe indicar el apellido del primer acompa\u00f1ante', 'Faltan datos');
				}else{
					jAlert ('Must indicate the surname of the first passenger', 'Missing data');
				}
				return false;
			}
			if (!comprobacion.vacio(formulario.dniacompanante1)){
				if (idioma == 1){
					jAlert ('Debe indicar el DNI del primer acompa\u00f1ante', 'Faltan datos');
				}else{
					jAlert ('Must indicate the DNI of the first passenger', 'Missing data');
				}
				return false;
			}
		}
	}
	// Segundo acompañante
	var total = formulario.nombreacompanante2.value.length + formulario.apellido1acompanante2.value.length + formulario.apellido2acompanante2.value.length;
	if (total > 0){
		// Si uno de los tres campos tiene algo
		if (!comprobacion.vacio(formulario.nombreacompanante2)){
			if (idioma == 1){
				jAlert ('Debe indicar el nombre del segundo acompa\u00f1ante', 'Faltan datos');
			}else{
				jAlert ('Must indicate the name of the second passenger', 'Missing data');
			}
			return false;
		}
		if (!comprobacion.vacio(formulario.apellido1acompanante2)){
			if (idioma == 1){
				jAlert ('Debe indicar el apellido del segundo acompa\u00f1ante', 'Faltan datos');
			}else{
				jAlert ('Must indicate the surname of the second passenger', 'Missing data');
			}
			return false;
		}
		if (!comprobacion.vacio(formulario.apellido2acompanante2)){
			if (idioma == 1){
				jAlert ('Debe indicar el apellido del segundo acompa\u00f1ante', 'Faltan datos');
			}else{
				jAlert ('Must indicate the surname of the second passenger', 'Missing data');
			}
			return false;
		}
		if (!comprobacion.vacio(formulario.dniacompanante2)){
			if (idioma == 1){
				jAlert ('Debe indicar el DNI del segundo acompa\u00f1ante', 'Faltan datos');
			}else{
				jAlert ('Must indicate the DNI of the second passenger', 'Missing data');
			}
			return false;
		}
	}
	// Tercer acompañante
	var total = formulario.nombreacompanante3.value.length + formulario.apellido1acompanante3.value.length + formulario.apellido2acompanante3.value.length;
	if (total > 0){
		// Si uno de los tres campos tiene algo
		if (!comprobacion.vacio(formulario.nombreacompanante3)){
			if (idioma == 1){
				jAlert ('Debe indicar el nombre del tercer acompa\u00f1ante', 'Faltan datos');
			}else{
				jAlert ('Must indicate the name of the third passenger', 'Missing data');
			}
			return false;
		}
		if (!comprobacion.vacio(formulario.apellido1acompanante3)){
			if (idioma == 1){
				jAlert ('Debe indicar el apellido del tercer acompa\u00f1ante', 'Faltan datos');
			}else{
				jAlert ('Must indicate the surname of the third passenger', 'Missing data');
			}
			return false;
		}
		if (!comprobacion.vacio(formulario.apellido2acompanante3)){
			if (idioma == 1){
				jAlert ('Debe indicar el apellido del tercer acompa\u00f1ante', 'Faltan datos');
			}else{
				jAlert ('Must indicate the surname of the third passenger', 'Missing data');
			}
			return false;
		}
		if (!comprobacion.vacio(formulario.dniacompanante3)){
			if (idioma == 1){
				jAlert ('Debe indicar el DNI del tercer acompa\u00f1ante', 'Faltan datos');
			}else{
				jAlert ('Must indicate the DNI of the third passenger', 'Missing data');
			}
			return false;
		}
	}
	// Fin de la validación de los acompañantes

	// Validación de los campos de cabecera
	if (!comprobacion.seleccionValida(formulario.salida, 0)){
		if (idioma == 1){
			jAlert ('Seleccione el lugar de salida', 'Faltan datos');
		}else{
			jAlert ('Select the output location', 'Missing data');
		}
		return false;
	}
	if (!comprobacion.seleccionValida(formulario.viaje, 0)){
		if (idioma == 1){
			jAlert ('Seleccione las fechas del viaje', 'Faltan datos');
		}else{
			jAlert ('Select travel dates', 'Missing data');
		}
		return false;
	}
	
	// Validación de los datos del corredor
	if (!comprobacion.vacio(formulario.nombreCorredor)){
		if (idioma == 1){
			jAlert ('Debe indicar el nombre', 'Faltan datos');
		}else{
			jAlert ('Should indicate the name', 'Missing data');
		}
		return false;
	}
	if (!comprobacion.vacio(formulario.apellido1Corredor)){
		if (idioma == 1){
			jAlert ('Debe indicar el apellido', 'Faltan datos');
		}else{
			jAlert ('You must enter surname', 'Missing data');
		}
		return false;
	}
	if (!comprobacion.vacio(formulario.apellido2Corredor)){
		if (idioma == 1){
			jAlert ('Debe indicar al menos un apellido', 'Faltan datos');
		}else{
			jAlert ('You must enter surname', 'Missing data');
		}
		return false;
	}
	if (!comprobacion.vacio(formulario.dniCorredor)){
		if (idioma == 1){
			jAlert ('Debe indicar el dni del corredor', 'Faltan datos');
		}else{
			jAlert ('Should indicate the corridor dni', 'Missing data');
		}
		return false;
	}
	if (!comprobacion.vacio(formulario.direccionCorredor)){
		if (idioma == 1){
			jAlert ('Debe indicar la direcci\u00f3n del corredor', 'Faltan datos');
		}else{
			jAlert ('Should indicate the corridor address', 'Missing data');
		}
		return false;
	}
	if (!comprobacion.vacio(formulario.localidadCorredor)){
		if (idioma == 1){
			jAlert ('Debe indicar la localidad del corredor', 'Faltan datos');
		}else{
			jAlert ('Should indicate the corridor city', 'Missing data');
		}
		return false;
	}
	if (formulario.cpCorredor.value != ''){
		if (!comprobacion.validarCP(formulario.cpCorredor)){
			if (idioma == 1){
				jAlert ('El c\u00f3digo postal indicado es erroneo', 'Error en los datos');
			}else{
				jAlert ('The zip code given is wrong', 'Data error');
			}
			return false;
		}
	}
	if (!comprobacion.vacio(formulario.telefonoCorredor)){
		if (idioma == 1){
			jAlert ('Debe indicar el tel\u00e9fono', 'Faltan datos');
		}else{
			jAlert ('Should indicate the phone number', 'Missing data');
		}
		return false;
	}
	if (!comprobacion.vacio(formulario.mailCorredor)){
		if (idioma == 1){
			jAlert ('Debe indicar el e-mail del corredor', 'Faltan datos');
		}else{
			jAlert ('Should indicate the corridor e-mail', 'Missing data');
		}
		return false;
	}
	if (!comprobacion.validarMail(formulario.mailCorredor)){
		if (idioma == 1){
			jAlert ('El e-mail indicado es erroneo', 'Error en los datos');
		}else{
			jAlert ('The e-mail given is wrong', 'Data error');
		}
		return false;
	}
	if (!comprobacion.vacio(formulario.nterminadosCorredor)){
		if (idioma == 1){
			jAlert ('Debe indicar el n\u00famero de maratones terminados', 'Faltan datos');
		}else{
			jAlert ('Should indicate the number of marathons completed', 'Missing data');
		}
		return false;
	}
	if (!comprobacion.vacio(formulario.profesionCorredor)){
		if (idioma == 1){
			jAlert ('Debe indicar la profesi\u00f3n del corredor', 'Faltan datos');
		}else{
			jAlert ('Should indicate the corridor job', 'Missing data');
		}
		return false;
	}
	if (!comprobacion.vacio(formulario.personaAviso)){
		if (idioma == 1){
			jAlert ('Debe indicar el nombre de la persona a contactar en caso de urgencia', 'Faltan datos');
		}else{
			jAlert ('Should indicate the name of the person to contact in case of emergency', 'Missing data');
		}
		return false;
	}
	if (!comprobacion.vacio(formulario.telefonoAviso)){
		if (idioma == 1){
			jAlert ('Debe indicar el tel\u00e9fono al que avisar en caso de emergencia', 'Faltan datos');
		}else{
			jAlert ('Should indicate the phone that alert emergency', 'Missing data');
		}
		return false;
	}
	if (!formulario.acepto_condiciones.checked){
		if (idioma == 1){
			jAlert ('No ha aceptado la pol\u00edtica de privacidad', 'Falta confirmar');
		}else{
			jAlert ('Has not accepted the privacy policy', 'To be confirmed');
		}
		return false;
	}
	var contenido = '<p>Enviando...</p>';
	$('#envio_inscripcion').slideDown();
	var ruta = 'ajax/nuevaInscripcion.php?idi='+idioma;
	$.post(ruta, $('#frmNuevaInscripcion').serialize(), function(data){
		$('#div_inscripciones').html(data);
		$('#envio_inscripcion').slideUp();
	});
	return false;
}

function recuperarDatos(idioma){
	// Solicito el mail
	var texto = '';
	if (idioma == 1){
		texto = "Introduzca su e-Mail";
		texto2 = "Consulta";
	}else{
		texto = "Put your e-Mail";
		texto2 = "Question"
	}
	var mail = jPrompt(texto, '', texto2, function(r) {
	    if( r ){
	    	var ruta = 'ajax/datosCorredor.php?mail='+r;
			$('#envio_inscripcion').slideDown();
			$.getJSON(ruta, function(data) {
				if (data.existe == '0'){
					if (idioma == 1){
						jAlert ("El e-Mail indicado no se encuentra en nuestra base de datos");
					}else{
						jAlert ("The e-Mail you is not found in our database");
					}
				}else{
					document.frmNuevaInscripcion.nombreCorredor.value = data.nombre;
					document.frmNuevaInscripcion.apellido1Corredor.value = data.apellido1;
					document.frmNuevaInscripcion.apellido2Corredor.value = data.apellido2;
					document.frmNuevaInscripcion.dniCorredor.value = data.dni;
					datosNacimiento = data.fNacimiento;
					arrayNacimiento = datosNacimiento.split("-");
					combo = document.frmNuevaInscripcion.diaNacimiento;
					cantidad = combo.length;
					for (i = 0; i < cantidad; i++) {
						if (combo[i].value == arrayNacimiento[0]) {
							combo[i].selected = true;
					    }   
					}
					combo = document.frmNuevaInscripcion.mesNacimiento;
					cantidad = combo.length;
					for (i = 0; i < cantidad; i++) {
						if (combo[i].value == arrayNacimiento[1]) {
							combo[i].selected = true;
					    }   
					}
					combo = document.frmNuevaInscripcion.anoNacimiento;
					cantidad = combo.length;
					for (i = 0; i < cantidad; i++) {
						if (combo[i].value == arrayNacimiento[2]) {
							combo[i].selected = true;
					    }   
					}
					document.frmNuevaInscripcion.direccionCorredor.value = data.direccion;
					document.frmNuevaInscripcion.localidadCorredor.value = data.localidad;
					combo = document.frmNuevaInscripcion.provinciaCorredor;
					cantidad = combo.length;
					for (i = 0; i < cantidad; i++) {
						if (combo[i].value == data.provincia) {
							combo[i].selected = true;
					    }   
					}
					document.frmNuevaInscripcion.cpCorredor.value = data.cp;
					combo = document.frmNuevaInscripcion.paisCorredor;
					cantidad = combo.length;
					for (i = 0; i < cantidad; i++) {
						if (combo[i].value == data.pais) {
							combo[i].selected = true;
					    }   
					}
					document.frmNuevaInscripcion.telefonoCorredor.value = data.telefono;
					document.frmNuevaInscripcion.mailCorredor.value = data.mail;
					document.frmNuevaInscripcion.nterminadosCorredor.value = data.nterminados;
					datosMarca = data.mejormarca;
					arrayMarca = datosMarca.split(":");
					combo = document.frmNuevaInscripcion.mejormarcaS;
					cantidad = combo.length;
					for (i = 0; i < cantidad; i++) {
						if (combo[i].value == arrayMarca[2]) {
							combo[i].selected = true;
					    }   
					}
					combo = document.frmNuevaInscripcion.mejormarcaM;
					cantidad = combo.length;
					for (i = 0; i < cantidad; i++) {
						if (combo[i].value == arrayMarca[1]) {
							combo[i].selected = true;
					    }   
					}
					combo = document.frmNuevaInscripcion.mejormarcaH;
					cantidad = combo.length;
					for (i = 0; i < cantidad; i++) {
						if (combo[i].value == arrayMarca[0]) {
							combo[i].selected = true;
					    }   
					}
					combo = document.frmNuevaInscripcion.tallaCorredor;
					cantidad = combo.length;
					for (i = 0; i < cantidad; i++) {
						if (combo[i].value == data.talla) {
							combo[i].selected = true;
					    }   
					}
					document.frmNuevaInscripcion.profesionCorredor.value = data.profesion;
					combo = document.frmNuevaInscripcion.ecivilCorredor;
					cantidad = combo.length;
					for (i = 0; i < cantidad; i++) {
						if (combo[i].value == data.ecivil) {
							combo[i].selected = true;
					    }   
					}
					document.frmNuevaInscripcion.personaAviso.value = data.personaaviso;
					document.frmNuevaInscripcion.telefonoAviso.value = data.telefonoaviso;
				}
				$('#envio_inscripcion').slideUp();
			});
	    }
	});
	
}

function cambiarAcompanantes(opcion){
	if (opcion == 1){
		$("#div_acompanantes").slideDown();
	}else{
		$("#div_acompanantes").slideUp();
	}
}

function validar_frm_contacto(idioma, formulario){
	// Validación y envio del contacto
	var comprobacion = new comprobador();
	if (!comprobacion.vacio(formulario.nombreapellidos)){
		if (idioma == 1){
			jAlert ('Debe indicar el nombre y apellidos', 'Faltan datos');
		}else{
			jAlert ('Should indicate the name and surname', 'Missing data');
		}
		return false;
	}
	if (!comprobacion.vacio(formulario.mail)){
		if (idioma == 1){
			jAlert ('Debe indicar el e-mail', 'Faltan datos');
		}else{
			jAlert ('Should indicate the e-mail', 'Missing data');
		}
		return false;
	}
	if (!comprobacion.validarMail(formulario.mail)){
		if (idioma == 1){
			jAlert ('El e-mail indicado es erroneo', 'Error en los datos');
		}else{
			jAlert ('The e-mail given is wrong', 'Data error');
		}
		return false;
	}
	if (!comprobacion.vacio(formulario.texto)){
		if (idioma == 1){
			jAlert ('Debe indicar el texto', 'Faltan datos');
		}else{
			jAlert ('Should indicate the text', 'Missing data');
		}
		return false;
	}
	if (!formulario.acepto_condiciones.checked){
		if (idioma == 1){
			jAlert ('Debe aceptar la pol\u00edtica de privacidad', 'Confirmar');
		}else{
			jAlert ('You must accept the privacy policy', 'Confirm');
		}
		return false;
	}
	// Una vez completado el procesamiento procedo al envío
	$('#envio_inscripcion').slideDown();
	var ruta = 'ajax/enviarContacto.php?idi='+idioma;
	$.post(ruta, $('#frm_contacto').serialize(), function(data){
		$('#envio_inscripcion').html(data);
	});
	return false;
}

function ponerDeporte(idioma){
	if ($("#deportes").val() != null){
		$("#deportes option:selected").remove().appendTo("#deportes2");
		var valor = $("#deportes2").find("option").length;
		$("#numselec").attr('value', valor);
	}else{
		if (idioma == 1){
			jAlert ('Debe indicar el deporte', 'Error');
		}else{
			jAlert ('You must select sport', 'Error');
		}
	}
}

function quitarDeporte(idioma){
	if ($("#deportes2").val() != null){
		$("#deportes2 option:selected").remove().appendTo("#deportes");
		var valor = $("#deportes2").find("option").length;
		$("#numselec").attr('value', valor);
	}else{
		if (idioma == 1){
			jAlert ('Debe indicar el deporte', 'Error');
		}else{
			jAlert ('You must select sport', 'Error');
		}
	}
}

//Valida el formulario de los bomberos
function validar_inscripcion_2(formulario, idioma){
	// Validación y envio de la inscripción
	var comprobacion = new comprobador();
	for(i=0; i < formulario.acompanado.length; i++){
	   if(formulario.acompanado[i].checked){
		   valorSeleccionado = formulario.acompanado[i].value;
	   }
	}
	// Validacion los acompañantes
	if (valorSeleccionado == 1){
		// Solo se valida si dice que viaja acompañado
		// Primer acompañante
		var total = formulario.nombreacompanante1.value.length + formulario.apellido1acompanante1.value.length + formulario.apellido2acompanante1.value.length;
		if (total > 0){
			// Si uno de los tres campos tiene algo
			if (!comprobacion.vacio(formulario.nombreacompanante1)){
				if (idioma == 1){
					jAlert ('Debe indicar el nombre del primer acompa\u00f1ante', 'Faltan datos');
				}else{
					jAlert ('Must indicate the name of the first passenger', 'Missing data');
				}
				return false;
			}
			if (!comprobacion.vacio(formulario.apellido1acompanante1)){
				if (idioma == 1){
					jAlert ('Debe indicar el apellido del primer acompa\u00f1ante', 'Faltan datos');
				}else{
					jAlert ('Must indicate the surname of the first passenger', 'Missing data');
				}
				return false;
			}
			if (!comprobacion.vacio(formulario.apellido2acompanante1)){
				if (idioma == 1){
					jAlert ('Debe indicar el apellido del primer acompa\u00f1ante', 'Faltan datos');
				}else{
					jAlert ('Must indicate the surname of the first passenger', 'Missing data');
				}
				return false;
			}
			if (!comprobacion.vacio(formulario.dniacompanante1)){
				if (idioma == 1){
					jAlert ('Debe indicar el DNI del primer acompa\u00f1ante', 'Faltan datos');
				}else{
					jAlert ('Must indicate the DNI of the first passenger', 'Missing data');
				}
				return false;
			}
		}
	}
	// Segundo acompañante
	var total = formulario.nombreacompanante2.value.length + formulario.apellido1acompanante2.value.length + formulario.apellido2acompanante2.value.length;
	if (total > 0){
		// Si uno de los tres campos tiene algo
		if (!comprobacion.vacio(formulario.nombreacompanante2)){
			if (idioma == 1){
				jAlert ('Debe indicar el nombre del segundo acompa\u00f1ante', 'Faltan datos');
			}else{
				jAlert ('Must indicate the name of the second passenger', 'Missing data');
			}
			return false;
		}
		if (!comprobacion.vacio(formulario.apellido1acompanante2)){
			if (idioma == 1){
				jAlert ('Debe indicar el apellido del segundo acompa\u00f1ante', 'Faltan datos');
			}else{
				jAlert ('Must indicate the surname of the second passenger', 'Missing data');
			}
			return false;
		}
		if (!comprobacion.vacio(formulario.apellido2acompanante2)){
			if (idioma == 1){
				jAlert ('Debe indicar el apellido del segundo acompa\u00f1ante', 'Faltan datos');
			}else{
				jAlert ('Must indicate the surname of the second passenger', 'Missing data');
			}
			return false;
		}
		if (!comprobacion.vacio(formulario.dniacompanante2)){
			if (idioma == 1){
				jAlert ('Debe indicar el DNI del segundo acompa\u00f1ante', 'Faltan datos');
			}else{
				jAlert ('Must indicate the DNI of the second passenger', 'Missing data');
			}
			return false;
		}
	}
	// Tercer acompañante
	var total = formulario.nombreacompanante3.value.length + formulario.apellido1acompanante3.value.length + formulario.apellido2acompanante3.value.length;
	if (total > 0){
		// Si uno de los tres campos tiene algo
		if (!comprobacion.vacio(formulario.nombreacompanante3)){
			if (idioma == 1){
				jAlert ('Debe indicar el nombre del tercer acompa\u00f1ante', 'Faltan datos');
			}else{
				jAlert ('Must indicate the name of the third passenger', 'Missing data');
			}
			return false;
		}
		if (!comprobacion.vacio(formulario.apellido1acompanante3)){
			if (idioma == 1){
				jAlert ('Debe indicar el apellido del tercer acompa\u00f1ante', 'Faltan datos');
			}else{
				jAlert ('Must indicate the surname of the third passenger', 'Missing data');
			}
			return false;
		}
		if (!comprobacion.vacio(formulario.apellido2acompanante3)){
			if (idioma == 1){
				jAlert ('Debe indicar el apellido del tercer acompa\u00f1ante', 'Faltan datos');
			}else{
				jAlert ('Must indicate the surname of the third passenger', 'Missing data');
			}
			return false;
		}
		if (!comprobacion.vacio(formulario.dniacompanante3)){
			if (idioma == 1){
				jAlert ('Debe indicar el DNI del tercer acompa\u00f1ante', 'Faltan datos');
			}else{
				jAlert ('Must indicate the DNI of the third passenger', 'Missing data');
			}
			return false;
		}
	}
	// Fin de la validación de los acompañantes
	
	// Validación de los campos de cabecera
	if (!comprobacion.seleccionValida(formulario.salida, 0)){
		if (idioma == 1){
			jAlert ('Seleccione el lugar de salida', 'Faltan datos');
		}else{
			jAlert ('Select the output location', 'Missing data');
		}
		return false;
	}
	if (formulario.salida.value == 100  && !comprobacion.vacio(formulario.otrasalida)){
		if (idioma == 1){
			jAlert ('Indique el lugar de salida', 'Faltan datos');
		}else{
			jAlert ('Indicate the location of output', 'Missing data');
		}
		return false;
	}
	var valorRadio = -1;
	for(i=0;i<formulario.viaje.length;i++){
        if(formulario.viaje[i].checked){
        	valorRadio = formulario.viaje[i].value;
        }
	}
	if (valorRadio < 0){
		if (idioma == 1){
			jAlert ('Indique la fecha de salida', 'Faltan datos');
		}else{
			jAlert ('Indicate date of output', 'Missing data');
		}
		return false;
	}
	
	// Validación de los datos del corredor
	if (!comprobacion.vacio(formulario.nombreCorredor)){
		if (idioma == 1){
			jAlert ('Debe indicar el nombre', 'Faltan datos');
		}else{
			jAlert ('Should indicate the name', 'Missing data');
		}
		return false;
	}
	if (!comprobacion.vacio(formulario.apellido1Corredor)){
		if (idioma == 1){
			jAlert ('Debe indicar el apellido', 'Faltan datos');
		}else{
			jAlert ('You must enter surname', 'Missing data');
		}
		return false;
	}
	if (!comprobacion.vacio(formulario.apellido2Corredor)){
		if (idioma == 1){
			jAlert ('Debe indicar al menos un apellido', 'Faltan datos');
		}else{
			jAlert ('You must enter surname', 'Missing data');
		}
		return false;
	}
	if (!comprobacion.vacio(formulario.dniCorredor)){
		if (idioma == 1){
			jAlert ('Debe indicar el dni del corredor', 'Faltan datos');
		}else{
			jAlert ('Should indicate the corridor dni', 'Missing data');
		}
		return false;
	}
	if (!comprobacion.vacio(formulario.direccionCorredor)){
		if (idioma == 1){
			jAlert ('Debe indicar la direcci\u00f3n del corredor', 'Faltan datos');
		}else{
			jAlert ('Should indicate the corridor address', 'Missing data');
		}
		return false;
	}
	if (!comprobacion.vacio(formulario.localidadCorredor)){
		if (idioma == 1){
			jAlert ('Debe indicar la localidad del corredor', 'Faltan datos');
		}else{
			jAlert ('Should indicate the corridor city', 'Missing data');
		}
		return false;
	}
	if (formulario.cpCorredor.value != ''){
		if (!comprobacion.validarCP(formulario.cpCorredor)){
			if (idioma == 1){
				jAlert ('El c\u00f3digo postal indicado es erroneo', 'Error en los datos');
			}else{
				jAlert ('The zip code given is wrong', 'Data error');
			}
			return false;
		}
	}
	if (!comprobacion.vacio(formulario.telefonoCorredor)){
		if (idioma == 1){
			jAlert ('Debe indicar el tel\u00e9fono', 'Faltan datos');
		}else{
			jAlert ('Should indicate the phone number', 'Missing data');
		}
		return false;
	}
	if (!comprobacion.vacio(formulario.mailCorredor)){
		if (idioma == 1){
			jAlert ('Debe indicar el e-mail del corredor', 'Faltan datos');
		}else{
			jAlert ('Should indicate the corridor e-mail', 'Missing data');
		}
		return false;
	}
	if (!comprobacion.validarMail(formulario.mailCorredor)){
		if (idioma == 1){
			jAlert ('El e-mail indicado es erroneo', 'Error en los datos');
		}else{
			jAlert ('The e-mail given is wrong', 'Data error');
		}
		return false;
	}
	if (formulario.numselec.value <= 0){
		if (idioma == 1){
			jAlert ('Debe seleccionar deportes', 'Faltan datos');
		}else{
			jAlert ('Must select sports', 'Missing data');
		}
		return false;
	}
	if (!comprobacion.vacio(formulario.profesionCorredor)){
		if (idioma == 1){
			jAlert ('Debe indicar la profesi\u00f3n del corredor', 'Faltan datos');
		}else{
			jAlert ('Should indicate the corridor job', 'Missing data');
		}
		return false;
	}
	if (!comprobacion.vacio(formulario.personaAviso)){
		if (idioma == 1){
			jAlert ('Debe indicar el nombre de la persona a contactar en caso de urgencia', 'Faltan datos');
		}else{
			jAlert ('Should indicate the name of the person to contact in case of emergency', 'Missing data');
		}
		return false;
	}
	if (!comprobacion.vacio(formulario.telefonoAviso)){
		if (idioma == 1){
			jAlert ('Debe indicar el tel\u00e9fono al que avisar en caso de emergencia', 'Faltan datos');
		}else{
			jAlert ('Should indicate the phone that alert emergency', 'Missing data');
		}
		return false;
	}
	if (!formulario.acepto_condiciones.checked){
		if (idioma == 1){
			jAlert ('No ha aceptado la pol\u00edtica de privacidad', 'Falta confirmar');
		}else{
			jAlert ('Has not accepted the privacy policy', 'To be confirmed');
		}
		return false;
	}
	// Recojo las opciones seleccionadas
	var deporteSeleccionados = '';
	var primero = true;
	$("#deportes2 option").each(function(){
		if (primero){
			primero = false;
		}else{
			deporteSeleccionados += ';';
		}
		deporteSeleccionados += $(this).attr('value');
	});
	var contenido = '<p>Enviando...</p>';
	$('#envio_inscripcion').slideDown();
	var ruta = 'ajax/nuevaInscripcion_2.php?idi='+idioma+'&depor='+deporteSeleccionados;
	$.post(ruta, $('#frmNuevaInscripcion').serialize(), function(data){
		$('#div_inscripciones').html(data);
		//$('#auxinscripcion').html(data);
		$('#envio_inscripcion').slideUp();
	});
	return false;
}

function recuperarDatos_2(idioma){
	// Solicito el mail
	var texto = '';
	if (idioma == 1){
		texto = "Introduzca su e-Mail";
		texto2 = "Consulta";
	}else{
		texto = "Put your e-Mail";
		texto2 = "Question"
	}
	var mail = jPrompt(texto, '', texto2, function(r) {
	    if( r ){
	    	var ruta = 'ajax/datosCorredor_2.php?mail='+r;
			$('#envio_inscripcion').slideDown();
			$.getJSON(ruta, function(data) {
				if (data.existe == '0'){
					if (idioma == 1){
						jAlert ("El e-Mail indicado no se encuentra en nuestra base de datos");
					}else{
						jAlert ("The e-Mail you is not found in our database");
					}
				}else{
					document.frmNuevaInscripcion.nombreCorredor.value = data.nombre;
					document.frmNuevaInscripcion.apellido1Corredor.value = data.apellido1;
					document.frmNuevaInscripcion.apellido2Corredor.value = data.apellido2;
					document.frmNuevaInscripcion.dniCorredor.value = data.dni;
					datosNacimiento = data.fNacimiento;
					arrayNacimiento = datosNacimiento.split("-");
					combo = document.frmNuevaInscripcion.diaNacimiento;
					cantidad = combo.length;
					for (i = 0; i < cantidad; i++) {
						if (combo[i].value == arrayNacimiento[0]) {
							combo[i].selected = true;
					    }   
					}
					combo = document.frmNuevaInscripcion.mesNacimiento;
					cantidad = combo.length;
					for (i = 0; i < cantidad; i++) {
						if (combo[i].value == arrayNacimiento[1]) {
							combo[i].selected = true;
					    }   
					}
					combo = document.frmNuevaInscripcion.anoNacimiento;
					cantidad = combo.length;
					for (i = 0; i < cantidad; i++) {
						if (combo[i].value == arrayNacimiento[2]) {
							combo[i].selected = true;
					    }   
					}
					document.frmNuevaInscripcion.direccionCorredor.value = data.direccion;
					document.frmNuevaInscripcion.localidadCorredor.value = data.localidad;
					combo = document.frmNuevaInscripcion.provinciaCorredor;
					cantidad = combo.length;
					for (i = 0; i < cantidad; i++) {
						if (combo[i].value == data.provincia) {
							combo[i].selected = true;
					    }   
					}
					document.frmNuevaInscripcion.cpCorredor.value = data.cp;
					combo = document.frmNuevaInscripcion.paisCorredor;
					cantidad = combo.length;
					for (i = 0; i < cantidad; i++) {
						if (combo[i].value == data.pais) {
							combo[i].selected = true;
					    }   
					}
					document.frmNuevaInscripcion.telefonoCorredor.value = data.telefono;
					document.frmNuevaInscripcion.mailCorredor.value = data.mail;
					combo = document.frmNuevaInscripcion.tallaCorredor;
					cantidad = combo.length;
					for (i = 0; i < cantidad; i++) {
						if (combo[i].value == data.talla) {
							combo[i].selected = true;
					    }   
					}
					document.frmNuevaInscripcion.profesionCorredor.value = data.profesion;
					combo = document.frmNuevaInscripcion.ecivilCorredor;
					cantidad = combo.length;
					for (i = 0; i < cantidad; i++) {
						if (combo[i].value == data.ecivil) {
							combo[i].selected = true;
					    }   
					}
					document.frmNuevaInscripcion.personaAviso.value = data.personaaviso;
					document.frmNuevaInscripcion.telefonoAviso.value = data.telefonoaviso;
				}
				$('#envio_inscripcion').slideUp();
			});
	    }
	});
	
}

function cambioSalida(salida){
	if (salida.value == 100){
		$("#divOtraCiudad").slideDown();
	}else{
		$("#divOtraCiudad").slideUp();
	}
}
