
//Script per questionario

//the following function checks whether or not the actual screen is filled (i.e. all questions have some value)
function notEmpty()
{
	var tuttoCompilato = true;
	var erroreMail = false;
	var erroreCap = false;
	var erroreConfermaMail = false;
	var errorePass = false;
	var pieno = true;
	var x;
	var errorMsg =""; //eventuale errore specifico
	var email = document.getElementById("email");
	var confermaEmail = document.getElementById("confermaEmail");
	var psw = document.getElementById("password");
	var confermapsw = document.getElementById("confermaPassword");
	var capAzienda = document.getElementById("cap_azienda");
	var form = document.getElementById("registrazione");
	var selections = form.getElementsByTagName("select");
	for (q=0;q<selections.length;q++){
		if (selections[q].selectedIndex == 0){
			//pensato con l'idea che se rimane selezionata la posizione zero è sbagliato perchè l'utente non ha scelto nulla nella tendina
			tuttoCompilato = false;
			selections[q].style.backgroundColor= "#FF6633";
		}else
			selections[q].style.backgroundColor= "#FFFFFF";
	}
	var inputs = form.getElementsByTagName("input");
	for (j=0;j<inputs.length;j++){
	  x=document.getElementsByName(inputs[j].name);
	   
	  if (x[0].type == "radio"){
		full= false;
		for (i=0;i<x.length;i++){
			if (x[i].checked)
			   full=true;
		}
		if (full==false){
		   tuttoCompilato=false;
		   document.getElementById("labelSesso").style.fontWeight="bold";
		   document.getElementById("labelSesso").style.color="#FF6633";	   
		}else{
			document.getElementById("labelSesso").style.fontWeight="normal";
		   	document.getElementById("labelSesso").style.color="#5a5a5a";	
		}
	  }
	  else if(x[0].type == "text"){
		if (x[0].value == ""){
		   tuttoCompilato=false;
		   x[0].style.backgroundColor= "#FF6633";
		   
		}else{
		   x[0].style.backgroundColor= "#FFFFFF";
		}
	  }
	  else if(x[0].type == "password"){
		if (x[0].value == ""){
		   tuttoCompilato=false;
		   x[0].style.backgroundColor= "#FF6633";
		   
		}else{
		   x[0].style.backgroundColor= "#FFFFFF";
		}
	  }
	  else if(x[0].type == "hidden"){
		if (x[0].value == "no")
		   tuttoCompilato=false;
		   
	  }else if(x[0].type == "file"){
		//il file è opzionale quindi qua non va niente!
	  } 
	}
	if (tuttoCompilato==false) {
		errorMsg = "<br/>* Alcuni campi non compilati (identificati in arancione).";
	}
	
	//Controlli specifici
	if (psw.value != confermapsw.value) {
		psw.style.backgroundColor= "#FF0000";
		confermapsw.style.backgroundColor= "#FF0000";
		errorePass=true;
		errorMsg = errorMsg + "<br/>* Le password inserite non corrispondono.";
	}
	if (psw.value.length <6) {
		psw.style.backgroundColor= "#FF0000";
		confermapsw.style.backgroundColor= "#FF0000";
		errorePass=true;
		errorMsg = errorMsg + "<br/>* Hai inserito una password troppo corta: questa deve comprendere almeno 6 caratteri.";
	}
	if (email.value != "" && (email.value.indexOf("@") == -1 || email.value.indexOf(".") == -1 )) {
		email.style.backgroundColor= "#FF0000";
		confermaEmail.style.backgroundColor= "#FF0000";
		erroreMail=true;
		errorMsg = errorMsg + "<br/>* Inserisci un indirizzo email corretto.";
	}
	if (email.value != "" &&(email.value != confermaEmail.value)) {
		confermaEmail.style.backgroundColor= "#FF0000";
		email.style.backgroundColor= "#FF0000";
		erroreConfermaMail=true;
		errorMsg = errorMsg + "<br/>* Gli indirizzi email inseriti non corrispondono.";
	}
	if (capAzienda.value.length != 0 && capAzienda.value.length != 4) {
		capAzienda.style.backgroundColor= "#FF0000";
		erroreCap=true;
		errorMsg = errorMsg + "<br/>* Il CAP deve essere composto da 4 cifre.";
	}
	//alert(tuttoCompilato);
	if (tuttoCompilato == false || errorePass || erroreMail || erroreConfermaMail || erroreCap){
		document.getElementById("erroriForm").innerHTML="* Attenzione: errori nella compilazione del modulo."+errorMsg;
		//alert(errorePass+ " " + erroreMail +" "+ erroreConfermaMail + " " + erroreCap);
		return false;
	
	}
	else {
		//alert("ciao");
		return true;
	}
}

