
function TestoVuoto(campo,nome) 
{ if (campo.value=="")
	{  
	  alert("Attenzione: il campo '"+nome+"' è obbligatorio!");
	  campo.focus();
	  return true;   
	} 
  return false;
}

function TestoVuotoMail(campo,nome) 
{ if (campo.value=="...@telematicaitalia.it")
	{  
	  alert("Attenzione: il campo '"+nome+"' è obbligatorio!");
	  campo.focus();
	  return true;   
	} 
  return false;
}

function CheckVuota(campo) 
{ 
 var ok;
 ok = false;
//controllo che almeno un articolo sia selezionato
	if (!campo.length)
	{
		if(campo.checked) {ok = true}
	}
	else
	{
		for(k=0;k<campo.length;k++)
		{
			if(campo[k].checked)  
			{
				ok = true
			}
		}
	}
	
	if (!ok) {
		alert("Nessuna opzione selezionata.");

		return true;

	}
  return false;


}

function CheckVuotaPrivacy(campo) 
{ 
 var ok;
 ok = false;
//controllo che almeno un articolo sia selezionato
	if (!campo.length)
	{
		if(campo.checked) {ok = true}
	}
	else
	{
		for(k=0;k<campo.length;k++)
		{
			if(campo[k].checked)  
			{
				ok = true
			}
		}
	}
	
	if (!ok) {
		alert("Attenzione! E' necesssario rilasciare il consenso al trattamento dei dati personali.");
		return true;

	}
  return false;


}


function CheckVuota1(campo) 
{ 
 var ok;
 ok = false;
//controllo che almeno un articolo sia selezionato
	if (!campo.length)
	{
		if(campo.checked) {ok = true}
	}
	else
	{
		for(k=0;k<campo.length;k++)
		{
			if(campo[k].checked)  
			{
				ok = true
			}
		}
	}
	
	if (!ok) {
		alert("Attenzione! Delega non valorizzata!.");

		return true;

	}
  return false;


}

function StringaNumerica(campo,nomeCampo,flagmsg) 
{ var str = campo.value;
  for (var i=0;i < str.length;i++)
       if ((str.charAt(i) < '0') || (str.charAt(i) > '9')) 
       { if (flagmsg) //se true, compare il messaggio altrimenti no.
         {
          alert("Attenzione: il campo '"+nomeCampo+"' deve essere numerico!");
	      campo.focus();
	     }
	     return true;
       }
  return false;
}

function ErrorSeparatori(str) 
{ var c1=str.charAt(2);
  var c2=
   str.charAt(5); if
        (((c1=='/')||(c1== '-')) //accetta anche il carattere  -
	    &&((c2=='/')||(c2=='-'))
      )	
      return false;
  return true;  
}	
	  	  
function RangeError(str,Lb,Ub) //controlla il range
{
 var num=parseInt(str,10);
 var vbool=false;
  for (var k=0;k < str.length;k++)
       if ((str.charAt(k) < '0') || (str.charAt(k) > '9'))
		{vbool=true;
		 break;
		}
 return ((vbool) || (num<Lb) || (num>Ub)); //errore se true
   
}


function ErrorEmail(campo)
{ 
  var st=campo.value; 
  if (st != "")
	{
		if ( 
		     	(st.indexOf("@")==-1) ||
		     	(st.indexOf(".")==-1) || 
				(st.length < 6) ||
				(st.indexOf("@.")!=-1) ||
		     	(st.indexOf("@@")!=-1) 
		      
		   )

		{  alert("Attenzione: indirizzo E- mail non valido.");
		   campo.focus();
		   return true;
		}
		return false;
	}
}     

function ErrorTel(campo,nomeCampo)
{var st=campo.value;
 var car;
  for (var k=0;k<st.length;k++)
  { car=st.charAt(k);
    if (
        ((car<'0') || (car>'9'))
        &&
        ((car != '+') && (car !='/') && (car !='-'))
       )
     { alert("Attenzione: numero di "+nomeCampo+" non valido.");
       campo.focus();
       return true;
     }
  }
  return false;
}  

function ErrorString(campo,nomeCampo)
{var st=campo.value;
  for (var k=0;k<st.length;k++)
    if ((st.charAt(k)>="0") && (st.charAt(k)<="9"))
    { alert("Attenzione: Il campo "+nomeCampo+" non deve contenere caratteri numerici.");
      campo.focus();
      return true;
    }  
  return false;
}  
       
function ErroreDataMeseBisestile(strGG,strMM,strAA)
{var GG=parseInt(strGG,10);
 var MM=parseInt(strMM,10);
 var AA=parseInt(strAA,10);
  if (
     (((MM==11) || (MM==4) || (MM==6) || (MM==9)) && (GG==31))//Nov,Apr,Giu,Set
       || 
     ((AA % 4 == 0) && (MM==2) && (GG>29)) //bisestile
       ||   
     ((AA % 4 != 0) && (MM==2) && (GG>28)) //non bisestile
     ) 
     return true; //errore
  return false;        
}          

function DataNonValida(campo,nomeCampo)
{var str=campo.value;
 var strGG=str.substring(0,2);
 var strMM=str.substring(3,5);
 var strAA=str.substring(6,10);
    
    if (str!='gg/mm/aaaa')
    {    
		if ( (str.length !=10) || (ErrorSeparatori(str)) )
		   {
			 alert("Il campo "+nomeCampo+" deve essere scritto nel formato gg/mm/aaaa");
		     campo.focus();
		     return true;
		   }        
	
		if (
		    (RangeError(strGG,1,31)) ||     //controllo giorno
		    (RangeError(strMM,1,12)) ||     //controllo mese
		    (RangeError(strAA,1890,2100))|| //controllo anno
		    (ErroreDataMeseBisestile(strGG,strMM,strAA))//controllo mesi e bisestili
		   )
		  {
		    alert("Attenzione: controllare i valori inseriti nel campo " + nomeCampo);
			campo.focus();
			return true;
		  }
	}
    return false;
}

function StringaVuotaLista(campo,nome,flag) 
{
 var indice=campo.selectedIndex;
 if (campo.options[indice].value=="")
	{ if (flag)
	  { 
	    alert("Attenzione: il campo '"+nome+"' è obbligatorio!");
	    campo.focus();
	  }  
	  return true;   
	} 
  return false;
}


