﻿// JavaScript Document
function PopupCentrata(collegamento) {
   var w = 650;
   var h = 580;
   var l = Math.floor((screen.width-w)/2);
   var t = Math.floor((screen.height-h)/2);
   window.open(collegamento,"","width=" + w + ",height=" + h + ",top=" + t + ",left=" + l);
}


	function prepareValues(){
		var checkinDay = document.getElementById('checkin_day').value;
		var checkinMonth = document.getElementById('checkin_month').value;
		var checkinYear = document.getElementById('checkin_year').value;
		var checkoutDay = document.getElementById('checkout_day').value;
		var checkoutMonth = document.getElementById('checkout_month').value;
		var checkoutYear = document.getElementById('checkout_year').value;

		var newFormat = checkinYear + '-' + checkinMonth + '-' + checkinDay;
		document.getElementById('checkin').value = newFormat;

		var checkout = Date.UTC(checkoutYear,checkoutMonth,checkoutDay);
		var checkin = Date.UTC(checkinYear,checkinMonth,checkinDay);
		var diff = checkout - checkin;

		if (diff > 0) {
			diff_in_days = diff / 1000 / 60 / 60 / 24;
			document.getElementById('interval').value = diff_in_days;
		}
		

		
		return true;
	}
	


function ctrlPrenotazioniIta() {
	var datasistema = document.prenotazione.datasistema.value;
	var nome = document.prenotazione.nome.value;
	var cognome = document.prenotazione.cognome.value;
	var email = document.prenotazione.email.value;
	var nazione = document.prenotazione.nazione.value;
	var arrivo = document.prenotazione.arrivo.value;
	var partenza = document.prenotazione.partenza.value;
	var classica = document.prenotazione.classica.value;
	var doppia = document.prenotazione.doppia.value;
	var minisuite = document.prenotazione.minisuite.value;
	var totalepersone = document.prenotazione.totalepersone.value;
	

    // Espressione regolare dell'email
     var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;

	if ((nome == "") || (nome == "undefined")) {
           alert("Il campo Nome e' obbligatorio.");
           document.prenotazione.nome.focus();
           return false;
       	}
  if ((cognome == "") || (cognome == "undefined")) {
           alert("Il campo Cognome e' obbligatorio.");
           document.prenotazione.cognome.focus();
           return false;
       	}
  if (!email_reg_exp.test(email) || (email == "") || (email == "undefined")) {
           alert("Inserire un indirizzo email corretto.");
           document.prenotazione.email.focus();
           return false;
       	}
	if ((nazione == "") || (nazione == "undefined")) {
           alert("Il campo Nazione e' obbligatorio.");
           document.prenotazione.nazione.focus();
           return false;
       	}
  if ((arrivo == "") || (arrivo == "undefined")) {
          alert("Indicare la data di arrivo");
          document.prenotazione.arrivo.focus();
          return false;
        }
        if ((partenza == "") || (partenza == "undefined")) {
          alert("Indicare la data di partenza");
          document.prenotazione.partenza.focus();
          return false;
        }
        if (arrivo < datasistema) {
        	alert("La data di arrivo non puo' essere precedente alla data odierna");
        	return false;
        }
        if (partenza < datasistema) {
        	alert("La data di partenza non può essere precedente alla data odierna");
        	return false;
        }
        
        if (partenza <= arrivo) {
        	alert("La data di partenza deve essere successiva alla data di arrivo");
        	return false;
        }
  if (((classica == "0") || (classica == "undefined")) && ((doppia == "0") || (doppia == "undefined")) && ((minisuite == "0") || (minisuite == "undefined")) ) {
           alert("Selezionare almeno un tipo di stanza");
           return false;
       	}
	if ((totalepersone == "0") || (totalepersone == "undefined")) {
           alert("Selezionare il numero totale di ospiti");
           document.prenotazione.totalepersone.focus();
           return false;
       	}
	if (document.prenotazione.accetto.checked == false){
		alert('Impossibile inviare la richiesta\nnon è stata data l\'autorizzazione al trattamento dei dati personali');
		return false;
				}		    
        else {
           return true;
        }
  }
  
function ctrlPrenotazioniEng() {
	var datasistema = document.prenotazione.datasistema.value;
	var nome = document.prenotazione.nome.value;
	var cognome = document.prenotazione.cognome.value;
	var email = document.prenotazione.email.value;
	var nazione = document.prenotazione.nazione.value;
	var arrivo = document.prenotazione.arrivo.value;
	var partenza = document.prenotazione.partenza.value;
	var classica = document.prenotazione.classica.value;
	var doppia = document.prenotazione.doppia.value;
	var minisuite = document.prenotazione.minisuite.value;
	var totalepersone = document.prenotazione.totalepersone.value;
	

    // Espressione regolare dell'email
     var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;

	if ((nome == "") || (nome == "undefined")) {
           alert("Name is required.");
           document.prenotazione.nome.focus();
           return false;
       	}
  if ((cognome == "") || (cognome == "undefined")) {
           alert("Last Name is required.");
           document.prenotazione.cognome.focus();
           return false;
       	}
  if (!email_reg_exp.test(email) || (email == "") || (email == "undefined")) {
           alert("E-mail Address is required and it must be correct.");
           document.prenotazione.email.focus();
           return false;
       	}
  if ((nazione == "") || (nazione == "undefined")) {
           alert("Country is required.");
           document.prenotazione.nazione.focus();
           return false;
       	}
  if ((arrivo == "") || (arrivo == "undefined")) {
          alert("Check-in Date is required");
          document.prenotazione.arrivo.focus();
          return false;
        }
        if ((partenza == "") || (partenza == "undefined")) {
          alert("Check-out Date is required");
          document.prenotazione.partenza.focus();
          return false;
        }
        if (arrivo < datasistema) {
        	alert("Check-in Date can't be earlier than today");
        	return false;
        }
        if (partenza < datasistema) {
        	alert("Check-out Date can't be earlier than today");
        	return false;
        }
        
        if (partenza <= arrivo) {
        	alert("Check-out Date must be after Check-in Date");
        	return false;
        }
  if (((classica == "0") || (classica == "undefined")) && ((doppia == "0") || (doppia == "undefined")) && ((minisuite == "0") || (minisuite == "undefined")) ) {
           alert("Select type of room");
           return false;
       	}
	if ((totalepersone == "0") || (totalepersone == "undefined")) {
           alert("Select Total Guests");
           document.prenotazione.totalepersone.focus();
           return false;
       	}
	 if (document.prenotazione.accetto.checked == false){
		alert('You must give consent to the processing of personal data');
		return false;
				}   
        else {
           return true;
        }
  }
  
 function ctrlPrenotazioniFra() {
	var datasistema = document.prenotazione.datasistema.value;
	var nome = document.prenotazione.nome.value;
	var cognome = document.prenotazione.cognome.value;
	var email = document.prenotazione.email.value;
	var nazione = document.prenotazione.nazione.value;
	var arrivo = document.prenotazione.arrivo.value;
	var partenza = document.prenotazione.partenza.value;
	var classica = document.prenotazione.classica.value;
	var doppia = document.prenotazione.doppia.value;
	var minisuite = document.prenotazione.minisuite.value;
	var totalepersone = document.prenotazione.totalepersone.value;
	

    // Espressione regolare dell'email
     var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;

	if ((nome == "") || (nome == "undefined")) {
           alert("le camp 'Prénom' est obligatoire.");
           document.prenotazione.nome.focus();
           return false;
       	}
  if ((cognome == "") || (cognome == "undefined")) {
           alert("le camp 'Nom de famille' est obligatoire.");
           document.prenotazione.cognome.focus();
           return false;
       	}
  if (!email_reg_exp.test(email) || (email == "") || (email == "undefined")) {
           alert("Inserer un adresse e-mail correct.");
           document.prenotazione.email.focus();
           return false;
       	}
  if ((nazione == "") || (nazione == "undefined")) {
           alert("Indiquer le pays de provénence.");
           document.prenotazione.nazione.focus();
           return false;
       	}
  if ((arrivo == "") || (arrivo == "undefined")) {
          alert("Indiquer la date d'arrivée.");
          document.prenotazione.arrivo.focus();
          return false;
        }
        if ((partenza == "") || (partenza == "undefined")) {
          alert("Indiquer la date de départ.");
          document.prenotazione.partenza.focus();
          return false;
        }
        if (arrivo < datasistema) {
        	alert("La date d'arrivée ne peut pas être précedente à celle d'aujourd'hui");
        	return false;
        }
        if (partenza < datasistema) {
        	alert("La date de départ ne peut pas être précedente à celle d'aujourd'hui");
        	return false;
        }
        
        if (partenza <= arrivo) {
        	alert("La date de départ doit suivre celle d'arrivée");
        	return false;
        }
  if (((classica == "0") || (classica == "undefined")) && ((doppia == "0") || (doppia == "undefined")) && ((minisuite == "0") || (minisuite == "undefined")) ) {
           alert("Selectioner au moin une catégorie de chambres");
           return false;
       	}
	if ((totalepersone == "0") || (totalepersone == "undefined")) {
           alert("Selectioner le nombre total de personnes");
           document.prenotazione.totalepersone.focus();
           return false;
       	}
	 if (document.prenotazione.accetto.checked == false){
		alert('Il est necessaire de donner la permission au traitement des donnés personnels');
		return false;
				}   
        else {
           return true;
        }
  }
  
  function ctrlPrenotazioniSpa() {
	var datasistema = document.prenotazione.datasistema.value;
	var nome = document.prenotazione.nome.value;
	var cognome = document.prenotazione.cognome.value;
	var email = document.prenotazione.email.value;
	var nazione = document.prenotazione.nazione.value;
	var arrivo = document.prenotazione.arrivo.value;
	var partenza = document.prenotazione.partenza.value;
	var classica = document.prenotazione.classica.value;
	var doppia = document.prenotazione.doppia.value;
	var minisuite = document.prenotazione.minisuite.value;
	var totalepersone = document.prenotazione.totalepersone.value;
	

    // Espressione regolare dell'email
     var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;

	if ((nome == "") || (nome == "undefined")) {
           alert("El nombre es obligatorio.");
           document.prenotazione.nome.focus();
           return false;
       	}
  if ((cognome == "") || (cognome == "undefined")) {
           alert("El apellido es obligatorio.");
           document.prenotazione.cognome.focus();
           return false;
       	}
  if (!email_reg_exp.test(email) || (email == "") || (email == "undefined")) {
           alert("Escriba una dirección válida de correo electrónico.");
           document.prenotazione.email.focus();
           return false;
       	}
  if ((nazione == "") || (nazione == "undefined")) {
           alert("Indicar el país de origen.");
           document.prenotazione.nazione.focus();
           return false;
       	}
  if ((arrivo == "") || (arrivo == "undefined")) {
          alert("Indicar la fecha de llegada.");
          document.prenotazione.arrivo.focus();
          return false;
        }
        if ((partenza == "") || (partenza == "undefined")) {
          alert("Indicar la fecha de salida.");
          document.prenotazione.partenza.focus();
          return false;
        }
        if (arrivo < datasistema) {
        	alert("La fecha de llegada no puede ser anterior al día de hoy.");
        	return false;
        }
        if (partenza < datasistema) {
        	alert("La fecha de salida no puede ser anterior al día de llegada.");
        	return false;
        }
        
        if (partenza <= arrivo) {
        	alert("La fecha de salida deberá ser posterior a la fecha de llegada.");
        	return false;
        }
  if (((classica == "0") || (classica == "undefined")) && ((doppia == "0") || (doppia == "undefined")) && ((minisuite == "0") || (minisuite == "undefined")) ) {
           alert("Seleccione al menos un tipo de habitación.");
           return false;
       	}
	if ((totalepersone == "0") || (totalepersone == "undefined")) {
           alert("Seleccione el número total de clientes.");
           document.prenotazione.totalepersone.focus();
           return false;
       	}
	 if (document.prenotazione.accetto.checked == false){
		alert('Es necesario dar su consentimiento al tratamiento de datos personales.');
		return false;
				}   
        else {
           return true;
        }
  }
