// JavaScript Document
function mostrarTexto(bloque, ver)
{
	if (ver=="siempre"){
		document.getElementById(bloque).style.display = 'block'
	}
	else {
		texto=document.getElementById(bloque).style.display;
		if (texto=='none')
			texto='block';
		else
			texto='none';
		document.getElementById(bloque).style.display = texto;
	}
}

function mostrar360(pelicula)
{
	switch (pelicula) {
		case "primero":
			document.getElementById("primero").style.display = 'block';
			document.getElementById("segundo").style.display = 'none';
			document.getElementById("tercero").style.display = 'none';
			break;
		case "segundo":
			document.getElementById("primero").style.display = 'none';
			document.getElementById("segundo").style.display = 'block';
			document.getElementById("tercero").style.display = 'none';
			break;
		case "tercero":
			document.getElementById("primero").style.display = 'none';
			document.getElementById("segundo").style.display = 'none';
			document.getElementById("tercero").style.display = 'block';
			break;
	}
	return true;
}

function cargarImagen(imagenSrc)
{
	window.document.imagenprincipal.src = imagenSrc;
}

function validaContacto()
{
    //Validar el nombre
    if (document.formulario.nombre_contacto.value.length==0){
       alert("Escriba su nombre");
       document.formulario.nombre_contacto.focus();
       return false;
    }
		
    //Validar los apellidos
    if (document.formulario.apellido_contacto.value.length==0){
       alert("Escriba sus apellidos");
       document.formulario.apellido_contacto.focus();
       return false;
    }

	//Validar el correo electronico
    if (document.formulario.correo_electronico.value.length==0){
       alert("Escriba un email");
       document.formulario.correo_electronico.focus();
       return false;
    }
	else {
		if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.formulario.correo_electronico.value))) {
			alert("Escriba un email correcto");
       		document.formulario.correo_electronico.focus();
       		return false;	   
		}
	}
	
     //Validar el texto de consulta
    if (document.formulario.consulta.value.length==0){
       alert("Escriba su consulta");
       document.formulario.consulta.focus();
       return false;
    }
	return true;
}

function validaReserva() 
{
	//Validar el nombre
    if (document.reserva.nombre_contacto.value.length==0){
       alert("Escriba su nombre");
       document.reserva.nombre_contacto.focus();
       return false;
    }
		
    //Validar los apellidos
    if (document.reserva.apellido_contacto.value.length==0){
       alert("Escriba sus apellidos");
       document.reserva.apellido_contacto.focus();
       return false;
    }

	//Validar DNI/NIE/Pasaporte
	if (document.reserva.dni_contacto.value.length==0) 
    {
      document.reserva.dni_contacto.focus();  
      alert ("Debe facilitarnos un número de documento que le identifique.");
      return false;
    }
	else {
   		var letras=0;
    	for (var i=0; i<document.reserva.dni_contacto.value.length; i++) 
    	{
      		var ch = document.reserva.dni_contacto.value.substring (i, i+1);
      		if ( (ch < "0" || ch > "9") && (ch < "a" || ch > "z") && (ch < "A" || ch > "Z") )
      		{
        		document.reserva.dni_contacto.focus();
        		alert("El número de documento identificativo facilitado no es correcto.");
       		 return false;
     		 }
     		 if ( (ch >= "a" && ch <= "z") || (ch >= "A" && ch <= "Z") )
     		 {
       			 letras++;
      		 }  
    	}
   		if (letras>1)
    	{
     		document.reserva.dni_contacto.focus();
      		alert("El número de documento identificativo facilitado no es correcto");
      		return false;
    	}
	}

	//Validar número de teléfono
	if (document.reserva.telefono_contacto.value.length==0){
		alert("Escriba un número de teléfono");
    	document.reserva.telefono_contacto.focus();
    	return false;
    }
	else {
		if (!(/^(?:\+|-)?\d+$/.test(document.reserva.telefono_contacto.value))) {
			alert("Escriba un número de teléfono correcto");
       		document.reserva.telefono_contacto.focus();
       		return false;	   
		}
	}

	//Validar el correo electronico
    if (document.reserva.correo_electronico.value.length==0){
       alert("Escriba un email");
       document.reserva.correo_electronico.focus();
       return false;
    }
	else {
		if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.reserva.correo_electronico.value))) {
			alert("Escriba un email correcto");
       		document.reserva.correo_electronico.focus();
       		return false;	   
		}
	}

	//Validar el número de adultos
	esNumero = parseInt(document.reserva.adulto_contacto.value);
	if (isNaN(esNumero)) {
		alert("Escriba un número de adultos válido, de 1 a 10");
		document.reserva.adulto_contacto.focus();
		return false;
	}
	else {
		if (document.reserva.adulto_contacto.value <= 0) {
			alert("Escriba un número de adultos mayor que 0");
   			document.reserva.adulto_contacto.focus();
   			return false;	   
		}
	}

	//Validar la casa seleccionada
	if ((!document.reserva.pajarcheck_contacto.checked) && (!document.reserva.labranzacheck_contacto.checked)){
		alert("Seleccione una de las casas disponibles.");
		document.reserva.pajarcheck_contacto.focus();
		return false;
	}
	
	//Validar la aceptación de condiciones de contratación y reserva
	if (!document.reserva.acepto_contacto[0].checked) {
		alert("No ha aceptado las condiciones de contratación y reserva.");
		document.reserva.consulta.focus();
		return false;
	}
	//Validar fecha de entrada y salida
	fechaEntrada = document.reserva.fecha_entrada.value.split('/')
	fechaSalida = document.reserva.fecha_salida.value.split('/')
	if (parseInt(fechaEntrada[2],10) < parseInt(fechaSalida[2],10)) return true;
	if (parseInt(fechaEntrada[1],10) < parseInt(fechaSalida[1],10)) return true;
	if (parseInt(fechaEntrada[0],10) < parseInt(fechaSalida[0],10)) return true;
	else 
	{
		alert("La fecha de salida debe ser posterior a la fecha de entrada.");
		document.reserva.fecha_salida.focus();
		return false;
	}
	return true;
}