	//=================================================================================================================================================================================================
	//==== CHIAMATA AJAX ==============================================================================================================================================================================
	//=================================================================================================================================================================================================

		function  display_ajax(AREA_AJAX, QUERY_STRING)
		{
			if ((AREA_AJAX == 0) || (AREA_AJAX == "")) AREA_AJAX = "ajax_container_id";

			/* URL di destinazione */
			var urlAjax = "public_ajax_manager.php"+ QUERY_STRING ;

			var returnNoAjax = ajaxRequest(urlAjax, AREA_AJAX) ;
			if (returnNoAjax)					// Non è possibile interagire con Ajax
				alert('Warning! NO ajax');
		}


	//=================================================================================================================================================================================================
	//==== GESTIONE DEI FORM ==========================================================================================================================================================================
	//=================================================================================================================================================================================================

	function submitFORM( ACTION ) {
		var returnValidate ;
		switch ( ACTION ) {
		case "SAVE_REG" :			// FORM modulo
				returnValidate = formValidate(document.form_modulo_reg);
				/*** Alert duplicati ***/
				if ((typeof(document.getElementById("duplicate_block")) != "undefined") && (document.getElementById("duplicate_block") != null) ) {
					alert("Attenzione! Sono stati inseriti dei valori duplicati non ammessi.\nModificarli prima di procedere.");
					returnValidate = false;
				}
				if (returnValidate) {
					document.form_modulo_reg.submit() ;
				}
				return false;
		break ;
		case "SAVE_CART" :
				returnValidate = formValidate(document.form_modulo) ;
				if (returnValidate) {
					xmlhttpPost_submit_cart('refreshcart', '', 'form_modulo', 'MasterContainerProductDetail', '');
					return false;
				}
		break ;
		case "SEARCH" :
				var filter_tables = document.getElementById('search_site_FilterTables').value;
				var words_key = document.getElementById('search_site_key').value;
				if ( (chkEmpty(filter_tables)) && (chkEmpty(words_key)) ) {
					document.form_modulo_search_site.submit() ;
				}
				return false;
		break ;
		case "SEARCH_PRODUCT" :
				var selected_value = document.getElementById('search_prod_key_hidden').value;
				if (selected_value == "") return false;
				document.location = 'dettagli.php?id=' + selected_value;
				return false;
		break ;
		case "SAVE_NEWSLETTER_ISCR" :
				returnValidate = formValidate(document.form_newsletter_iscrizione) ;
				if (returnValidate) {
					document.getElementById('container_iscrizione').style.display = 'none';
					document.getElementById('container_esito_1').style.display = 'block';
					xmlhttpPost('public_ajax_manager.php?act_ajax=iscrizione_newsletter', 'form_newsletter_iscrizione', 'container_esito_1', ' Operazione in corso...');
					return false;
				}
		break ;
		case "SAVE_NEWSLETTER_CANC" :
				returnValidate = formValidate(document.form_newsletter_cancellazione) ;
				if (returnValidate) {
					document.getElementById('container_cancellazione').style.display = 'none';
					document.getElementById('container_esito_2').style.display = 'block';
					xmlhttpPost('public_ajax_manager.php?act_ajax=cancellazione_newsletter', 'form_newsletter_cancellazione', 'container_esito_2', ' Operazione in corso...');
					return false;
				}
		break ;
		case "SAVE_PASS" :
				returnValidate = formValidate(document.form_modulo_pass);
				if (returnValidate) {
					document.form_modulo_pass.submit() ;
				}
				return false;
		break ;
		default :
				returnValidate = formValidate(document.form_modulo);
				if (returnValidate) {
					document.form_modulo.submit() ;
				}
				return false;
		break ;
		}
	}

	//=================================================================================================================================================================================================
	//==== CONTROLLI INSERIMENTO CAMPI INPUT ==========================================================================================================================================================
	//=================================================================================================================================================================================================


		//# ritorna FALSE se item è VUOTO
		function  chkEmpty(item, l) {
			var returnValue = false;
			var i = 0;
			if (l != 0 && chkLength(item, l)) return false;
			while (item.length > i && !returnValue) {
				if(item.charAt(i) != " ") returnValue = true;
				i++;
			}
			return (returnValue);
		}
		function  chkLength(item, len) {
			if (item.length == len) return true;
			else return false;
		}

	//=================================================================================================================================================================================================

		function isDigitAlphaNumber(e) {
		var returnValue = false ;
		if (typeof(e.which) == "undefined") {
			//## Explorer
			if ((e.keyCode >= 48) && (e.keyCode <= 57))	returnValue = true ;		// 0-9
			if ((e.keyCode >= 65) && (e.keyCode <= 90))	returnValue = true ;		// A-Z
			if ((e.keyCode >= 97) && (e.keyCode <= 122))	returnValue = true ;		// a-z
			if (e.keyCode == 13)				returnValue = true ;		// RETURN
			if (e.keyCode == 8)				returnValue = true ;		// BACKSPACE
		} else {
			//## Firefox
			if ((e.which >= 48) && (e.which <= 57))		returnValue = true ;		// 0-9
			if ((e.which >= 65) && (e.which <= 90))		returnValue = true ;		// A-Z
			if ((e.which >= 97) && (e.which <= 122))	returnValue = true ;		// a-z
			if (e.which == 13)				returnValue = true ;		// RETURN
			if (e.which == 8) 				returnValue = true ;		// BACKSPACE
			if ((e.keyCode >= 35) && (e.keyCode <= 40))	returnValue = true ;		// FRECCIE, INIZIO, FINE
			if (e.keyCode == 9)				returnValue = true ;		// TAB
			if (e.keyCode == 46)				returnValue = true ;		// CANC
			if (e.keyCode == 116)				returnValue = true ;		// F5
		}
		return returnValue ;
	}

	//=================================================================================================================================================================================================

	function isDigitNumber(e) {
		var returnValue = false ;
		if (typeof(e.which) == "undefined") {
			//## Explorer
			if ((e.keyCode >= 48) && (e.keyCode <= 57))	returnValue = true ;		// 0-9
			if (e.keyCode == 46)				returnValue = true ;		// .
			if (e.keyCode == 13)				returnValue = true ;		// RETURN
			if (e.keyCode == 8)				returnValue = true ;		// BACKSPACE
		} else {
			//## Firefox
			if ((e.which >= 48) && (e.which <= 57))		returnValue = true ;		// 0-9
			if (e.which == 46)				returnValue = true ;		// .
			if (e.which == 13)				returnValue = true ;		// RETURN
			if (e.which == 8) 				returnValue = true ;		// BACKSPACE
			if ((e.keyCode >= 35) && (e.keyCode <= 40))	returnValue = true ;		// FRECCIE, INIZIO, FINE
			if (e.keyCode == 9)				returnValue = true ;		// TAB
			if (e.keyCode == 46)				returnValue = true ;		// CANC
			if (e.keyCode == 116)				returnValue = true ;		// F5
		}
		return returnValue ;
	}

	//=================================================================================================================================================================================================
	//=================================================================================================================================================================================================
	//=================================================================================================================================================================================================

		/* Lista a tendina dei prodotti / offerte */

		var variabileSearcher;
		var histstato;

		function OpenDivSearcher(variabileSearcher)
		{
			if (histstato == undefined || histstato != variabileSearcher ){

				/* Chiamata Ajax per popolare la lista */
				if (variabileSearcher == "Fil01") display_ajax("Fil01", "?act_ajax=prodotti_list");
				if (variabileSearcher == "Fil02") display_ajax("Fil02", "?act_ajax=offerte_list");

				if (histstato == undefined) {
					$('#'+variabileSearcher).animate({height: 'toggle'},400);
					histstato = variabileSearcher;
				} else {
					$('#'+histstato).animate({height: 'toggle'},400, function() {	
						//timerId = setTimeout('Tendina('+variabileSearcher+')', 10);
						$('#'+variabileSearcher).animate({height: 'toggle'},400, function() {
							histstato = variabileSearcher;
						});
					});
				}
			} else if (histstato == variabileSearcher ) {

				$('#'+variabileSearcher).animate({height: 'toggle'},400, function() {
					histstato = undefined;
				});
			}
		}

		/* Gestione del campo incremento: pulsanti */
		function  tasto_incremento_manager(ACTION_VALUE, NOME_CAMPO)
		{
			var valore_campo = document.getElementById(NOME_CAMPO).value;
			if ((isNaN(valore_campo)) || (valore_campo <= 0)) valore_campo = 1;

			if (ACTION_VALUE == 0) {	// incremento
				valore_campo++;
			} else {			// decremento
				valore_campo--;
			}
			if (valore_campo <= 0) valore_campo = 1;
			document.getElementById(NOME_CAMPO).value = valore_campo;
		}

		/* Gestione del campo incremento: tasti freccie */
		function  tasto_incremento_key(e, NOME_CAMPO)
		{
			if (e.keyCode == 38)  tasto_incremento_manager(0, NOME_CAMPO);
			if (e.keyCode == 40)  tasto_incremento_manager(1, NOME_CAMPO);
		}

	//=================================================================================================================================================================================================

		function mostra_prezzo(VALORE_CAMPO, ID_PRODOTTO) {
			if ( document.getElementById("area_evidenza_prezzo_"+ ID_PRODOTTO) ) {
				display_ajax("area_evidenza_prezzo_"+ ID_PRODOTTO, "?act_ajax=mostra_prezzo_evidenza&id_formato="+ VALORE_CAMPO);
			}
			if ( document.getElementById("area_breve_prezzo_"+ ID_PRODOTTO) ) {
				display_ajax("area_breve_prezzo_"+ ID_PRODOTTO, "?act_ajax=mostra_prezzo_breve&id_formato="+ VALORE_CAMPO);
			}
			if ( document.getElementById("area_dettaglio_prezzo_"+ ID_PRODOTTO) ) {
				display_ajax("area_dettaglio_prezzo_"+ ID_PRODOTTO, "?act_ajax=mostra_prezzo_dettaglio&id_formato="+ VALORE_CAMPO);
			}
		}


	//=================================================================================================================================================================================================
	//==== FUNZIONI DEL CARRELLO ======================================================================================================================================================================
	//=================================================================================================================================================================================================

		/* AGGIUNGE UN PRODOTTO */
		function FuncAddToCart(ID_PRODOTTO)
		{
			if ( confirm('Vuoi aggiungere il prodotto al carrello?') ) {
				/* mostra il carrello */
				document.getElementById("ShoppingCart").style.display = "block";
				var ID_FORMATO = document.getElementById("select_formato_"+ID_PRODOTTO).value;
				if (document.getElementById("_quantita_incremento")) {
					N_QUANTITA = document.getElementById("_quantita_incremento").value;
				} else {
					N_QUANTITA = 1;
				}
				display_ajax("ShoppingCart", "?act_ajax=addcart&id="+ID_PRODOTTO+"&id_formato="+ID_FORMATO+"&qt="+N_QUANTITA);
			}
			return false;
		}

		/* SVUOTA IL CARRELLO */
		function FuncEmptyCart()
		{
			if ( confirm('Sei sicuro di voler svuotare il carrello?') ) {
				var l = location.href;
				var this_page_name = l.substr(l.lastIndexOf("/")+1).split(/[?#]/)[0];

				if (this_page_name == "carrello.php") {
					document.location = 'carrello.php?act=emptycart';
				} else {
					display_ajax("ShoppingCart", "?act_ajax=emptycart");
				}
			}
			return false;
		}

		/* CONFERMA PRE-ORDINE */
		function FuncConfirmCart( USER_STATUS )
		{
			if (USER_STATUS == 99) {	// Utente Loggato
				if ( confirm("Sei sicuro di voler confermare l'ordine?") ) {
					document.location = 'carrello.php?act=confirmcart';
				}
			} else {
				document.location = 'carrello.php?act=confirmcart';
			}
			return false;
		}

		/* CONFERMA PRE-ORDINE */
		function FuncConfirmCart2()
		{
			var radioObj = document.form_modulo.ID_ORDINE;
			var radioLength = radioObj.length;
			for(var i = 0; i < radioLength; i++) {
				if(radioObj[i].checked) {
					radioValue = radioObj[i].value;
				}
			}
			if (radioValue == 0) {
				if ( confirm("Inserire i prodotti del carrello in un nuovo ordine?") ) {
					document.location = 'carrello.php?act=create_pre';
				}
			} else {
				if ( confirm("Accodare i prodotti del carrello nell'ordine N. " + radioValue + " ?") ) {
					document.location = 'carrello.php?act=append_pre&id=' + radioValue;
				}
			}
		}


	//=================================================================================================================================================================================================
	//=================================================================================================================================================================================================
	//=================================================================================================================================================================================================

		function call_tooltip_function()
		{
			$('a, input, img, select, Textarea, area').tooltip({
				track: true,
				delay: 0,
				showURL: false,
				showBody: " - ",
		 	   	opacity: 1, 
		   		fade: 250,
				positionLeft: false
			});
		}

	//=================================================================================================================================================================================================

		function CancMail() {
			document.getElementById('MailingFrameDisplayOff').style.display = 'block';
			document.getElementById('MailingFrameDisplayOn').style.display = 'none';
			document.getElementById('container_cancellazione').style.display = 'block';

			document.form_newsletter_cancellazione.reset();

			document.getElementById('container_esito_1').style.display = 'none';
			document.getElementById('container_esito_2').style.display = 'none';
		}
		function SendMail() {
			document.getElementById('MailingFrameDisplayOff').style.display = 'none';
			document.getElementById('MailingFrameDisplayOn').style.display = 'block';
			document.getElementById('container_iscrizione').style.display = 'block';

			document.form_newsletter_iscrizione.reset();

			document.getElementById('container_esito_1').style.display = 'none';
			document.getElementById('container_esito_2').style.display = 'none';
		}

	//=================================================================================================================================================================================================

