// <![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);
	};
	
	$(document).ready( function() {
		$('a.blank').attr('target', '_blank');
		$('a[rel=facebox]').facebox();
		
		var so;
		
		if ($('div#header').length > 0) {
			so = new SWFObject('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 ($('div#navigation_banner').length > 0) {
			so = new SWFObject('images/banner.swf', '', '596', '156', '8', '');
			so.addParam('menu', 'false');
			so.addParam('quality', 'high');
			so.addParam('wmode', 'transparent');
			so.write('navigation_banner');
		};
		
		if ($('div#navigation_ticker').length > 0) {
			so = new SWFObject('images/ticker.swf', '', '293', '156', '8', '');
			so.addParam('menu', 'false');
			so.addParam('quality', 'high');
			so.addParam('wmode', 'transparent');
			so.write('navigation_ticker');
		};
		
		$('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', '');
		
		$('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', '400', '50', '2');
		};
		
		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()); }; });
		};
		
		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('ajax_accessori.asp', { ID_Prodotto: id }, function(data) {
			switch(data) {
				case '##errore##'				: { window.alert('Errore interno'); break; };
				case '##errore-login##'			: { window.location.href='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="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="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);
		})();
	};
// ]]>