<!--
// Funzione di controllo del formato data
function checkDate(dateField) { 
	/* Espressione regolare per i formati accettati */
	var reDate = /^(\d{1,2})\s*[-\/\s\.]\s*(\d{1,2})\s*[-\/\s\.]\s*(\d{1,4})\s*$/;
        
	try { 
		if (reDate.exec(dateField.value)) {
			var anno;
			if (RegExp.$3.length == 4)
				anno = RegExp.$3;
			else if (RegExp.$3.length == 3)
				if (RegExp.$3 > '030')
					anno = '1' + RegExp.$3;
				else
					anno = '2' + RegExp.$3;
			else if (RegExp.$3.length == 2)
				if (RegExp.$3 > '30')
					anno = '19' + RegExp.$3;
				else
					anno = '20' + RegExp.$3;
			else if (RegExp.$3.length == 1)
				anno = '200' + RegExp.$3;
	
			// Genero un oggetto Date in base al testo trovato
			var datetime = new Date(anno, RegExp.$2 - 1, RegExp.$1);
			
			var mese = (RegExp.$2);
			var giorno = (RegExp.$1);
			
			// Uniformo la formattazione della stringa
			var stringa_mese = ((mese.length < 2) ? "0" : "") + mese;
			var stringa_giorno = ((giorno.length < 2) ? "0" : "") + giorno ;
			
			// Controllo che la data sia corretta
			if (anno < 1900)
				throw "yearNotValid" ;
			if (datetime.getDate() != giorno)
				throw "dayNotValid";
			if ((datetime.getMonth()+1) != mese)
				throw "monthNotValid";
			if (datetime.getFullYear() != anno)
				throw "yearNotValid";
		  
			dateField.value = "" + stringa_giorno + "-" + stringa_mese + "-" + anno;
		}
		else
			throw e;
   }
   catch(e) {
		if (dateField.value != null && dateField.value != '') {
			switch(e){
				case "yearNotValid": 
					alert("Anno non valido!");
					break;
				case "monthNotValid": 
					alert("Mese  non valido!" );
					break;
				case "dayNotValid": 
					alert("Giorno  non valido!" );
					break;
				default: 
					alert("Data non valida!");
					break;
			}
			if (!dateField.id) { 
				// L'elemento non ha dichiarato l'id. Lo imposto ad un qualche valore.
				dateField.id = "dateField" + Math.random();
			}
			setTimeout("document.getElementById('" + dateField.id + "').focus(); document.getElementById('" + dateField.id + "').select()", 1);
		}
   }
}



// Funzione di controllo del formato eMail
function checkEmail(eMailField) {
	var eMailString = eMailField.value;
	
	try {
		// Espressione regolare pre verificare il formato user@domain
		var userDomainPattern = /^(.+)@(.+)$/;

		// Porzione di espressione regolare per rappresentare i caratteri speciali (vietati)
		var specialChars = "\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";

		// Porzione di espressione regolare per rappresentare i caratteri legali
		var validChars = "\[^\\s" + specialChars + "\]";

		// Porzione di espressione regolare utilizzata nel caso in cui user sia una stringa fra doppi apici (permessi tutti i caratteri)
		var quotedUser = "(\"[^\"]*\")";

		// Espressione regolare per i domini indicati come IP (necessarie le parentesi [])
		var ipDomainPattern = /^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

		// Porzione di espressione regolare che rappresenta un atomo (una serie di caratteri non speciali)
		var atom = validChars + '+';

		// Porzione di espressione regolare che rappresenta una parola dello username. Es: donald.duck@disney.us donald è una parola
		var word = "(" + atom + "|" + quotedUser + ")";

		// Espressione regolare che rappresenta lo user
		var userPattern = new RegExp("^" + word + "(\\." + word + ")*$");

		// Espressione regolare che rappresenta il dominio, nel caso non-IP
		var domainPattern = new RegExp("^" + atom + "(\\." + atom +")*$");


		// Per prima cosa separo user e domain
		var matchArray = eMailString.match(userDomainPattern);

		if (matchArray == null) {
			throw "eMailNotValid";
		}

		var user = matchArray[1];
		var domain = matchArray[2];

		// Verifico lo user
		if (user.match(userPattern) == null) {
			throw "eMailUserNotValid";
		}

		// Se il dominio è espresso come IP verifico che sia valido
		var IPArray = domain.match(ipDomainPattern);
		if (IPArray != null) {
			// controllo che sia un IP
			for (var i = 1; i <= 4; i++) {
				if (IPArray[i] > 255) {
					throw "eMailDomainNotValid";
				}
			}
		}

		// Se invece il dominio è espresso come nome simbolico verifico che sia valido
		var domainArray = domain.match(domainPattern);
		if (domainArray == null) {
			throw "eMailDomainNotValid";
		}


		// Il dominio sembra valido. Devo verificare che sia di 2, 3 o 4 lettere e che ci sia un hostname prima dell'indicazione dello stato
		// Spezzo il dominio negli atomi costituenti 
		var atomPattern = new RegExp(atom, "g");
		var domArr = domain.match(atomPattern);
		var len = domArr.length;
		if (domArr[domArr.length-1].length < 2 || 
		    domArr[domArr.length-1].length > 4) {
			// L'indirizzo deve terminare con una parola di 2, 3 o 4 lettere
			throw "eMailDomainNotValid";
		}

		// Verifico che ci sia un hostname
		if (len < 2) {
			throw "eMailDomainNotValid";
		}

		// Sembrerebbe un indirizzo valido
		return;
	}
	
   	catch(e) {
		if (eMailString != null && eMailString != '') {
			switch(e){
				case "eMailNotValid": 
					alert("eMail non valida!");
					break;
				case "eMailUserNotValid": 
					alert("User non valido!" );
					break;
				case "eMailDomainNotValid": 
					alert("Dominio  non valido!" );
					break;
				default: 
					alert("eMail non valida!");
					break;
			}
			if (!eMailField.id) { 
				// L'elemento non ha dichiarato l'id. Lo imposto ad un qualche valore.
				eMailField.id = "eMailField" + Math.random();
			}
			setTimeout("document.getElementById('" + eMailField.id + "').focus(); document.getElementById('" + eMailField.id + "').select()", 1);
		}
   }
}



// Funzione di controllo del formato data
function checkNumeric(numericField) { 
	if (isNaN(numericField.value)) {
		alert('Numero non valido!');

		if (!numericField.id) { 
			// L'elemento non ha dichiarato l'id. Lo imposto ad un qualche valore.
			numericField.id = "numericField" + Math.random();
		}
		setTimeout("document.getElementById('" + numericField.id + "').focus(); document.getElementById('" + numericField.id + "').select()", 1);
	}
}



// Funzione di controllo popolamento campi obbligatori
function checkMandatoryFields(mandatoryFieldIdArray) {
	for (currentFieldIndex in mandatoryFieldIdArray) {
		currentField = document.getElementById(mandatoryFieldIdArray[currentFieldIndex]);
		if (!currentField.value) {
			alert("Campo obbligatorio non valorizzato!");
	
			setTimeout("document.getElementById('" + currentField.id + "').focus();", 1);

			return false;
		}
	}
	return true;
}
-->