function checkEmail(str){
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (filter.test(str)){	return true;	}else{		return false;	}
}		
function trim(stringa) { return stringa.replace(/^\s+|\s+$/, ''); };
function subme(modulo) {
	var errors='';
  	var ook = true;
	
	if (modulo.firstname.value=="") {
		errors+='- Nome\n';
    	ook=false;
  	}; 
	
	if (modulo.realname.value=="") {
		errors+='- Cognome\n';
    	ook=false;
  	}; 
	
	if (!checkEmail(modulo.email.value)) {
		errors+='- Indirizzo E-mail valido\n';
     	ook=false;
   	};
	
	if (modulo.citta.value=="") {
		errors+='- Citt' + String.fromCharCode(224) + '\n';
    	ook=false;
	}; 
	
	if (modulo.provincia.selectedIndex==0) {
		errors+='- Provincia\n';
    	ook=false;
  	};
	
	/* Controlla l'estensione del file: */
	if (modulo.allegati.value!="") {
		var nome_file = modulo.allegati.value;  
		var ext = modulo.estensioni_file.value;
		
		var extErr = true;
		if (ext != null) {
			var exts = ext.split(",");
			var app = nome_file.split(".");
			var our_ext = app[app.length-1];
										
			for (a in exts) {
				if (trim(exts[a]) == trim(our_ext)) {
					extErr = false;
				}
			}
		}
		
		if (extErr) {
			errors+='- Estensione del file allegato\n';
			ook=false;
		}    
   	};

	if (!(modulo.tratt_dati.checked)) {
		errors+='\n'+'E\' necessario acconsentire al trattamento dei dati personali\n';
    	ook=false;
  	};

	if (!ook) {
  		alert('Attenzione: i seguenti campi sono obbligatori:\n\n'+errors);
  	}
  
  	return ook;
}
