var loginForm;

window.onload = init;

function init() {
	loginForm = document.getElementById('cssform');
	loginForm.onsubmit = function () {
		return canSubmit(this);
	}
	loginForm.e_mail.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 \u00E8 obbligatorio.");
		form.nome.focus();
		document.getElementById('nome').style.border = '1px solid #FF6600';
		return false;
	}
	if (!filled(form.cognome)) {
		alert("Il tuo Cognome \u00E8 obbligatorio.");
		form.cognome.focus();
		document.getElementById('cognome').style.border = '1px solid #FF6600';
		return false;
	}
	if (!filled(form.e_mail)) {
		alert("La tua email \u00E8 obbligatoria.");
		form.e_mail.focus();
		document.getElementById('e_mail').style.border = '1px solid #FF6600';
		return false;
	}
	if (!filled(form.richiesta)) {
		alert("Non hai inserito nessun messaggio.");
		form.richiesta.focus();
		document.getElementById('richiesta').style.border = '1px solid #FF6600';
		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 + "Z3n" + c1){
			alert("Il codice di verifica antirobot in basso nella pagina \u00E8 errato.");
			form.verifica_cod.focus();
			codVer.style.border = '1px solid #FF6600';
			return false;
		}
	}

	return true;
}
