//controlla se la seconda data è successiva alla prima    
function confronta_data(data1, data2){

	//trasformo le date nel formato aaaammgg (es. 20081103)        
	data1str = data1.substr(6)+data1.substr(3, 2)+data1.substr(0, 2);		
	data2str = data2.substr(6)+data2.substr(3, 2)+data2.substr(0, 2);
		
	return (data2str-data1str)

}
//---------------------------------------------
function valiDate(f,error) {

	var dmy = f.split(/\//);
	var td = new Date( dmy[2], dmy[1]-1, dmy[0] );
	var result = (td.getFullYear() == parseInt(dmy[2],10) && td.getMonth() == parseInt(dmy[1]-1,10) && td.getDate() == parseInt(dmy[0],10));
	if (result == false) {
		return false;
	}	
}


//---------------------------------------------
//1. Selezione periodo/adulti/camere/vincoli in base a configurazione
function checkForm1(form,lingua) {	
	
	if (lingua=='ENG') {
		error1='Select arrival date'
		error2='Select departure date'
		error3='The arrival date must be before the departure date'
		error4='The arrival date must be greater than today'
		error5='The number of rooms cannot be greater than the number of guests'
		error6='Minimum number of night is '
		error7a='You can book maximum '
		error7b=' nights'
		error8a='Arrivals on '
		error8b=' are not allowed'
		error9='Select arrival time'		
	} else {
		error1='Selezionare la data di arrivo'
		error2='Selezionare la data di partenza'
		error3='La data di arrivo deve essere precedente a quella di partenza'
		error4='La data di arrivo deve essere successiva alla data odierna'
		error5='Il numero di camere non può essere superiore al numero di adulti dichiarati'
		error6='Il numero minimo di notti è '
		error7a='Sono prenotabili al massimo '
		error7b=' notti'
		error8a='Arrivi di '
		error8b=' non consentiti'
		error9='Selezionare l\'ora indicativa di arrivo'
	}
	
	//CONTROLLO DATE
	var DataDa = document.getElementById('DataDa').value
	var DataA = document.getElementById('DataA').value
	
	if (DataDa=='') {
		alert(error1);
		return false;
	}

	if (DataA=='') {
		alert(error2);
		return false;
	}	
	
	//Verifica sequenza date arrivo/partenza
	var ControlloData = DateDiff('d',DataYYYYYMMDD(DataDa),DataYYYYYMMDD(DataA));
	
	if (ControlloData<=0) {            
		alert(error3);
		return false;       
	}	
	
	//Verifica data arrivo vs data odierna	
	var today = new Date();
	
	var gg = today.getDate();
	if (gg < 10) {
		var gg = "0" + gg;
	}
		
	var mm = today.getMonth()+1;
	if (mm < 10) {
		var mm = "0" + mm;
	}	
	
	var yyyy = today.getFullYear();
	
	oggi = gg + "/" + mm + "/" + yyyy;
	
	var ControlloData2 = DateDiff('d',DataYYYYYMMDD(oggi),DataYYYYYMMDD(DataA));
	
	if (ControlloData2<=0) {            
		alert(error4);
		return false;       
	}
	
	//Ora di arrivo
	if (document.getElementById('OraArrivo').value=='0' && document.getElementById('RichiestaOraArrivo').value=='True') {
		alert(error9);
		return false;
	}	
	
	//CONTROLLO ADULTI>=CAMERE
	var Adulti = document.getElementById('Adulti').value
	var Camere = document.getElementById('Camere').value
	
	if (Camere>Adulti) {            
		alert(error5);
		return false;       
	}	
	
	//CONTROLLI VINCOLI DA CONFIGURAZIONE (converte la data per uso di getDay)
	//N° Min di notti
	var NottiMin = document.getElementById('NottiMin').value
	if (ControlloData<NottiMin) {
		alert(error6+NottiMin)
		return false;
	}
	
	//N° Max di notti
	var NottiMax = document.getElementById('NottiMax').value
	if (ControlloData>NottiMax) {
		alert(error7a + NottiMax + error7b)
		return false;
	}	
		
	//Giorni con arrivi non consentiti
	DataArrivo = new Date(DataYYYYYMMDD(DataDa))
	
	var myDays=["domenica","lunedì","martedì","mercoledì","giovedì","venerdì","sabato","domenica"]
	var GiornoSettimana = DataArrivo.getDay()+1
	//Se esiste hidden -> giorno di arrivo non consentito
	//0=domenica, nel db 1
	if (document.getElementById('Giorno'+String(GiornoSettimana))) {
		alert(error8a +myDays[GiornoSettimana-1]+ error8b)
		return false;
	}		
	
	return true;
}
//----------------------------------------------------------

//---------------------------------------------
//3. Dati personali
function checkForm3(form,lingua) {	

	if (lingua=='ENG') {
		error1='Name needed'
		error8='Phone needed'
		error9='Email needed'		
	} else {
		error1='Nome obbligatorio'
		error8='Telefono obbligatorio'
		error9='Email obbligatoria'
	}
		
	if (form.Referente.value == "")  {
		alert(error1)
		form.Referente.focus()
		form.Referente.select()
		return false;      
	}
	
	if (form.telefono.value == "")  {
		alert (error8)
		form.telefono.focus()
		form.telefono.select()
		return false;      
	}	
	
	if (form.email.value == "")  {
		alert (error9)
		form.email.focus()
		form.email.select()
		return false;      
	}
	
	if (isEmail(form.email.value)==false) {
		alert ("L'indirizzo email inserito non è corretto!")
		form.email.focus()
		form.email.select()
		return(false);}	
			
	return true;
}
//----------------------------------------------------------





