num = 500

function checkchar(campo)
{
	/* CharCodes
	10, 13 -> Carriage Return, Line Feed
	224 -> à
	232 -> è
	233 -> é
	236 -> ì
	242 -> ò
	249 -> ù
	*/
	lettere=eval('String.fromCharCode(13)') + eval('String.fromCharCode(10)')
			+ eval('String.fromCharCode(224)') + eval('String.fromCharCode(232)') + eval('String.fromCharCode(233)')
			+ eval('String.fromCharCode(236)') + eval('String.fromCharCode(242)') + eval('String.fromCharCode(249)')
			+ '1234567890 \'@!?,.;:-_=()[]{}qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM'; 
	valore=campo.value;
	for (i=0; i<valore.length; i++) 
		if (lettere.indexOf(valore.charAt(i))==-1) 
		{ 
			alert('Sono accettate solo lettere, numeri e i seguenti \n caratteri speciali: \' @ ! ? , . ; : - _ = ( ) [ ] { } '); 
			campo.value=valore.substr(0,i); 
			break; 
		}
	if (campo.name == 'messaggio'){
		if (campo.value.length>num)
		{
			alert('Hai raggiunto il limite di caratteri a disposizione.');
			campo.value=campo.value.substring(0, num);
		}
		document.getElementById('num_char').innerHTML = num - campo.value.length;
	}
}

function resetnum() 
{
	document.getElementById('num_char').innerHTML = num;
}

function checkmail() 
{
	var msg = "";
	var espressione = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;

	if (!document.getElementById('email').innerHTML == ''){
		if (!espressione.test(document.getElementById('email').innerHTML)){
			msg += "La mail non sembra valida.";
		}
	}
	else{
		msg += "Indirizzo mail non specificato.";
	}
	
	if (!msg == ''){
		alert(msg);
		return false;
	}
}






function checkfields() {
     // Variabili associate ai campi del richiestainfo
     var nome = document.richiestainfo.nome.value;
     var cognome = document.richiestainfo.cognome.value;
     var tel = document.richiestainfo.tel.value;
     var email = document.richiestainfo.email.value;
     var msg = document.richiestainfo.messaggio.value;
     // Espressione regolare dell'email
     var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
        //Effettua il controllo sul campo NOME
        if ((nome == "") || (nome == "undefined")) {
           alert("Il campo Nome e' obbligatorio.");
           document.richiestainfo.nome.focus();
           return false;
        }
        //Effettua il controllo sul campo COGNOME
        else if ((cognome == "") || (cognome == "undefined")) {
           alert("Il campo Cognome e' obbligatorio.");
           document.richiestainfo.cognome.focus();
           return false;
        }
        //Effettua il controllo sul campo TELEFONO
        else if ((isNaN(tel)) || (tel == "") || (tel == "undefined")) {
           alert("Il campo Telefono e' numerico ed obbligatorio.");
           document.richiestainfo.tel.value = "";
           document.richiestainfo.tel.focus();
           return false;
        }
        else if (!email_reg_exp.test(email) || (email == "") || (email == "undefined")) {
           alert("Inserire un indirizzo email corretto.");
           document.richiestainfo.email.select();
           return false;
        }
        //INVIA IL richiestainfo
        else {
           document.richiestainfo.action = "contatti2.asp";
           document.richiestainfo.submit();
        }
  }


