function reset(){
	document.promocion.nombre.value='';
	document.promocion.apellidos.value='';
	document.promocion.direccion.value='';
	document.promocion.cp.value='';
	document.promocion.localidad.value='';
	document.promocion.pais.value='';
	document.promocion.profesion.value='';
	document.promocion.sexo.value='';
	document.promocion.edad.value='';
	document.promocion.email.value='';
	document.promocion.telefono1.value='';
	document.promocion.telefono2.value='';
	document.promocion.horario.value='';
	document.promocion.origen.value='';
	document.promocion.nivel.value='';
	document.promocion.provincia.value='';
	document.promocion.acepto.value='';
}
function validarEdad(obj, lowval, hival) {
	if ((obj.value < lowval) || (obj.value > hival))
      return false
   else return true
}
function validar_enviar(){
	var errores = "";
	//----- VALIDAR CAMPOS ----- //
	if (document.promocion.nombre.value == ''){
		//alert('Nombre debe estar informado');
		//return;
		errores=errores.concat("- Nombre debe estar informado","\n");
	}
	if (document.promocion.apellidos.value == ''){
		//alert('Apellidos debe estar informado');
		//return;
		errores=errores.concat("- Apellidos debe estar informado","\n");
	}
	if (document.promocion.direccion.value == ''){
		//alert('Apellidos debe estar informado');
		//return;
		errores=errores.concat("- Dirección debe estar informado","\n");
	}
	if (document.promocion.cp.value == ''){
		//alert('Código Postal debe estar informado');
		//return;
		errores=errores.concat("- Código Postal debe estar informado","\n");
	} else if( !esNumero( document.promocion.cp.value ) ) {
		errores=errores.concat("- Código Postal debe ser numérico","\n");
	}
	if (document.promocion.localidad.value == ''){
		//alert('Localidad debe estar informado');
		//return;
		errores=errores.concat("- Localidad debe estar informado","\n");
	}
	//------- validar edad
	if(document.promocion.edad.value!="") {
		if (!validarEdad(document.promocion.edad, 2, 99)){
			errores=errores.concat("- Edad debe ser entre 2 y 99 años","\n");
		}
	} 
	//------- validar email
	var value = document.promocion.email.value;
	var laststring = value.substring(value.indexOf("@"),value.length);		
	if (document.promocion.email.value == ''){
		//alert('Email debe estar informado');
		//return;
		errores=errores.concat("- Email debe estar informado","\n");
	} else {
				
	if(value.indexOf("@") == -1){
			//alert('Email con formato incorrecto');
			//return;
			errores=errores.concat("- Email con formato incorrecto","\n");
	} else if(value.indexOf("@") == 0){
				//alert('Email con formato incorrecto');
				//return;
				errores=errores.concat("- Email con formato incorrecto","\n");
		} else if(laststring.indexOf(".") == -1){
					//alert('Email con formato incorrecto');
					//return;
					errores=errores.concat("- Email con formato incorrecto","\n");
				} else if(laststring.indexOf(".") == 0){
					//alert('Email con formato incorrecto');
					//return;
					errores=errores.concat("- Email con formato incorrecto","\n");
					}
						else if(laststring.charAt(laststring.length-1) == '.'){
							//alert('Email con formato incorrecto');
							//return;
							errores=errores.concat("- Email con formato incorrecto","\n");
						}
	}
	if (document.promocion.telefono1.value == ''){
		//alert('Teléfono de contacto 1 debe estar informado');
		//return;
		errores=errores.concat("- Teléfono de contacto 1 debe estar informado","\n");
	} else if( !esNumero( document.promocion.telefono1.value ) ) {
		errores=errores.concat("- Teléfono de contacto 1 debe ser numérico","\n");
	}
	
	if( document.promocion.telefono2.value != '' && !esNumero(document.promocion.telefono2.value) ) {
		errores=errores.concat("- Teléfono de contacto 2 debe ser numérico","\n");
	}
	
	if (document.promocion.horario.value == ''){
		//alert('Horario de contacto debe estar informado');
		//return;
		errores=errores.concat("- Horario de contacto debe estar informado","\n");
	} 
	
	if (document.promocion.acepto.checked == false){
		//alert('Debe aceptar las condiciones de privacidad');
		//return;
		errores=errores.concat("- Debes aceptar las condiciones de privacidad","\n");
	}
	if (errores == "") document.promocion.submit();
	else alert(errores);
	
				 
}

function validar_enviar_td(){
	var errores = "";
	//----- VALIDAR CAMPOS ----- //
	if (document.promocion.nombre.value == ''){
		//alert('Nombre debe estar informado');
		//return;
		errores=errores.concat("- Nombre debe estar informado","\n");
	}
	if (document.promocion.apellidos.value == ''){
		//alert('Apellidos debe estar informado');
		//return;
		errores=errores.concat("- Apellidos debe estar informado","\n");
	}
	if (document.promocion.direccion.value == ''){
		//alert('Apellidos debe estar informado');
		//return;
		errores=errores.concat("- Dirección debe estar informado","\n");
	}
	if (document.promocion.cp.value == ''){
		//alert('Código Postal debe estar informado');
		//return;
		errores=errores.concat("- Código Postal debe estar informado","\n");
	} else if( !esNumero( document.promocion.cp.value ) ) {
		errores=errores.concat("- Código Postal debe ser numérico","\n");
	}
	if (document.promocion.localidad.value == ''){
		//alert('Localidad debe estar informado');
		//return;
		errores=errores.concat("- Localidad debe estar informado","\n");
	}
	//------- validar email
	var value = document.promocion.email.value;
	var laststring = value.substring(value.indexOf("@"),value.length);		
	if (document.promocion.email.value == ''){
		//alert('Email debe estar informado');
		//return;
		errores=errores.concat("- Email debe estar informado","\n");
	} else {
				
	if(value.indexOf("@") == -1){
			//alert('Email con formato incorrecto');
			//return;
			errores=errores.concat("- Email con formato incorrecto","\n");
	} else if(value.indexOf("@") == 0){
				//alert('Email con formato incorrecto');
				//return;
				errores=errores.concat("- Email con formato incorrecto","\n");
		} else if(laststring.indexOf(".") == -1){
					//alert('Email con formato incorrecto');
					//return;
					errores=errores.concat("- Email con formato incorrecto","\n");
				} else if(laststring.indexOf(".") == 0){
					//alert('Email con formato incorrecto');
					//return;
					errores=errores.concat("- Email con formato incorrecto","\n");
					}
						else if(laststring.charAt(laststring.length-1) == '.'){
							//alert('Email con formato incorrecto');
							//return;
							errores=errores.concat("- Email con formato incorrecto","\n");
						}
	}
	if (document.promocion.telefono1.value == ''){
		//alert('Teléfono de contacto 1 debe estar informado');
		//return;
		errores=errores.concat("- Teléfono de contacto 1 debe estar informado","\n");
	} else if( !esNumero( document.promocion.telefono1.value ) ) {
		errores=errores.concat("- Teléfono de contacto 1 debe ser numérico","\n");
	}
	
	if( document.promocion.telefono2.value != '' && !esNumero(document.promocion.telefono2.value) ) {
		errores=errores.concat("- Teléfono de contacto 2 debe ser numérico","\n");
	}
	
	if (errores == "") document.promocion.submit();
	else alert(errores);
	
				 
}

function esNumero(numero) {
	return /^\d+$/.test(numero);
}