function validaFormUtenti(){
 form = document.formUtenti; 
    if (form.username.value == ""){
        alert("Specificare username");
        form.username.style.borderColor="red";
        form.username.focus();        
        return false;
    }
    if ((form.password.value == "") || (form.password.value.length<8)){
        alert("La password deve essere almeno di 8 caratteri");
        form.password.style.borderColor="red";
        form.password.focus();        
        return false;
    }    
    if (form.password.value != form.ripeti_password.value){
        alert("Errore nella ripetizione della password");
        form.ripeti_password.style.borderColor="red";
        form.ripeti_password.focus();        
        return false;
    }
   
 if (form.nome.value == "")
 {
 	alert("Specificare nome / Specify name");
    form.nome.style.borderColor="#988A6A";
    form.nome.focus();
	return false; 
 }
 if (form.cognome.value == "")
 {
 	alert("Specificare cognome / Specify surname");
    form.cognome.style.borderColor="#988A6A";
    form.cognome.focus();
	return false; 
 } 



 if (form.email.value == "")
 {
 	alert("Specificare e-mail / Specify e-mail");
    form.email.style.borderColor="#988A6A";
    form.email.focus();
	return false; 
 }   
 if (!validaEmail(form.email.value))
 {
 	alert("Specificare un indirizzo e-mail valido / Specify a valid e-mail address");
    form.email.style.borderColor="#988A6A";
    form.email.focus();
	return false; 
 } 
 	if (form.privacy.checked==false){			
	 alert("Accettare le condizioni di privacy");	
	 return false;							
  }
 

 return true;   

}

function validaFormIndirizzi(i){
 form = document.formIndirizzi+i; 
 if (form.telefono.value == "")
 {
 	alert("Specificare telefono ");
    form.telefono.style.borderColor="#988A6A";
    form.telefono.focus();
	return false; 
 }  
 if (form.indirizzo.value == "")
 {
 	alert("Specificare indirizzo / Specify address");
    form.indirizzo.style.borderColor="#988A6A";
    form.indirizzo.focus();
	return false; 
 }   
 if (form.cap.value == "")
 {
 	alert("Specificare cap / Specify address");
    form.cap.style.borderColor="#988A6A";
    form.cap.focus();
	return false; 
 }   
 if (form.citta.value == "")
 {
 	alert("Specificare cittą / Specify city");
    form.citta.style.borderColor="#988A6A";
    form.citta.focus();
	return false; 
 }    

}

function validaEmail(email)
{
		var carattere;
		var isAt = false;
		var isDot = false;
		for (var i=1; i < (email.length-2); i++)
  	{
    	carattere = email.substring(i, i+1);
    	if (carattere == "@") 
			{
    	 isAt = true;
    	 break;
    	}
  	}
		if ( (isAt == true) && (email.substring(i+1, i+2)!=".") )
		{
  		email = email.substring(i+2,email.length);
  		email = email.substring(email.length-4,email.length-2);
  		for (var u=0; u < (email.length); u++)
  		{
    		carattere = email.substring(u, u+1);
    		if (carattere == ".") isDot = true;					
  		}				
  		if (isDot == true) return true;
		}
		return false;
}

function validaFormContratto()
{
	if (document.formOrdini.contratto_vendita.checked==false){			
	 alert("Accettare le condizioni di vendita");	
	 return false;							
  }		
   return true;
  
}


function validaFormOrdine()
{
	form = document.formOrdine; 
	
	var i, tipo_pagamento, tipo_spedizione;
   for (i=0; i < form.tipo_pagamento.length; i++)
   {
   if (form.tipo_pagamento[i].checked)
      {
      tipo_pagamento = form.tipo_pagamento[i].value;
      }
   }
   for (i=0; i < form.tipo_spedizione.length; i++)
   {
   if (form.tipo_spedizione[i].checked)
      {
      tipo_spedizione = form.tipo_spedizione[i].value;
      }
   }   
   
	if ((tipo_pagamento == 'T') && (tipo_spedizione!='C')){
	 alert("Con contrassegno selezionare corriere!");	
	 return false;								
	}

	if ((tipo_pagamento == 'B') && (tipo_spedizione!='C')){
	 alert("Con Bonifico bancario selezionare corriere!");	
	 return false;								
	}	

	if ((tipo_pagamento == 'CP') && (tipo_spedizione!='C')){
	 alert("Con Conto corrente postale selezionare corriere!");	
	 return false;								
	}	

	if ((tipo_pagamento == 'C') && (tipo_spedizione!='S')){
	 alert("Pagamento in contanti possibile solo per ritiri in sede!");	
	 return false;								
	}
   return true;
  
}
