function load_linee(id_marchio){
	thisForm=window.document.ricerca;

	if(id_marchio!="0"){
		marchio=id_marchio-1;
		numLinee=array_linee[marchio].length;
		thisForm.linea.options.length = numLinee + 1;
		thisForm.linea.options[0].text = 'Linea';
		thisForm.linea.options[0].value = '';

		for( var i=1; i<=numLinee; i++){
			thisForm.linea.options[i].text = array_linee[marchio][i-1];
			thisForm.linea.options[i].value = array_id_linee[marchio][i-1];
		}
	}
	else{
		thisForm.linea.options.length = 1;
		thisForm.linea.options[0].text = 'Linea';
		thisForm.linea.options[0].value = '';
	}
	
}
function controlSearch(){
	thisForm=window.document.ricerca;
	if ((thisForm.marca.selectedIndex == 0) && (thisForm.categoria.selectedIndex == 0) && (thisForm.linea.selectedIndex == 0) && (!thisForm.offerte.checked) && (!thisForm.novita.checked) && (thisForm.testo.value == '')) {
		alert('Selezionare almeno un criterio di ricerca');
		thisForm.testo.focus();
		return false;
	}
	thisForm.submit();
}

function addCart(refere, id_marchio){
	thisForm=document.opCart;
	thisForm.method="POST";
	thisForm.action="_class/classOperazioniCarrello.php";
	thisForm.azione.value="addCart";
	thisForm.id.value=refere;
	thisForm.id_marchio.value=id_marchio;
	thisForm.submit();
}

function apricolore(idColore){
	if(idColore!=""){
		winGallery=window.open("showColore.php?idColore=" + idColore, "colore", "left=100, top=80, status=0, resizable=0, directories=0, toolbars=0, menubar=0, scrollbars=1");
		winGallery.focus();
	}
}

/******************
 CARRELLO
*****************/

function svuotaCarrello(){
	thisForm=document.carrello;
	thisForm.method="POST";
	thisForm.azione.value='emptyCart';
	thisForm.action='_class/classOperazioniCarrello.php';
	thisForm.submit();
}

function ricalcolaCarrello(){
	thisForm=document.carrello;
	thisForm.method="POST";
	thisForm.azione.value='updateCart';
	thisForm.action='_class/classOperazioniCarrello.php';
	thisForm.submit();
}

function eliminaArticolo(cont){
	if(confirm("Sei sicuro di voler rimuovere l'articolo?")){
		thisForm=document.carrello;
		thisForm.method="POST";
		thisForm.azione.value='delCart';
		thisForm.cont.value=cont;
		thisForm.action='_class/classOperazioniCarrello.php';
		thisForm.submit();
	}
	else return;
}


function controlLogin(){
	thisForm=document.login;
	if(thisForm.user.value==''){
		alert('Inserire la propria username');
        thisForm.user.focus();
		return;
	}
	if(thisForm.pass.value==''){
		alert('Inserire la propria password');
        thisForm.pass.focus();
		return;
	}

	//if(!checkEmailAddress(thisForm.user)) return;
	
	thisForm.method="POST";
	thisForm.action='_class/classAzioni.php';
	thisForm.submit();
}

function controlLoginRivenditore(){
	thisForm=document.login_rivenditore;
	if(thisForm.user.value==''){
		alert('Inserire la propria username');
        thisForm.user.focus();
		return;
	}
	if(thisForm.pass.value==''){
		alert('Inserire la propria password');
        thisForm.pass.focus();
		return;
	}

	//if(!checkEmailAddress(thisForm.user)) return;
	
	thisForm.method="POST";
	thisForm.action='_class/classAzioni.php';
	thisForm.submit();
}


var indirizzoEmail;
function checkEmailAddress(field) {

     var goodEmail = field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
     
     if (goodEmail){
        indirizzoEmail = true
     } 
     else {
        alert('Inserire un indirizzo email valido');
        field.focus();
        field.select();
        indirizzoEmail = false;
        }
  	return indirizzoEmail;
}

function controlNewsletter(){
	thisForm=document.newsletter;
	if(!checkEmailAddress(thisForm.email)) return;
	thisForm.method="POST";
	thisForm.action='_class/classAzioni.php';
	thisForm.submit();
}

function apriAlert(lang, nome){
	switch(lang){
		case "1":
			switch (nome){
				case "nome":
					alert("Riemprire il campo NOME");
				break;
				case "cognome":
					alert("Riemprire il campo COGNOME");
				break;
				case "indirizzo":
					alert("Riemprire il campo INDIRIZZO");
				break;
				case "citta":
					alert("Riemprire il campo CITTA'");
				break;
				case "provincia":
					alert("Riemprire il campo PROVINCIA");
				break;
				case "nazione":
					alert("Riemprire il campo NAZIONE");
				break;
				case "telefono":
					alert("Riemprire il campo TELEFONO");
				break;
				case "password":
					alert("Riemprire il campo PASSWORD");
				break;
				case "control":
					alert("Le PASSWORD non corrispondono");
				break;
				case "lettere":
					alert("La PASSWORD deve essere almeno di 6 caratteri");
				break;
			}
			
		break;
		case "2":
			switch (nome){
				case "nome":
					alert("Fill field NAME");
				break;
				case "cognome":
					alert("Fill field LAST NAME");
				break;
				case "indirizzo":
					alert("Fill field ADDRESS");
				break;
				case "citta":
					alert("Fill field CITY");
				break;
				case "provincia":
					alert("Fill field PROVINCE");
				break;
				case "nazione":
					alert("Fill field COUNTRY");
				break;
				case "telefono":
					alert("Fill field PHONE");
				break;
				case "password":
					alert("Fill field PASSWORD");
				break;
				case "control":
					alert("PASSWORD mismatch");
				break;
				case "lettere":
					alert("The PASSWORD must be almost 6 chars");
				break;
			}
			alert();
		break;
	}
	return;
}

/******************
 REGISTRAZIONE
*****************/
function controlloRegistrazione(){
	lang=1;
	thisForm = document.registrati;
	
	if(thisForm.nome.value==''){
		apriAlert(lang, "nome");
		return;
	}
		
	if(thisForm.cognome.value==''){
		apriAlert(lang, "cognome");
		return;
	}
	if(thisForm.indirizzo.value==''){
		apriAlert(lang, "indirizzo");
		return;
	}
	if(thisForm.citta.value==''){
		apriAlert(lang, "citta");
		return;
	}
	if(thisForm.provincia.value==''){
		apriAlert(lang, "provincia");
		return;
	}
	
	//if(!controllaData(thisForm.gg.value, thisForm.mm.value, thisForm.aaaa.value, lang)) return;
	
	if(thisForm.telefono.value==''){
		apriAlert(lang, "telefono");
		return;
	}
	if(!checkEmailAddress(thisForm.email, lang)) return;
	
	thisForm.action="_class/classAzioni.php";
	thisForm.submit();
	
}

function controlloRequire(){
	lang=1;
	thisForm = document.requirepass;
	
	if(!checkEmailAddress(thisForm.email, lang)) return;
	
	thisForm.action="_class/classAzioni.php";
	thisForm.submit();
	
}

/******************
 ORDINE
*****************/
function controlloOrdine(lang){

	thisForm = document.datiOrdine;
	
	if(thisForm.nome.value==''){
		apriAlert(lang, "nome");
		return;
	}
		
	if(thisForm.cognome.value==''){
		apriAlert(lang, "cognome");
		return;
	}
	if(thisForm.indirizzo.value==''){
		apriAlert(lang, "indirizzo");
		return;
	}
	if(thisForm.citta.value==''){
		apriAlert(lang, "citta");
		return;
	}
	if(thisForm.provincia.value==''){
		apriAlert(lang, "provincia");
		return;
	}
	
	//if(!controllaData(thisForm.gg.value, thisForm.mm.value, thisForm.aaaa.value, lang)) return;
	
	if(thisForm.nazione.value==''){
		apriAlert(lang, "nazione");
		return;
	}
	if(thisForm.telefono.value==''){
		apriAlert(lang, "telefono");
		return;
	}
	if(!checkEmailAddress(thisForm.email, lang)) return;
	
	thisForm.action="ordineConfirmDati.php";
	thisForm.submit();
	
}

function riepilogoOrdine(){
	thisForm=document.riepilogoOrdine;
	
	thisForm.action="_class/classAzioni.php";
	thisForm.submit();
	
}

/******************
 CONTATTACI
*****************/
function controlloContattaci(){
	lang=1;
	thisForm = document.contattaci;
	
	if(thisForm.nome.value==''){
		apriAlert(lang, "nome");
		return;
	}
		
	if(thisForm.cognome.value==''){
		apriAlert(lang, "cognome");
		return;
	}
	
	if(!checkEmailAddress(thisForm.email, lang)) return;
	
	thisForm.action="_class/classAzioni.php";
	thisForm.submit();
	
}

/******************
 ESPERTO
*****************/
function controlEsperto(){
	lang=1;
	thisForm = document.esperto;
	
	if(thisForm.domanda.value==''){
		apriAlert(lang, "domanda");
		return;
	}
		
	thisForm.action="_class/classAzioni.php";
	thisForm.submit();
	
}