// <![CDATA[
	function IsNumber(str) {
		str = str.toLowerCase();
		RefString = '0123456789';
		
		if (str.length < 1) { return(false); };
		
		for (var i=0; i<str.length; i++)  {
			var ch = str.substr(i, 1);
			var a = RefString.indexOf(ch, 0);
			if (a == -1) { return(false); };
		};
		return(true);
	};
	
	var weburl = '/';
	
	$(document).ready( function() {
		$('a.blank').attr('target', '_blank');
		$('a[rel=facebox]').facebox({ loadingImage: 'images/facebox/loading.gif', closeImage: 'images/facebox/closelabel.gif' });
		
		var so;
		weburl = $('div#hidden_weburl').text();
		
		/* DISABILITATO */
		if ($('div#header_').length > 0) {
			so = new SWFObject(weburl + 'images/header' + ($('#header').hasClass('int') ? '-int' : '') + '.swf', '', '900', '100', '8', '');
			so.addParam('menu', 'false');
			so.addParam('quality', 'high');
			so.addParam('wmode', 'transparent');
			so.write('header');
		};
		
		if ($('#header').hasClass('int')) {
			$('div#header a:first').css('background-position', '0px 0px');
		} else {
			$('div#header a:first').animate( { backgroundPosition: '0px 0px' }, { queue: false, duration: 1000 } );
		};
		
		if ($('div#navigation_banner').length > 0) {
			slideShow(2000);
			
			so = new SWFObject(weburl + 'images/banner.swf', '', '596', '156', '8', '');
			so.addParam('menu', 'false');
			so.addParam('quality', 'high');
			so.addParam('wmode', 'transparent');
		//	so.write('navigation_banner');
		};
		
		/* DISABILITATO */
		if ($('div#navigation_ticker_').length > 0) {
			so = new SWFObject(weburl + 'images/ticker.swf', '', '293', '156', '8', '');
			so.addParam('menu', 'false');
			so.addParam('quality', 'high');
			so.addParam('wmode', 'transparent');
			so.write('navigation_ticker');
		};
		
		$('select#id_tipo_cliente').bind('change', function() {
			if ($('select#id_tipo_cliente option:selected').val() == '1' || $('select#id_tipo_cliente option:selected').val() == '3') {
				$('div.id_tipo_cliente_1').slideDown();
				$('div.id_tipo_cliente_1 input').removeAttr('disabled');
				$('div.id_tipo_cliente_2').slideUp();
				$('div.id_tipo_cliente_2 input').attr('disabled', 'disabled');
			} else {
				$('div.id_tipo_cliente_1').slideUp();
				$('div.id_tipo_cliente_1 input').attr('disabled', 'disabled');
				$('div.id_tipo_cliente_2').slideDown();
				$('div.id_tipo_cliente_2 input').removeAttr('disabled');
			};
		}).change();
		
		$('input#privacy').bind('click', function() {
			if ($(this).attr('checked')) {
				$('button#btnprocedi').attr('disabled', '').removeClass('disabled');
			} else {
				$('button#btnprocedi').attr('disabled', 'disabled').addClass('disabled');
			};
		}).attr('checked', '');
		
		if ($('form#frmRegistrazione input#privacy').length > 0 && $('form#frmRegistrazione input#accetto').length > 0) {
			$('input#privacy').unbind().bind('click', function() {
				if ($('form#frmRegistrazione input#privacy').attr('checked') && $('form#frmRegistrazione input#accetto').attr('checked')) {
					$('button#btnapprova').attr('disabled', '').removeClass('disabled');
				} else {
					$('button#btnapprova').attr('disabled', 'disabled').addClass('disabled');
				};
			}).attr('checked', '');
			
			$('input#accetto').unbind().bind('click', function() {
				if ($('form#frmRegistrazione input#privacy').attr('checked') && $('form#frmRegistrazione input#accetto').attr('checked')) {
					$('button#btnapprova').attr('disabled', '').removeClass('disabled');
				} else {
					$('button#btnapprova').attr('disabled', 'disabled').addClass('disabled');
				};
			}).attr('checked', '');
		};
		
		$('button#btnstampa').bind('click', function() {
			window.print();
		});
		
		$('button#btnannulla').bind('click', function() {
			window.location.href = 'prodotto.asp?id=' + $('input#ID_Prodotto').val();
		});
		
		if ($('ul#fcbklist').length > 0) {
			$.fcbkListSelection('ul#fcbklist', '560', '50', '3');
		};
		
		if ($('.text-data').length > 0) {
			$('.text-data').datePicker( { clickInput: true } );
			$('#inizio_riprese').bind('dpClosed', function(e, selectedDates) { var d = selectedDates[0]; if (d) { d = new Date(d); $('#fine_riprese').dpSetStartDate(d.addDays(1).asString()); }; });
			$('#fine_riprese').bind('dpClosed', function(e, selectedDates) { var d = selectedDates[0]; if (d) { d = new Date(d); $('#inizio_riprese').dpSetEndDate(d.addDays(-1).asString()); }; });
		};
		
		News_Init();
		
		GoogleAnalytics();
	} );
	
	function view_ProdList() {
		$('#box-add_Prod_temp').html( $('#box-add_Prod').html() );
		
		$('#box-add_Prod_temp select').attr('id', 'Prodotti');
		$('#box-add_Prod_temp button').attr('id', 'Aggiungi');
		
		$('#Prodotti option').each(function (i) {
			if ($('#box-prod-' + this.value).length > 0) {
				$(this).attr('disabled', 'disabled');
			};
		});
		
		$('#Prodotti').msDropDown();
		$('#Aggiungi').bind('click', function() { add_Prod(); });
	};
	
	function view_AccList(acc) {
		var id = acc.replace('btn-add_Acc-', '');
		var box = '#box-add_Acc_temp-' + id;
		
		$(box).html( $('#box-add_Acc').html() );
		
		$.post(weburl + 'ajax_accessori.asp', { ID_Prodotto: id }, function(data) {
			switch(data) {
				case '##errore##'				: { window.alert('Errore interno'); break; };
				case '##errore-login##'			: { window.location.href=weburl+'login.asp?err=true'; break; };
				case '##nessun-prodotto##'		: { window.alert('Errore interno: necessario indicare il prodotto.'); break; };
				case '##nessun-accessorio##'	: { $(box).html('<em>Nessun accessorio disponibile per questo prodotto..</em>'); break; };
				default: {
					$(box + ' select').attr('id', 'Accessori-' + id);
					$(box + ' button').attr('id', 'acc_Aggiungi-' + id);
					
					$('#Accessori-' + id).html( data ).msDropDown({ dd: 'dd_accessori' });
					$('#acc_Aggiungi-' + id).bind('click', function() { add_Acc(id); });
				};
			};
		});
	};
	
	function add_Prod() {
		var id = $('#Prodotti :selected').val();
		
		if ($('#box-prod-' + id).length == 0) {
			var txt = $('#Prodotti :selected').text();
				txt = txt.split(' // ');
			var img = '<img src="' + ($('#Prodotti :selected').attr('title') != '' ? $('#Prodotti :selected').attr('title') : 'public/nopic_100x80.png') + '" width="100" height="80" alt="' + txt[0] + '" class="alignLeft border" />';
			var html = '<div id="box-prod-' + id + '" style="display: none;"><div>' + img + '<h3><a href="javascript:void(0);" title="Elimina prodotto" class="alignRight" onclick=" if (window.confirm(\'Eliminare questo prodotto dal preventivo?\')) { $(\'#box-prod-' + id + '\').fadeOut(\'slow\', function() { $(\'#box-prod-' + id + '\').remove(); }); };"><img src="' + weburl + 'images/no.png" width="16" height="16" alt="X" title="Elimina prodotto" /></a>' + txt[0] + '</h3>' + txt[1] + '<input type="hidden" id="prod-' + id + '" name="ID_Prodotto" value="' + id + '" /><div class="clear"></div></div><br /><div id="box-add_Acc_temp-' + id + '"><a href="javascript:void(0);" title="Aggiungi un accessorio" id="btn-add_Acc-' + id + '" class="btn_add_Acc"><em>&raquo; Aggiungi un accessorio</em></a></div><br /><ul class="accessori"></ul><br /></div>';
			
			$('#box-add_Prod_temp').before( html );
			$('#box-prod-' + id).fadeIn();
			$('#box-add_Prod_temp').html( '<a href="javascript:void(0);" title="Aggiungi un prodotto" id="btn-add_Prod"><em>&raquo; Aggiungi un prodotto</em></a>' );
			
			$('#btn-add_Prod').bind('click', function() { view_ProdList(); });
			$('#btn-add_Acc-' + id).bind('click', function() { view_AccList( id ); });
		} else {
			window.alert('Prodotto gia\' selezionato..');
		};
	};
	
	function add_Acc(prod) {
		var id = $('#Accessori-' + prod + ' :selected').val();
		
		if ($('#row-acc-' + id + '-prod-' + prod).length == 0) {
			var txt = $('#Accessori-' + prod + ' :selected').text();
				txt = txt.split(' // ');
			var img = '<img src="' + ($('#Accessori-' + prod + ' :selected').attr('title') != '' ? $('#Accessori-' + prod + ' :selected').attr('title') : 'public/nopic_100x80.png') + '" width="80" height="60" alt="' + txt[0] + '" class="alignLeft border" />';
			var html = '<li id="row-acc-' + id + '-prod-' + prod + '">' + img + '<h4><a href="javascript:void(0);" title="Elimina accessorio" class="alignRight" onclick=" if (window.confirm(\'Eliminare questo accessorio dal preventivo?\')) { $(\'#row-acc-' + id + '-prod-' + prod + '\').fadeOut(\'slow\', function() { $(\'#row-acc-' + id + '-prod-' + prod + '\').remove(); }); };"><img src="' + weburl + 'images/no.png" width="16" height="16" alt="X" title="Elimina accessorio" /></a>' + txt[0] + '</h4>' + txt[1] + '<input type="hidden" id="acc-' + id + '-prod-' + prod + '" name="ID_Accessorio-' + prod + '" value="' + id + '" /><div class="clear"></div></li>'
			
			$('#box-prod-' + prod + ' ul').append( html );
		} else {
			window.alert('Accessorio gia\' selezionato..');
		};
	};
	
	
	function GoogleAnalytics() {
		var _gaq = _gaq || [];
			_gaq.push(['_setAccount', 'UA-12664440-4']);
			_gaq.push(['_trackPageview']);
		
		(function() {
			var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
				ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
			var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
		})();
	};
	
	
	/* BANNER FLASH */
		function slideShow(speed) {
			$('ul.slideshow').append('<li id="slideshow-caption" class="caption"><div class="slideshow-caption-container"><h3></h3><p></p></div></li>');
			$('ul.slideshow li').css({opacity: 0.0});
			$('ul.slideshow li:first').css({opacity: 1.0});
			$('#slideshow-caption h3').html($('ul.slideshow a:first').find('img').attr('title'));
			$('#slideshow-caption').css({opacity: 0.7, bottom: 0});
			
			var timer = setInterval('gallery()', speed);
			
			$('ul.slideshow').hover(
				function () {
					clearInterval(timer);
				}, 
				function () {
					timer = setInterval('gallery()', speed); 
				}
			);
		};
		
		function gallery() {
			var current = ($('ul.slideshow li.show') ? $('ul.slideshow li.show') : $('#ul.slideshow li:first'));
			var next = ((current.next().length) ? ((current.next().attr('id') == 'slideshow-caption') ? $('ul.slideshow li:first') : current.next()) : $('ul.slideshow li:first'));
			var title = next.find('img').attr('title');
			var desc = next.find('img').attr('alt');
			
			next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 1000);
			
			$('#slideshow-caption').slideToggle(300, function () {
				$('#slideshow-caption h3').html(title);
				$('#slideshow-caption').slideToggle(500);
			});
			
			current.animate({opacity: 0.0}, 1000).removeClass('show');
		};
	
	
	/* NEWS */
		function News_Init() {
			if ($.browser.msie == true) {
				News_IE();
			} else {
				News();
			};
		};
		
		function News() {
			var ticker = $('#ticker');
			
			ticker.children().filter('dt').each(function() {
				var dt = $(this), container = $('<div>');
				
				dt.next().appendTo(container);
				
				dt.prependTo(container);
				
				container.appendTo(ticker);
			});
			
			ticker.css('overflow', 'hidden');
			
			function animator(currentItem) {
				var distance = currentItem.height() + 0;
				
				duration = (distance + parseInt(currentItem.css('margin-top'))) / 0.025;
				
				currentItem.animate({ marginTop: -distance }, duration, 'linear', function() {
					currentItem.appendTo(currentItem.parent()).css('margin-top', 0);
					animator(currentItem.parent().children(':first'));
				});
			};
			
			animator(ticker.children(':first'));
			
			ticker.mouseenter(function() { ticker.children().stop(); });
			
			ticker.mouseleave(function() { animator(ticker.children(':first')); });
		};
		
		function News_IE() {
			initializemarquee();
		};
	
		/*****************************************************************
		* Cross browser Marquee II- © Dynamic Drive (www.dynamicdrive.com)
		* This notice MUST stay intact for legal use
		* Visit http://www.dynamicdrive.com/ for this script and 100s more.
			*****************************************************************/
			var delayb4scroll	= 500;
			var marqueespeed	= 1;
			var pauseit			= 1;
			var copyspeed		= marqueespeed
			var pausespeed		= (pauseit == 0) ? copyspeed : 0;
			var actualheight	= '';
			
			function scrollmarquee() {
				if (parseInt(cross_marquee.style.top) > (actualheight * (-1) + 8)) {
					cross_marquee.style.top = parseInt(cross_marquee.style.top) - copyspeed + 'px';
				} else {
					cross_marquee.style.top = parseInt(marqueeheight) + 8 + 'px';
				};
			};
			
			function initializemarquee() {
				if (document.getElementById('vmarquee')) {
					cross_marquee = document.getElementById('vmarquee');
					
					cross_marquee.style.top = 0;
					
					marqueeheight = document.getElementById('marqueecontainer').offsetHeight;
					
					actualheight = cross_marquee.offsetHeight;
					
					if (window.opera || navigator.userAgent.indexOf('Netscape/7') != -1) {
						cross_marquee.style.height = marqueeheight + 'px';
						cross_marquee.style.overflow = 'scroll';
						return;
					};
					
					setTimeout('lefttime=setInterval("scrollmarquee()",30)', delayb4scroll);
				};
			};
// ]]>
