/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  *
  * Title : 		Form Validation Example
  * Author : 		Vito Tardia
  * URL : 			http://www.vtardia.com
  *
  * Description :	Includes functions from HackerJournal magazine
  *					(http://www.hackerjournal.it)
  *				- 	filled
  *				- 	canSubmit
  *
  * Created : 	27/03/2006
  * Modified : 	27/11/2006
  *
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

	var loginForm;

	//Attach an "onLoad" event to the current window
	window.onload = init;
	
	//Initialization function
	function init() {
		//Attaching the onSubmit event to the login form
		loginForm = document.getElementById('login');
		loginForm.onsubmit = function () {
			return canSubmit(this);
		}
		
		//Setting focus to the user field
		loginForm.cognome.focus();
	}

	function filled(field) {
		if (field.value == "" || field.value == null) {
			return false;
		} else {
			return true;
		}
	}
	
	function canSubmit(form) {
		if (!filled(form.cognome)) {
			alert("In campo congnome e' obbligatorio");
			form.cognome.focus();
			return false;
		}
		
		if (!filled(form.nome)) {
			alert("In campo nome e' obbligatorio");
			form.nome.focus();
			return false;
		}
		if (!filled(form.provincia)) {
			alert("In campo provincia e' obbligatorio");
			form.provincia.focus();
			return false;
		}
		if (!filled(form.comune)) {
			alert("In campo comune e' obbligatorio");
			form.comune.focus();
			return false;
		}
		if (!filled(form.email)) {
			alert("In campo email e' obbligatorio");
			form.email.focus();
			return false;
		}
		if (!filled(form.telefono)) {
			alert("In campo telefono e' obbligatorio");
			form.telefono.focus();
			return false;
		}
		if (!filled(form.data)) {
			alert("Inserire la data/periodo della performance");
			form.data.focus();
			return false;
		}
		if (!filled(form.localita)) {
			alert("Inserire la localita' dove si svolgera' la performance");
			form.localita.focus();
			return false;
		}
		if (!filled(form.location)) {
			alert("Inserire la location prevista per la performance");
			form.location.focus();
			return false;
		}
		if (!form.autorizzo.checked) {
			alert("E' obbligatorio accettare il trattamento dei dati personali");
			form.autorizzo.focus();
			return false;
		}
		return true;
	}

