/*/////////////////////////////////////////////////////////*/
// CONTROLLO FORM
/*/////////////////////////////////////////////////////////*/



////////////////////////
// Controllo dati form
////////////////////////
function controllo_invio_form(modulo){
	
	
	var reg_email = new RegExp("^([-_.#$&a-zA-Z0-9]+)[@][-_.a-zA-Z0-9]+(\\.[a-zA-Z]{2,4})(\\.[a-zA-Z]{2,4})?$","");
	
	// Recupero alcuni elementi della pagina
	var nome = modulo.nome.value;
	var rag_soc = modulo.ragione_sociale.value;
	var citta = modulo.citta.value;
	var indirizzo = modulo.indirizzo.value;
	var telefono = modulo.telefono.value;
	var email = modulo.email.value;
	var richieste = modulo.richieste.value;
	var privacy = modulo.privacy.checked;

	/////////////////////////////////////////////
	// Messaggio vuoto
	/////////////////////////////////////////////
	var avv = '';
	var msg = new Array();
	var i_m = -1;
	
	//////////////////////////////////////////////
	// Dati obbligatori
	//////////////////////////////////////////////
	if(!nome){i_m++; msg[i_m] = '-> you must fill in the Name and Surname .\n';}
	if(!citta){i_m++; msg[i_m] = '-> you must fill in Town.\n';}
	if(!telefono){i_m++; msg[i_m] = '-> you must fill in the Telephone.\n';}
	if(!email){i_m++; msg[i_m] = '-> you must fill in the E-mail.\n';}
		else if (!email.match(reg_email)){i_m++; msg[i_m] = "-> invalid E-mail address\n";}
	if(!richieste){i_m++; msg[i_m] = '-> you must fill in the requests.\n';}
	if(!privacy){i_m++; msg[i_m] = '-> you must agree our privacy policy .\n';}
	
	
	// Se ci sono messaggi
	if(msg.length > 0){
		if(msg.length){avv = 'The are some missing informations...\n\n';}
		
		var i = 0;
		while(i <= (msg.length-1)){
			avv += msg[i];
			i++;
		}
		alert(avv);
	}else{
		// Altrimenti invio il form
		modulo.submit();
	}

}

