window.addEvent('domready', function() {

	$('myForm').addEvent('submit', function(e) {
		//Prevents the default submit event from loading a new page.
		e.stop();
		var ok = true;
		if ($('cognome').value == "") {
			ok = false;
			alert("Manca il cognome");
		}
		if ((ok) && ($('nome').value=="")) {
			ok = false;
			alert("Manca il nome");
		}
		if ((ok) && ($('citta').value=="")) {
			ok = false;
			alert("Manca la cittą");
		}
		if ((ok) && ($('prov').value=="")) {
			ok = false;
			alert("Manca la provincia");
		}
		if ((ok) && ($('regione').value == "")) {
			ok = false;
			alert("Manca la regione");
		}
		if ((ok) && ($('telefono').value=="") && ($('contattoTelefono').checked!="")) {
			ok = false;
			alert("Manca il numero di telefono");
		}
		if ((ok) && ($('mail').value == "")) {
			ok = false;
			alert("Manca l'indirizzo email");
		}
		
		if ((ok) && ($('acconsentoPrivacy').checked == false)) {
			ok = false;
			alert("Acconsentire il trattamento dei dati personali");
		}
		
		//Empty the log and show the spinning indicator.
		var log = $('log_res').empty();
		//Set the options of the form's Request handler. 
		//("this" refers to the $('myForm') element).
		this.set('send', {onComplete: function (response) { 
			//log.removeClass('ajax-loading');
			//log.set('html', response);
			alert(response);
		}});
		//Send the form.
		if (ok) {
			this.send();
		}
	});
	
});
