function gestModulo()
  {
  var myErr=new Array();
  var myMust=false;
  // controllo nome
  myString=trim(document.forms[0].elements[2].value);
  if(myString.length<2)myErr.push(2);
  
  //controllo e-mail
  e=/^[a-z][a-z.-]{3,25}@[a-z-]{2,25}\.\w{2,3}$/;
  myString=trim(document.forms[0].elements[3].value.toLowerCase());
  if(myString!="" && !e.test(myString))myErr.push(3);
  
  //controllo telefono 1 e 2
  e=/^[0-9]{2,4}\D{0,3}[0-9]{6,9}$/
	myString=trim(document.forms[0].elements[4].value);
  if(!e.test(myString))myErr.push(4);
	
  myString=trim(document.forms[0].elements[5].value);
  if(myString!="" && !e.test(myString))myErr.push(5);
  
  //controllo località
  myString=trim(document.forms[0].elements[6].value);
  if(myString.length<3)myErr.push(6);
  
  for(i=0;i<myErr.length;i++)
	if(myErr[i]==2||myErr[i]==4||myErr[i]==6)myMust=true;
	
  if(myErr.length>0)
    {
	manageErr(myErr);
		}
  else
    {
	manageSub();	
  	}
  }
  
function manageSub()
  {
  document.forms[0].submit();
	myLeft=Math.round((screen.width-550)/2);
	myTop=Math.round((screen.height-180)/2-100);
	
	var f=window.open("about:blank","","width=550, height=180, top="+myTop+", left="+myLeft+", location=no, "+
		"status=no, resizable=no");
  f.document.write('<html><head><title>Conferma invio</title>'+
    '<link rel="stylesheet" href="Stili.css" type="text/css">'+
	'</head><body bgcolor="#F1FCFB" text="#000000"><p align="center" class="Titolo3">'+
	'<img src="myImmagini/okeio.gif" alt="okay" width="46" height="46" hspace="10" vspace="10" align="absmiddle">'+
	'I dati sono stati inviati correttamente<br>Grazie!<br><br><br>'+
	'<input type=button value="Chiudi finestra" onClick="window.close()">');
  f.document.close();
  }

function manageErr(myErr)
  {
  myMust=false;
  var myLabel=new Array("h","h","Nome","Indirizzo e-mail","Telefono","Telefono 2","Località");
  myHeight=myErr.length*40+180;
  myLeft=Math.round((screen.width-600)/2);
  myTop=Math.round((screen.height-myHeight)/2-100);
  var f=window.open("about:blank","","width=600, height="+myHeight+", top="+myTop+", left="+myLeft+", location=no, "+
		"status=no, resizable=no");
  f.document.write('<html><head><title>Errore nel modulo</title>'+
    '<link rel="stylesheet" href="Stili.css" type="text/css">'+
	'</head><body bgcolor="#F1FCFB" text="#000000"><p align="center" class="Titolo3">'+
	'<img src="myImmagini/errore.gif" alt="errore" width="46" height="46" hspace="10" vspace="10" align="absmiddle">');
  if(myErr.length==1)f.document.write('Il seguente campo non é stato riempito correttamente:</P>')
	else f.document.write('I seguenti campi non sono stati riempiti correttamente:</p>');
  for(i=0;i<myErr.length;i++)
	{
	if(myErr[i]%2==0)myMust=true;
	f.document.write('<p class="TestoForteCentrato">'+myLabel[myErr[i]]+'</p>');
	}
  f.document.write('<p>&nbsp;</p><div align="center">');
  if(myMust)f.document.write('<input type=button value="Chiudi finestra" onclick="window.close();" />')
    else
	  {f.document.write('<hr><p class="Testo-centrato">Inviare comunque?<p>'+
	    '<input type=button value="Invia" onClick="window.close();window.opener.manageSub();">'+
	    '<input type=button value="Non inviare" onClick="window.close();">');
	  f.resizeTo(600, myHeight+150);
	  }

  f.document.write('</div></body></html>');
  f.document.close();
  }
	
function trim(myStr)
	{
	return myStr.replace(/^\s+|\s+$/g,"");
	}
