<!--
	// jQuery
	$(document).ajaxStop($.unblockUI);
	
	$(document).ready(function(){
		$(".lavaLamp").lavaLamp({
			fx: "backout", 
			speed: 700
		});
		
		$("a.menu, a.lateral, a.new, a.all_right").livequery("click", function(event){
			var url_rel = $(this).attr("rel");
			
			$.blockUI.defaults.applyPlatformOpacityRules = false;
			
			$.blockUI({
				message: $("#loader")
			});
			
			$.ajax({
				url: url_rel, 
				cache: false, 
				success: function(html){
					$("#main_right").html(html);
				}
			});
		});
	});
	
	// Googlemaps
	//<![CDATA[
	var WINDOW_HTML = '<div style="text-align: left;"><font style="font-family: Verdana; font-size: 11px; color: #000000;"><font style="font-weight: bold; color: #303192;">Magni Graniti</font><br /><br />Via Adda, 93<br />23013 Cosio Valtellino<br />Fraz. Regoledo (SO)</font></div>';
	
	function initialize(){
		if(GBrowserIsCompatible()){
			var mapOptions = {
				googleBarOptions : {
					style : "new"
				}
			}
			
			map = new GMap2(document.getElementById("mappa"), mapOptions);
			map.setMapType(G_PHYSICAL_MAP);
			map.setCenter(new GLatLng(46.143188, 9.552816), 13);
			
			var customUI = map.getDefaultUI();
			customUI.controls.menumaptypecontrol = true;
			customUI.controls.maptypecontrol = false;
			map.setUI(customUI);
			
			var marker = new GMarker(new GLatLng(46.143188, 9.552816));
     		map.addOverlay(marker);
      		GEvent.addListener(marker, "click", function(){
        		marker.openInfoWindowHtml(WINDOW_HTML);
      		});
			
			marker.openInfoWindowHtml(WINDOW_HTML);
			var ovcontrol = new GOverviewMapControl(new GSize(150, 150)); 
			map.addControl(ovcontrol);
		}
	}
	
	function showLocation(){
		initialize();
  	}
	//]]>
	
	// Mail antispam
	function mailNoSpam(user, dominio){
		document.location.href = "mailto:" + user + "@" + dominio;
	}
	
	// Controlla gli spazi vuoti nella compilazione dei campi di testo
	function trim(stringa){
		while(stringa.substring(0, 1) == " ")
			stringa = stringa.substring(1, stringa.length);
		
		while(stringa.substring(stringa.length-1, stringa.length) == " ")
			stringa = stringa.substring(0, stringa.length-1);
		
		return stringa;
	}
	
	// Submit di ricerca pagina nel catalogo per pagina
	function passForPid(whatValue, coidValue, pageValue, letterValue, orderbyValue, senseValue){
		var url_rel = "content.php?cmd=catalogo&" + whatValue + "=" + coidValue + "&page=" + pageValue + "&letter=" + letterValue + "&orderby=" + orderbyValue + "&sense=" + senseValue;
		
		$.blockUI.defaults.applyPlatformOpacityRules = false;
		
		$.blockUI({
			message: $("#loader")
		});
		
		$.ajax({
			url: url_rel,
			cache: false,
			success: function(html){
				$("#main_right").html(html);
			}
		});
	}
	
	// Submit di ricerca pagina nel catalogo per lettera
	function passForLid(whatValue, coidValue, letterValue, orderbyValue, senseValue){
		var url_rel = "content.php?cmd=catalogo&" + whatValue + "=" + coidValue + "&letter=" + letterValue + "&orderby=" + orderbyValue + "&sense=" + senseValue;
		
		$.blockUI.defaults.applyPlatformOpacityRules = false;
		
		$.blockUI({
			message: $("#loader")
		});
		
		$.ajax({
			url: url_rel,
			cache: false,
			success: function(html){
				$("#main_right").html(html);
			}
		});
	}
	
	// Submit di ordinamento pagina nel catalogo
	function passForOid(whatValue, sidValue, pageValue, whoValue, orderValue){
		if(whoValue == "" || whoValue == "N")
			alert("Attenzione!\nIl campo d'ORDINAMENTO non è stato selezionato correttamente.");
		else{
			if(document.getElementById('button_value').value == 'Crescente')
				orderValue = "ASC";
			else if(document.getElementById('button_value').value == 'Decrescente')
				orderValue = "DESC";
			
			var url_rel = "content.php?cmd=catalogo&" + whatValue + "=" + sidValue + "&page=" + pageValue + "&orderby=" + whoValue + "&sense=" + orderValue;
			
			$.blockUI.defaults.applyPlatformOpacityRules = false;
			
			$.blockUI({
				message: $("#loader")
			});
			
			$.ajax({
				url: url_rel,
				cache: false,
				success: function(html){
					$("#main_right").html(html);
				}
			});
		}
	}
	
	// Formatta un numero
	function numberFormat(number, decimals, dec_point, thousands_sep){
		var n = !isFinite(+number) ? 0 : +number, 
			prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
			sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
			dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
			s = "",
			toFixedFix = function (n, prec){
				var k = Math.pow(10, prec);
				return '' + Math.round(n * k) / k;
			};
    	
    	s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
		
		if(s[0].length > 3)
	        s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
    	
		if((s[1] || '').length < prec){
	        s[1] = s[1] || '';
    	    s[1] += new Array(prec - s[1].length + 1).join('0');
	    }
		
    	return s.join(dec);
	}
	
	// Aggiorna il prezzo del prodotto in base alla quantità inserita
	function refreshPrice(this_i, tot_i, qnt, price){
		if((qnt != "" && qnt != 0) && (price != "" && price != 0)){
			var new_tot = 0;
			var all_qnt = "";
			
			for(var i=1; i<=tot_i; i++){
				new_tot += parseFloat(($("#price_" + i).html()).replace(',', '.'))*($("#quantita_" + i).val());
				all_qnt += $("#quantita_" + i).val() + "||";
				
				$("#quantita_mini_" + i).html("");
				$("#quantita_mini_" + i).html($("#quantita_" + i).val());
			}
			
			$.ajax({
				type: "POST", 
				url: "content.php", 
				data: "cmd=catalogo&rid=S&all_qnt=" + all_qnt + ""
			});
			
			$("#total").html("");
			$("#total").html(numberFormat(new_tot, 2, ',', '.'));
			$("#total_mini").html("");
			$("#total_mini").html(numberFormat(new_tot, 2, ',', '.'));
			
			if(new_tot >= 500)
				$("#order").html("<a href=\"javascript:void(0);\" onclick=\"javascript:checkOrder(" + tot_i + ", " + new_tot + ");\"><img src=\"images/order_ok.gif\" border=\"0\" alt=\"Prosegui\" title=\"Prosegui\" /></a>");
			else
				$("#order").html("<img src=\"images/order_ko.gif\" border=\"0\" alt=\"Bloccato\" title=\"Bloccato\" />");
		}
		else if(qnt == 0){
			alert("Attenzione!\nIl campo QUANTITA' non è stato compilato correttamente.\nAnche se momentaneamente questo prodotto NON è disponibile in magazzino, inserite comunque la quantità desiderata.");
			$("#quantita_" + this_i).focus();
		}
	}
	
	// Controlla la form dell'ordine
	function checkOrder(tot_i, tot){
		var all_qnt = "";
		
		for(var i=1; i<=tot_i; i++){
			if(trim($("#quantita_" + i).val()) == "" || trim($("#quantita_" + i).val()) == 0){
				alert("Attenzione!\nIl campo QUANTITA' non è stato compilato correttamente.\nAnche se momentaneamente questo prodotto NON è disponibile in magazzino, inserite comunque la quantità desiderata.");
				$("#quantita_" + i).focus();
				
				return false;
			}
			
			all_qnt += $("#quantita_" + i).val() + "||";
		}
		
		if($("#condition:checked").val() == null)
			alert("Attenzione!\nE' obbligatorio accettare le CONDIZIONI COMMERCIALI.");
		else{
			all_qnt = all_qnt.substring(0, (all_qnt.length-2));
			var url_rel = "content.php?cmd=catalogo&did=S&totale=" + tot + "&all_qnt=" + all_qnt + "";
			
			$.blockUI.defaults.applyPlatformOpacityRules = false;
			
			$.blockUI({
				message: $("#loader")
			});
			
			$.ajax({
				url: url_rel, 
				cache: false, 
				success: function(html){
					$("#main_right").html(html);
				}
			});
		}
	}
	
	// Elimina il prodotto dal carrello
	function delProdBasket(i){
		if(confirm("Siete sicuri di voler eliminare questo prodotto dal carrello?")){
			var url_rel = "content.php?cmd=catalogo&rid=" + i;
			
			$.blockUI.defaults.applyPlatformOpacityRules = false;
			
			$.blockUI({
				message: $("#loader")
			});
			
			$.ajax({
				url: url_rel,
				cache: false,
				success: function(html){
					$("#main_right").html(html);
				}
			});
		}
	}
	
	// Controlla la compilazione della form in CONTATTI
	function checkForm(tot, all_qnt, ragione_sociale, partita_iva, codice_fiscale, citta, indirizzo, cap, provincia, mail, note){
		var goodEmail = document.forms[0].mail.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
		
		if(trim(document.forms[0].ragione_sociale.value) == ""){
			alert("Attenzione!\nIl campo RAGIONE SOCIALE non è stato compilato correttamente.");
			document.forms[0].ragione_sociale.focus();
		}
		else if(trim(document.forms[0].partita_iva.value) == "" && trim(document.forms[0].codice_fiscale.value) == ""){
			alert("Attenzione!\nAlmeno uno fra i campi P.IVA e CODICE FISCALE dev'essere compilato correttamente.");
			document.forms[0].partita_iva.focus();
		}
		else if(trim(document.forms[0].citta.value) == ""){
			alert("Attenzione!\nIl campo CITTA' non è stato compilato correttamente.");
			document.forms[0].citta.focus();
		}
		else if(trim(document.forms[0].indirizzo.value) == ""){
			alert("Attenzione!\nIl campo INDIRIZZO non è stato compilato correttamente.");
			document.forms[0].indirizzo.focus();
		}
		else if(trim(document.forms[0].cap.value) == ""){
			alert("Attenzione!\nIl campo CAP non è stato compilato correttamente.");
			document.forms[0].cap.focus();
		}
		else if(isNaN(document.forms[0].cap.value)){
			alert("Attenzione!\nIl campo CAP deve essere numerico.");
			document.forms[0].cap.focus();
		}
		else if(!goodEmail){
			alert("Attenzione!\nIl campo E-MAIL non è stato compilato correttamente.");
			document.forms[0].mail.focus();
		}
		else{
			var url_rel = "content.php?cmd=catalogo&did=S&esito=S&totale=" + tot + "&all_qnt=" + all_qnt + "&partita_iva=" + partita_iva + "&ragione_sociale=" + ragione_sociale + "&codice_fiscale=" + codice_fiscale + "&indirizzo=" + indirizzo + "&citta=" + citta + "&cap=" + cap + "&provincia=" + provincia + "&mail=" + mail + "&note=" + note + "";
			
			$.blockUI.defaults.applyPlatformOpacityRules = false;
			
			$.blockUI({
				message: $("#loader")
			});
			
			$.ajax({
				url: url_rel,
				cache: false,
				success: function(html){
					$("#main_right").html(html);
				}
			});
		}
	}
//-->
