// JavaScript Document

function checkMail () {
	if (document.getElementById('email').value!="") {
		//alert ('email non corretta');
		var criterio = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		var email = document.getElementById('email').value;
		//alert(email);
		var result = criterio.test(email);
		//alert(result);
		if (result==false) {
			alert("Attenzione, controllare l'esattezza dell'indirizzo email. Esempio: esempio@email.it");
		}
	}
}


function ProvDefiner(x,y) {
	if (x.value!="" && x.value!="Italy") {
		//alert('Non e\' l\'Italia');
		y.value="";
		y.disabled=true;
	} else {
		y.style.backgroundColor="";
		y.disabled=false;
	}
}


function validaCampo(x) {
	var campo_ok = true;
	var a= document.getElementById(x);
	
	if (a.value=="") {
		a.style.backgroundColor="#FFFF99";
		campo_ok = false;
	} else {
		a.style.backgroundColor="";	
	}
	
	return campo_ok;
}

function validaTendina(x) {
	var tendina_ok = true;
	var a = document.getElementById(x);
	if (a.value=="" || a.value=="Scegli l'opzione...") {
		a.style.backgroundColor="#FFFF99";
		tendina_ok = false;
	} else {
		a.style.backgroundColor="";	
	}
	
	return tendina_ok;
}


function validaCheck(x,y) {
	var check_ok = true;

	var a = document.getElementById(x);
	var b = document.getElementById(y);
	if (a.checked==false) {
		b.style.backgroundColor="#FFFF99";
		check_ok = false;
	} else {
		b.style.backgroundColor="";		
	}
	return check_ok;
}


function validaRadio(x,y,k) {
	var radio_ok = true;
	var a = document.getElementById(x);
	var b = document.getElementById(y);
	var j = document.getElementById(k);
	
	if (a.checked==false && c.checked==false) {
		j.style.backgroundColor="#FFFF99";
		radio_ok = false;
	} else {
		j.style.backgroundColor="";	
	}
	
	return radio_ok;
}


function validaRadio3(x,y,z,k) {
	var radio_ok = true;
	var a = document.getElementById(x);
	var b = document.getElementById(y);
	var c = document.getElementById(z);
	var j = document.getElementById(k);
	
	if (a.checked==false && b.checked==false && c.checked==false) {
		j.style.backgroundColor="#FFFF99";
		radio_ok = false;
	} else {
		j.style.backgroundColor="";	
	}
	
	return radio_ok;
}


function validaRadio5(v,w,x,y,z,k) {
	var radio_ok = true;
	var a = document.getElementById(v);
	var b = document.getElementById(w);
	var c = document.getElementById(x);
	var d = document.getElementById(y);
	var e = document.getElementById(z);
	var j = document.getElementById(k);
	
	if (a.checked==false && b.checked==false && c.checked==false && d.checked==false && e.checked==false) {
		j.style.backgroundColor="#FFFF99";
		radio_ok = false;
	} else {
		j.style.backgroundColor="";	
	}
	
	return radio_ok;
}

function validaForm() {		
	var autorizzazione = true;

  if (validaCampo('nome')==false) {
		autorizzazione = false;	
	}
	if (validaCampo('cognome')==false) {
		autorizzazione = false;	
	}
	if (validaCampo('azienda')==false) {
		autorizzazione = false;	
	}
	if (validaCampo('mail')==false) {
		autorizzazione = false;	
	}	
	if (validaCheck('privacy','privacy1')==false) {
		autorizzazione = false;
	}
	if (validaCheck('consenso','consenso1')==false) {
		autorizzazione = false;
	}
	if (validaTendina('tipologiasito') == false) {
		autorizzazione = false;
  }
	
	if (autorizzazione == false) {
		document.getElementById('inizio').style.visibility="visible";
		document.getElementById('inizio').focus();
	}
	
	return autorizzazione;
}



