
function ValidateAndSubmit() {
	var errortext = "";
	var firstfield = 1;
	if (document.editdata.nome.value == "") {
		errortext = errortext + "Il campo Nome è obbligatorio.\n";
		if (firstfield == 1) {
			firstfield = 0;
			document.editdata.nome.focus();
		}
	}

	if (document.editdata.cognome.value == "") {
		errortext = errortext + "Il campo cognome è obbligatorio.\n";
		if (firstfield == 1) {
			firstfield = 0;
			document.editdata.cognome.focus();
		}
	}

	if (document.editdata.email.value == "" || !isEmail(document.editdata.email.value)) {
			errortext = errortext +"Il campo Indirizzo e-mail è obbligatorio o quello inserito non è valido.\n";
			if (firstfield == 1) {
				firstfield = 0;
				document.editdata.email.focus();
			}
	}

	if (document.editdata.commento.value.replace(/\s/g,"").length < 1) {
		errortext = errortext + "Non hai inserito nessuna richiesta/commento .\n";
		if (firstfield == 1) {
			firstfield = 0;
			document.editdata.commento.focus();
		}
	}
	
	if (!document.editdata.autorizzazione.checked) {
		errortext = errortext + "Non è 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));
}
