var loginForm;

window.onload = init;

function init() {
	loginForm = document.getElementById('form_reg');
	loginForm.onsubmit = function () {
		return canSubmit(this);
	}
	//loginForm.email.focus();
}

//Definisce il valore del campo VUOTO
function filled(field) {
	if (field.value == "" || field.value == " " || field.value == null || field.value == 0 || field.value == '00' || field.value == 'anno') {
	//if (field.value == 0 || field.value == null) {
		return false;
	} else {
		return true;
	}
}
	
function canSubmit(form) {
	if (!filled(form.nome)) {
		alert("Il tuo Nome è obbligatorio.");
		form.nome.focus();
		document.getElementById('nome').style.border = '1px solid #FF6600';
		return false;
	}
	if (!filled(form.cognome)) {
		alert("Il tuo Cognome è obbligatorio.");
		form.cognome.focus();
		document.getElementById('cognome').style.border = '1px solid #FF6600';
		return false;
	}
	if (!filled(form.email)) {
		alert("L'email è obbligatoria");
		document.getElementById('email').style.border = '1px solid #FF6600';
		form.email.focus();
		return false;
	} else {
		regExp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
   		if (regExp.test(form.email.value)) {
   		} else {
			alert("L'email non risulta valida");
			document.getElementById('email').style.border = '1px solid #FF6600';
			form.email.focus();
			return false;
		}
	}
	if (!filled(form.richiesta)) {
		alert("Il messaggio è obbligatorio");
		form.richiesta.focus();
		return false;
	}
	if (!filled(form.verifica_cod)) {
		alert("Non hai inserito il codice di verifica antirobot in basso nella pagina.");
		form.verifica_cod.focus();
		document.getElementById('verifica_cod').style.border = '1px solid #FF6600';
		return false;
	} else {
		codVer = document.getElementById('verifica_cod');
		c1 = document.getElementById('code').value;
		c2 = document.getElementById('code2').value;
		if (codVer.value != c2 + "S4m" + c1){
			alert("Il codice di verifica antirobot in basso nella pagina è errato.");
			form.verifica_cod.focus();
			codVer.style.border = '1px solid #FF6600';
			return false;
		}
	}

	return true;
}