function sfoglia_menu_alto (id_box, id_voce){
	
	document.getElementById("box-ricerca").style.display="none";
	document.getElementById("box-area-commerce").style.display="none";
	document.getElementById("box-area-operativa").style.display="none";
	document.getElementById("box-lingue").style.display="none";

	document.getElementById(id_box).style.display="inline";

	document.getElementById('voce1').className="ricerca";
	document.getElementById('voce2').className="area-commerce";
	document.getElementById('voce3').className="area-operativa";
	document.getElementById('voce4').className="lingue";

	var stringa = '';
	stringa = document.getElementById(id_voce).className +' ';
	stringa += 'selezionato-'+ document.getElementById(id_voce).className;
	//alert (stringa);

	document.getElementById(id_voce).className = stringa;

}

// funzione che controlla la validità delle email inserite
function controlla_email(email) {
	if (email!="") {
		re = /^[0-9a-z]([-_\.]?[0-9a-z])*@[0-9a-z]([-_\.]?[0-9a-z])*\.[a-z]{2,4}$/i;
		if ( re.test(email) ) return true
		return false
	} else return true;
} //end func

//*********************** controlla i dati inseriti nel form di richiesta info****************/
function controlla_dati(nomeform) {
	switch (nomeform){
/*	case "newsletter":
		if (document.forms[nomeform].email.value!="") {
			ok=controlla_email(document.forms[nomeform].email.value);
			if (ok==false) {
				alert(testo_emailOk);
				return false;
			} else {
				if (document.forms[nomeform].valore_campo02.value==""){
					alert(testo_no_nome);
					return false;
				} else {
					if (document.forms[nomeform].valore_campo03.value==""){
						alert(testo_no_cognome);
						return false;
					} else {
						if (document.forms[nomeform].valore_campo05.value==""){
							alert(testo_no_citta);
							return false;
						} else {
							if ((document.forms[nomeform].valore_campo06.value=="") && (document.forms[nomeform].valore_campo07.value=="")){
								alert(testo_no_provinciastato);
								return false;
							} else {
								if (document.forms[nomeform].valore_campo08.value==""){
									alert(testo_no_nazione);
									return false;
								}
							}
						}
					}
				}
			}
		} else {
			alert(testo_email);
			return false;
		}
	break;*/
	case "newsletter":
		if (document.forms[nomeform].email.value!="") {
			ok=controlla_email(document.forms[nomeform].email.value);
			if (ok==false) {
				alert(testo_emailOk);
				return false;
			} else {
				if (document.forms[nomeform].email.value!=document.forms[nomeform].email1.value){
					alert(emailnoncoincidono);
					return false;
				} else {
					if (document.forms[nomeform].valore_campo05.value==""){
						alert(testo_no_citta);
						return false;
					} else {
						if ((document.forms[nomeform].valore_campo06.value=="") && (document.forms[nomeform].valore_campo07.value=="")){
							alert(testo_no_provinciastato);
							return false;
						} else {
							if (document.forms[nomeform].valore_campo08.value==""){
								alert(testo_no_nazione);
								return false;
							}
						}
					}
				}
			}
		} else {
			alert(testo_email);
			return false;
		}
	break;
	case "info":
		if ( document.forms[nomeform].email.value != "" ) {
			ok = controlla_email(document.forms[nomeform].email.value);
			if ( ok == false ) {
				alert(testo_emailOk);
				return false;
			}
			else {
				if ( document.forms[nomeform].email.value != document.forms[nomeform].conferma_email.value ) {
					alert(emailnoncoincidono);
					return false;
				}
				else {
					if ( document.forms[nomeform].valore_campo02.value == "" ) {
						alert(testo_no_nome);
						return false;
					}
					else {
						if ( document.forms[nomeform].valore_campo03.value == "" ) {
							alert(testo_no_cognome);
							return false;
						}
						else {
							if ( document.forms[nomeform].valore_campo05.value == "" ) {
								alert(testo_no_citta);
								return false;
							}
							else {
								if ( document.forms[nomeform].valore_campo06.value=="" && document.forms[nomeform].valore_campo07.value=="" ) {
									alert(testo_no_provinciastato);
									return false;
								}
								else {
									if ( document.forms[nomeform].messaggio.value == "" ) {
										alert(testo_no_messaggio);
										return false;
									}
									else {
										if ( document.forms[nomeform].valore_campo08.value == "" ) {
											alert(testo_no_nazione);
											return false;
										}
										else {
											indice = document.forms[nomeform].valore_campo08.selectedIndex;
											document.forms[nomeform].valore_campo08.value = document.forms[nomeform].valore_campo08[indice].text;
											return true;
										}
									}
								}
							}
						}
					}
				}
			}
		}
		else {
			alert(testo_email);
			return false;
		}
	break;
	case "commenti":
	/*	if (document.forms[nomeform].email.value!="") {
			ok=controlla_email(document.forms[nomeform].email.value);
			if (ok==false) {
				alert(testo_emailOk);
				return false;
			} else {*/
			/*	if (document.forms[nomeform].nome.value==""){
					alert(testo_no_nome);
					return false;
				} else {*/
					if (document.forms[nomeform].messaggio.value==""){
						alert(testo_no_commento);
						return false;
					}
			//	}
	/*		}
		} else {
			alert(testo_email);
			return false;
		}*/
	break;
	case "Finvia_amica":
	if (document.forms[nomeform].email_amica.value!="") {
		ok=controlla_email(document.forms[nomeform].email_amica.value);
		if (ok==false) {
			alert(testo_emailOk);
			return false;
		}
	} else {
		alert(testo_email);
		return false;
	}
	if (document.forms[nomeform].mia_email.value!="") {
		ok=controlla_email(document.forms[nomeform].mia_email.value);
		if (ok==false) {
			alert(testo_emailOk);
			return false;
		}
	} else {
		alert(testo_email);
		return false;
	}
break;

	}
} //end func



/********funzione per l'inserimento asimmetrico dei filati nel carrello*****/

  function makePOSTRequest_add_carrello(url, parameters) {
     http_request = false;
     if (window.XMLHttpRequest) { // Mozilla, Safari,...
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            // set type accordingly to anticipated content type
           //http_request.overrideMimeType('text/xml');
           http_request.overrideMimeType('text/html');
        }
     } else if (window.ActiveXObject) { // IE
        try {
           http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
           try {
              http_request = new ActiveXObject("Microsoft.XMLHTTP");
           } catch (e) {}
        }
     }
     if (!http_request) {
        alert('Cannot create XMLHTTP instance');
        return false;
     }
         http_request.onreadystatechange = alertContents_add_carrello;
     http_request.open('POST', url, true);
     http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
     http_request.setRequestHeader("Content-length", parameters.length);
     http_request.setRequestHeader("Connection", "close");
     http_request.send(parameters);
  }

  function alertContents_add_carrello() {
     if (http_request.readyState == 4) {
        if (http_request.status == 200) {
           //alert('http_request =>' + http_request.responseText);
			var result = http_request.responseText;
			document.getElementById('aggiungi_carrello').innerHTML = '<img style="margin:0px;" src="../img/icona-aggiungi-ok.gif" alt="ok" />';
			
        } else {
           //alert('Sono sorti problemi nell\'invio dei dati');
		   document.getElementById('aggiungi_carrello').innerHTML = '<img style="margin:0px;" src="../img/icona-aggiungi-ko.gif" alt="no ok" />';
        }
     }
  }


function aggiungi_filato_al_carrello(cod_prod, sigla_lingua, id_lingua) {

	//alert(document.forms[cod_prod].cod_colore.value);
	document.getElementById('aggiungi_carrello').innerHTML = '<img style="margin:0px;" src="../img/ingranaggi.gif" alt="" />';

	qt_min=document.forms[cod_prod].qt_min.value;
	if (qt_min<1) { qt_min=1; }
		qt_max=document.forms[cod_prod].qt_max.value;
	if (qt_max<1) { qt_max=1000; }
	if ((eval(document.forms[cod_prod].qt.value)>=qt_min) && (eval(document.forms[cod_prod].qt.value)<=qt_max)) {
		if (document.forms[cod_prod].cod_colore.value!="") {
			descrizione=escape(document.forms[cod_prod].nome.value);
			var url='';
			//url = "?";
			url += "lingua=" + sigla_lingua;
			url += "&id_lingua=" + id_lingua;
			url += "&cod_prod=" + document.forms[cod_prod].id_filato.value +' colore '+ document.forms[cod_prod].cod_colore.value;
			//url += "&desc_prod=" + descrizione + " - " + document.forms[cod_prod].cod_colore.value + "("+document.forms[cod_prod].elements["colore_"+document.forms[cod_prod].cod_colore.value].value + ")";
			url += "&desc_prod=" + descrizione + " - " + document.forms[cod_prod].cod_colore.value ;
			if (document.forms[cod_prod].peso.value=="") {
				document.forms[cod_prod].peso.value=0;
			}
			url += "&peso=" + document.forms[cod_prod].peso.value;
			url += "&quantita=" + document.forms[cod_prod].qt.value;
			//url += "&config=" + config;


			//var poststr = "nome_file=" + encodeURI(nome_file);

			//alert(poststr);
			makePOSTRequest_add_carrello('../salva-filato-in-carrello.php', url);

			/*aWindow=window.open(url, "aggiungi", "width=430,height=120,scrollbars=no,toolbar=no,menubar=no,status=no,resizable=yes" );*/

		} else {
			document.getElementById('aggiungi_carrello').innerHTML ='';
			alert(testo_colori);
		}
	} else {
		document.getElementById('aggiungi_carrello').innerHTML ='';
		alert(testo_qt);
	}
}



/************funzione per l'inserimento della rivista nel carrello**********************/


  function makePOSTRequest_add_carrello_rivista(url, parameters) {
     http_request = false;
     if (window.XMLHttpRequest) { // Mozilla, Safari,...
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            // set type accordingly to anticipated content type
           //http_request.overrideMimeType('text/xml');
           http_request.overrideMimeType('text/html');
        }
     } else if (window.ActiveXObject) { // IE
        try {
           http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
           try {
              http_request = new ActiveXObject("Microsoft.XMLHTTP");
           } catch (e) {}
        }
     }
     if (!http_request) {
        alert('Cannot create XMLHTTP instance');
        return false;
     }
         http_request.onreadystatechange = alertContents_add_carrello_rivista;
     http_request.open('POST', url, true);
     http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
     http_request.setRequestHeader("Content-length", parameters.length);
     http_request.setRequestHeader("Connection", "close");
     http_request.send(parameters);
  }

  function alertContents_add_carrello_rivista() {
     if (http_request.readyState == 4) {
        if (http_request.status == 200) {
           //alert('http_request =>' + http_request.responseText);
			var result = http_request.responseText;
			document.getElementById('aggiungi_rivista_carrello').innerHTML = '<img style="margin:0px;" src="../img/icona-aggiungi-ok.gif" alt="ok" />';
        } else {
           alert('Sono sorti problemi nell\'invio dei dati');
		   document.getElementById('aggiungi_rivista_carrello').innerHTML = '<img style="margin:0px;" src="../img/icona-aggiungi-ko.gif" alt="no ok" />';
        }
     }
  }

function aggiungi_rivista(nome_form, sigla_lingua, id_lingua) {


	document.getElementById('aggiungi_rivista_carrello').innerHTML = '<img style="margin:0px;" src="../img/ingranaggi.gif" alt="" />';

	qt_min=document.forms[nome_form].qt_min.value;
	if (qt_min<1) { qt_min=1; }
	//qt_max=document.forms[nome_form].qt_max.value;
	qt_max=document.forms[nome_form].disponibilita.value;
	if (qt_max<1) { qt_max=100; }
	if ((eval(document.forms[nome_form].qt.value)>=qt_min) && (eval(document.forms[nome_form].qt.value)<=qt_max)) {
		var url
		//url = "http://ecommerce2.infotel.it/carrello/adriafil/aggiungi.html?";
		url = "?";
		url += "lingua=" + sigla_lingua;
		url += "&id_lingua=" + id_lingua;
		url += "&cod_prod=" + document.forms[nome_form].codice_prodotto.value;
		url += "&desc_prod=" + escape(document.forms[nome_form].descrizione.value) + " - " + document.forms[nome_form].lingua.value;
		if (document.forms[nome_form].peso.value=="") {
			document.forms[nome_form].peso.value=0;
		}
		url += "&peso=" + document.forms[nome_form].peso.value;
		url += "&quantita=" + document.forms[nome_form].qt.value;
		//url += "&config=" + config;
//alert(url);
		//aWindow=window.open(url, "aggiungi", "width=430,height=120,scrollbars=no,toolbar=no,menubar=no,status=no,resizable=yes" );


		makePOSTRequest_add_carrello_rivista('../salva-rivista-in-carrello.php', url);

		document.getElementById('contenitore-menu-carrello').innerHTML = '<div id="menu-carrello-dx" class="box-semplice"><a href="ecommerce1.html" ><span>'+testo_carrello_stretto_menu+'</span></a><div class="interruzione"></div></div>';

	} else {
		document.getElementById('aggiungi_rivista_carrello').innerHTML ='';
		alert(testo_qt);
	}
}







