
function Controlla(theForm)
{

if (theForm.Azienda.value == "")
  {
    alert("Inserire un valore per il campo \"Azienda\".");
    theForm.Azienda.focus();
    return (false);
  }

if (theForm.Piva.value == "")
  {
    alert("Inserire un valore per il campo \"Partita Iva\".");
    theForm.Piva.focus();
    return (false);
  }

// Check Piva

if (theForm.Piva.value.length != 11)
	{
	alert("La lunghezza della partita IVA non è corretta.");
    theForm.Piva.focus();
    return (false);
	}

b=0
for( a = 0; a < 10; a++ )
	{
	if( theForm.Piva.value.charAt(a) == theForm.Piva.value.charAt(a+1) )
		{
		b = b+1
		if (b == 10)
			{
			alert("La partita IVA non é valida");
			theForm.Piva.focus();
			return (false);
			}
		}
	
	}

validi = "0123456789";
for( i = 0; i < 11; i++ )
	{
	if( validi.indexOf( theForm.Piva.value.charAt(i) ) == -1 )
		{
		alert("La partita IVA contiene un carattere non valido.");
		theForm.Piva.focus();
		return (false);
		}
	}

s = 0;
for( i = 0; i <= 9; i += 2 )
	{
	s += theForm.Piva.value.charCodeAt(i) - '0'.charCodeAt(0);
	}
for( i = 1; i <= 9; i += 2 )
	{
	c = 2*( theForm.Piva.value.charCodeAt(i) - '0'.charCodeAt(0) );
	if( c > 9 )  c = c - 9;
	s += c;
	}
if( ( 10 - s%10 )%10 != theForm.Piva.value.charCodeAt(10) - '0'.charCodeAt(0) )
	{
	alert("La partita IVA non è valida.");
    theForm.Piva.focus();
    return (false);
	}
	
//fine Check Piva

if (theForm.Referente.value == "")
  {
    alert("Inserire un valore per il campo \"Referente\".");
    theForm.Referente.focus();
    return (false);
  }

if (theForm.Email.value  == "")
  {
    alert("Inserire un valore per il campo \"Email\".");
    theForm.Email.focus();
    return (false);
  }

if (theForm.Motivo.value  == "")
  {
    alert("Inserire un valore per il campo \"Motivo del contatto\".");
    theForm.Motivo.focus();
    return (false);
  }

if (!confirm("Vi ricordiamo che il modulo é dedicato esclusivamente alle aziende"))
  {
    return (false)
  }
return(true)
}
