// ============================================================
// Script:     Email Address Checker-Validator
// 
// Functions:
// 
//    Checks name field to see if empty
//    Checks e-mail address, which must have:
//       - "@" symbol and no spaces
//       - one or more good characters before
//             and after "@" 
//       - .xx country code or .com, .net,
//             .edu, .mil, .gov, .org at end
//    First (em) and second (emx) email addresses
//       must be equal and name field must have more
//       than one character to pass the script tests
// 
// Browsers:   All 4.0 and later browsers
// 
// Author:     etLux
// ============================================================

// (C) 2000 www.CodeLifter.com
// http://www.codelifter.com
// Free for all users, but leave in this  header

var good;
function checkEmailAddress(field) {

	// Note: The next expression must be all on one line...
	//       allow no spaces, linefeeds, or carriage returns!
	var goodEmail = field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\.xxx)|(\..{2,4}))$)\b/gi);
	
	if (goodEmail){
	   good = true;
	} else {
		alert("Il campo E-mail non è stato specificato correttamente");
	   field.focus();
	   field.select();
	   good = false;
	}
}

function sendOff(){
	name_check = document.Form_Contatti.c2.value;
	surname_check = document.Form_Contatti.c3.value;
	email_check = document.Form_Contatti.c4;
	message_check = document.Form_Contatti.c5.value;
	
	if (name_check.length < 1) { alert("Il campo Nome non è stato specificato"); return; }
	if (surname_check.length < 1) { alert("Il campo Cognome non è stato specificato"); return; }         
	if (message_check.length < 1) { alert("Il campo Messaggio non è stato specificato"); return; }         

	if (document.Form_Contatti.privacy.checked == false) {
		alert("E' necessario acconsentire al trattamento dei dati.");
		return;
	}
	
	good = false;
	checkEmailAddress(email_check);

	if(good == true){
		document.Form_Contatti.submit();
	}

}

function checkContact(wich){
	OFORM = wich.form;

	if(wich.checked == true){
		OFORM.submit_contact.disabled = false;
	}else{
		OFORM.submit_contact.disabled = true;
	}
}
