/*/////////////////////////////////////////////////////////*/
// 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 citta = modulo.citta.value;
	var nazione = modulo.nazione.value;
	var telefono = modulo.telefono.value;
	var posta_e = modulo.posta_e.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){msg[++i_m] = '-> Name and Surname are required .\n';}
	//if(!indirizzo){msg[++i_m] = '-> devi inserire l\'indirizzo .\n';}
	//if(!citta){msg[++i_m] = '-> devi inserire la Citta\'.\n';}
	//if(!nazione){msg[++i_m] = '-> devi inserire la Nazione .\n';}
	//if(!cap){msg[++i_m] = '-> devi inserire il Cap.\n';}else if (isNaN(cap)){
		//msg[++i_m] = '-> devi inserire il Cap nel formato corretto.\n';}
	//if(!cap){msg[++i_m] = '-> devi inserire il Cap.\n';}
	if (telefono){
		if(isNaN(telefono)){msg[++i_m] = '-> Phone must be only numbers and no spaces.\n';}	
	}
	if(!posta_e){msg[++i_m] = '-> E-mail is required.\n';}
		else if (!posta_e.match(reg_email)){msg[++i_m] = "-> E-mail must be a valid address.\n";}
	if(!richieste){msg[++i_m] = '-> Request is required.\n';}
	if(!privacy){msg[++i_m] = '-> you must agree Privacy Policy .\n';}
	
	
	// Se ci sono messaggi
	if(msg.length > 0){
		if(msg.length){avv = 'Some information is missing...\n\n';}
		
		var i = 0;
		while(i <= (msg.length-1)){
			avv += msg[i];
			i++;
		}
		alert(avv);
	}else{
		// Altrimenti invio il form
		modulo.submit();
	}

}

