
function ValidateAndSubmit() {
	var errortext = "";
	var firstfield = 1;

	if (document.editdata.nome.value == "") {
		errortext = errortext + "Il campo Nome &egrave; obbligatorio.\n";
		if (firstfield == 1) {
			firstfield = 0;
			document.editdata.nome.focus();
		}
	}

	if (document.editdata.citta.value == "") {
		errortext = errortext + "Il campo Citt&agrave; &egrave; obbligatorio.\n";
		if (firstfield == 1) {
			firstfield = 0;
			document.editdata.citta.focus();
		}
	}

	if (document.editdata.email.value == "" || !isEmail(document.editdata.email.value)) {
			errortext = errortext +"Il campo Indirizzo e-mail &egrave; obbligatorio o quello inserito non &egrave; valido.\n";
			if (firstfield == 1) {
				firstfield = 0;
				document.editdata.email.focus();
			}
	}

	if (document.editdata.commento.value == "") {
		errortext = errortext + "Non hai inserito nessuna richiesta.\n";
		if (firstfield == 1) {
			firstfield = 0;
			document.editdata.commento.focus();
		}
	}

	if (!document.editdata.autorizzazione.checked) {
		errortext = errortext + "Non &egrave; possibile inviare il modulo se non si autorizza al trattamento dei dati.\n";
		if (firstfield == 1) {
			firstfield = 0;
			document.editdata.autorizzazione.focus();
		}
	}

	if (errortext != "") {
		alert(errortext);
	} else {
		document.editdata.submit();
	}
}

function isEmail(str) {
	var supported = 0;
	if (window.RegExp) {
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) supported = 1;
	}

	if (!supported) 
		return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);

	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	return (!r1.test(str) && r2.test(str));
}
