
// variabile contenente il nome del Cookie di riferimento....
search = "etsLogin=";
// ====================================================================================
function verificaPWD () {
	if (document.invioPasswordForm.email.value == "") {
		alert("Inserire l'indirizzo email");
		return false;
	}
	return true;
}
//=====================================================
function submitPWD() {
	if (verificaPWD())
		document.invioPasswordForm.submit();
}
// =====================================================
function goSubmit(action, url) {
	document.formDati.action = url;
	document.formDati.actionSubmit.value = action;
	document.formDati.submit();
}
// ============= POPUP ======================
function popupPassword(url) {
	window.open(url,"","toolbar=no,width=380,height=240,top=50,left=50,directories=no,status=no,statusbar=no,resizable=1,menubar=no,scrollbars=no");
}
// ============= POPUP ======================
function Popup2(url) {
	window.open(url,"","toolbar=no,width=380,height=240,top=50,left=50,directories=no,status=no,statusbar=no,resizable=1,menubar=no,scrollbars=no");
}
// ============= MODIFICA ====================
function modifica() {
	document.modifica.callerPage.value = document.location.href;
	document.modifica.submit();
}
// ============= VERIFICA ====================
/*function verifica() {
	//document.login.url.value = "" + document.location.href.substring((document.location.href.indexOf("/auth/")));
	document.login.url.value = "" + document.location.href;
	if (document.login.username.value == "" || document.login.password.value == "") {
		alert("Impostare Username e Password");
		return false;
	}
	return true;
}*/
//============== PROVA =======================
function prova() {
	alert("CIAO");
	//if(document.hiddenForm.sito.value == "") {
		//alert("uffa");
	//}
	//document.hiddenForm.sito.value = document.location.href;
	//alert(document.hiddenForm.sito.value);
	//document.hiddenForm.submit();
	//alert(obj.value);
	//obj.value = document.location.href;
	//alert(obj.value);
	return true;
}
// ===============PREV PATH =====================
function prevPath() {
	return document.location.href;
}
// ============= LOGOUT ======================
function urlLogout() {
	if(document.location.href.indexOf("eidon") != -1) {
			document.out.url.value = "http://www.eidon.net";
	//		alert(document.out.url.value);
	}
	else if(document.location.href.indexOf("tetractis") != -1) {
			document.out.url.value = "http://www.tetractis.it";
	//		alert(document.out.url.value);
	}
	else if(document.location.href.indexOf("sportworld") != -1) {
			document.out.url.value = "http://www.sportworld.it";
	//		alert(document.out.url.value);
	}
	//TODO levare l'if di rossini usato solo per lo sviluppo
	else if(document.location.href.indexOf("rossini") != -1) {
			document.out.url.value = "http://www.eidon.net";
	//		alert(document.out.url.value);
	}
	return true;
	//document.login.submit();
}

//============== REINDIRIZZAMENTO HOME ================
function reindirizzamentoHome() {
	if(document.location.href.indexOf("eidon") != -1) {
		self.location="http://www.eidon.net";
	}
	else if(document.location.href.indexOf("tetractis") != -1) {
		self.location="http://www.tetractis.it";
	}
	else if(document.location.href.indexOf("sportworld") != -1) {
		self.location="http://www.sportworld.it";
	}
	//TODO levare l'if di rossini usato solo per lo sviluppo
	else if(document.location.href.indexOf("rossini") != -1) {
		self.location="http://rossini:9090/servizi/login.html";
	}
}

// ============= SET SITO  ======================
function setSito() {
	if(document.location.href.indexOf("eidon") != -1) {
			document.soluzioniProblemiForm.sito_rich.value = "eidon";
			return;
	}
	if(document.location.href.indexOf("tetractis") != -1) {
			document.soluzioniProblemiForm.sito_rich.value = "tetractis";
			return;
	}
	if(document.location.href.indexOf("sportworld") != -1) {
			document.soluzioniProblemiForm.sito_rich.value = "sportworld";
			return;
	}
	if(document.location.href.indexOf("rossini") != -1) {
			document.soluzioniProblemiForm.sito_rich.value = "eidon";
			return;
	}
	return true;	
}
// ============= IDENTIFICA SITO ======================
function identificaSito() {
	if(document.location.href.indexOf("eidon") != -1) {
	//	alert("eidon");
		return "Eidon";
	}
	else if(document.location.href.indexOf("tetractis") != -1) {
		return "Tetractis";
	}
	else if(document.location.href.indexOf("sportworld") != -1) {
		return "SportWorld";
	}
	//questo non ci va alla fine... serve solo per lavorarci
	else if(document.location.href.indexOf("rossini") != -1) {
	//	alert("Rossini");
		return "Eidon";
	}
	//return true;
	//document.login.submit();
}
//=============DOWNLOAD FILE FORM NASCOSTA==================
function download(nomefile){
//	document.nascosta.contentType.value="application/pdf";
	document.nascosta.terminalPathFile.value = nomefile;
	document.nascosta.urlPrev.value = prevPath();
	document.nascosta.sito.value = identificaSito();
	document.nascosta.submit();
}
// ============= VERIFICA =======================
function verifica() {
	document.login.url.value = document.location.href;
	if (document.login.username.value == "" || document.login.password.value == "") {
		alert("Impostare Username e Password");
		return false;
	}
	return true;
}
// =============================================
function logon(urlKo) {
	document.login.username.value = document.formDati.tUsername.value;
	document.login.password.value = document.formDati.tPassword.value;
	document.login.urlKo.value = urlKo
	if (verifica()) {
		document.login.submit();
	}
}
// ============= LOGIN =======================
function urlLogin() {
	document.login.url.value = document.location.href;
	if(document.login.userName.value == ""){
		alert("Attenzione: immettere nome utente");
		return false;
	}
	if(document.login.password.value == ""){
		alert("Attenzione: immettere password");
		return false;
	}
	return true;
}
// ============= BOXLOGIN ====================
function getLoginValue() {
	var value = "notFound";
	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search);
		if (offset != -1) 
		{
			offset += search.length;
			end = document.cookie.indexOf(";", offset);
			if (end == -1)
				end = document.cookie.length;
			value = document.cookie.substring(offset, end);
			if (value.indexOf("|") > -1)
				value = value.substring(0, value.indexOf("|"));
		}
	}
	return value;
}
// ============= ISCOOKIEVALID ====================
function getIsLoginValid() {
	var value = getLoginValue();
	if (value == "notValid")
		return false;
	else
		return true;
}

// ============= ISCOOKIEVALID ====================
function getIsCookieValid() {
	var value = "" + getLoginValue();
//alert("value: " + value);
	if (value == "notFound" || value == "undefined" || value == "notValid") {
//alert("false");
		return false;
	} else {
//alert("true");
		return true;
	}
}

// ============== ASSISTENZA REMOTA =================
function checkAssistenzaRemota() {
	
	if(document.assistenzaRemotaForm.nome.value == "") {
		alert("attenzione: campo Nome vuoto");
		return false;
	}
	if(document.assistenzaRemotaForm.cognome.value == "") {
		alert("attenzione: campo Cognome vuoto");
		return false;
	}
	if( (document.assistenzaRemotaForm.telPrefisso.value == "") || (document.assistenzaRemotaForm.telNumero.value == "") ){
		alert("attenzione: campo Telefono non valido");
		return false;
	}
	if(document.assistenzaRemotaForm.mail.value == "") {
		alert("attenzione: campo E-mail vuoto");
		return false;
	}
	else if(document.assistenzaRemotaForm.mail.value.indexOf("@") != -1){
			index = document.assistenzaRemotaForm.mail.value.indexOf("@");
			index = index + 1;
			end = document.assistenzaRemotaForm.mail.value.length;
			value = document.assistenzaRemotaForm.mail.value.substring(index, end);
			if(value.indexOf("@") != -1){
				alert("Attenzione: mail non valida");
				return false;
			}
			else if(value.indexOf(".") == -1){
				alert("Attenzione: mail non valida");
				return false;
			}
		}
		else{
			alert("Attenzione: mail non valida");
			return false;
		}
	if(document.assistenzaRemotaForm.localita.value == "") {
		alert("attenzione: campo Citt? vuoto");
		return false;
	}
	
	return true;
}

// ============== SOLUZIONE PROBLEMI =================
function checkSoluzioneProblemi() {
	//alert("check FORM");
	if(document.soluzioniProblemiForm.nome.value == "") {
		alert("attenzione: campo Nome vuoto");
		return false;
	}
	if(document.soluzioniProblemiForm.cognome.value == "") {
		alert("attenzione: campo Cognome vuoto");
		return false;
	}
	if ((document.soluzioniProblemiForm.giorno_nascita.value != "") || (document.soluzioniProblemiForm.mese_nascita.value != "") || (document.soluzioniProblemiForm.anno_nascita.value != "")){
		if( (document.soluzioniProblemiForm.giorno_nascita.value == "") || (document.soluzioniProblemiForm.mese_nascita.value == "") || (document.soluzioniProblemiForm.anno_nascita.value == "")){
			alert("attenzione: campo data nascita non valido");
			return false;
		}	
	}
	
	
	
	
	if(document.soluzioniProblemiForm.mail.value == "") {
		alert("attenzione: campo E-mail vuoto");
		return false;
	}
	else {
		if(document.soluzioniProblemiForm.mail.value.indexOf("@") != -1){
			index = document.soluzioniProblemiForm.mail.value.indexOf("@");
			index = index + 1;
			end = document.soluzioniProblemiForm.mail.value.length;
			value = document.soluzioniProblemiForm.mail.value.substring(index, end);
			if(value.indexOf("@") != -1){
				alert("Attenzione: mail non valida");
				return false;
			}
			else if(value.indexOf(".") == -1){
				alert("Attenzione: mail non valida");
				return false;
			}
		}
		else{
			alert("Attenzione: mail non valida");
			return false;
		}
	}
	if(document.soluzioniProblemiForm.localita.value == "") {
		alert("attenzione: campo Citt? vuoto");
		return false;
	}
	if(document.soluzioniProblemiForm.societa.value == "") {
		alert("attenzione: campo Societ? vuoto");
		return false;
	}
	
	if(document.soluzioniProblemiForm.oggetto_richiesta.value == ""){
		alert("attenzione: oggetto richiesta non valido");
		return false;
	
	}
	
	if(document.soluzioniProblemiForm.testo_richiesta.value == ""){
		alert("attenzione: testo richiesta non valido");
		return false;
	
	}
	
	if(document.soluzioniProblemiForm.autorizzazione[1].checked != true){
		alert("attenzione: Autorizzare il trattamento dei dati personali");
		return false;
	
	}
	
	return true;
}

// ============== REGISTRAZIONE =================
function registrazioneForm() {
	if(document.reg.nome.value == "") {
		alert("attenzione: campo Nome vuoto");
		return false;
	}
	if(document.reg.cognome.value == "") {
		alert("attenzione: campo Cognome vuoto");
		return false;
	}
	if(document.reg.mail.value == "") {
		alert("attenzione: campo Email vuoto");
		return false;
	}
	else if(document.reg.mail.value.indexOf("@") != -1){
			index = document.reg.mail.value.indexOf("@");
			index = index + 1;
			end = document.reg.mail.value.length;
			value = document.reg.mail.value.substring(index, end);
			if(value.indexOf("@") != -1){
				alert("Attenzione: mail non valida");
				return false;
			}
			else if(value.indexOf(".") == -1){
				alert("Attenzione: mail non valida");
				return false;
			}
		}
		else{
			alert("Attenzione: mail non valida");
			return false;
		}
	if(document.reg.provincia.value == "") {
		alert("attenzione: campo Provincia vuoto");
		return false;
	}
	if(document.reg.localita.value == "") {
		alert("attenzione: campo Localita' vuoto");
		return false;
	}
	if(document.reg.userName.value == "") {
		alert("attenzione: campo User vuoto");
		return false;
	}
	if(document.reg.userName.value.length < 6 || document.reg.userName.value.length > 15) {
		alert("attenzione: campo User deve essere di lunghezza compresa tra i 6 e i 15 caratteri");
		return false;
	}	
	if(document.reg.password.value == "") {
		alert("attenzione: campo Password vuoto");
		return false;
	}
	if(document.reg.password.value.length < 6 || document.reg.password.value.length > 15) {
		alert("attenzione: campo Password deve essere di lunghezza compresa tra i 6 e i 15 caratteri");
		return false;
	}	
	if(document.reg.conf_password.value == "") {
		alert("attenzione: campo Conferma Password vuoto");
		return false;
	}
	if(document.reg.password.value != document.reg.conf_password.value) {
		alert("attenzione: le password fornite non sono uguali");
		return false;
	}
	if(!document.reg.autorizzazione[1].checked) {
		alert("attenzione: autorizzazione al trattamento dei dati personali necessaria per proseguire con la registrazione");	
		return false;
	}
	return true;
}
// ============== MODIFICA DATI UTENTE =================
function modificaForm() {
	if(document.mod.nome.value == "") {
		alert("attenzione: campo Nome vuoto");
		return false;
	}
	if(document.mod.cognome.value == "") {
		alert("attenzione: campo Cognome vuoto");
		return false;
	}
	if(document.mod.mail.value == "") {
		alert("attenzione: campo Email vuoto");
		return false;
	}
	else if(document.mod.mail.value.indexOf("@") != -1){
			index = document.mod.mail.value.indexOf("@");
			index = index + 1;
			end = document.mod.mail.value.length;
			value = document.mod.mail.value.substring(index, end);
			if(value.indexOf("@") != -1){
				alert("Attenzione: mail non valida");
				return false;
			}
			else if(value.indexOf(".") == -1){
				alert("Attenzione: mail non valida");
				return false;
			}
		}
		else{
			alert("Attenzione: mail non valida");
			return false;
		}
	if(document.mod.provincia.value == "") {
		alert("attenzione: campo Provincia vuoto");
		return false;
	}
	if(document.mod.localita.value == "") {
		alert("attenzione: campo Localita' vuoto");
		return false;
	}
	if(!document.mod.old_password.value == "" || !document.mod.new_password.value == "" || !document.mod.conf_new_password.value == "") {
		if(document.mod.old_password.value == "") {
			alert("attenzione: inserire Vecchia password");
			return false;
		}
		if(document.mod.old_password.value.length < 6 || document.mod.old_password.value.length > 15) {
			alert("attenzione: campo Vecchia password deve essere di lunghezza compresa tra i 6 e i 15 caratteri");
			return false;
		}	
		if(document.mod.new_password.value == "") {
			alert("attenzione: campo Nuova password vuoto");
			return false;
		}
		if(document.mod.new_password.value.length < 6 || document.mod.new_password.value.length > 15) {
			alert("attenzione: campo Nuova password deve essere di lunghezza compresa tra i 6 e i 15 caratteri");
			return false;
		}	
		if(document.mod.conf_new_password.value == "") {
			alert("attenzione: campo Conferma Nuova password vuoto");
			return false;
		}
		if(document.mod.new_password.value != document.mod.conf_new_password.value) {
			alert("attenzione: le Nuove password fornite non sono uguali");
			return false;
		}
	}
	return true;
}
// =============== MODIFICA FORM SOCIETA=================
//function modificaFormSocieta_societaAlert(){
//	alert("attenzione: per poter effettuare il download e' obbligatorio compilare anche il campo Societa'");
//}

// ============== MODIFICA SOCIETA FORM =================
function modificaFormSocieta() {
	if(document.modSoc.nome.value == "") {
		alert("attenzione: campo Nome vuoto");
		return false;
	}
	if(document.modSoc.cognome.value == "") {
		alert("attenzione: campo Cognome vuoto");
		return false;
	}
	if(document.modSoc.mail.value == "") {
		alert("attenzione: campo Email vuoto");
		return false;
	}
	else if(document.modSoc.mail.value.indexOf("@") != -1){
			index = document.modSoc.mail.value.indexOf("@");
			index = index + 1;
			end = document.modSoc.mail.value.length;
			value = document.modSoc.mail.value.substring(index, end);
			if(value.indexOf("@") != -1){
				alert("Attenzione: mail non valida");
				return false;
			}
			else if(value.indexOf(".") == -1){
				alert("Attenzione: mail non valida");
				return false;
			}
		}
		else{
			alert("Attenzione: mail non valida");
			return false;
		}
	if(document.modSoc.provincia.value == "") {
		alert("attenzione: campo Provincia vuoto");
		return false;
	}
	if(document.modSoc.localita.value == "") {
		alert("attenzione: campo Localita' vuoto");
		return false;
	}
	if(document.modSoc.societa.value == "") {
		alert("attenzione: campo Societa' vuoto");
		return false;
	}
	if(!document.modSoc.old_password.value == "" || !document.modSoc.new_password.value == "" || !document.modSoc.conf_new_password.value == "") {
		if(document.modSoc.old_password.value == "") {
			alert("attenzione: inserire Vecchia password");
			return false;
		}
		if(document.modSoc.old_password.value.length < 6 || document.modSoc.old_password.value.length > 15) {
			alert("attenzione: campo Vecchia password deve essere di lunghezza compresa tra i 6 e i 15 caratteri");
			return false;
		}	
		if(document.modSoc.new_password.value == "") {
			alert("attenzione: campo Nuova password vuoto");
			return false;
		}
		if(document.modSoc.new_password.value.length < 6 || document.modSoc.new_password.value.length > 15) {
			alert("attenzione: campo Nuova password deve essere di lunghezza compresa tra i 6 e i 15 caratteri");
			return false;
		}	
		if(document.modSoc.conf_new_password.value == "") {
			alert("attenzione: campo Conferma Nuova password vuoto");
			return false;
		}
		if(document.modSoc.new_password.value != document.modSoc.conf_new_password.value) {
			alert("attenzione: le Nuove password fornite non sono uguali");
			return false;
		}
	}
	return true;
}
// ============== RECUPERO PASSWORD =============
function recPwd() {
	if(document.recupero_passw.mail.value == "") {
		alert("Attenzione: campo e-mail vuoto");
		return false;
	}
	return true;
}
// ============== UPLOAD DI UN FILE (CURRICULUM) ==========================
function checkFileToUpload() {
	
	if(document.curriculum.uploaded.value == "") {
		alert("attenzione: inserire un File");
		return false;
	}
	return true;
}
// ============== SUGGERIMENTI UTENTE E SOLUZIONI PROBLEMI=================
function soluzioni_problemiForm() {
	if(document.sol_probl.nome.value == "") {
		alert("attenzione: campo Nome vuoto");
		return false;
	}
	if(document.sol_probl.cognome.value == "") {
		alert("attenzione: campo Cognome vuoto");
		return false;
	}
	if(document.sol_probl.mail.value == "") {
		alert("attenzione: campo Email vuoto");
		return false;
	}
	else if(document.sol_probl.mail.value.indexOf("@") != -1){
			index = document.sol_probl.mail.value.indexOf("@");
			index = index + 1;
			end = document.sol_probl.mail.value.length;
			value = document.sol_probl.mail.value.substring(index, end);
			if(value.indexOf("@") != -1){
				alert("Attenzione: mail non valida");
				return false;
			}
			else if(value.indexOf(".") == -1){
				alert("Attenzione: mail non valida");
				return false;
			}
		}
		else{
			alert("Attenzione: mail non valida");
			return false;
		}
	if(document.sol_probl.provincia.value == "") {
		alert("attenzione: campo Provincia vuoto");
		return false;
	}
	if(document.sol_probl.localita.value == "") {
		alert("attenzione: campo Localita' vuoto");
		return false;
	}
	if(document.sol_probl.societa.value == "") {
		alert("attenzione: campo Societa vuoto");
		return false;
	}
	if(!document.sol_probl.autorizzazione[1].checked) {
		alert("attenzione: autorizzazione al trattamento dei dati personali necessaria per proseguire con la registrazione");	
		return false;
	}	
	return true;
}
// ============== VERIFICA ======================
function verifica() {
	if (document.login.username.value == "" || document.login.password.value == "") {
		alert("Impostare Username e Password");
		return false;
	}
	return true;
}
// ================= FORM ======================
function formLogin (url, operation) {
	document.write('<form name="login" method="post" action="http://www.corriere.it/registrati/loginServlet" onsubmit="return verifica();">');
	document.write('<input type="hidden" name="debugLevel" value="0">');
	document.write('<input type="hidden" name="applicationName" value="COR">');
	document.write('<input type="hidden" name="operation" value="' + operation + '">');
	document.write('<input type="hidden" name="registration" value="/registrati/registration.jsp">');
	if ("" + url == "") url = "/index.shtml";
	document.write('<input type="hidden" name="url" value="' + url + '">');
	document.write('<input type="hidden" name="urlKo" value="">');
	document.write('<input type="hidden" name="username">');
	document.write('<input type="hidden" name="password">');
	document.write('</form>');
}

// =============== NUMBER DATE =====================
function numberDate(e){
	if (document.all){ // Explorer
//		alert("MSIE primo");
		code = e.keyCode;
		//Inibisce l'immissione di un carattere che non sia un numero: "0123456789"
    	if (code < 48 || code > 57){
    		//ie
    		alert("carattere non valido");
    		e.returnValue = false;
    	}
	}
	else if (document.getElementById){ //Netscape 6.x
//		alert("netscape 6 primo");
		code = e.charCode;
		//Inibisce l'immissione di un carattere che non sia un numero: "0123456789"
    	if ((code < 48 || code > 57) && code!=0){
    		//firefox
  //  		alert("codice" + code);
    		alert("carattere non valido");
    		e.preventDefault();
      		e.stopPropagation();
    	}
	}
}
//===================ISANUMBER=========================
function isANumber(string) {
  if (string.value.search(/^[0-9]*$/) != -1) {
    return true;
  }
  else {
    return false;
  }
}


function anno(windows){
	alert(windows.event.KeyCode);
	if (windows.event.KeyCode < 48 || windows.event.KeyCode > 57){
		alert("al va si o no");
		windows.event.KeyCode=0;
	}
}


function formLogout () {
	document.write('<form name="logout" method="post" action="http://www.corriere.it/registrati/loginServlet" onsubmit="return verifica();">');
	document.write('<input type="hidden" name="debugLevel" value="0">');
	document.write('<input type="hidden" name="applicationName" value="COR">');
	document.write('<input type="hidden" name="operation" value="logout">');
	document.write('<input type="hidden" name="registration" value="/index.shtml">');
	document.write('<input type="hidden" name="url" value="/index.shtml">');
	document.write('<input type="hidden" name="urlKo" value="/index.shtml">');
	document.write('<input type="hidden" name="username">');
	document.write('<input type="hidden" name="password">');
	document.write('</form>');
}
function formModifica () {
	document.write('<form name="modifica" method="post" action="http://www.corriere.it/registrati/userServlet">');
	document.write('<input type="hidden" name="applicationName" value="COR">');
	document.write('<input type="hidden" name="operation" value="verify">');
	document.write('<input type="hidden" name="callerPage" value="">');
	document.write('<input type="hidden" name="urlOk" value="/registrati/password_verifica.jsp">');
	document.write('<input type="hidden" name="urlKo" value="/registrati/errorPage.jsp">');
	document.write('</form>');
}

function galleria(path,n_galleria){
pathcompleta="/speciali/"+path+"/galleria/sopra.html?"+n_galleria
path_sin="/speciali/popup/foto.html"
path_des="/speciali/popup/vuoto.html"
newWin=open("","","menubar=no,location=no,toolbar=yes,status=no,scrollbars=yes,resizable=no,width=680,height=480");
newWin.document.write('<html><head><title>Galleria di immagini</title>');
newWin.document.write('</head>');
newWin.document.write('<frameset rows="45,*" border="0" frameborder="NO" framespacing="0">');
newWin.document.write('<frame src="'+pathcompleta+'" name="sopra" scrolling="NO" marginheight="5" marginwidth="5">');
newWin.document.write('<frameset cols="120,*" border="0" frameborder="NO" framespacing="0">');
newWin.document.write('<frame src="'+path_sin+'" name="sin">');
newWin.document.write('<frame src="'+path_des+'" name="des">');
newWin.document.write('</frameset></frameset>');
newWin.document.write('<noframes><body>Per visualizzare questa pagina &egrave; necessario un browser che supporti i frames</body></noframes>');
newWin.document.write('</html>');
//newWin.frames["sopra"].location.href=pathcompleta
}

var TYPE_DAY = "DAY";
var TYPE_MONTH = "MONTH";
var TYPE_YEAR = "YEAR";
var TYPE_HOUR = "HOUR";
var TYPE_MINUTES = "MINUTES";

function tabBackOnKeyDown(component, tipo,  evento) {
	//Gestione di BACKSPACE (keyCode=8)
	if ( evento.keyCode==8 && component.value=="" ) {
		if ( tipo != TYPE_DAY && tipo != TYPE_HOUR ) {
			component.form[(getIndexInForm(component)-1) % component.form.length].focus();
		}
	}
}

function tabNextOnKeyUp(component, tipo, evento) {
	//Verifica se si tratta di un campo anno (4-digit), altrimenti (2-digit)
	var digitab;
	if ( tipo == TYPE_YEAR ) {
		digitab = 3;
	} else {
		digitab = 1;
	}
	//Inibisce il cambiamento di fuoco sui tasti:
	// TAB(9) o SHIFT+TAB(16)o KeyLeft(37) o KeyRight(39) o Backspace(8)
	if ( evento.keyCode != 9
		&& evento.keyCode != 16
		&& evento.keyCode != 37
		&& evento.keyCode != 39
		&& evento.keyCode!=8)
	{
		//Sposta il fuoco sul componente successivo se non  su un campo anno o minuti
		if ( component.value.length > digitab && tipo != TYPE_YEAR && tipo != TYPE_MINUTES) {
			component.form[(getIndexInForm(component)+1) % component.form.length].select();
		}
	} 
	if ( evento.keyCode == 8 && component.value.length > digitab) {
		component.select();
	} 
}

function isValidValue(component, tipo) {
	//Funzione di auto-completamento de campi
	var digits = component.value.length;
	if ( digits > 0 ) {
		if ( tipo == TYPE_YEAR ){
			//Valore di soglia per completamento del secolo = 50.
			var year = new Date().getYear();
			if( component.value > 50 && digits < 4 ) {
				year = ((year - (year%100))-100);
			}
			component.value = ((""+year).substring(0,(4-digits))) + component.value;
		} else {
			if( digits == 1 ) {
				component.value = "0"+component.value;
			}
		}

		if ( tipo == TYPE_DAY && !isValidDay(component.value) ){
			alert("campo GIORNO errato");
			eval('document.' + component.form.name + '.' + component.name + '.select()');
			return false;
		}
		if ( tipo == TYPE_MONTH && !isValidMonth(component.value) ){
			alert("campo MESE errato");
			eval('document.' + component.form.name + '.' + component.name + '.select()');
			return false;
		}
		if ( tipo == TYPE_HOUR && !isValidHour(component.value) ){
			alert("campo ORA errato");
			eval('document.' + component.form.name + '.' + component.name + '.select()');
			return false;
		}
		if ( tipo == TYPE_MINUTES && !isVlaidMinute(component.value) ){
			alert("campo MINUTI errato");
			eval('document.' + component.form.name + '.' + component.select() + '.select()');
			return false;
		}
	}
	return true;
}

function getIndexInForm(component) {
	//Ritorna l'indice del componente nel form che lo contiene
	var index = -1, i = 0, found = false;
	while (i < component.form.length && index == -1)
		if (component.form[i] == component)index = i;
		else i++;
	return index;
}

function isValidDay(strDay)	{
	if (strDay.length != 2) {
		return false;
	}
	day = parseInt( strDay, 10 );
	if ( (day < 1) || (day > 31 ) ) {
		return false;
	}
	return true;
}

function isValidMonth(strMonth) {
	if (strMonth.length!=2) {
		return false;
	}
	month=parseInt( strMonth, 10 );
	if ( (month < 1) || (month > 12 ) )	{
		return false;
	}
	return true;	
}

function isValidHour(strHour)	{
	if (strHour.length!=2) {
		return false;
	}
	hour=parseInt( strHour, 10 );
	if ( (hour < 0) || (hour > 23 ) ) {
		return false;
	}
	return true;
}

function isVlaidMinute(strMin)	{
	if (strMin.length!=2) {
		return false;
	}
	min=parseInt( strMin, 10 );
	if ( (min < 0) || (min > 59 ) ) {
		return false;
	}
	return true;
}

function isInteger(s){
	var i;
	for (i = 0; i < s.length; i++){   
		// Check that current character is number.
		var c = s.charAt(i);
		if (((c < "0") || (c > "9"))) return false;
	}
	// All characters are numbers.
	return true;
}
	
function getDaysFebruary(year){
	return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31;
		if (i==4 || i==6 || i==9 || i==11) { this[i] = 30; }
		if (i==2) { this[i] = 29; }
	}
	return this;
}

function isValidDate(day, month, year) {
	var strDay = day.value;
	var strMonth = month.value;
	var strYear = year.value;

	var daysInMonth = DaysArray(12);

	if (strDay.charAt(0) == "0" && strDay.length > 1) {
		strDay = strDay.substring(1);
	}
	if (strMonth.charAt(0) == "0" && strMonth.length > 1) {
		strMonth = strMonth.substring(1);
	}
	for (var i = 1; i <= 3; i++) {
		if (strYear.charAt(0) == "0" && strYear.length > 1) strYear = strYear.substring(1);
	}

	intMonth = parseInt(strMonth);
	intDay = parseInt(strDay);
	intYear = parseInt(strYear);

	if(strMonth.length<1 || intMonth<1 || intMonth>12) {
		alert("campo MESE errato");
		eval('document.' + month.form.name + '.' + month.name + '.select()');
		return false;
	}
	if (strDay.length<1 || intDay<1 || (intMonth == 2 && intDay > getDaysFebruary(intYear)) || intDay > daysInMonth[intMonth]) {
		alert("campo GIORNO errato");
		eval('document.' + day.form.name + '.' + day.name + '.select()');
		return false;
	}
	if (strYear.length != 4 || intYear==0) {
		alert("campo ANNO errato");
		eval('document.' + year.form.name + '.' + year.name + '.select()');
		return false;
	}
	return true;
}

var char_nome = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz??????????????????????????????????????????????????????????????????????' \t\r\n\f";
var char_indirizzo = "?()/.,-\ 1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz??????????????????????????????????????????????????????????????????????' \t\r\n\f";
var char_email = "@.-_1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
var char_completo = "\|!?$%&/()=?^*+[]@?#;:??<>-_.,1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz??????????????????????????????????????????????????????????????????????' \t\r\n\f" + '"';
var char_numeri = "0123456789";
var char_telefono = "()0123456789+-./\ #";
var char_codice_fiscale ="1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
var char_valuta = "0123456789.,";
var char_password = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
var char_alfanumerici =" 1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";



function check_campo_testo(field,obbligatorio,messaggio, caratteriAmmessi) {
  var checkOK = caratteriAmmessi;
  var checkStr = field.value;
  var allValid = true;
  var i, j;

  if (field.value == "" && obbligatorio) {
    if (messaggio==null)
	  alert("Dati obbligatori nel campo \"" + field.name +"\" ");
    else
	  alert(messaggio);
    field.focus();
    return (false);
  }
  for (i = 0;  i < checkStr.length;  i++) {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length) {
      allValid = false;
      break;
    }
  }
  if (!allValid) {
    if (messaggio==null)
	  alert("Caratteri non validi nel campo \"" + field.name +"\" ");
    else
	  alert(messaggio);
    field.focus();
    return (false);
  }
  return (true);
}

function isNumber(strNum){
	var mikExp = /[^0-9]/;
    if(strNum.search(mikExp) != -1) {
        return false;
    } else {
    	return true;
    }
}

function considersIfNumber(evento){
    //Inibisce l'immissione di un carattere che non sia un numero: "0123456789"
    if (evento.keyCode < 48 || evento.keyCode > 57)event.returnValue = false;
}

function considersIfNumber2(field){
    if(field.value.length!=0){
   	 	if(isNaN(parseInt(field.value))){
    		field.value="";
    		alert("msg2");
    	}
    }else{
    	alert("msg1")
    }
    
}

function sostituiscistringa(stringainput,valoredacercare,valoredasostituire) {
	checkStr = stringainput;
	var nvolte;	
 	var i;	
	var nuovastr = new String();		
	var ch = new String();		
	for (i = 0; i < checkStr.length; i++) {
		ch = checkStr.charAt(i);
	    if (ch != valoredacercare)
			nuovastr = nuovastr + ch
        else
			nuovastr = nuovastr + valoredasostituire
	}
	return (nuovastr);
}

function controlla_email(nomecampo) {
	var emailStr = nomecampo.value;
	
	/* The following variable tells the rest of the function whether or not
	to verify that the address ends in a two-letter country or well-known
	TLD.  1 means check it, 0 means don't. */

	var checkTLD=1;

	/* The following is the list of known TLDs that an e-mail address must end with. */

	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

	/* The following pattern is used to check if the entered e-mail address
	fits the user@domain format.  It also is used to separate the username
	from the domain. */

	var emailPat=/^(.+)@(.+)$/;

	/* The following string represents the pattern for matching all special
	characters.  We don't want to allow special characters in the address. 
	These characters include ( ) < > @ , ; : \ " . [ ] */

	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

	/* The following string represents the range of characters allowed in a 
	username or domainname.  It really states which chars aren't allowed.*/

	var validChars="\[^\\s" + specialChars + "\]";

	/* The following pattern applies if the "user" is a quoted string (in
	which case, there are no rules about which characters are allowed
	and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
	is a legal e-mail address. */

	var quotedUser="(\"[^\"]*\")";

	/* The following pattern applies for domains that are IP addresses,
	rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
	e-mail address. NOTE: The square brackets are required. */

	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

	/* The following string represents an atom (basically a series of non-special characters.) */

	var atom=validChars + '+';

	/* The following string represents one word in the typical username.
	For example, in john.doe@somewhere.com, john and doe are words.
	Basically, a word is either an atom or quoted string. */

	var word="(" + atom + "|" + quotedUser + ")";

	// The following pattern describes the structure of the user

	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

	/* The following pattern describes the structure of a normal symbolic
	domain, as opposed to ipDomainPat, shown above. */

	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

	/* Finally, let's start trying to figure out if the supplied address is valid. */

	/* Begin with the coarse pattern to simply break up user@domain into
	different pieces that are easy to analyze. */

	var matchArray=emailStr.match(emailPat);

	if (matchArray==null) {

	/* Too many/few @'s or something; basically, this address doesn't
	even fit the general mould of a valid e-mail address. */

	nomecampo.focus();
	alert("E' necessario inserire un e-mail corretto (controllare @ e i punti) per poter procedere");
	return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];

	// Start by checking that only basic ASCII characters are in the strings (0-127).

	for (i=0; i<user.length; i++) {
	if (user.charCodeAt(i)>127) {
	nomecampo.focus();
	alert("Il nome utente dell'email contiene dei caratteri scorretti.");
	return false;
	   }
	}
	for (i=0; i<domain.length; i++) {
	if (domain.charCodeAt(i)>127) {
	nomecampo.focus();
	alert("Il dominio dell'email contiene dei caratteri scorretti.");
	return false;
	   }
	}

	// See if "user" is valid 

	if (user.match(userPat)==null) {

	// user is not valid
	nomecampo.focus();
	alert("Il nome utente dell'email contiene dei caratteri scorretti.");
	return false;
	}

	/* if the e-mail address is at an IP address (as opposed to a symbolic
	host name) make sure the IP address is valid. */

	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {

	// this is an IP address

	for (var i=1;i<=4;i++) {
	if (IPArray[i]>255) {
	nomecampo.focus();
	alert("L'indirizzo IP della email non ? corretto.");
	return false;
	   }
	}
	return true;
	}

	// Domain is symbolic name.  Check if it's valid.
	 
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
	if (domArr[i].search(atomPat)==-1) {
	nomecampo.focus();
	alert("Il dominio dell'email non ? valido.");
	return false;
	   }
	}

	/* domain name seems valid, but now make sure that it ends in a
	known top-level domain (like com, edu, gov) or a two-letter word,
	representing country (uk, nl), and that there's a hostname preceding 
	the domain or country. */

	if (checkTLD && domArr[domArr.length-1].length!=2 && 
	domArr[domArr.length-1].toLowerCase().search(knownDomsPat)==-1) {
	nomecampo.focus();
	alert("L'indirizzo email deve terminare con un dominio conosciuto o un codice internazionale di 2 lettere.");
	return false;
	}

	// Make sure there's a host name preceding the domain.

	if (len<2) {
	nomecampo.focus();
	alert("Nell'email manca la parte tra la @ e il punto.");
	return false;
	}

	// If we've gotten this far, everything's valid!
	return true;
}

function check_fiscale(field,obbligatorio,messaggio)
{
var HascPari = new Array();
var HascDispari = new Array();
var HascControllo = new Array();
var pari=0;
var dispari=0;
var controllo;
var codice = new String();
codice=field.value;

 if (messaggio==null)
	messaggio=field.name;

if (codice.length!=16)
	{
	 if (obbligatorio)
	   {
	    alert("Il codice fiscale contenuto nel campo \"" + messaggio +"\" ? errato");
	   field.focus();
	    return (false);
	   }
	 else
	   {
		if (codice.length!=0)
		   {
		    return (confirm("Il codice fiscale contenuto nel campo \"" + messaggio +"\" ? errato; Proseguo?"));
		   }
	   }
	}

HascControllo=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];

HascPari[0]=[["0"],[0]];
HascPari[1]=[["1"],[1]];
HascPari[2]=[["2"],[2]];
HascPari[3]=[["3"],[3]];
HascPari[4]=[["4"],[4]];
HascPari[5]=[["5"],[5]];
HascPari[6]=[["6"],[6]];
HascPari[7]=[["7"],[7]];
HascPari[8]=[["8"],[8]];
HascPari[9]=[["9"],[9]];
HascPari[10]=[["A"],[0]];
HascPari[11]=[["B"],[1]];
HascPari[12]=[["C"],[2]];
HascPari[13]=[["D"],[3]];
HascPari[14]=[["E"],[4]];
HascPari[15]=[["F"],[5]];
HascPari[16]=[["G"],[6]];
HascPari[17]=[["H"],[7]];
HascPari[18]=[["I"],[8]];
HascPari[19]=[["J"],[9]];
HascPari[20]=[["K"],[10]];
HascPari[21]=[["L"],[11]];
HascPari[22]=[["M"],[12]];
HascPari[23]=[["N"],[13]];
HascPari[24]=[["O"],[14]];
HascPari[25]=[["P"],[15]];
HascPari[26]=[["Q"],[16]];
HascPari[27]=[["R"],[17]];
HascPari[28]=[["S"],[18]];
HascPari[29]=[["T"],[19]];
HascPari[30]=[["U"],[20]];
HascPari[31]=[["V"],[21]];
HascPari[32]=[["W"],[22]];
HascPari[33]=[["X"],[23]];
HascPari[34]=[["Y"],[24]];
HascPari[35]=[["Z"],[25]];

HascDispari[0]=[["0"],[1]];
HascDispari[1]=[["1"],[0]];
HascDispari[2]=[["2"],[5]];
HascDispari[3]=[["3"],[7]];
HascDispari[4]=[["4"],[9]];
HascDispari[5]=[["5"],[13]];
HascDispari[6]=[["6"],[15]];
HascDispari[7]=[["7"],[17]];
HascDispari[8]=[["8"],[19]];
HascDispari[9]=[["9"],[21]];
HascDispari[10]=[["A"],[1]];
HascDispari[11]=[["B"],[0]];
HascDispari[12]=[["C"],[5]];
HascDispari[13]=[["D"],[7]];
HascDispari[14]=[["E"],[9]];
HascDispari[15]=[["F"],[13]];
HascDispari[16]=[["G"],[15]];
HascDispari[17]=[["H"],[17]];
HascDispari[18]=[["I"],[19]];
HascDispari[19]=[["J"],[21]];
HascDispari[20]=[["K"],[2]];
HascDispari[21]=[["L"],[4]];
HascDispari[22]=[["M"],[18]];
HascDispari[23]=[["N"],[20]];
HascDispari[24]=[["O"],[11]];
HascDispari[25]=[["P"],[3]];
HascDispari[26]=[["Q"],[6]];
HascDispari[27]=[["R"],[8]];
HascDispari[28]=[["S"],[12]];
HascDispari[29]=[["T"],[14]];
HascDispari[30]=[["U"],[16]];
HascDispari[31]=[["V"],[10]];
HascDispari[32]=[["W"],[22]];
HascDispari[33]=[["X"],[23]];
HascDispari[34]=[["Y"],[24]];
HascDispari[35]=[["Z"],[23]];
codice=codice.toUpperCase();
  for (i = 0;  i < codice.length-1;  i++)
  {
      for(n=0;n<36;++n)
      {
		if(((i+1)%2)==0)
			{
			  	if(HascPari[n][0]==codice.charAt(i))
			  		pari+=parseInt(HascPari[n][1]);
			 }
		else	  		
			{
			  	if(HascDispari[n][0]==codice.charAt(i))
			  		dispari+=parseInt(HascDispari[n][1]);
			 }
      }
  }
  controllo=HascControllo[(pari+dispari)%26];
  if(controllo!=codice.charAt(15))
   {
	 if (obbligatorio)
	   {
	    alert("Il codice fiscale contenuto nel campo \"" + messaggio +"\" ? errato");
	    return (false);
	   }
	 else
	    return (confirm("Il codice fiscale contenuto nel campo \"" + messaggio +"\" ? errato; Proseguo?"));
   }
  else
  	return(true);
}


