function mail(valore)
{

if (valore !="")
{
     if (valore.indexOf("@")<1)
       {
	   alert("Il campo e-mail non è stato inserito correttamente!!");
	   return false;
       }
	  punto=valore.indexOf("@") 
    if (valore.indexOf(".",punto)<1)
	{
		alert("Il campo e-mail non è stato inserito correttamente!!");
	   return false;
    }
}
	return true
}

function controlladata(str)
{
        if (str=="")
        {
            return true;   
            
        }
		if (str.length != 10)
		{
					return false;
		}
		pos = str.indexOf("/");
		if (pos == 2)
		{
					pos1 = str.indexOf("/",pos+1);
					if (pos1 != 5)
					{
									return false;
					}
		}
		else
		{
					return false;
		}
		gg=str.substr(0,2);
		mm=str.substr(3,2);
		aaaa=str.substr(6,4);
		if(isNaN(gg))
		{
					return false;
		}
		if(isNaN(mm))
		{
					return false;
		}
				if(isNaN(aaaa))
		{
					return false;
		}
		
	
		if ((gg > 31) || (gg < 1))
		{
					return false;
		}
		if ((mm > 12) || (mm < 1))
		{
					return false;
		}
		if ((aaaa < 1930) || (aaaa > 2100))
		{
					return false;
		}
		if (((gg=="30") && (mm=="02")) || ((gg=="31") && (mm=="02")) || ((gg=="31") && (mm=="04")) || ((gg=="31") && (mm=="06")) || ((gg=="31") && (mm=="09")) || ((gg=="31") && (mm=="11")))
  {
					return false;
		}	
		
		
		return true;
}



function validaCampo(tipo,nomeForm,nomeCampo,valoreCampo)
{
    
valoreCampo = valoreCampo.replace(/[" "]/g,"")

				switch (tipo) 
				{   
				case "1" :       
							if(isNaN(valoreCampo))
							{
										alert ("Attenzione! inserire solo numeri");
										eval("document."+nomeForm+"."+nomeCampo).focus();
										eval("document."+nomeForm+"."+nomeCampo).select();

										return false;
							}
							else
							{
											
											return true;
							}
							      
							break;    
				case "2" :  
							if (controlladata(valoreCampo))
 						{
											
											return true;
							}
							else
							{
										alert ("Attenzione! formato data errato (gg/mm/aaaa)");
										eval("document."+nomeForm+"."+nomeCampo).focus();
										eval("document."+nomeForm+"."+nomeCampo).select();
										return false;
							}

							break; 
				case "3" :  
							if (controlladatalight(valoreCampo))
 						{

											
											 
											return true;
							}
							else
							{
										alert ("Attenzione! formato data errato (mm/aaaa)");
										eval("document."+nomeForm+"."+nomeCampo).focus();
										eval("document."+nomeForm+"."+nomeCampo).select();
										return false;
							}

							break;    
							case "4" :  
											
											if (mail(valoreCampo))
 						{

											
											 
											return true;
							}
							else
							{
										//alert ("Attenzione! formato data errato (mm/aaaa)");
										eval("document."+nomeForm+"."+nomeCampo).focus();
										eval("document."+nomeForm+"."+nomeCampo).select();
										return false;
							}

							break;    

				default :       
				alert ("Generata Eccezione."); 
				} 
}

