<!-- // Inizio
var popUpWin=0;
var d = document;

function popUpWindow(URLStr, left, top, width, height) {
	left = ((screen.width - width) / 2);
	top = ((screen.height - height) / 2);

	if(popUpWin) {
		if(!popUpWin.closed) popUpWin.close();
	}
	popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

function showLingua() {
	if ($('lingua').style.margin != "" && $('lingua').style.margin != '-40px 0px 0px 0px')
		$('lingua').style.margin = '-40px 0px 0px 0px  !important';
	else
		$('lingua').style.margin = '0px 0px 0px 0px !important';
}

/*
function checkquantita(val) {
	var valore_minimo = $("form" + val).ordine_minimo.value;
	var valore = $("form" + val).quantita.value;
	if ( valore < 0) {
		alert('Non puoi inserire una quantità negativa!');
		$("form" + val).quantita.focus();
		return false;
	} else if (valore == 0) {
		alert('Hai inserito 0 come quantità.\r\n Se vuoi cancellare il prodotto, clicca sulla X rossa a destra.');
		$("form" + val).quantita.focus();
		return false;
	} else if (valore < valore_minimo) {
		alert('Il prodotto selezionato ha un quantitativo minimo ordinabile pari a ' + valore_minimo);
		$("form" + val).quantita.value = valore_minimo;
		return false;
	} else {
		return true;
	}
}*/

// chiamata di gestione dell'errore Ajax
function errore(request, div) {
	if ($(div)) {
		$(div).innerHTML = "Errore nella chiamata Ajax";
	}
}

function checkquantita(val) {
	if ($("form" + val).ordine_minimo.value) {
		var valore_minimo = $("form" + val).ordine_minimo.value;
		var valore = $("form" + val).quantita.value;
		var imballaggio = $("form" + val).imballaggio.value;
		var cod_art = $("form" + val).cod_art.value;
		var prezzo = $("form" + val).prezzo.value;
		if ( valore < 0) {
			alert('Non puoi inserire una quantità negativa!');
			$("form" + val).quantita.focus();
			return false;
		} else if (valore == 0) {
			alert('Hai inserito 0 come quantità.');
			$("form" + val).quantita.value = valore_minimo;
			$("form" + val).quantita.focus();
			return false;
		/*} else if (valore != NaN && valore_minimo != NaN && parseInt(valore) < parseInt(valore_minimo)) {
			alert('Il prodotto selezionato ha un quantitativo minimo consigliato pari a ' + valore_minimo);
			$("form" + val).quantita.value = valore_minimo;
			return false;
		*/
		} else if (valore != NaN && valore_minimo != NaN && parseInt(valore) < parseInt(valore_minimo)) {
			if (!isNaN(imballaggio)) {
				if (parseInt(valore) % parseInt(imballaggio) != 0) {
					alert('Un imballo contiene '+ parseInt(imballaggio) + ' pezzi. Il sito proporrà l\'intero più vicino.');
					$("form" + val).quantita.value = Math.ceil(parseInt(valore) / parseInt(imballaggio)) * parseInt(imballaggio);
					var valore = $("form" + val).quantita.value;
					// aggiorno il carrello con Ajax
					var url = "upd_carrello.php";
					var pars = "prezzo="+prezzo+"&quantita=" + valore + "&cod_art=" + cod_art + "&frase=1";
					$("loading").style.display = "block";
					var MyAjax = new Ajax.Updater(
						{success: 'ordinesx'},
						url,
						{
							method: 'post',
							parameters: pars,
							onFailure: errore('ordinedx')
						}
					);

					// controllo che quantità sia maggiore di minimo
					if (parseInt(valore) < parseInt(valore_minimo)) {
						$("qta_messaggio").innerHTML = "<strong>ATTENZIONE!</strong> Il prodotto selezionato ha un quantitativo minimo consigliato pari a <strong>" + valore_minimo + "</strong>";

					} else {
						$("qta_messaggio").innerHTML = "Il quantitativo minimo consigliato è <strong>" + valore_minimo + "</strong> mentre la quantità per confezione è <strong>" + imballaggio + "</strong>";
					}
					return false;
				} else {
					// aggiorno il carrello con Ajax
					var url = "upd_carrello.php";
					var pars = "prezzo="+prezzo+"&quantita=" + valore + "&cod_art=" + cod_art + "&frase=1";
					$("loading").style.display = "block";
					var MyAjax = new Ajax.Updater(
						{success: 'ordinesx'},
						url,
						{
							method: 'post',
							parameters: pars,
							onFailure: errore('ordinedx')
						}
					);
					return true;
				}
			} else {
				// aggiorno il carrello con Ajax
				var url = "upd_carrello.php";
				var pars = "prezzo="+prezzo+"&quantita=" + valore + "&cod_art=" + cod_art + "&frase=2";
				$("loading").style.display = "block";
				var MyAjax = new Ajax.Updater(
					{success: 'ordinesx'},
					url,
					{
						method: 'post',
						parameters: pars,
						onFailure: errore('ordinedx')
					}
				);
			}
		} else {
			// aggiorno il carrello con Ajax
			var url = "upd_carrello.php";
			var pars = "prezzo="+prezzo+"&quantita=" + valore + "&cod_art=" + cod_art + "&frase=2";
			$("loading").style.display = "block";
			var MyAjax = new Ajax.Updater(
				{success: 'ordinesx'},
				url,
				{
					method: 'post',
					parameters: pars,
					onFailure: errore('ordinedx')
				}
			);
			if (!isNaN(imballaggio)) {
				if (parseInt(valore) % parseInt(imballaggio) != 0) {
					alert('Un imballo contiene '+ parseInt(imballaggio) + ' pezzi. Il sito proporrà l\'intero più vicino.');
					$("form" + val).quantita.value = Math.ceil(parseInt(valore) / parseInt(imballaggio)) * parseInt(imballaggio);
					var valore = $("form" + val).quantita.value;
					// aggiorno il carrello con Ajax
					var url = "upd_carrello.php";
					var pars = "prezzo="+prezzo+"&quantita=" + valore + "&cod_art=" + cod_art + "&frase=1";
					$("loading").style.display = "block";
					var MyAjax = new Ajax.Updater(
						{success: 'ordinesx'},
						url,
						{
							method: 'post',
							parameters: pars,
							onFailure: errore('ordinedx')
						}
					);
					
					$("qta_messaggio").innerHTML = "Il quantitativo minimo consigliato è <strong>" + valore_minimo + "</strong> mentre la quantità per confezione è <strong>" + imballaggio + "</strong>";
					return false;
				} else {
					$("qta_messaggio").innerHTML = "Il quantitativo minimo consigliato è <strong>" + valore_minimo + "</strong> mentre la quantità per confezione è <strong>" + imballaggio + "</strong>";
					return true;
				}
			}
		}
	} else {
		$("form" + val).quantita.value =1;
	}
}//checkquantita




// funzione per visualizzare o nascondere un elemento tramite id
function swapId(id) {
	if ($(id).style.display == "none" || $(id).style.display == "") {
		$(id).style.display = "block";
	} else {
		$(id).style.display = "none";
	}
}

// funzione per il cambio della mappa
function showMap(id, titolo) {
	titololnk = "'"+titolo+"'";
	if (id < 3 && id > 0) {
		next = id + 1;
	} else {
		next = 1;
	}
	$("mappa").innerHTML = '<h2>'+titolo+'</h2><img id="mapImage" src="immagini/piantina_'+id+'.gif" alt="" title="" style="margin: 10px 0" width="350" height="343" onclick="javascript:showMap('+next+', '+titololnk+');" />';
}

// funzione per l'ingrandimento delle immagini
function zoomImage(evento, URLStr, width, height) { //function zoomImage(URLStr, left, top, width, height) {
	var evento;
	var left;
	var top;
	var width;
	var height;
	// posizione mouse
	if (window.opera) {
		left = evento.clientX;
		top = evento.clientY;
	} else if (d.all) {
		top = d.documentElement.scrollTop + evento.clientY;
		left = d.documentElement.scrollLeft + evento.clientX;
	} else if (evento.pageX){
		left = evento.pageX;
		top = evento.pageY;
	} else {
		left = ((screen.width - width) / 2);
		top = ((screen.height - height) / 2);
	}

	width -= 20;
	height -= 20;

	left = left - width;
	if (left < -150) left = -150;
	top = top - height;
	if (top < -100) top = -100;

	$('zoomImg').style.display = 'block';
	$('zoomImg').style.position = 'absolute';
	$('zoomImg').style.width = width + 'px';
	$('zoomImg').style.height = height + 'px';
	$('zoomImg').style.zIndex = '100';
	$('zoomImg').style.top = top + 'px';
	$('zoomImg').style.left = left + 'px';
	$('zoomImg').style.border = '1px solid #000';
	$('zoomImg').style.padding = '10px';
	$('zoomImg').style.backgroundColor = '#FFF';
	$('zoomImg').innerHTML = '<img src="'+URLStr+'" title="" alt="" />';
}

// funzione per il ripristino dell'immagine zoomata
function restoreImage() {
	$('zoomImg').style.display = 'none';
}

// funzione per il controllo dei campi del form
function controllo() {
	if ($F("nome") == "" || $F("nome") == "Ragione sociale" || $F("nome").length < 4) {
		alert("Il campo Ragione sociale non può essere vuoto");
		$("nome").focus();
		return false;
	}
	if ($F("citta") == "" || $F("citta") == "Città" || $F("citta").length < 4) {
		alert("Il campo Città non può essere vuoto");
		$("citta").focus();
		return false;
	}
	if ($F("provincia") == "" || $F("provincia") == "Provincia" || $F("provincia").length < 4) {
		alert("Il campo Provincia non può essere vuoto");
		$("provincia").focus();
		return false;
	}
	if ($F("indirizzo") == "" || $F("indirizzo") == "Indirizzo" || $F("indirizzo").length < 4) {
		alert("Il campo Indirizzo non può essere vuoto");
		$("indirizzo").focus();
		return false;
	}
	if ($F("attivita") == "" || $F("attivita") == "Attività" || $("attivita").length < 4) {
		alert("Il campo Attività svolta non può essere vuoto");
		$("attivita").focus();
		return false;
	}
	if ($F("telefono") == "" || $F("telefono") == "Numero di telefono" || $("telefono").length < 4) {
		alert("Il campo Telefono non può essere vuoto");
		$("telefono").focus();
		return false;
	}
	// privacy
	if ($("accetto")) {
		if ($("accetto").checked != true) {
			alert("Devi accettare la normativa sulla privacy");
			$("accetto").focus();
			return false;
		}
	}
	return true;
}


/* posizionamento dinamico del foot della pagina */
function layout() {
	var pageHeight;
	if (self.innerHeight) { /* Mozilla e opera */
		if ($("colonnasx")) {
			// colonne (pagina normale)
			if (!$("colonnadx") || ($("colonnasx").clientHeight > $("colonnadx").clientHeight)) {
				altezza = $("colonnasx").clientHeight;
			} else {
				altezza = $("colonnadx").clientHeight;
			}
		} else if ($("ordinesx")) {
			// ordine (solo ordine)
			if ($("ordinesx").clientHeight > $("ordinedx").clientHeight) {
				altezza = $("ordinesx").clientHeight;
			} else {
				altezza = $("ordinedx").clientHeight;
			}
		} else if ($("mappa")) {
			// ordine (solo ordine)
			if ($("mappa").clientHeight > $("stretta").clientHeight) {
				altezza = $("mappa").clientHeight;
			} else {
				altezza = $("stretta").clientHeight;
			}
		} else if ($("colonnadx")) {
			altezza = $("colonnadx").clientHeight;
		}
		altezza += 130;
		if (altezza < self.innerHeight) {
			altezza = self.innerHeight;
			altezza -= 40;
		}
	} else { /* Netscape e IE5.x */
		if ($("colonnasx")) {
			// colonne (pagina normale)
			if (!$("colonnadx") || ($("colonnasx").clientHeight > $("colonnadx").clientHeight)) {
				altezza = $("colonnasx").clientHeight;
			} else {
				altezza = $("colonnadx").clientHeight;
			}
		} else if ($("ordinesx")) {
			// ordine (solo ordine)
			if ($("ordinesx").clientHeight > $("ordinedx").clientHeight) {
				altezza = $("ordinesx").clientHeight;
			} else {
				altezza = $("ordinedx").clientHeight;
			}
		} else if ($("mappa")) {
			// ordine (solo ordine)
			if ($("mappa").clientHeight > $("stretta").clientHeight) {
				altezza = $("mappa").clientHeight;
			} else {
				altezza = $("stretta").clientHeight;
			}
		} else if ($("colonnadx")) {
			altezza = $("colonnadx").clientHeight;
		}
		if (altezza < $("menu").clientHeight) altezza = $("menu").clientHeight;
		altezza += 208;
	}
	altezza = altezza + "px";
	if ($("foot"))
		$("foot").style.top = altezza;
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

addLoadEvent(layout);
// Fine -->