function TargetBlank(){
  var i = 0;
  var collegamenti = document.links;
  for (i=0; i<collegamenti.length; i++)  {
    var primo_carattere=collegamenti[i].title.charAt(0);
    if (primo_carattere == " ") {
      collegamenti[i].target = "_blank";
    }
  }
}

function controlla_email(txt){
	var r = /^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i;

	if(r.test(txt)) return true;
	else return false;
}

function controllaForm(form_tipo){
	var check = true;
	var output = '';
	
	switch(form_tipo) {

			case 'contatti':
/*
				if(document.contatti.nome.value==''){
					check = false;
					output += 'Inserisci il Nome'+"\n";
				}
				if(document.contatti.cognome.value==''){
					check = false;
					output += 'Inserisci il Cognome'+"\n";
				}
*/				
				if(!controlla_email(document.contatti.mail.value)){
					check = false;
					output += 'Inserisci un indirizzo E-MAIL corretto'+"\n";
				}
/*				
				if(document.contatti.telefono.value==''){
					check = false;
					output += 'Inserisci il Telefono'+"\n";
				}
*/
				if(document.contatti.oggetto.value==''){
					check = false;
					output += "Inserisci l'oggetto del messaggio"+"\n";
				}
				if(document.contatti.richiesta.value==''){
					check = false;
					output += 'Inserisci la richiesta'+"\n";
				}				
				if(document.contatti.privacy.checked == false ){
					check = false;
					output += 'Acconsenti al trattamento dei dati'+"\n\n";
				}
				
			if(!check) alert(output);
			return check;
			
			break;
								
			case 'contacts':
							
				if(!controlla_email(document.contacts.mail.value)){
					check = false;
					output += 'Insert a correct E-MAIL address'+"\n";
				}
				if(document.contacts.oggetto.value==''){
					check = false;
					output += "Insert the Subject"+"\n";
				}
				if(document.contacts.richiesta.value==''){
					check = false;
					output += 'Insert the message'+"\n";
				}				
				if(document.contacts.privacy.checked == false ){
					check = false;
					output += 'Accept the privacy terms'+"\n\n";
				}

			if(!check) alert(output);
			return check;
			
			break;

	}
}

// FUNZIONE CHE CONTROLLA I DATI INSERITI NEL FORM REGISTRAZIONE UTENTI / CONTATTI / COMMENTI / AMICO / PRENOTAZIONE GRUPPI - SCUOLE
function controlla_dati(form) {
	switch (form) {
		case "RegUtenteEcommerce":
		        if (document.forms[0].nome.value=="") {
					alert("Inserire il Nome!");
					document.forms[0].nome.focus();
					return false;
				}
				if (document.forms[0].cognome.value=="") {
					alert("Inserire il Cognome!");
					document.forms[0].cognome.focus();
					return false;
				}
				if (document.forms[0].email.value=="") {
					alert("Inserire l'E-mail!");
					document.forms[0].email.focus();
					return false;
				} else {
					// controllo se la mail inserita č corretta
					ok=controlla_email(document.forms[0].email.value);
					if (ok==false) {
						
						alert("Inserire un indirizzo E-mail corretto!");
						document.forms[0].email.focus();
						return false;
					}
				}
				if (document.forms[0].indirizzo.value=="") {
					alert("Inserire L'indirizzo!");
					document.forms[0].indirizzo.focus();
					return false;
				}
				if (document.forms[0].cap.value=="") {
					alert("Inserire il cap!");
					document.forms[0].cap.focus();
					return false;
				}
				if (document.forms[0].citta.value=="") {
					alert("Inserire la cittā!");
					document.forms[0].citta.focus();
					return false;
				}
				if (document.forms[0].provincia.selectedIndex==0) {
					alert("Inserire la provincia!");
					document.forms[0].provincia.focus();
					return false;
				}
				if (document.forms[0].paese.value=="") {
					alert("Inserire il paese!");
					document.forms[0].paese.focus();
					return false;
				}
				if (document.forms[0].telefono.value=="") {
					alert("Inserire il telefono!");
					document.forms[0].telefono.focus();
					return false;
				}
				if (document.forms[0].cod_fiscale.value=="") {
					alert("Inserire il codice fiscale!");
					document.forms[0].cod_fiscale.focus();
					return false;
				}
				
				//Se inseriamo la ragione sociale dobbiamo inserire anche la P.IVA
				if (document.forms[0].ragione_sociale.value!="") {
					if (document.forms[0].piva.value=="") {
						alert("Inserire la P.IVA!");
						document.forms[0].piva.focus();
						return false;
					}
				}

				//Se la checkbox č selezionata effettua i controlli anche per i dati di consegna
				if(document.forms[0].consegna_check.checked==true){
					/*Dati per la consegna*/
					if (document.forms[0].consegna_nome.value=="") {
						alert("Dati per la consegna:inserire il Nome!");
						document.forms[0].consegna_nome.focus();
						return false;
					}
					if (document.forms[0].consegna_cognome.value=="") {
						alert("Dati per la consegna: inserire il Cognome!");
						document.forms[0].consegna_cognome.focus();
						return false;
					}
					if (document.forms[0].consegna_indirizzo.value=="") {
						alert("Dati per la consegna: inserire L'indirizzo!");
						document.forms[0].consegna_indirizzo.focus();
						return false;
					}
					if (document.forms[0].consegna_cap.value=="") {
						alert("Dati per la consegna: inserire il cap!");
						document.forms[0].consegna_cap.focus();
						return false;
					}
					if (document.forms[0].consegna_citta.value=="") {
						alert("Dati per la consegna: inserire la cittā!");
						document.forms[0].consegna_citta.focus();
						return false;
					}
					if (document.forms[0].consegna_provincia.selectedIndex==0) {
						alert("Dati per la consegna: inserire la provincia!");
						document.forms[0].consegna_provincia.focus();
						return false;
					}
					if (document.forms[0].consegna_telefono.value=="") {
						alert("Dati per la consegna: inserire il telefono!");
						document.forms[0].consegna_telefono.focus();
						return false;
					}
				}
			break;
			
			
		case "RegUtenteEcommerce_en":
				if (document.forms[0].nome.value=="") {
					alert("Insert the name!");
					document.forms[0].nome.focus();
					return false;
				}
				if (document.forms[0].cognome.value=="") {
					alert("Insert the surname!");
					document.forms[0].cognome.focus();
					return false;
				}
				if (document.forms[0].email.value=="") {
					alert("Insert the E-mail!");
					document.forms[0].email.focus();
					return false;
				} else {
					// controllo se la mail inserita č corretta
					ok=controlla_email(document.forms[0].email.value);
					if (ok==false) {
						
						alert("Insert a correct E-MAIL address!");
						document.forms[0].email.focus();
						return false;
					}
				}
				if (document.forms[0].indirizzo.value=="") {
					alert("Insert the address!");
					document.forms[0].indirizzo.focus();
					return false;
				}
				if (document.forms[0].cap.value=="") {
					alert("Insert the ZIP code!");
					document.forms[0].cap.focus();
					return false;
				}
				if (document.forms[0].citta.value=="") {
					alert("Insert the city!");
					document.forms[0].citta.focus();
					return false;
				}
				/*
				if (document.forms[0].provincia.selectedIndex==0) {
					alert("Insert the province!");
					document.forms[0].provincia.focus();
					return false;
				}
				
				if (document.forms[0].paese.value=="") {
					alert("Insert the country!");
					document.forms[0].paese.focus();
					return false;
				}
				*/
				if (document.forms[0].telefono.value=="") {
					alert("Insert the telephone number!");
					document.forms[0].telefono.focus();
					return false;
				}

				/*Dati per la consegna*/
				//Se la checkbox č selezionata effettua i controlli anche per i dati di consegna
				if(document.forms[0].consegna_check.checked==true){
					if (document.forms[0].consegna_nome.value=="") {
						alert("Data for delivery: insert the name!");
						document.forms[0].consegna_nome.focus();
						return false;
					}
					if (document.forms[0].consegna_cognome.value=="") {
						alert("Data for delivery: insert the surname!");
						document.forms[0].consegna_cognome.focus();
						return false;
					}
					if (document.forms[0].consegna_indirizzo.value=="") {
						alert("Data for delivery: insert the address!");
						document.forms[0].consegna_indirizzo.focus();
						return false;
					}
					if (document.forms[0].consegna_cap.value=="") {
						alert("Data for delivery: insert the ZIP code!");
						document.forms[0].consegna_cap.focus();
						return false;
					}
					if (document.forms[0].consegna_citta.value=="") {
						alert("Data for delivery: insert the city!");
						document.forms[0].consegna_citta.focus();
						return false;
					}
					/*
					if (document.forms[0].consegna_provincia.selectedIndex==0) {
						alert("Data for delivery: insert the province!");
						document.forms[0].consegna_provincia.focus();
						return false;
					}
					*/
					if (document.forms[0].consegna_telefono.value=="") {
						alert("Data for delivery: insert the telephone number!");
						document.forms[0].consegna_telefono.focus();
						return false;
					}
				}
			break;
			
		case "UpdUtenteEcommerce":
				if (document.forms[0].cognome.value=="") {
					alert("Inserire il Cognome!");
					document.forms[0].cognome.focus();
					return false;
				}
				if (document.forms[0].nome.value=="") {
					alert("Inserire il Nome!");
					document.forms[0].nome.focus();
					return false;
				}
				if (document.forms[0].email.value=="") {
					alert("Inserire l'E-mail!");
					document.forms[0].email.focus();
					return false;
				} else {
					// controllo se la mail inserita č corretta
					ok=controlla_email(document.forms[0].email.value);
					if (ok==false) {
						
						alert("Inserire un indirizzo E-mail corretto!");
						document.forms[0].email.focus();
						return false;
					}
				}
				if (document.forms[0].indirizzo.value=="") {
					alert("Inserire L'indirizzo!");
					document.forms[0].indirizzo.focus();
					return false;
				}
				if (document.forms[0].cap.value=="") {
					alert("Inserire il cap!");
					document.forms[0].cap.focus();
					return false;
				}
				if (document.forms[0].citta.value=="") {
					alert("Inserire la cittā!");
					document.forms[0].citta.focus();
					return false;
				}
				if (document.forms[0].paese.value=="") {
					alert("Inserire il paese!");
					document.forms[0].paese.focus();
					return false;
				}
				if (document.forms[0].telefono.value=="") {
					alert("Inserire il telefono!");
					document.forms[0].telefono.focus();
					return false;
				}	

				/*Dati per la consegna*/
				if (document.forms[0].consegna_cognome.value=="") {
					alert("Dati per la consegna: inserire il Cognome!");
					document.forms[0].consegna_cognome.focus();
					return false;
				}
				if (document.forms[0].consegna_nome.value=="") {
					alert("Dati per la consegna:inserire il Nome!");
					document.forms[0].consegna_nome.focus();
					return false;
				}
				if (document.forms[0].consegna_indirizzo.value=="") {
					alert("Dati per la consegna: inserire L'indirizzo!");
					document.forms[0].consegna_indirizzo.focus();
					return false;
				}
				if (document.forms[0].consegna_cap.value=="") {
					alert("Dati per la consegna: inserire il cap!");
					document.forms[0].consegna_cap.focus();
					return false;
				}
				if (document.forms[0].consegna_citta.value=="") {
					alert("Dati per la consegna: inserire la cittā!");
					document.forms[0].consegna_citta.focus();
					return false;
				}
				if (document.forms[0].consegna_telefono.value=="") {
					alert("Dati per la consegna: inserire il telefono!");
					document.forms[0].consegna_telefono.focus();
					return false;
				}
				
				
			break;
			
		case "UpdUtenteEcommerce_en":
				if (document.forms[0].cognome.value=="") {
					alert("Insert the surname!");
					document.forms[0].cognome.focus();
					return false;
				}
				if (document.forms[0].nome.value=="") {
					alert("Insert the name!");
					document.forms[0].nome.focus();
					return false;
				}
				if (document.forms[0].email.value=="") {
					alert("Insert the E-mail!");
					document.forms[0].email.focus();
					return false;
				} else {
					// controllo se la mail inserita č corretta
					ok=controlla_email(document.forms[0].email.value);
					if (ok==false) {
						
						alert("Insert a correct E-MAIL address!");
						document.forms[0].email.focus();
						return false;
					}
				}
				if (document.forms[0].indirizzo.value=="") {
					alert("Insert the address!");
					document.forms[0].indirizzo.focus();
					return false;
				}
				if (document.forms[0].cap.value=="") {
					alert("Insert the ZIP code!");
					document.forms[0].cap.focus();
					return false;
				}
				if (document.forms[0].citta.value=="") {
					alert("Insert the city!");
					document.forms[0].citta.focus();
					return false;
				}
				if (document.forms[0].paese.value=="") {
					alert("Insert the country!");
					document.forms[0].paese.focus();
					return false;
				}
				if (document.forms[0].telefono.value=="") {
					alert("Insert the telephone number!");
					document.forms[0].telefono.focus();
					return false;
				}

				/*Dati per la consegna*/
				if (document.forms[0].consegna_cognome.value=="") {
					alert("Data for delivery: insert the surname!");
					document.forms[0].consegna_cognome.focus();
					return false;
				}
				if (document.forms[0].consegna_nome.value=="") {
					alert("Data for delivery: insert the name!");
					document.forms[0].consegna_nome.focus();
					return false;
				}
				if (document.forms[0].consegna_indirizzo.value=="") {
					alert("Data for delivery: insert the address!");
					document.forms[0].consegna_indirizzo.focus();
					return false;
				}
				if (document.forms[0].consegna_cap.value=="") {
					alert("Data for delivery: insert the CAP!");
					document.forms[0].consegna_cap.focus();
					return false;
				}
				if (document.forms[0].consegna_citta.value=="") {
					alert("Data for delivery: insert the city!");
					document.forms[0].consegna_citta.focus();
					return false;
				}
				if (document.forms[0].consegna_telefono.value=="") {
					alert("Data for delivery: insert the telephone number!");
					document.forms[0].consegna_telefono.focus();
					return false;
				}
			break;
	}
		
} // end func

// FUNZIONE CHE CONTROLLA CHE IL NUMERO DI TELEFONO/FAX SIA CORRETTO
function controlla_numero(numero) {
	var i=new RegExp("([0-9]{2,})([0-9]{5,})");
//	alert('%'+numero+'%');
	if (numero!="") {
		if(!i.test(numero)) return false;
		else return true;
	} else return true;
}

function spese_spedizione() {
var valoreselect=document.sp.spedizione.value;
alert(valoreselect);
return valoreselect;
}

function controllo_consegna() {   
	if (document.getElementById('consegna_check').checked) { 
	 document.getElementById('consegna').style.display = ''; 
	} else { 
	 document.getElementById('consegna').style.display = 'none'; 
	} 
} 

function url_no_parametri(url){
	var url_pulito;
	url_pulito = url.substring(0,url.indexOf("?"));
	return url_pulito;
}
