var clicks = 0;

function validEmail(email){      
	var emailReg = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
	return emailReg.test(email); 
}

function Validator(theForm) {

if ( theForm.cache_quantita.value == "" || isNaN(theForm.cache_quantita.value) || theForm.cache_quantita.value == "0" || theForm.cache_quantita.value <= 0)
  {
    alert(theForm.alert_p1.value);
    theForm.cache_quantita.focus();
    return (false);
  }

/*var almenoUno = 0;
for (var n = 1; n <= 10; n++) {
		var checkboxObject = eval("theForm.cache_rich"+n);
	if (checkboxObject.checked == true)
		{
		  almenoUno = 1;
		} 
}

if (almenoUno == 0)
		{
		  alert("E' necessario selezionare almeno un tipo di richiesta.");
		  theForm.cache_rich1.focus();
		  return (false);
		} 
*/

if (theForm.cache_user.selectedIndex == 0)
  {
    alert(theForm.alert1.value);
    theForm.cache_user.focus();
    return (false);
  }

var prova = theForm.cache_email.value;

if (validEmail(prova) === false)

  {
    alert(theForm.alert2.value);   
    theForm.cache_email.focus();
    return (false);
  } 


/*if (theForm.cache_city.value == "")
  {
    alert(theForm.alert3.value);
    theForm.cache_city.focus();
    return (false);
  }  */

if (((theForm.cache_stato.value == theForm.check1.value) || (theForm.cache_stato.value == theForm.check2.value)) && (theForm.cache_provincia.value == ""))
  {
    alert(theForm.alert4.value);
    theForm.cache_provincia.focus();
    return (false);
   }  
    
if (theForm.cache_stato.value == "---")
  {
    alert(theForm.alert20.value);
    theForm.cache_stato.focus();
    return (false);
  }     
    
   
if (theForm.cache_nome.value == "")
  {
    alert(theForm.alert5.value);
    theForm.cache_nome.focus();
    return (false);
  } 

if (theForm.cache_cognome.value == "")
  {
    alert(theForm.alert6.value);
    theForm.cache_cognome.focus();
    return (false);
  } 

/*if (theForm.cache_tel.value.length < 7) 
  {
    alert(theForm.alert7.value);
    theForm.cache_tel.focus();
    return (false);
  }*/ 

// da abilitare se si vuole fare check indirizzo, mettendo anche il campo indirizzo cache_address

/*if (theForm.cache_rich3.checked && theForm.cache_address.value == "")
  {
    alert(theForm.alert8.value);
    theForm.cache_address.focus();
    return (false);
  } else

if (theForm.cache_rich3.checked && theForm.cache_cap.value == "")
  {
    alert(theForm.alert9.value);
    theForm.cache_cap.focus();
    return (false);
  } else
*/

if (theForm.privacy.checked == false)
  {
    alert(theForm.alert10.value);
    theForm.privacy.focus();
    return (false);
  }


if (theForm.cache_newsletter_checker.checked == false)
  	{
   	theForm.cache_newsletter.value = "Newsletter = NO";
  	}  
  
if (clicks == 1) { 
	alert(theForm.alert11.value);
	return (false); 
	}
	
if (clicks == 0) { clicks = 1;}
	
  return (true);

}//chiusura function


function alertPrivate (theForm) {
	if (theForm.selectedIndex == 12) {	 	 
	alert(privateAlert.value);
    }

}

