
	function CheckStatoNegozio() {

		if (!StatoNegozio) {
			alert('In questo momento il negozio č temporaneamente chiuso.');
			return(false);
		}
		else
			return(true);
	}
	function GoHome() {

	 location.href = './'
	}
	function Categoria(id, urlDescrizione) {

	 var f = document.run;

		f.sezione.value = 'categoria';
		f.idCategoria.value = id;
		f.action += '?categoria=' + id;
		if (arguments.length == 2)
			f.action += '#' + urlDescrizione;
		else if (id == -1)
			f.action += '#Tutte-le-Offerte';
		else if (id == -2)
			f.action += '#Tutte-le-Novitā';

		f.stringa.value = '';
		f.submit();
	}
	function Articolo(idCategoria, idProdotto, urlDescrizione) {

	 var f = document.run;

		f.sezione.value = 'articolo';
		f.idCategoria.value = idCategoria;
		f.idProdotto.value = idProdotto;
		f.action += '?categoria=' + idCategoria + '&articolo=' + idProdotto;

		if (arguments.length == 3)
			f.action += '#' + urlDescrizione;

		f.submit();
	}
	function Cerca(stringa) {

	 var s = document.search;
	 var stringa = new String();

	 	stringa = s.searchstring.value;

		if (stringa.length < 3 ) {

			alert('Il testo da ricercare deve esser lungo almeno 3 caratteri.')
		}
		else {

			var f = document.run;

			f.sezione.value = 'cerca';
			f.stringa.value = stringa;
			f.submit();
		}
		return (false);
	}
	function ArticoloNelCarrello(id, disponibili, minimoOrdinabile, indice) {


		if (!CheckStatoNegozio()) return;

		if (disponibili == 0)	{

			alert('Il prodotto non č attualmente disponibile');
		}
		else {

			var eraVuoto = (carrello.numeroProdotti == 0) ? 1: 0;

			if (carrello.Aggiungi(id)) {

				if (arguments.length > 2) {

					var quantita = (minimoOrdinabile > 0) ? minimoOrdinabile: 1;
					if (quantita > disponibili)  quantita = disponibili;

					eval("document.getElementById('disponibilitaProdotto_" + indice + "').innerHTML = '" + (disponibili - quantita) + "';");
				}
				run_external.location.href="./php/extruns.php?azione=aggiungialcarrello&idprodotto=" + id + "&eraVuoto=" + eraVuoto + "&sezione=" + sezione;
			}
			else
				alert('Articolo giā nel carrello !');
		}
	}
	function EliminaDalCarrello(riga, id) {

		if (!CheckStatoNegozio()) return;

		if (!confirm('Confermi l\' eliminazione di questo prodotto dalla lista ?'))
			return;

		eval("document.carrello.quantita_" + riga + ".value=0;");
		document.getElementById('rigaCarrello_' + riga).style.display = 'none';
		document.getElementById('riga_' + riga).style.display = 'none';

	}
	function RicalcolaCarrello() {

		if (!CheckStatoNegozio()) return;

	  var dataString = '';
	  var f = document.carrello
	  var quantita;

		for (var i = selected = 0; i < carrello.numeroProdotti; i++) {

			eval("quantita = f.quantita_" + i + ".value;");
			if (quantita > 0) {
				if (selected > 0) dataString += ',';
				dataString += carrello.IDProdotto[i] + ',' + quantita
				selected++;
			}
		}
		run_external.location.href="./php/extruns.php?azione=ricalcolacarrello&datastring=" + dataString;
	}
	function Carrello() {

		if (!CheckStatoNegozio()) return;

		if (carrello.numeroProdotti == 0) {

				alert('Il carrello č vuoto !');
				return;
		}
		var f = document.run;
		f.sezione.value = 'carrello';
		f.action += '?carrello=1';
		f.submit();

	 /*
	 var f = document.run;

		f.sezione.value = 'carrello';
		f.submit();
	 */
	}
	function PulsantiCarrello() {

	 var p1 = document.getElementById('pulsantiCarrello1');

		if (p1.style.display == 'none') {

	 		var p2 = document.getElementById('pulsantiCarrello2');
	 		var n1 = document.getElementById('notaCarrello1');
	 		var n2 = document.getElementById('notaCarrello2');

			p1.style.display = n1.style.display = p2.style.display = n2.style.display = '';
		}

	}
	function Acquisto() {

		if (!CheckStatoNegozio()) return;

	 var f = document.run;

		f.sezione.value = 'acquisto';
		f.submit();
	}
	function ConfermaAcquisto() {

		if (!CheckStatoNegozio()) return;

	 var f = document.moduloAcquisto;
	 var messaggioErrore = '';

		if (f.cognome.value == '') 			messaggioErrore += 'Cognome o Nome Azienda\n';
		if (f.indirizzo.value == '') 			messaggioErrore += 'Indirizzo\n';
		if (f.cap.value == '') 					messaggioErrore += 'CAP\n';
		if (f.citta.value == '') 				messaggioErrore += 'Cittā\n';
		if (f.provincia.value == '') 			messaggioErrore += 'Provincia\n';
		if (f.stato.value == '') 				messaggioErrore += 'Stato\n';
		if (f.telefono.value == '') 			messaggioErrore += 'Telefono\n';
		if (f.email.value == '') 				messaggioErrore += 'e-Mail\n';
		if (f.metodopagamento.value == '') 	messaggioErrore += 'Metodo di Pagamento\n';

		if (messaggioErrore != '')
			alert('Dati mancanti:\n\n' + messaggioErrore)
		else if (confirm('Confermi l\' acquisto ?')) {
			f.action = './php/registra.php';
			f.target = 'run_external';
			f.submit();
		}
	}
	function InviaEmail(codiceOrdine)	{

	 var f = document.moduloAcquisto;

			f.codiceOrdine.value = codiceOrdine;
			f.action = './lasso/sendmail.lasso';
			//f.action = './lasso/sendmail.php';

			f.target = 'run_external';
			f.submit();
	}
	function RegistrazioneEffettuata()	{

			alert('L\' ordine č stato inviato.*');

			location.href = "http://www.presepi.com";
			/*
	 		var r = document.run;
	 		r.sezione.value = 'home';
			r.target = "_self";
	 		r.submit();
			*/

	}
	function ZoomProdotto(idProdotto, idCategoria) {

		  var look = 'width=100,height=100,status=no,scrollbars=no,menubar=no,toolbar=no';
			zoom = window.open('./php/zoom.php?idProdotto=' + idProdotto + '&idCategoria=' + idCategoria, 'zoom', look);
			zoom.focus();
	}
	function ZoomManuale(nomefile) {

		  var look = 'width=600,height=600,status=no,scrollbars=no,menubar=no,toolbar=no, resizable=yes';
			zoom = window.open(nomefile, 'zoom', look);
			zoom.focus();
	}
	function ZoomVideo(nomefile) {

		  var look = 'width=690,height=500,status=no,scrollbars=no,menubar=no,toolbar=no, resizable=yes';
			zoom = window.open('./video.php?flvfile=' + nomefile, 'zoom', look);
			zoom.focus();
	}
	
	

	function InviaIscrizioneNews()	{

	 var f = document.iscrizioneNews;

			f.action = './lasso/sendmailnews.lasso';
			f.target = 'run_external';
			f.submit();

	}
	function IscrizioneNewsEffettuata()	{

			alert('Richiesta inviata');
	 		var r = document.run;
	 		r.sezione.value = 'home';
	 		r.submit();
	}
		function Presepi() {

	 var f = document.run;

		f.sezione.value = 'presepi';
		f.submit();
	}

	function Condizioni() {

	 var f = document.run;

		f.sezione.value = 'condizioni';
		f.submit();
	}
	function IscrizioneNews() {

	 var f = document.run;

		f.sezione.value = 'iscrizioneNews';
		f.submit();
	}
	function Links() {

	 var f = document.run;

		f.sezione.value = 'links';
		f.submit();
	}
	function Segnalazione() {

	 var f = document.run;

		f.sezione.value = 'segnalazione';
		f.submit();
	}
	function Infos(index) {

	 var f = document.run;

		f.sezione.value = 'info_' + index;
		f.submit();
	}


 var now = new Date();
 var days = new Array('Domenica','Lunedi','Martedi','Mercoledi','Giovedi','Venerdi','Sabato');
 var months = new Array('Gennaio','Febbraio','Marzo','Aprile','Maggio','Giugno','Luglio','Agosto','Settembre','Ottobre','Novembre','Dicembre');
 var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();

	function fourdigits(number) {
		return (number < 1000) ? number + 1900 : number;
	}

	today =  days[now.getDay()] + " " + date + " " + months[now.getMonth()] + " " + (fourdigits(now.getYear())) ;

	function ContenutoCarrello() {

		var carrelloImmagine = (sezione == 'home') ? '': '<img src="./images/carrello.gif" border="0" />';

		if (sezione == 'acquisto')
			var testo = (carrello.numeroProdotti == 0) ? 'Nessun prodotto nel carrello': '<a href="javascript:Carrello();">' + carrelloImmagine + 'Prodotti nel carrello: ' + carrello.numeroProdotti + '</a>&nbsp;';
		else
			var testo = (carrello.numeroProdotti == 0) ? 'Nessun prodotto nel carrello': '<a href="javascript:Carrello();">' + carrelloImmagine + 'Prodotti nel carrello: ' + carrello.numeroProdotti + '</a>&nbsp;<br><a href="javascript:Acquisto();">Conferma l\' acquisto !</a>&nbsp;';

		document.getElementById('contenutoCarrello').innerHTML = ((sezione == 'home') ? today: '') + '<br><span style="color: #919100;">' + testo + '</span>';
	}


