// CONTROLLO FORM DI informazioni
// (C) Matteo Gattei 12/2001
function InizialeMaiuscola(stringa)
  {
	stringa=stringa.toLowerCase();
	var l=stringa.length;
	var car="";
	var maiuscolo=true;
	var risultato="";
	for (var i=0;i<l+1;i++)
		{
		car=stringa.charAt(i);	
		if (maiuscolo)
			{
			car=car.toUpperCase();
			maiuscolo=false;
			}
		if (car==" " || car=="'") maiuscolo=true;
		risultato+=car;
		}
	stringa=risultato;			
	return stringa;
  }

function check_form()
  {
	// TRADUZIONI
	// ---------------------------------------------------------------------------------------------
	errNome1	= "Name field must be filled in!";
	errNome2	= "Name field must have a maximum length of 30 characters!";
	errCognome1	= "Last name field must be filled in!";
	errCognome2	= "Last Name field must have a minimum 2 and a maximum length of 30 characters!";
	errEmail1	= "E-MAIL field must be filled in!";
	errEmail2	= "E-MAIL field incorrect!";
	errEmail3	= "E-MAIL field must have @ e . characters!";
	errHow1		= "HOW field must be filled in";
	errHow2		= "HOW field must have a minimum 2 and a maximum length of 60 characters!";
	errInfo1	= "INFO field must be filled in!";
	errInfo2	= "INFO field must have a minimum 2 and a maximum length of 200 characters!";
	errCheck	= "Please enter the verification code you see in the picture.";
	errPrivacy	= "To send you information you have to authorize the treatment of your personal data.";
	// Non dovrebbe essere necessario cambiare niente qui sotto...
	// ---------------------------------------------------------------------------------------------
	
	// Controllo Nome
	var nome=document.informazioni.nome.value;
	document.informazioni.nome.value=InizialeMaiuscola(nome)
	if (nome=="")
	  {
		window.alert (errNome1);
		return false;
	  }
	if (nome.length<2 || nome.length>30)
	  {
		window.alert (errNome2);
		return false;
	  }

	// Controllo Cognome
	var cognome=document.informazioni.cognome.value;
	document.informazioni.cognome.value=InizialeMaiuscola(cognome);
	if (cognome=="")
	  {
		window.alert (errCognome1);
		return false;
	  }
	if (cognome.length<2 || cognome.length>30)
	  {
		window.alert (errCognome2);
		return false;
	  }

	// Controllo Email	 
	var email=document.informazioni.email.value;
	var flag_at,flag_dot;
	if (email=="")
	  {
		window.alert (errEmail1);
		return false;
	  }
	if (email.length<7 || email.length>50)
	  {
		window.alert (errEmail2);
		return false;
	  }
	flag_at=false;
	flag_dot=false;
	for (var j=0;j<51;j++)
	  {
		if (email.charAt(j)=="@") { flag_at=true; }
		if (email.charAt(j)==".") { flag_dot=true; }
	  }
	if (flag_at==false || flag_dot==false)
	  {
		window.alert (errEmail3);
		return false;
	  }
	document.informazioni.email.value=email.toLowerCase();

	// Controllo How
	var how=document.informazioni.how.value;
	if (how=="")
	  {
		window.alert (errHow1);
		return false;
	  }
	if (how.length<2 || how.length>60)
	  {
		window.alert (errHow2);
		return false;
	  }

	// Controllo Info
	var info=document.informazioni.info.value;
	if (info=="")
	  {
		window.alert (errInfo1);
		return false;
	  }
	if (info.length<2 || info.length>200)
	  {
		window.alert (errInfo2);
		return false;
	  }

	// Controllo CAPTCHA
	var check_code=document.informazioni.check_code.value;
	if (check_code=="")
	  {
		window.alert (errCheck);
		return false;
	  }
	// Controllo checkbox Privacy
	if (!document.informazioni.privacy.checked)
	  {
		window.alert (errPrivacy);
		return false;
	  }

	document.informazioni.submit();
  }