/*########## Inizio funzioni guestbook ##########*/
function checkPost(){
	if (self.document.frmPost.nome.value==""){
		alert("ATTENZIONE!\nInserire il tuo nome.");
		self.document.frmPost.nome.focus();
		return false;
	}
	if (self.document.frmPost.messaggio.value==""){
		alert("ATTENZIONE!\nInserire il messaggio.");
		self.document.frmPost.messaggio.focus();
		return false;
	}
	return true;
}
/*########## Fine funzioni guestbook ##########*/

/*########## Inizio funzioni prenotazioni ##########*/
function checkRichiesta(){
	if (self.document.frmRichiesta.cognome_nome.value==""){
		alert("ATTENZIONE!\nInserire il tuo cognome e nome.");
		self.document.frmRichiesta.cognome_nome.focus();
		return false;
	}
	
	if (self.document.frmRichiesta.indirizzo.value==""){
		alert("ATTENZIONE!\nInserire il tuo indirizzo.");
		self.document.frmRichiesta.indirizzo.focus();
		return false;
	}
	if (self.document.frmRichiesta.telefono.value==""){
		alert("ATTENZIONE!\nInserire il tuo telefono.");
		self.document.frmRichiesta.telefono.focus();
		return false;
	}
	
	//VALORI EMAIL
	var regExpEmail = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
	if (!(regExpEmail.test(self.document.frmRichiesta.email.value))) {
		alert ("Attenzione!\nInserire per il campo [email] un indirizzo di posta elettronica valido.");
		return false;
	}
	
	if (self.document.frmRichiesta.persone.value==""){
		alert("ATTENZIONE!\nInserire il numero delle persone.");
		self.document.frmRichiesta.persone.focus();
		return false;
	}
	if (isNaN(self.document.frmRichiesta.persone.value)){
		alert("ATTENZIONE!\nInserire solo valori numerici per indicare il numero delle persone.");
		self.document.frmRichiesta.persone.focus();
		return false;
	}
	if (self.document.frmRichiesta.camere.value==""){
		alert("ATTENZIONE!\nInserire il numero delle camere.");
		self.document.frmRichiesta.camere.focus();
		return false;
	}
	if (isNaN(self.document.frmRichiesta.camere.value)){
		alert("ATTENZIONE!\nInserire solo valori numerici per indicare il numero delle camere.");
		self.document.frmRichiesta.camere.focus();
		return false;
	}
	if (self.document.frmRichiesta.data_arrivo.value==""){
		alert("ATTENZIONE!\nInserire la data di arrivo.");
		self.document.frmRichiesta.data_arrivo.focus();
		return false;
	}
	if (self.document.frmRichiesta.data_partenza.value==""){
		alert("ATTENZIONE!\nInserire la data di partenza.");
		self.document.frmRichiesta.data_partenza.focus();
		return false;
	}
	if (self.document.frmRichiesta.autorizzazione.checked == false ){
		alert("ATTENZIONE!\nE' obbligatorio accettare il trattamento dei dati personali per preseguire.");
		return false;
	}
	
	return true;
}

function checkDate(Campo, Tipo) {
	eval("Val=self.document.frmRichiesta." + Campo + ".value;");
	if (Val.length>0) {
		eval("self.document.frmRichiesta." + Campo + ".style.backgroundColor='#FFFFFF';");
	}
	if (Tipo=='Data'&&Val.length>0) {
		Temp=Val.toString();
		Data_vet=Temp.split("/");
		num=Data_vet.length;
		Errore=false;
		if (num==3) {
			if (isNaN(Data_vet[0])||isNaN(Data_vet[1])||isNaN(Data_vet[2])) {Errore=true}
			if (!Errore) {
				if (Data_vet[2]<1900||Data_vet[2]>2100||Data_vet[0]<1||Data_vet[0]>31||Data_vet[1]<1||Data_vet[1]>12) {Errore=true}
			}
		} else {
			Errore=true
		}
		if (Errore) {
			alert("Attenzione! \nLe date vanno inserite nella forma gg/mm/aaaa")
			eval('self.document.frmRichiesta.' + Campo + '.value="";');
			eval('self.document.frmRichiesta.' + Campo + '.focus();');
		} else {
			if (Data_vet[0].length==1||Data_vet[1].length==1) {
				if (Data_vet[0].length==1) {Data_vet[0]='0'+Data_vet[0].toString()}
				if (Data_vet[1].length==1) {Data_vet[1]='0'+Data_vet[1].toString()}
				Temp=Data_vet[0]+'/'+Data_vet[1]+'/'+Data_vet[2];
				eval('self.document.frmRichiesta.' + Campo + '.value=Temp;');
			}
		}
	}
}
/*########## Fine funzioni prenotazioni ##########*/

/*########## Inizio funzioni generali ##########*/
function popUp(nome_pagina,w,h) {
    	var l = Math.floor((screen.width-w)/2);
    	var t = Math.floor((screen.height-h)/2);
        window.open(nome_pagina,"","width=" + w + ",height=" + h + ",top=" + t + ",left=" + l + ",resizable=no, menubar=no, scrollbars=yes");
}
/*########## Fine funzioni generali ##########*/
