
function ValidLength(str,number) {
	if (str < number)
		return false;
	return true;
}

function ValidChars(CheckStr,chars) {
	for (i = 0;  i < CheckStr.length;  i++) {
    	ch = CheckStr.charAt(i);
    for (j = 0;  j < chars.length;  j++)
		if (ch == chars.charAt(j))
        	break;
		if (j == chars.length)
		return false;
	}
	return true;
}

function ValidString(CheckStr,RepeatNum) {
	if (CheckStr.length >= RepeatNum) {
		for (k = 0; k < CheckStr.length - 2; k++) {
		l = k+1;
			if  (CheckStr.charAt(k) == CheckStr.charAt(l)) {
				m = l+1;
				if (CheckStr.charAt(k) == CheckStr.charAt(m)) {
					return false;
					break;
				}
				else {
					k++;
				};
			}
		}
	}
	return true;
}

function ValidNumber (checkStr) {
	checkNumber = "0123456789";
	for (z = 0; z < checkStr.length; z++) {
		for (a = 0; a < checkNumber.length; a++) {
			if (checkStr.charAt(z) == checkNumber.charAt(a)) {
				return true;
			}
		}
	}
	return false;
}

/*
FUNZIONE validate() - Come dice il nome stesso, controlla i campi di una form prima di spedirli
*/
	function validate() {
		if(document.forms[0].Nome.value=='') {
			alert('Please, write your Name and Surname')
			document.forms[0].Nome.focus();
			return false;
		}
		if(document.forms[0].Indirizzo.value=='') {
			alert('Please, write your Address')
			document.forms[0].Indirizzo.focus();
			return false;
		}
		if(document.forms[0].Cap.value=='') {
			alert('Please, write your Zip code')
			document.forms[0].Cap.focus();
			return false;
		}
		if(document.forms[0].Citta.value=='') {
			alert('Please, write your Town,State or Province')
			document.forms[0].Citta.focus();
			return false;
		}
		if(document.forms[0].Prov.value=='') {
			alert('Please, write your Country')
			document.forms[0].Prov.focus();
			return false;
		}
/*------------------ INIZIO Validazione Email --------------------*/
var FormEmail = document.forms[0].Email.value
ValidEmailChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_@.";

	if (!ValidLength(FormEmail.length, 5)) {
		alert ('Please, write your Email address');
		document.forms[0].Email.focus();
		return false;
	}
dot = FormEmail.indexOf(".");
afterdot = FormEmail.charAt(dot +1);

	if (dot == -1 || afterdot == "") {
		alert('You have to put a valid Email address');
		document.forms[0].Email.focus();
		return false;
	}
at = FormEmail.indexOf("@");
afterat = FormEmail.charAt(at +1);

	if (at == -1 || afterat == "") {
		alert('You have to put a valid Email address');
		document.forms[0].Email.focus();
		return false;
	}
	if (!ValidChars(FormEmail, ValidEmailChars)) {
		alert('Your Email address is uncorrect!');
		document.forms[0].Email.focus();
		return false;
	}
/*------------------ FINE Validazione Email --------------------*/

		if(document.forms[0].Messaggio.value=='') {
			alert('Please, write your Message')
			document.forms[0].Messaggio.focus();
			return false;
		}
		if(!(document.forms[0].Trattamento_dati.checked)) {
			alert('You have to accept your personal data treatment in order to send us your information request')
			document.forms[0].Trattamento_dati.focus();
			return false;
		}
	}
