function test(src) 
{
	if (document.registrati.email.value == "") 
  	{
    		return true;
  	}
	else 
	{
  		var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
  		return regex.test(src);
	}
}


function isnumeric(str)
{
	var len= str.length;
  	if (len==0)
    	return false;
	var p=0;
  	var ok= true;
  	var ch= "";
  	while (ok && p<len)
  	{
    		ch= str.charAt(p);
    		if ('0'<=ch && ch<='9')
      			p++;
    		else
      			ok= false;
  	}
  	return ok;
}

//funzione trim che elimina gli spazi
  function trim(strText) {  
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);
    return strText;
  } 
  
//*********Funzione per il controllo dell'obbligatorietà dei campi e sulle lunghezze
function cont()
{
  str = "";
  ok = true;
 
//controllo sul nome-------------------
  if ((document.registrati.nome.value=="") && ok)
  {
     ok = false;
     if (document.registrati.lingua.value=="ita"){
     	str = "Inserire il nome"
	 }
	 if (document.registrati.lingua.value=="eng"){
     	str = "Insert your name"
	 }
	 if (document.registrati.lingua.value=="ted"){
     	str = "Geben sie unten im Feld ihre vorname"
	 }
	 if (document.registrati.lingua.value=="spa"){
     	str = "Inserte debajo su nombre"
	 }
	 if (document.registrati.lingua.value=="fra"){
     	str = "Insérer ci prenom"
	 }
  } 
  else 
  {
      if ((document.registrati.nome.value.length > 100) && ok)
      {
      ok = false;
      str = "Il campo nome contiene un numero elevato di caratteri"
      }

  }

//Fine controllo sul nome-------------------
//controllo sul cognome-------------------
  if ((document.registrati.cognome.value=="") && ok)
  {
  
     ok = false;
	 if (document.registrati.lingua.value=="ita"){
     	str = "Inserire il cognome"
	 }
	 if (document.registrati.lingua.value=="eng"){
     	str = "Insert your surname"
	 }
	 if (document.registrati.lingua.value=="ted"){
     	str = "Geben sie unten im Feld ihre Nachname"
	 }
	 if (document.registrati.lingua.value=="spa"){
     	str = "Inserte debajo su apellido"
	 }
	 if (document.registrati.lingua.value=="fra"){
     	str = "Insérer ci nom"
	 }
  } 
  else 
  {
      if ((document.registrati.cognome.value.length > 100) && ok)
      {
      ok = false;
	  
      str = "Il campo cognome contiene un numero elevato di caratteri"
      }

  }
//Fine controllo sul cognome-------------------
//Controllo sul Campo Email------------------------------------------------------------------
 
 document.registrati.email.value=trim(document.registrati.email.value);
	 if ((document.registrati.email.value=="") && ok)
   {
      ok = false;
	  if (document.registrati.lingua.value=="ita"){
     	str = "Il Campo E-mail è obbligatorio"
	 }
	 if (document.registrati.lingua.value=="eng"){
     	str = "Insert your e-mail"
	 }
	 if (document.registrati.lingua.value=="ted"){
     	str = "Geben sie unten im Feld ihre e.mail adresse ein"
	 }
	 if (document.registrati.lingua.value=="spa"){
     	str = "Inserte debajo su e-mail"
	 }
	 if (document.registrati.lingua.value=="fra"){
     	str = "Insérer ci dessous ton adresse e-mail"
	 }
      
   } 
   else 
   { 

if (!test(document.registrati.email.value) && ok)
   {
      ok = false;
	  if (document.registrati.lingua.value=="ita"){
     	str = "Attenzione! I caratteri nel campo E-mail non sono corretti!"
	 }
	 if (document.registrati.lingua.value=="eng"){
     	str = "Insert a correct e-mail"
	 }
	 if (document.registrati.lingua.value=="ted"){
     	str = "e-mail Fehler"
	 }
	 if (document.registrati.lingua.value=="spa"){
     	str = "Inserte debajo su e-mail correcto"
	 }
	 if (document.registrati.lingua.value=="fra"){
     	str = "Insérer ci dessous ton adresse e-mail correct"
	 }
      
   }
   else 
   {
      if ((document.registrati.email.value.length > 200) && ok)
      {
         ok = false;
         str = "Hai superato il numero di caratteri disponibili per il campo E-mail"
      }
   } 
}

//fine controllo sul campo email-------------------

//controllo flag testo privacy -------------------
  if (!document.registrati.privacy.checked && ok)
   {
	   ok = false;
	   
	 if (document.registrati.lingua.value=="ita"){
     	str = "è obbligatorio leggere e accettare l'informativa sul trattamento dei dati!"
	 }
	 if (document.registrati.lingua.value=="eng"){
     	str = "è obbligatorio leggere e accettare l'informativa sul trattamento dei dati!"
	 }
	 if (document.registrati.lingua.value=="ted"){
     	str = "è obbligatorio leggere e accettare l'informativa sul trattamento dei dati!"
	 }
	 if (document.registrati.lingua.value=="spa"){
     	str = "è obbligatorio leggere e accettare l'informativa sul trattamento dei dati!"
	 }
	 if (document.registrati.lingua.value=="fra"){
     	str = "è obbligatorio leggere e accettare l'informativa sul trattamento dei dati!"
	 }
  } 
//Fine controllo flag privacy -------------------
//controllo CLICK SU TASTO AGGIORNA DATI -------------------
  if (document.registrati.update.checked)
   {
	   ok = false;
	   str = "update";
  } 
//Fine controllo CLICK SU TASTO AGGIORNA DATI -------------------

return str;
} 

function controllo()
{ 

c = cont();
	if (c=="") {
		document.registrati.action="./registrazione_ins.php";
		document.registrati.submit();
	} else if(c=="update") {
		document.registrati.action="./check_user.php";
		document.registrati.submit();
	} else {
		alert(str)
	}
}
 
	
