function verifica(form) {   
  if (registrazione.Company.value == "") {     
    alert("Company Field cannot be empty:"); 
    return false;   
  } else if (registrazione.Country.value== "nessuno") {     
    alert("Country Field cannot be empty:");     
    return false; 
  } else if (registrazione.state.value == "") {     
    alert("State Field cannot be empty:");     
    return false;  
  } else if (registrazione.Address.value == "") {     
    alert("Address Field cannot be empty:");     
    return false;  		
  } else if (registrazione.ZipCode.value == "") {     
    alert("ZipCode Field cannot be empty:");     
    return false;  		
  } else if (registrazione.City.value == "") {     
    alert("City Field cannot be empty:");     
    return false;
  } else if (registrazione.Telephone.value == "") {     
    alert("Telephone Field cannot be empty:");     
    return false;
  } else if (registrazione.Contact.value == "") {     
    alert("Contact Field cannot be empty:");     
    return false;
  } else if (registrazione.email.value == "") {     
    alert("Email Field cannot be empty:");     
    return false;  
	} else if(registrazione.email.value.indexOf('@', 0)== -1)  {     
    alert("Please insert correct Email Address");     
    return false; 
	} else if (registrazione.password.value == "") {     
    alert("Password Field cannot be empty:");     
    return false;
  } else if (registrazione.cpassword.value == "") {     
    alert("Confirm Password Field cannot be empty:");     
    return false;
  } 
  	else if ( registrazione.password.value != registrazione.cpassword.value ) 
	{
alert("The passwords you entered do not match.")
registrazione.password.value == "";
registrazione.cpassword.value == "";
registrazione.password.focus();
return false
	}
  alert("Il modulo è stato accettato.");   
    return true; 
} 

function checkzip(form)	
{
if (isNaN(registrazione.ZipCode.value))
	{
alert("Please insert correct Zip Code")
registrazione.ZipCode.value = "";
registrazione.ZipCode.focus();
return false
	}
return true	
}
/* ######################### controllo form contatti ####################################### */
function controllo_contact(form) {   
  if (contactform.Company.value == "") {     
    alert("Company Field cannot be empty:"); 
	contactform.Company.focus();
    return false;   
  } else if (contactform.Country.value== "nessuno") {     
    alert("Country Field cannot be empty:");     
    return false; 
  } else if (contactform.state.value == "") {     
    alert("State Field cannot be empty:");     
    return false;  
  } else if (contactform.Address.value == "") {     
    alert("Address Field cannot be empty:");     
    return false;  		
  } else if (contactform.ZipCode.value == "") {     
    alert("ZipCode Field cannot be empty:");     
    return false;  		
  } else if (contactform.City.value == "") {     
    alert("City Field cannot be empty:");     
    return false;
  } else if (contactform.Telephone.value == "") {     
    alert("Telephone Field cannot be empty:");     
    return false;
  } else if (contactform.contact.value == "") {     
    alert("Contact Field cannot be empty:");     
    return false;
  } else if (contactform.email.value == "") {     
    alert("Email Field cannot be empty:");     
    return false;  
	} else if(contactform.email.value.indexOf('@', 0)== -1)  {     
    alert("Please insert correct Email Address");     
    return false; 
  } 
  /*alert("Il modulo è stato accettato.");*/   
    return true; 
} 

function checkzip2(form)	
{
if (isNaN(contactform.ZipCode.value))
	{
alert("Please insert correct Zip Code")
contactform.ZipCode.value = "";
contactform.ZipCode.focus();
return false
	}
return true	
}
/* ############################################################# */
/*Siete liberi di usare e/o modificare questo codice. Vi chiediamo soltanto di 
indicare la fonte del codice con un link www.nextlevelprogramming.com 

articolo:
*/


var user,domain, regex, _match, email;


/* costruttore dell'oggetto email*/
function Email(e){
    this.emailAddr=e;
    this.message="";
    this.valid=false;
}

function eMsg(msg,sColor){
	//metodo che stampa su schermo il risultato della validazione dell'email
    var div = document.getElementById("messaggio_email");/*prende l'id del div contenitore del messaggio*/
    div.style.color=sColor;
    div.style.fontSize="0.9em";
   
    if(div.hasChildNodes()){ //se il div contenitore ha già un messaggio viene rimosso
        div.removeChild(div.firstChild);
    }
    div.appendChild(document.createTextNode(msg)); //altrimenti viene appeso direttamente

}

function validate(){
	
/* questo metodo controlla la validità dell'indirizzo email attraverso espressioni regolari.
   ad esempio controlla se sono state inserite stringhe vuote, spazi etc.*/
    
    
    if (this.emailAddr == null || this.emailAddr.length == 0 ||
        this.emailAddr.indexOf(".") == -1 ||
        this.emailAddr.indexOf("@") == -1 ||
        this.emailAddr.indexOf(" ") != -1){
        this.message="Please insert correct Email Address";
        this.valid=false;

        return;
    }

    /*la parte user dell'email non può iniziare o finire per "."*/
    regex=/(^\w{2,}\.?\w{2,})@/;
    _match = regex.exec(this.emailAddr); //viene chiamato il metodo exec che fa il match della stringa email con l'espressione regolare regex.
                                         //se non c'è match viene restituito null, cioè false. se c'è match viene restituito un array contenente
                                         //la (o le) posizione/i del matching nella stringa 
                                   
    if ( _match){
        user=RegExp.$1;
  
    } else {
        this.message="Please insert correct Email Address";
        this.valid=false;
        return;
    }
    /*controlla il dominio della mail*/
    regex=/@(\[\d{1,3}\.\d{1,3}\.\d{1,3}.\d{1,3}\])$/;
    _match = regex.exec(this.emailAddr);

    if( _match){
        domain=RegExp.$1;
       
        this.valid=true;
    } else {
        /* il carattere @ seguito da almeno 2 caratteri che non sono un periodo (.)
seguito da un periodo, seguito da zero o istanze di almeno due
caratteri che termina con un periodo, seguito da due-tre caratteri che non sono periodi
         */
        regex=/@(\w{2,}\.(\w{2,}\.)?[a-zA-Z]{2,3})$/;
        _match = regex.exec(this.emailAddr);
        if( _match){
            domain=RegExp.$1;
           
        } else {
            this.message="Please insert correct Email Address";
            this.valid=false;
            return;
        }
    }//fine controllo dominio
    this.valid=true;

}


//validate() l'oggetto email
Email.prototype.validate=validate;

function checkAddress(val){
	/*questa funzione instanzia l'oggetto email con il valore passato in input 
	e chiama il metodo validate su di esso*/
    var eml = new Email(val);
    var url; 
    eml.validate();
    if (! eml.valid) {//email non valida sintatticamente
    	eMsg(eml.message,"#de7275"); //viene stampato sulla pagina un messaggio di errore
    	
    }else {//email valida sintatticamente
    	
    	url="script_validazione_email.php?email="+
            encodeURIComponent(val);
        httpRequest("GET",url,true,handleResponse);
    }
    
}

function handleResponse(){
    var usedTag,answer,xmlReturnVal;
    if(request.readyState == 4){
        if(request.status == 200){
           
            xmlReturnVal = request.responseXML;
            usedTag = xmlReturnVal.getElementsByTagName("is_used")[0];
            answer= usedTag.childNodes[0].data;
            if(answer==true){
                eMsg("L'email inserita e' gia' stata registrata.",
                        "red");
                        email=0; //imposto le variabili controllo che mi serviranno in my_submit per sapere se i controlli sono andati a buon fine
             }
            else { eMsg("L'email inserita e' disponibile.","blue"); 
                        email=1;
            }
        } else {
            alert("Si è verificato un problema di  "+
                  "tra l'oggetto XMLHttpRequest ed il server!");
                        email=0;
                 
        }
    }
}
//###################### validazione questionario ######################
function checkquest(form) {   
  if (questionario.age.value == "not_compiled") {     
    alert("Age Field cannot be empty:"); 
	questionario.age.focus();	
    return false;   
  } else if (questionario.hearsp.value== "not_compiled") {     
    alert("Please answer at question 'How did you hear about Sportarredo?':");     
	questionario.hearsp.focus();		
    return false; 
  } else if (questionario.hearmysun.value == "not_compiled") {     
    alert("Please answer at question 'How did you hear about MySun?':");     
	questionario.hearmysun.focus();		
    return false; 
  } else if (questionario.getinfo.value == "not_compiled") {     
    alert("Please answer at question 'When researching tanning equipment, where do you get information?':");
	questionario.getinfo.focus();		
    return false;  		
  } else if (questionario.consider.value == "not_compiled") {     
    alert("Please answer at question 'What is the most important thing you consider when purchasing a bed?':");     
	questionario.consider.focus();		
    return false;  		
  } else if (questionario.forumyes.value == "not_compiled") {     
    alert("Please answer at question 'Do you spend time in one of these tanning forums?':");
	questionario.forumyes.focus();		
    return false;
  } else if (questionario.cname.value == "") {     
    alert("Company Field cannot be empty:");     
	questionario.cname.focus();	
    return false;
  } else if (questionario.contact.value == "") {     
    alert("Contact Field cannot be empty:");     
	questionario.contact.focus();		
    return false;
  } else if (questionario.address.value == "") {     
    alert("Address Field cannot be empty:");     
	questionario.address.focus();		
    return false;  
  } else if (questionario.city.value == "") {
    alert("City Field cannot be empty:");
	questionario.city.focus();
    return false;  
  } else if (questionario.state.value == "") {
    alert("State Field cannot be empty:");
	questionario.state.focus();	
    return false;
  } else if (questionario.zipcode.value == "") {
    alert("Zip Code Field cannot be empty:");
	questionario.zipcode.focus();
    return false; 
  }
	else if (isNaN(questionario.zipcode.value))
	{
	alert("Please insert correct Zip Code")
	questionario.zipcode.value = "";
	questionario.zipcode.focus();
	return false
  } else if (questionario.phone.value == "") {     
    alert("Phone Field cannot be empty:");     
	questionario.phone.focus();	
    return false;  	
} else if (questionario.email.value == "") {     
    alert("Email Field cannot be empty:");     
	questionario.email.focus();	
    return false;  
	} else if(questionario.email.value.indexOf('@', 0)== -1)  {     
    alert("Please insert correct Email Address"); 
	questionario.email.value= "";
	questionario.email.focus();
    return false; 
  } 
  /*alert("Il modulo è stato accettato.");*/   
    return true; 
} 

function checkzip3(form)	
{
if (isNaN(questionario.zipcode.value))
	{
alert("Please insert correct Zip Code")
questionario.zipcode.value = "";
questionario.zipcode.focus();
return false
	}
return true	
}
//#############################################//
function seleziona(id) {
  if (!document.getElementById) return;
	selDiv = document.getElementById(id);
	selDiv2 = document.getElementById(id + 'a');  
	selDiv2.style.color = "black";
/*  selDiv.style.borderStyle = "thin";*/
/*  selDiv.style.borderColor = "orange";*/
/* selDiv.style.fontWeight = "bolder"; */
	selDiv.style.background = "#b7b7b7";
}
function deseleziona(id) {
  if (!document.getElementById) return;
  selDiv = document.getElementById(id);
  selDiv2 = document.getElementById(id + 'a');  
  selDiv2.style.color = "#b7b7b7";
/*  selDiv.style.borderStyle = "thin";*/
	selDiv.style.background = "#0b0b0b";
/*  selDiv.style.fontWeight = "normal";  */
}
//################## sample form ####################
function controllo_sample(form) {   
  if (sampleform.salon.value == "") {     
    alert("Salon Name Field cannot be empty:"); 
	sampleform.salon.focus();
    return false;   
  } else if (sampleform.Country.value== "nessuno") {     
    alert("Country Field cannot be empty:");     
    return false; 
  } else if (sampleform.state.value == "") {     
    alert("State Field cannot be empty:");     
    return false;  
  } else if (sampleform.Address.value == "") {     
    alert("Address Field cannot be empty:");     
    return false;  		
  } else if (sampleform.ZipCode.value == "") {     
    alert("ZipCode Field cannot be empty:");     
    return false;  		
  } else if (sampleform.City.value == "") {     
    alert("City Field cannot be empty:");     
    return false;
  } else if (sampleform.Telephone.value == "") {     
    alert("Telephone Field cannot be empty:");     
    return false;
  } else if (sampleform.contact.value == "") {     
    alert("Contact Field cannot be empty:");     
    return false;
  } else if (sampleform.email.value == "") {     
    alert("Email Field cannot be empty:");     
    return false;  
	} else if(sampleform.email.value.indexOf('@', 0)== -1)  {     
    alert("Please insert correct Email Address");     
    return false; 
  } 
  /*alert("Il modulo è stato accettato.");*/   
    return true; 
} 

function checkzip4(form)	
{
if (isNaN(sampleform.ZipCode.value))
	{
alert("Please insert correct Zip Code")
sampleform.ZipCode.value = "";
sampleform.ZipCode.focus();
return false
	}
return true	
}