function stopModule() {
	document.getElementById("gomodule").style.visibility = 'hidden';
}


function restartModule() {
	document.getElementById("gomodule").style.visibility = 'visible';
}


function elabora(bookingok) {

var arrivo_gg = document.getElementById("arrivo_gg").value;
var arrivo_mm = document.getElementById("arrivo_mm").value;
var arrivo_aa = document.getElementById("arrivo_aa").value;

if(arrivo_gg=="" | arrivo_mm=="" | arrivo_aa=="") {
	 alert('E\' necessario specificare correttamente la data di arrivo!');		
	 return false;
}

var notti = document.getElementById("notti").value;

if(notti=="" | typeof notti=="undefined") {
	 alert('E\' necessario specificare il numero di notti!');		
	 return false;
}

var camere = document.getElementById("camere").value;

if(camere=="" | typeof camere=="undefined") {
	 alert('E\' necessario specificare il numero di camere!');		
	 return false;
}

var trattamento = document.getElementById("trattamento").value;

if(trattamento=="" | typeof trattamento=="undefined") {
	 alert('E\' necessario specificare il tipo di trattamento!');		
	 return false;
}

if(camere >1) {
   elabora_due(arrivo_gg,arrivo_mm,arrivo_aa,notti,camere,trattamento,bookingok);
}else{
   elabora_una(arrivo_gg,arrivo_mm,arrivo_aa,notti,camere,trattamento,bookingok);
}

}


function elabora_una(arrivo_gg,arrivo_mm,arrivo_aa,notti,camere,trattamento,bookingok) {

var adulti = document.getElementById("adulti").value;

if(adulti=="" | typeof adulti=="undefined") {
	 alert('E\' necessario specificare il numero di adulti!');		
	 return false;
}

var bambini = document.getElementById("bambini").value;

var bambinoEta = document.getElementById("bambinoEta").value;

if(bambini & bambinoEta=='') {
	 alert('E\' necessario specificare l\'età del bambino!');		
	 return false;
}

var tipologia = document.getElementById("tipologia").value;

if(tipologia=="" | typeof tipologia=="undefined") {
	 alert('E\' necessario specificare la tipologia!');		
	 return false;
}

var totPersone = parseFloat(document.getElementById("adulti").value) + parseFloat(document.getElementById("bambini").value);

if(totPersone>3) {
	 alert('Attenzione si possono indicare fino a 3 persone al MASSIMO per camera!');		
	 return false;
}


     if(bookingok == 1) {

     var nome = document.getElementById("nome").value;
     var cognome = document.getElementById("cognome").value;
     var indirizzo = document.getElementById("indirizzo").value;
     var cap = document.getElementById("cap").value;
     var localita = document.getElementById("localita").value;
     var provincia = document.getElementById("provincia").value;
     var nazione = document.getElementById("nazione").value;
     var telefono = document.getElementById("telefono").value;
     var email = document.getElementById("email").value;
     var cellulare = document.getElementById("cellulare").value;
     var fax = document.getElementById("fax").value;
     var note = document.getElementById("note").value;
     var trattamentoNomi = document.getElementById("trattamentoNomi").value;

     var url = "booking.php?on=1&bookingok=1&arrivo_gg=" + escape(arrivo_gg) + "&arrivo_mm=" + escape(arrivo_mm) + "&arrivo_aa=" + escape(arrivo_aa) + "&notti=" + escape(notti) + "&camere=" + escape(camere) + "&adulti=" + escape(adulti) + "&bambini=" + escape(bambini) + "&bambinoEta=" + escape(bambinoEta) + "&tipologia=" + escape(tipologia) + "&trattamento=" + escape(trattamento) + "&nome=" + escape(nome) + "&cognome=" + escape(cognome)
		+"&indirizzo="+escape(indirizzo) + "&cap="+escape(cap) + "&localita=" + escape(localita) + "&provincia=" + escape(provincia) + "&nazione=" + escape(nazione) + "&telefono=" + escape(telefono) + "&email=" + escape(email)
		+"&cellulare="+escape(cellulare) + "&fax="+escape(fax) + "&note=" + escape(note) + "&trattamentoNomi=" + escape(trattamentoNomi);
   

     }else{

     var url = "booking.php?on=1&arrivo_gg=" + escape(arrivo_gg) + "&arrivo_mm=" + escape(arrivo_mm) + "&arrivo_aa=" + escape(arrivo_aa) + "&notti=" + escape(notti) + "&camere=" + escape(camere) + "&adulti=" + escape(adulti) + "&bambini=" + escape(bambini) + "&bambinoEta=" + escape(bambinoEta) + "&tipologia=" + escape(tipologia) + "&trattamento=" + escape(trattamento);

     }

     request.open("GET", url, true);
     request.onreadystatechange = updatePage;
     request.send(null);
	 
     }
	
function elabora_due(arrivo_gg,arrivo_mm,arrivo_aa,notti,camere,trattamento,bookingok) {

var adulti1 = document.getElementById("adulti1").value;
var adulti2 = document.getElementById("adulti2").value;

if(adulti1=="" | typeof adulti1=="undefined" | adulti1=="" | typeof adulti2=="undefined") {
	 alert('E\' necessario specificare il numero di adulti!');		
	 return false;
}

var bambini1 = document.getElementById("bambini1").value;
var bambini2 = document.getElementById("bambini2").value;

var bambinoEta1 = document.getElementById("bambinoEta1").value;
var bambinoEta2 = document.getElementById("bambinoEta2").value;

if(bambini1 & bambinoEta1=='') {
	 alert('E\' necessario specificare l\'età del bambino!');		
	 return false;
}

if(bambini2 & bambinoEta2=='') {
	 alert('E\' necessario specificare l\'età del bambino!');		
	 return false;
}

var tipologia1 = document.getElementById("tipologia1").value;
var tipologia2 = document.getElementById("tipologia2").value;

if(tipologia1=="" | typeof tipologia1=="undefined" | tipologia2=="" | typeof tipologia2=="undefined") {
	 alert('E\' necessario specificare la tipologia!');		
	 return false;
}

var totPersone1 = parseFloat(document.getElementById("adulti1").value) + parseFloat(document.getElementById("bambini1").value);


if(totPersone1>3) {
	 alert('Attenzione si possono indicare fino a 3 persone al MASSIMO per camera!');		
	 return false;
}

var totPersone2 = parseFloat(document.getElementById("adulti2").value) + parseFloat(document.getElementById("bambini2").value);


if(totPersone2>3) {
	 alert('Attenzione si possono indicare fino a 3 persone al MASSIMO per camera!');		
	 return false;
}


     if(bookingok == 1) {

     var nome = document.getElementById("nome").value;
     var cognome = document.getElementById("cognome").value;
     var indirizzo = document.getElementById("indirizzo").value;
     var cap = document.getElementById("cap").value;
     var localita = document.getElementById("localita").value;
     var provincia = document.getElementById("provincia").value;
     var nazione = document.getElementById("nazione").value;
     var telefono = document.getElementById("telefono").value;
     var email = document.getElementById("email").value;
     var cellulare = document.getElementById("cellulare").value;
     var fax = document.getElementById("fax").value;
     var note = document.getElementById("note").value;
     var trattamentoNomi = document.getElementById("trattamentoNomi").value;

     var url = "booking.php?on=2&bookingok=1&arrivo_gg=" + escape(arrivo_gg) + "&arrivo_mm=" + escape(arrivo_mm) + "&arrivo_aa=" + escape(arrivo_aa) + "&notti=" + escape(notti) + "&camere=" + escape(camere) + "&adulti1=" + escape(adulti1) + "&bambini1=" + escape(bambini1) + "&adulti2=" + escape(adulti2) + "&bambini2=" + escape(bambini2) + "&bambinoEta1=" + escape(bambinoEta1) +  "&bambinoEta2=" + escape(bambinoEta2) + "&tipologia1=" + escape(tipologia1) + "&tipologia2=" + escape(tipologia2) + "&trattamento=" + escape(trattamento) + "&nome=" + escape(nome) + "&cognome=" + escape(cognome)
		+"&indirizzo="+escape(indirizzo) + "&cap="+escape(cap) + "&localita=" + escape(localita) + "&provincia=" + escape(provincia) + "&nazione=" + escape(nazione) + "&telefono=" + escape(telefono) + "&email=" + escape(email)
		+"&cellulare="+escape(cellulare) + "&fax="+escape(fax) + "&note=" + escape(note) + "&trattamentoNomi=" + escape(trattamentoNomi);
   

     }else{

     var url = "booking.php?on=2&arrivo_gg=" + escape(arrivo_gg) + "&arrivo_mm=" + escape(arrivo_mm) + "&arrivo_aa=" + escape(arrivo_aa) + "&notti=" + escape(notti) + "&camere=" + escape(camere) + "&adulti1=" + escape(adulti1) + "&bambini1=" + escape(bambini1) + "&adulti2=" + escape(adulti2) + "&bambini2=" + escape(bambini2) + "&bambinoEta1=" + escape(bambinoEta1) +  "&bambinoEta2=" + escape(bambinoEta2) + "&tipologia1=" + escape(tipologia1) + "&tipologia2=" + escape(tipologia2) + "&trattamento=" + escape(trattamento);

     }

     
     request.open("GET", url, true);
     request.onreadystatechange = updatePage;
     request.send(null);	 
	}
	
function updatePage() {

     if (request.readyState == 4) {
       if (request.status == 200) {
	      
	     document.getElementById("loading").style.display = 'none';
		 
         var response = request.responseText.split("|");

		if(response[0] == 'ok') {
				document.getElementById("il_tuo_preventivo").innerHTML = response[1].replace(/\n/g, "");
				document.getElementById("booking").style.display = 'block';
				document.getElementById("bookingok").value = 1;
		}

		if(response[0] == 'ko') {
				document.getElementById("booking").style.display = 'none';
				document.getElementById("bookingok").value = '';
		}

		if(response[0] == 'end') {
		document.getElementById("booking").style.display = 'none';
		document.getElementById("bookingok").value = '';
		document.getElementById("una-camera").style.display = 'none';
		document.getElementById("due-camere").style.display = 'none';
		document.getElementById("gomodule").style.display = 'none';
		document.getElementById("trattamento-space").style.display = 'none';
		document.getElementById("loading").style.display = 'block';
		document.getElementById("booking-sending").style.display = 'block';
		document.getElementById("booking-sending").innerHTML = response[1].replace(/\n/g, "");
		setTimeout( "refresh()", 3000 );

		}
		
       } else
         alert("status is " + request.status);
       }
	   
	 if (request.readyState == 1) {  
	 	document.getElementById("loading").style.display = 'block';
	 }
	   
   }


function checkAnagrafica(frm) {
	if (!(frm.nome.value!=""))
	{
		alert("E' obbligatorio inserire il nome!");
		frm.nome.focus();
		return false;
	}
	if (!(frm.cognome.value!=""))
	{
		alert("E' obbligatorio inserire il cognome!");
		frm.cognome.focus();
		return false;
	}	
	if (!(frm.indirizzo.value!=""))
	{
		alert("E' necessario inserire un indirizzo!");
		frm.indirizzo.focus();
		return false;
	}
	if (!(frm.localita.value!=""))
	{
		alert("E' obbligatorio inserire la località!");
		frm.localita.focus();
		return false;
	}
	if (!(frm.provincia.value!=""))
	{
		alert("E' obbligatorio inserire la provincia!");
		frm.provincia.focus();
		return false;
	}
	if (!(frm.nazione.value!=""))
	{
		alert("E' obbligatorio inserire la nazione!");
		frm.nazione.focus();
		return false;
	}
	if (!(frm.telefono.value!=""))
	{
		alert("E' obbligatorio inserire un numero di telefono!");
		frm.telefono.focus();
		return false;
	}	
	if (!(frm.email.value!=""))
	{
		alert("E' obbligatorio inserire l'email!");
		frm.email.focus();
		return false;
	}

	if (!(frm.informativa.checked))
	{
		alert("E' obbligatoria l'autorizzazione al trattamento dati personali!");
		frm.informativa.focus();
		return false;
	}
	
	var bookingok = document.getElementById("bookingok").value;
	elabora(bookingok);

}

function refresh() {
document.getElementById("loading").style.display = 'none';
window.location.reload( true );
}

