function ValidaEmail(stringa)
{ 
  if (stringa=="")
	return(true)
  var carrattere=""
  var testo =0
  var vannobene = "abcdefghijklmnopqrstuvwxyz_@.ABCDEFGHIJKLMNOPQRSTUVWXYZƒŠŒšœŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþ0123456789";
  var checkStr = stringa;
  var aposto = true;
  var chiocciola = 0
  var punto = 0
  for (i = 0;  i < checkStr.length;  i++)
  {
	 carattere = checkStr.charAt(i);
	 for (j = 0;  j < vannobene.length;  j++)
	 {
		if (carattere == vannobene.charAt(j))
		{
		  if (carattere=="@")
		  {
			 if (testo==0)
				aposto=false;
			 chiocciola = chiocciola +1;
			 testo = -1;
		  }
		  if (carattere==".")
		  {
			 if (testo==0)
				aposto=false;
			 punto= punto +1
			 testo = -1;
		  }
		  testo = testo + 1;
		  break;
		}

		if (j == vannobene.length)
		{
		  aposto = false;
		  break;
		}
	 }
   }
	if (!aposto || chiocciola !=1 || punto ==0 || testo < 2 || testo >3 )
   {
		return (false);
   }
return (true);
}

function ValidaTelefono(checkStr)
{ 
  if (checkStr=="")
	return(true)

  var carrattere="";
  var vannobene = "0123456789/";
  var bolAposto = true;
  var bolTrovato = false;

  for (i = 0;  i < checkStr.length;  i++)
  {
		carattere = checkStr.charAt(i);
		bolTrovato = false;

	    for (j = 0;  j < vannobene.length;  j++)
		{
			if (carattere == vannobene.charAt(j))
			{		
				bolTrovato = true;
				break;
			}		
		}
		
		if (!bolTrovato ) 
		{
			bolAposto = false;
			break;
		}
  }		

  if (!bolAposto )
  {
    return (false);
  }
return (true);
}

function CheckData()
{
	if ((document.form.Area_Registrazione.selectedIndex == 2) || (document.form.Area_Registrazione.selectedIndex == 1)|| (document.form.Area_Registrazione.selectedIndex == 0)){
	//
	}else{		
		if (document.form.Ragione_Sociale.value.length == 0)
		{
		   alert("Inserire la ragione sociale");
		   document.form.Ragione_Sociale.focus();
		   return false ;
		}	
	}


	if (document.form.Nome.value.length == 0)
	{
		alert("Inserire il nome");
		document.form.Nome.focus();
		return false ;
	}

	if (document.form.Cognome.value.length == 0)
	{
		alert("Inserire il cognome");
		document.form.Cognome.focus();
		return false ;
	}
	
	if (document.form.Indirizzo.value.length == 0)
	{
		alert("Inserire l'indirizzo");
		document.form.Indirizzo.focus();
		return false  ;
	}
	
	if (document.form.CAP.value.length > 5)
	{
		alert("CAP Errato!!");
		document.form.CAP.focus();
		return false ;
	}
	
	if (document.form.Citta.value.length == 0)
	{
		alert("Inserire La Citta");
		document.form.Citta.focus();
		return false  ;
	}

	if (document.form.Telefono.value.length == 0)
	{
		alert("Inserire il Telefono");
		document.form.Telefono.focus();
		return false ;
	}
	
	if (ValidaTelefono(document.form.Telefono.value) == false)
	{
		alert("Il numero di Telefono errato");
		document.form.Telefono.focus();
		return false ;
	}
	
	
	if (document.form.Codice_Fiscale.value.length >16)
	{
		alert("Codice Fiscale errato");
		document.form.Codice_Fiscale.focus();
		return false ;
	}

	if (document.form.Partita_Iva.value.length >16)
	{
		alert("Partita Iva errata");
		document.form.Partita_Iva.focus();
		return false ;
	}

			

	if (ValidaEmail(document.form.Email.value) == false)
	{
		alert("Indirizzo Email errato");
		document.form.Email.focus();
		return false ;
	}

	if (document.form.Email.value.length == 0)
	{
		alert("Inserire l'indirizzo E-mail");
		document.form.Email.focus();
		return false ;
	}				
	
}
