function clickBanner(id, url_dest)
	{
		//pulisco gli url di provenienza e destinazione
		
		if(url_dest!="")
			page_dest = url_dest.split("/").pop();
		else
			page_dest = "none";
		//alert(page_dest);
		page_ref = self.location.href.split("/").pop();
		if(page_ref=="")
			page_ref = "index.php";
		
		$.post("banner_click.php", { id: id, page_ref: page_ref, page_dest: page_dest } );
		//in caso di url a siti esterni
		if(page_dest=="")
			window.setTimeout("doRedirect('"+url_dest+"')", 500);
		else
		if(url_dest!="")
			window.setTimeout("doRedirect('"+page_dest+"')", 500);
		//alert(id + url_dest + page_ref);
		return false;
	}
	
function doRedirect(page_dest)
	{
		location.href = page_dest;
	}
	
function showHidePro(id)
	{
		if(document.getElementById(id).style.display == "none")
			{
				document.getElementById(id).style.display = "block";
				if(subtotale>0)	
					document.getElementById("cart_mensaje_2").style.display = "block";
				//se ci sono già selezionati dei messaggi, risommo
				tot = tot + subtotale;
				document.getElementById("cart_tot").innerHTML = tot + " &euro; + IVA";				
			}
		else
			{
				document.getElementById(id).style.display = "none";
				document.getElementById("cart_mensaje_2").style.display = "none";
				//se erano selezionati dei messaggi, sottraggo
				tot = tot - subtotale;
				document.getElementById("cart_tot").innerHTML = tot + " &euro; + IVA";								
			}
	}
	
/*function video()
	{
		document.getElementById('video_intro').style.display = "none";
		//var clone = $("#video_intro_flv").clone(true);
		$("#video_intro_flv").remove();
		$("#video_intro").removeAttr('onclick').append("<div id='video_intro_flv'><img src='images/close2.png' border='0' onClick='video();' style='float:right; cursor:pointer;' alt='Chiudi'><object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' width='550' height='367' style='top:-300px;'><param name='movie' value='video_ITA.swf' /><param name='wmode' value='transparent' /><param name='flashvars' value='id=FlabellComponent&amp;name=FlabellComponent' /><!--[if !IE]>--><object type='application/x-shockwave-flash' data='video_ITA.swf' width='550' height='367'><param name='wmode' value='transparent' /><param name='flashvars' value='id=FlabellComponent&amp;name=FlabellComponent' /><!--<![endif]--><!--[if !IE]>--></object><!--<![endif]--></object></div>");
	} */
	
function video()
	{
		document.getElementById('video_intro').style.display = "none";
		//var clone = $("#video_intro_flv").clone(true);
		$("#video_intro_flv").remove();
		$("#video_intro").append("<div id=\"video_intro_flv\" style=\"width:548px; height:366px; top:50%; margin-top:100px;\"><img src=\"images/close2.png\" border=\"0\" onClick=\"video();\" style=\"float:right; cursor:pointer;\" alt=\"Chiudi il video\"><object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\"550\" height=\"367\" style=\"top:-300px;\"><param name=\"movie\" value=\"video_ITA.swf\" /><param name=\"wmode\" value=\"transparent\" /><param name=\"flashvars\" value=\"id=FlabellComponent&amp;name=FlabellComponent\" /><!--[if !IE]>--><object type=\"application/x-shockwave-flash\" data=\"video_ITA.swf\" width=\"550\" height=\"367\"><param name=\"wmode\" value=\"transparent\" /><param name=\"flashvars\" value=\"id=FlabellComponent&amp;name=FlabellComponent\" /><!--<![endif]--><!--[if !IE]>--></object><!--<![endif]--></object></div>");
	}
	
// GESTIONE FOCUS / BLUR FORM
$(document).ready(function() {
	$('.focus_blur input:text').addClass("idleField");
	$('.focus_blur textarea').addClass("idleField");
	
	// INPUT
	$('.focus_blur input').focus(function() {
		// set font color to black on focus event
		$(this).removeClass("idleField").addClass("focusField");
		// if field is readonly, any status control is applied to it
		if(this.readOnly){
			return;
		}
		else{
			if (this.value == this.defaultValue){ 
				this.value = '';
			}
			if(this.value != this.defaultValue){
				this.select();
			}
		}
	});

	$('.focus_blur input').blur(function() {
        if ($.trim(this.value) == ''){
			// if field hasn't been filled, restore default value with default color
			$(this).removeClass("focusField").addClass("idleField");
            this.value = (this.defaultValue ? this.defaultValue : ''); 
        }
	});
	
	// TEXTAREA
	$('.focus_blur textarea').focus(function() {
		// if field is readonly, any status control is applied to it
		if(this.readOnly){
			return;
		}
		// set font color to black on focus event
		$(this).removeClass("idleField").addClass("focusField");
		if (this.value == this.defaultValue){ 
			this.value = '';
		}
		if(this.value != this.defaultValue){
			this.select();
		}
	});

	$('.focus_blur textarea').blur(function() {
		if ($.trim(this.value) == ''){
			// if field hasn't been filled, restore default value with default color
			$(this).removeClass("focusField").addClass("idleField");
			this.value = (this.defaultValue ? this.defaultValue : '');
		}
	});
	
	
	/******************/
	/* RICERCA NUMERO */
	/******************/
	
	//INPUT
	$('form.cerca_numero input:text').focus(function() {
		// set font color to black on focus event
		$(this).removeClass("idleField").addClass("focusField");
		// if field is readonly, any status control is applied to it
		if(this.readOnly){
			return;
		}
		else{
			/*if (this.value == this.defaultValue){ 
				this.value = '';
			}*/
			if(this.value != this.defaultValue){
				this.select();
			}
		}
	});

	$('form.cerca_numero input:text').blur(function() {
        if ($.trim(this.value) == this.defaultValue){
			// if field hasn't been filled, restore default value with default color
			$(this).removeClass("focusField").addClass("idleField");
            //this.value = (this.defaultValue ? this.defaultValue : ''); 
        }
	});
	

	// TOP MENU
	$('.main_menu ul ul').hide();
	$('.main_menu li').hover(function() {
		var zindex = $(this).children('ul').css('z-index');
		if($(this).children('ul').is(':hidden')) {
			$(this).css('z-index',zindex+1);
			$(this).children('ul').show()
		}
	}, function() {
		var zindex = $(this).children('ul').css('z-index');
		$(this).css('z-index',zindex-1);
		$(this).children('ul').hide();
	});
});


/**************************************/
/* AREA RISERVATA / RECUPERO PASSWORD */
/**************************************/

$(document).ready(function() {
	/* recupero valori di default campi numero verde / password / email */
	var userDefault = $('#user_login').val();
	var pwdDefault = $('#pwd_login').val();
	var emailRecuperoDefault = $('#email_recupero').val();
	
	/* ACCESSO AREA RISERVATA */
	
	// apertura box login
	/*$('#open_login').click(function() {
		$('#login_panel').slideToggle();
		return false;
	});
	
	// controllo campi numero verde / password al click sul bottone di accesso area riservata
	$('#btnLogin').click(function() {
		if( $('#user_login').val() == userDefault) {
			$('#user_login').css('border','1px solid red');
			return false;
		}
		if( $('#pwd_login').val() == pwdDefault) {
			$('#pwd_login').css('border','1px solid red');
			return false;
		}
	});*/
	
	/* RECUPERO DATI DI ACCESSO */
	$('#recupera_pwd').click(function() {
		// apertura popup recupero dati di accesso
		$( ".popup_recupero_pwd" ).dialog({
			show: 'fade', 
			hide: 'fade',
			position: 'center',
			draggable: false,
			resizable: false,
			closeOnEscape: true,
			modal: true,
			width: 500,
			click: function() { $(this).dialog("close"); }
		});
		// Bug fixing: rimuovo focus di default su primo input popup
		$('.popup input').blur();
	});
	
	// click su bottone recupero dati di accesso
	$('#btnRecupero').click(function() {
		var emailRecupero = $('#email_recupero').val();
		// email regular expression
		var rege = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		var rege_numero = /[^0-9]/g;
		
		function validateEmailRecupero(){
			if( (emailRecupero == emailRecuperoDefault) || (emailRecupero == "") || (!rege.test(emailRecupero)) ) {
				$("#email_recupero").css("border", "1px solid red");
				//$("#email").addClass("form_error");
				return false;
			}
			else{
				//$("#email").removeClass("form_error");
				return true;
			}
		};
		
		// valido campi di richiesta recupero dati di accesso
		if(validateEmailRecupero()) {	
			$('.popup_recupero_pwd').find('.load_img').addClass('loading_image').fadeIn();
			$.ajax({
			  type: 'POST',
			  url: 'recupera_test.php',
			  data: { numero: $('#numero_recupero').val(), email: emailRecupero },
			  success: ( function(results) { 
				$('.popup_recupero_pwd').find('.load_img').fadeOut(function() {
					// se i dati inseriti sono corretti
					if(results == 'ok') {
						// spariscono campi form recupero dati, compare messaggio di conferma
						$('.popup_recupero_pwd').children('div').not('.ok_message').slideUp(500, function() {
							var email_invio = $('#email_recupero').val()
							$('.popup_recupero_pwd')
							.children('.popup_result_message')
							.css('color','green')
							.html(" I tuoi dati di accesso sono stati inviati correttamente all'indirizzo <strong>"+email_invio+"</strong>").show();
						});
						setTimeout('$(".popup").dialog("close")',8000); 
					}
					// se i dati inseriti non sono corretti
					else {
						// mostro messaggio di errore
						$('.popup_recupero_pwd')
						.children('.popup_result_message')
						.css('color','red')
						.html("Numero verde o e-mail errati.").show();
					}
				});
			  }),
			  error: ( function(results) { alert("Si è verificato un errore. Riprova."); })
			});
			return false;
		}
		else
			return false;
	});
});
