function abilitadatifatturazione() {
	var List = document.getElementsByName("datifatturazione");
	for(var i=0; i<List.length; i++) {
	  if(List[i].checked) {
		if(List[i].value == 'si'){
			document.getElementById("dati_fatturazione").style.display="none";
		}else{
			document.getElementById("dati_fatturazione").style.display="block";
			/*document.getElementById("nome_fatturazione").value=document.getElementById("nome").value;
			document.getElementById("cognome_fatturazione").value=document.getElementById("cognome").value;
			document.getElementById("indirizzo_fatturazione").value=document.getElementById("indirizzo").value;
			document.getElementById("localita_fatturazione").value=document.getElementById("localita").value;
			document.getElementById("cap_fatturazione").value=document.getElementById("cap").value;
			document.getElementById("provincia_fatturazione").value=document.getElementById("provincia").value;
			document.getElementById("paese_fatturazione").value=document.getElementById("paese").value;
			document.getElementById("telefono_fatturazione").value=document.getElementById("telefono").value;
			document.getElementById("piva_fatturazione").value=document.getElementById("piva").value;
			document.getElementById("ragione_sociale_fatturazione").value=document.getElementById("ragione_sociale").value;
			document.getElementById("codice_fiscale_fatturazione").value=document.getElementById("codice_fiscale").value;*/
		}
		break;
	  }
	}
}


function valida_email(txt){
	var r = /^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i;

	if(r.test(txt)) return true;
	else return false;
}

function ControllaRegistrazione(f){
	var check = true;
	var output = '';

		if(!valida_email(f.elements.username.value)){
			check = false;
			output += 'Inserisci un indirizzo EMAIL corretto'+"\n";
		}

		if(f.elements.password.value==''){
			check = false;
			output += 'Inserisci una password'+"\n";
		}

		if(f.elements.password2.value==''){
			check = false;
			output += 'Inserisci la conferma password'+"\n";
		}

		if(f.elements.password.value != f.elements.password2.value){
			check = false;
			output += 'La password non coincide con la password di conferma'+"\n";
		}
		

	if(!check) alert(output);
	return check;

}

function AbilitaEmailAmico(f){
	if (f.checked==true) {
		document.getElementById("email_amico").style.display="block";
	} else {
		document.getElementById("email_amico").style.display="none";
	}
}

function controllaForm(f){
	var check = true;
	var output = '';

	if(f.elements.nome.value==''){
		check = false;
		output += 'Inserisci Nome'+"\n";
	}

	if(f.elements.cognome.value==''){
		check = false;
		output += 'Inserisci Cognome '+"\n";
	}
	if(f.elements.codice_fiscale.value==''){
		check = false;
		output += 'Inserisci il Codice Fiscale '+"\n";
	}
	if(f.elements.ragione_sociale.value !=''){
		if(f.elements.piva.value==''){
			check = false;
			output += 'Hai compilato la ragione sociale, inserisci la partita iva '+"\n";
		}
	}

	if(f.elements.indirizzo.value==''){
		check = false;
		output += 'Inserisci indirizzo '+"\n";
	}

	if(f.elements.cap.value==''){
		check = false;
		output += 'Inserisci CAP '+"\n";
	}
	if(f.elements.localita.value==''){
		check = false;
		output += 'Inserisci la cittą '+"\n";
	}

	if(f.elements.provincia.value==''){
		check = false;
		output += 'Inserisci provincia '+"\n";
	}

	if(f.elements.paese.value==''){
		check = false;
		output += 'Inserisci nazione '+"\n";
	}

	if(f.elements.telefono.value==''){
		check = false;
		output += 'Inserisci telefono '+"\n";
	}

	if(!valida_email(f.elements.mail.value)){
		check = false;
		output += 'Inserisci un indirizzo EMAIL corretto'+"\n";
	}


	/*Dati per la fatturazione*/
	if (document.getElementsByName("datifatturazione")[1].checked == true){
		if(f.elements.nome_fatturazione.value==''){
			check = false;
			output += 'Inserisci Nome per la fatturazione'+"\n";
		}

		if(f.elements.cognome_fatturazione.value==''){
			check = false;
			output += 'Inserisci Cognome  per la fatturazione'+"\n";
		}

		if(f.elements.codice_fiscale_fatturazione.value==''){
		check = false;
		output += 'Inserisci il Codice Fiscale  per la fatturazione'+"\n";
		}	
		if(f.elements.ragione_sociale_fatturazione.value !=''){
			if(f.elements.piva_fatturazione.value==''){
				check = false;
				output += 'Inserisci la P.IVA per la fatturazione'+"\n";
			}
		}

		if(f.elements.indirizzo_fatturazione.value==''){
			check = false;
			output += 'Inserisci indirizzo per la fatturazione '+"\n";
		}

		if(f.elements.cap.value==''){
			check = false;
			output += 'Inserisci CAP per la fatturazione'+"\n";
		}
		if(f.elements.localita_fatturazione.value==''){
			check = false;
			output += 'Inserisci la cittą  per la fatturazione'+"\n";
		}

		if(f.elements.provincia_fatturazione.value==''){
			check = false;
			output += 'Inserisci provincia per la fatturazione'+"\n";
		}

		if(f.elements.paese_fatturazione.value==''){
			check = false;
			output += 'Inserisci nazione  per la fatturazione'+"\n";
		}

		if(f.elements.telefono_fatturazione.value==''){
			check = false;
			output += 'Inserisci telefono per la fatturazione'+"\n";
		}
	}

	if(!check) alert(output);
	return check;
}
