// JavaScript Document
function controlPrenotazione(){
	
		d = new Date(); 
		giorno = d.getDate() >= 10 ? d.getDate() : '0'+d.getDate();
		mese = (d.getMonth() + 1) >= 10 ? (d.getMonth() + 1) : '0'+ (d.getMonth() + 1) 
		data = d.getFullYear() + '/' + mese + '/' + giorno;
		//data = giorno + '/' + mese + '/' + d.getFullYear(); 
				
		var calendar = document.formprenotazioni.calendar.value;
		var calendar2 = document.formprenotazioni.calendar2.value;
		if((calendar=="yyyy/mm/dd") || (calendar=="undefined")){
			alert("Select the check-in date.");
			return false;
			
		}else if(calendar >= calendar2){
			alert("The check-out date must not precede or be the same as the check-in date.");
			return false;
		
		}else if(calendar < data){
			alert("Check-in must not precede today’s date.");
			return false;
		
		}else if((calendar2=="yyyy/mm/dd") || (calendar2=="undefined")){
			alert("Select the check-out date.");
			return false;
		}else{
			return true;
		}
}

function controlPrenotazione2(){
	
		d = new Date(); 
		giorno = d.getDate() >= 10 ? d.getDate() : '0'+d.getDate();
		mese = (d.getMonth() + 1) >= 10 ? (d.getMonth() + 1) : '0'+ (d.getMonth() + 1) 
		data = d.getFullYear() + '/' + mese + '/' + giorno;
		//data = giorno + '/' + mese + '/' + d.getFullYear(); 
				
		var calendar3 = document.formprenotazioni2.calendar3.value;
		var calendar4 = document.formprenotazioni2.calendar4.value;
		if((calendar3=="yyyy/mm/dd") || (calendar3=="undefined")){
			alert("Select the check-in date.");
			return false;
			
		}else if(calendar3 > calendar4){
			alert("The check-out date must not precede or be the same as the check-in date.");
			return false;
		
		}else if(calendar3 < data){
			alert("Check-in must not precede today’s date.");
			return false;
		
		}else if((calendar4=="yyyy/mm/dd") || (calendar4=="undefined")){
			alert("Select the check-out date.");
			return false;
		}else{
			return true;
		}
}

function controlRichieste(){
	var nome = document.richiesta.nome.value;
	var comune = document.richiesta.comune.value;
	var telefono = document.richiesta.telefono.value;
	var email = document.richiesta.email.value;
	var espressione = /^[_a-z0-9+-]+(\.[_a-z0-9+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$/;
	var messaggio = document.richiesta.messaggio.value;
	
			if ((nome == "") || (nome == "undefined")) {
				   alert("The Name field is compulsory.");
				   document.richiesta.nome.focus();
				   return false;
			}else if ((comune == "") || (comune == "undefined")) {
				   alert("The Surname field is compulsory.");
				   document.richiesta.comune.focus();
				   return false;
			}else if ((telefono == "") || (telefono == "undefined")) {
				   alert("The Telephone field is compulsory.");
				   document.richiesta.telefono.focus();
				   return false;
			}else if ((email == "") || (email == "undefined")) {
				   alert("The Email field is compulsory.");
				   document.richiesta.email.focus();
				   return false;
			}else if (!espressione.test(email)) {
				   alert("The Email field must contain a valid email address.");
				   document.richiesta.email.focus();
				   return false;
			}else if ((messaggio == "") || (messaggio == "undefined")) {
				   alert("The Message field is compulsory.");
				   document.richiesta.messaggio.focus();
				   return false;
			}else{
				//Invio modulo
				document.richiesta.action = "sendrichiesta.php";
				document.richiesta.submit();
			}
}