/* Foglio javascript CONTATTI per LIBERTA' DI VACANZA */
/* ****************************************************** GET ELEMENT BY ID */
function restituisciElemento(id) {
	if (document.getElementById)
		elemento = document.getElementById(id);
	else if (document.all)
		elemento = document.all[id];
	else if (document.layers)
		elemento =  document.layers[id];
	else
		alert("Browser incompatibile!");
	return elemento;
}

/* ****************************************************** CONTROLLO FORM */
function controlloform() {
	nome = restituisciElemento('nome');
	cognome = restituisciElemento('cognome');
	email = restituisciElemento('email');
	note = restituisciElemento('note');
	accetto = restituisciElemento('accetto');	
	if (nome.value=="") {
		alert("Ha dimenticato di inserire il Nome");
		return false;
	} else if (cognome.value=="") {
		alert("Ha dimenticato di inserire il Cognome");
		return false;
	} else if (note.value=="") {
		alert("Ha dimenticato di inserire il Messaggio");
		return false;
	} else if (validaEmail(email)) {
		if (accetto.checked) {
			return true;
		} else {
			alert("Per inviare il messaggio è necessario accettare le condizioni sul trattamento dei dati personali");
			return false;
		}
	} else {
		return false;
	}
}	


function controlloform_en() {
  nome = restituisciElemento('nome');
  cognome = restituisciElemento('cognome');
  email = restituisciElemento('email');
  note = restituisciElemento('note');
  accetto = restituisciElemento('accetto');	
	if 	(nome.value=="") {
		alert("You forgot to insert the Name");
		return false;
	} else if (cognome.value=="") {
		alert("You forgot to insert the Last Name");
		return false;
	} else if (note.value=="") {
		alert("You forgot to insert the Message");
		return false;
	} else if (validaEmail_en(email)) {
		if (accetto.checked) {
			return true;
		} else {
			alert("You forgot to accept the conditions of law n. 196/2003");
			return false;
		}
	} else {
		return false;
	}
}

/* ****************************************************** CONTROLLO MAIL */
function validaEmail(campoEmail) {
	_pattern=/^[\w\-]+(\.?\-?\w+)*@[a-zA-Z0-9]+(\.?\-?[a-zA-Z0-9]+){2,}\.[a-zA-Z]{2,}$/;
	if (_pattern.test(campoEmail.value)==false) {
		alert("Non è stato inserito un indirizzo mail valido");
		return false;
	}
	return true;
}


function validaEmail_en(campoEmail) {
	_pattern=/^[\w\-]+(\.?\-?\w+)*@[a-zA-Z0-9]+(\.?\-?[a-zA-Z0-9]+){2,}\.[a-zA-Z]{2,}$/;
	if (_pattern.test(campoEmail.value)==false) {
		alert("You forgot to insert a valid e-mail address");
		return false;
	}
	return true;
}
/* ****************************************************** HISTORY BACK */
function indietro(){
  history.back();
	return false;
}

//Fine Javascript