/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  *
  * 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('mioForm');
		loginForm.onsubmit = function () {
			return canSubmit(this);
		}
		
		//Setting focus to the user field
		loginForm.COGNOME_UTENTE.focus();
	}

	function filled(field) {
		if (field.value == "" || field.value == null) {
			return false;
		} else {
			return true;
		}
	}
	
	function canSubmit(form) {

		if (!filled(form.COGNOME_UTENTE)) {
			alert("Inserire un cognome valido.");
			form.COGNOME_UTENTE.focus();
			return false;
		}

		if (!filled(form.NOME_UTENTE)) {
			alert("Inserire un nome valido.");
			form.NOME_UTENTE.focus();
			return false;
		}

		if (!filled(form.EMAIL_UTENTE)) {
			alert("Inserire una email valida.");
			form.EMAIL_UTENTE.focus();
			return false;
		}
		
		if (!filled(form.USERNAME_UTENTE)) {
			alert("Inserire una username Valida.");
			form.USERNAME_UTENTE.focus();
			return false;
		}

		if (!filled(form.PW_UTENTE)) {
			alert("Inserire una password Valida.");
			form.PW_UTENTE.focus();
			return false;
		}

		if (!filled(form.C_PW_UTENTE)) {
			alert("Inserire la seconda password.");
			form.C_PW_UTENTE.focus();
			return false;
		}

		if (!filled(form.gruppoClub)) {
			alert("Cliccare sul servizio richiesto.");
			form.gruppoClub.focus();
			return false;
		}
		
		if (!filled(form.gruppoClub)) {
			alert("Cliccare sul servizio richiesto.");
			form.gruppoClub.focus();
			return false;
		}
		// Questi campi non so quanto servano in articoloNew.php
		if (!filled(form.gruppoNet)) {
			alert("Cliccare sul servizio richiesto.");
			form.gruppoNet.focus();
			return false;
		}
	}
