// determino il browser : nome e versione
function ClientSnifferJr() {
  this.ua = navigator.userAgent.toLowerCase();
  this.major = parseInt(navigator.appVersion);
  this.minor = parseFloat(navigator.appVersion);
  // DOM Support
  if (document.addEventListener && document.removeEventListener) this.dom2events = true;
  if (document.getElementById) this.dom1getbyid = true;
  // Opera
  this.opera = this.ua.indexOf('opera') != -1;
  if (this.opera) {
    this.opera5 = (this.ua.indexOf("opera 5") != -1 || this.ua.indexOf("opera/5") != -1);
    this.opera6 = (this.ua.indexOf("opera 6") != -1 || this.ua.indexOf("opera/6") != -1);
    return;
  }
  // Konqueror
  this.konq = this.ua.indexOf('konqueror') != -1;
  // MSIE
  this.ie = this.ua.indexOf('msie') != -1;
  if (this.ie) {
    this.ie3 = this.major < 4;
    this.ie4 = (this.major == 4 && this.ua.indexOf('msie 5') == -1 && this.ua.indexOf('msie 6') == -1);
    this.ie4up = this.major >= 4;
    this.ie5 = (this.major == 4 && this.ua.indexOf('msie 5.0') != -1);
    this.ie5up = !this.ie3 && !this.ie4;
    this.ie6 = (this.major == 4 && this.ua.indexOf('msie 6.0') != -1);
    this.ie6up = (!this.ie3 && !this.ie4 && !this.ie5 && this.ua.indexOf("msie 5.5") == -1);
    return;
  }
  // Misc.
  this.hotjava = this.ua.indexOf('hotjava') != -1;
  this.webtv = this.ua.indexOf('webtv') != -1;
  this.aol = this.ua.indexOf('aol') != -1;
  if (this.hotjava || this.webtv || this.aol) return;
  // Gecko, NN4+, and NS6
  this.gecko = this.ua.indexOf('gecko') != -1;
  this.nav = (this.ua.indexOf('mozilla') != -1 && this.ua.indexOf('spoofer') == -1 && this.ua.indexOf('compatible') == -1);
  if (this.nav) {
    this.nav4  = this.major == 4;
    this.nav4up= this.major >= 4;
    this.nav5up= this.major >= 5;
    this.nav6  = this.major == 5;
    this.nav6up= this.nav5up;
  }
}

window.is = new ClientSnifferJr();

// 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

// apre il popup per l'inserimento del prodotto nel carrello
function aggiungi() {
	qt_min=document.FormFilato.qt_min.value;
	if (qt_min<1) { qt_min=1; }
	qt_max=document.FormFilato.qt_max.value;
	if (qt_max<1) { qt_max=1000; }
	if ((eval(document.FormFilato.qt.value)>=qt_min) && (eval(document.FormFilato.qt.value)<=qt_max)) {
		if ((document.FormFilato.cod_colore.value!="") && (document.FormFilato.elenco_colori.value.indexOf(document.FormFilato.cod_colore.value)>=0)) {
			descrizione=escape(document.FormFilato.nome.value);
			var url
			url = "http://ecommerce2.infotel.it/carrello/adriafil/aggiungi.html?";
			url += "lingua=" + sigla_lingua;
			url += "&id_lingua=" + id_lingua;
			url += "&cod_prod=" + document.FormFilato.id_filato.value +' colore '+ document.FormFilato.cod_colore.value;
			url += "&desc_prod=" + descrizione + " - " + document.FormFilato.cod_colore.value + "("+document.FormFilato.elements["colore_"+document.FormFilato.cod_colore.value].value + ")";
			if (document.FormFilato.peso.value=="") {
				document.FormFilato.peso.value=0;
			}
			url += "&peso=" + document.FormFilato.peso.value;
			url += "&quantita=" + document.FormFilato.qt.value;
			url += "&config=" + config;

			aWindow=window.open(url, "aggiungi", "width=430,height=120,scrollbars=no,toolbar=no,menubar=no,status=no,resizable=yes" );
		} else {
			alert(testo_colori);
		}
	} else {
		alert(testo_qt);
	}
} //end func

// apre il form di iscrizione alla newsletter in popup
function apri() {
	if ((document.formN.email.value!="") && (document.formN.email.value!="e-mail"))
		window.open('iscrizione_newsletter.html?id_lingua='+document.formN.id_lingua.value+'&email='+document.formN.email.value, 'Newsletter', 'width=460, height=430, scrollbars=yes, menubar=no, resizable=yes');
	else
		alert(testo_email);
} // end func

// 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


// apre il popup per l'acquisto della rivista
function aggiungi_rivista(nome_form) {
	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 += "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" );
	} else {
		alert(testo_qt);
	}
} //end func

/**************************************************************/
// apre il popup per l'inserimento del prodotto nel carrello
function aggiungi_al_carrello(nome_form) {
	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;
	if (qt_max<1) { qt_max=1000; }
	if ((eval(document.forms[nome_form].qt.value)>=qt_min) && (eval(document.forms[nome_form].qt.value)<=qt_max)) {
		if ((document.forms[nome_form].cod_colore.value!="") && (document.forms[nome_form].elenco_colori.value.indexOf(document.forms[nome_form].cod_colore.value)>=0)) {
			descrizione=escape(document.forms[nome_form].nome.value);
			var url
			url = "http://ecommerce2.infotel.it/carrello/adriafil/aggiungi.html?";
			url += "lingua=" + sigla_lingua;
			url += "&id_lingua=" + id_lingua;
			url += "&cod_prod=" + document.forms[nome_form].id_filato.value +' colore '+ document.forms[nome_form].cod_colore.value;
			url += "&desc_prod=" + descrizione + " - " + document.forms[nome_form].cod_colore.value + "("+document.forms[nome_form].elements["colore_"+document.forms[nome_form].cod_colore.value].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;

			aWindow=window.open(url, "aggiungi", "width=430,height=120,scrollbars=no,toolbar=no,menubar=no,status=no,resizable=yes" );
		} else {
			alert(testo_colori);
		}
	} else {
		alert(testo_qt);
	}
} //end func
/**************************************************************/

// pagina credits
function credits(str) {
searchWin = window.open(str,'credits','scrollbars=no,resizable=no,width=340,height=160,status=no,location=no,toolbar=no,menubar=no');
} //end func

/***********************************/
/*				funzioni per il rollover				 */
/***********************************/

function MM_preloadImages() { //v3.0
  var d=document;
  if(d.images){
		if(!d.MM_p) d.MM_p=new Array();
	    var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
		for(i=0; i<a.length; i++)
	    if (a[i].indexOf("#")!=0){
			d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];
		}
	}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr;
  for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments;
	document.MM_sr=new Array;
	for(i=0;i<(a.length-2);i+=3)
		if ((x=MM_findObj(a[i]))!=null) {
			document.MM_sr[j++]=x;
			if(!x.oSrc) x.oSrc=x.src;
			x.src=a[i+2];
		}
}

function MM_findObj(n, d) { //v4.0
	var p,i,x;
	if(!d) d=document;
	if((p=n.indexOf("?"))>0&&parent.frames.length) {
	    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
	}
	if(!(x=d[n])&&d.all) x=d.all[n];
	for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && document.getElementById) x=document.getElementById(n); return x;
}


function invia_form (nome_form) {
	document.forms[nome_form].submit();
}