<!--

	var valuta="Euro ";
var valuta2="L ";
var exch= .000516457;
var SecVal= 0;
var sepmigl=".";
var sepdec=",";
var PutDec= 1;
var PutDec2= 0;
var scimp = new Array( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
var scperc = new Array( 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);

	
	nc = "eDenter_basket";
	document.writeln("<script src=\"dynamic.php\"></script>");
			
	function MettiPunti(prezzo) {
		var newprice='';
		var oldprice=prezzo+'s';
		var lung=oldprice.length-1;
		oldprice=oldprice.substring(0,lung);
		while (lung>3) {
			newprice=sepmigl+oldprice.substring(lung-3,lung)+newprice;
			oldprice=oldprice.substring(0,lung-3);
			lung=oldprice.length;  
		}
		newprice=oldprice+newprice;
		return (newprice);
	}
	
	function alterError(value) {
		if (PutDec !=0) {
			if (value<=0.99) {
				newPounds = '0';
			} else {
				newPounds = parseInt(value);
			}
			newPence = Math.round((value - newPounds)* 100);
			if (newPence == 100) {newPence =0; newPounds ++;}
			if (eval(newPence) <= 9) newPence='0'+newPence;
			newString = MettiPunti(newPounds);
			if (eval(newPence) != 0) {
				newString= newString + sepdec + newPence;
			}
			else {
				newString= newString + sepdec + '00';
			}
		}
		else {
			newPounds = Math.round(value);
			newString = MettiPunti(newPounds);
		}
		return (newString);
	}

function MostraCarrello(l) {
                var sfondocarrello = 'tr_uno';
		var dImg = new Array("","");
		dImg[0] = '<img src="edis_disp0.gif" alt="non disponibile">';
		dImg[1] = '<img src="edis_disp1.gif" alt="disponibile">';
		nc = "eDenter_basket" + l;
                index = document.cookie.indexOf(nc);
		countbegin = (document.cookie.indexOf("=", index) + 1);
        	countend = document.cookie.indexOf(";", index);
        	if (countend == -1) {
            		countend = document.cookie.length;
        	}
		if (index == -1) {
			countbegin = 0;
			countend = 0;
		}
		fulllist = document.cookie.substring(countbegin, countend);
		fulllist = basket;
		index = document.cookie.indexOf("eDenter_disp");
		countbegin = (document.cookie.indexOf("=", index) + 1);
        	countend = document.cookie.indexOf(";", index);
        	if (countend == -1) {
            		countend = document.cookie.length;
        	}
		if (index == -1) {
			countbegin = 0;
			countend = 0;
		}
		available = document.cookie.substring(countbegin, countend);
		totprice = 0;
		totiva = 0;
		impsconto = 0;
		impscontoiva = 0;
		document.writeln('<form NAME="updateform">');
		document.writeln('<table id="cart">');
		document.writeln('<tr><th>'+"Articolo"+'</th><th>'+"Varianti"+'</th><th align="right">'+"Quantita'"+'</th><th align="right">'+"Prezzo unitario"+'</th><th align="right">'+"Prezzo totale"+'</th><th align="center" colspan="2">' + "Disponibilita'" + '</th></tr>');
		itemlist = 0;
		for (var i = 0; i <= fulllist.length; i++) {
			if (fulllist.substring(i,i+1) == '[') {
				itemstart = i+1;
				thisitem = 1;
				thisavail = available.substring(itemlist, itemlist +1);
				if (thisavail == "") {
					availimg=0;
				} else {
					availimg=parseInt(available.substring(itemlist, itemlist +1));
				}
			} else if (fulllist.substring(i,i+1) == ']') {
				itemend = i;
				thequantity = unescape(fulllist.substring(itemstart, itemend));
				if (thequantity * 1 >= scq2 && scq2 > -1) {
					theprice = theprice * imp2;
					ivaitem = ivaitem * imp2;
				} else if (thequantity * 1 >= scq1 && scq1 > -1) {
					theprice = theprice * imp1;
					ivaitem = ivaitem * imp1;
				}
				itemtotal = 0;
				itemtotal = (eval(theprice*thequantity));
				itemtotaliva = 0;
				itemtotaliva = (eval(ivaitem*thequantity));
				temptotal = itemtotal * 100;
				totprice = totprice + itemtotal;
				totiva = totiva + itemtotaliva;
				itemlist=itemlist+1;
document.write('<tr id="cart_prodotti" valign="top" class="'+sfondocarrello+'"><td><a href="' + artlink + '">(' + thecode + ') ' +theitem+'</a></td>');
				option1234 = '';
				if (option1 != '') {
					option1234 = option1;
				}
				if (option2 != '') {
					if (option1234 != '') {
						option1234 = option1234 + '<br />';
					}
					option1234=option1234 + option2;
				}
				if (option3 != '') {
					if (option1234 != '') {
						option1234 = option1234 + '<br />';
					}
					option1234=option1234 + option3;
				}
				if (option4 != '') {
					if (option1234 != '') {
						option1234 = option1234 + '<br />';
					}
					option1234=option1234 + option4;
				}
				document.write('<td>'+option1234 +'</td>');
document.write('<td valign="top" align="right"><INPUT TYPE=TEXT NAME="quant'+itemlist+'" VALUE="'+thequantity+'" SIZE=3></td><td valign="top" align="right">'+alterError(eval(theprice))+'</td><td valign="top" align="right">'+alterError(itemtotal)+'</td><td align="center" valign="top">' + dImg[availimg] + '</td><td><div class="elimina_cart"><a href="javascript:EliminaArt('+itemlist+')" onMouseOver="window.status=\'\'; return true">'+"Elimina"+'</a><br /><a href="javascript:ModificaArt('+itemlist+',document.updateform.quant'+itemlist+'.value)" onMouseOver="window.status=\'\'; return true">'+"Aggiorna"+'</a></div></td></tr>');
                                if (sfondocarrello == 'tr_uno') {
                                  sfondocarrello = 'tr_due';
                                } else {
                                  sfondocarrello = 'tr_uno';
                                }



			} else if (fulllist.substring(i,i+1) == '|') {
				if (thisitem==1) theitem = unescape(fulllist.substring(itemstart, i));
				if (thisitem==2) thecode = unescape(fulllist.substring(itemstart, i));
				if (thisitem==3) artid = unescape(fulllist.substring(itemstart, i));
				if (thisitem==4) option1 = unescape(fulllist.substring(itemstart, i));
				if (thisitem==5) option2 = unescape(fulllist.substring(itemstart, i));
				if (thisitem==6) option3 = unescape(fulllist.substring(itemstart, i));
				if (thisitem==7) option4 = unescape(fulllist.substring(itemstart, i));
				if (thisitem==8) pesoitem = unescape(fulllist.substring(itemstart, i));
				if (thisitem==9) theprice = unescape(fulllist.substring(itemstart, i));
				if (thisitem==10) ivaitem = unescape(fulllist.substring(itemstart, i));
				if (thisitem==11) codeitem= unescape(fulllist.substring(itemstart, i));
				if (thisitem==12) scq1 = unescape(fulllist.substring(itemstart, i));
				if (thisitem==13) imp1 = unescape(fulllist.substring(itemstart, i));
				if (thisitem==14) scq2 = unescape(fulllist.substring(itemstart, i));
				if (thisitem==15) imp2 = unescape(fulllist.substring(itemstart, i));
				if (thisitem==16) artlink = unescape(fulllist.substring(itemstart, i));
				if (thisitem==17) alq = unescape(fulllist.substring(itemstart, i));
				if (thisitem==18) acqid = unescape(fulllist.substring(itemstart +1, i -1));
				thisitem++;
				itemstart=i+1;
			}
		}

		if (itemlist==0) {
			document.writeln('<tr id="cart_vuoto"><td colspan="7">'+"(Il tuo carrello attualmente è vuoto)"+'</td></tr>');
		}

document.writeln('<tr><td colspan=4 class="txt_totali"><b>'+"Totale ordine"+'</b></td><td nowrap class="txt_totali"><b>'+valuta+alterError(totprice)+'</b></td><td  colspan="2">&nbsp;</td></tr>');

		scp = 1;
		if (scl > 0) {
			scp = 1 - scl;
			scp = Math.round(scp * 100) / 100;
		} else if (totprice * 1 > scimp[l] && scperc[l] * 1 < 1) {
			scp = scperc[l];
		}
		if (scp < 1) {
			newtotprice = totprice * scp;
			impsconto = totprice - newtotprice;
			totprice = newtotprice;
			newtotiva = totiva * scp;
			impscontoiva = totiva - newtotiva;
			totiva = newtotiva;
			
document.writeln('<tr><td colspan=4 class="txt_totali">'+"Sconto"+'</td><td align=right nowrap class="txt_totali">'+ '-' +alterError(impsconto)+'</td><td colspan="2">&nbsp;</td></tr>');
document.writeln('<tr><td colspan=4 class="txt_totali"><b>'+"Totale scontato"+'</b></td><td align=right nowrap class="txt_totali"><b>'+valuta+alterError(totprice)+'</b></td><td colspan="2">&nbsp;</td></tr>');

		}

if (0 == 0) {
			document.writeln('<tr><td colspan=4 class="txt_totali"><b>'+"IVA"+'</b></td><td align=right nowrap class="txt_totali"><b>'+valuta+alterError(totiva)+'</b></td><td colspan="2">&nbsp;</td></tr>');
		}
		document.writeln('</table><cr>');
		document.writeln('</FORM>');
	}
		
	function ModificaArt(itemno, newquant) {
		if (isNaN(newquant)) {
			newquant=0;
		}
		newquant=Math.floor(newquant);
		if (newquant <= 0) {
			rc = alert("Inserire una quantita' corretta!");
		} else {
			self.location = "dynamic.php?action=edit&url=" + "cart.php&itemno=" + itemno + "&newquant=" + newquant;
		}

	}

	function EliminaArt(itemno) {
		newItemList = null;
		itemlist = 0;
		for (var i = 0; i <= fulllist.length; i++) {
			if (fulllist.substring(i,i+1) == '[') {
				itemstart = i+1;
			} else if (fulllist.substring(i,i+1) == ']') {
				itemend = i;
				theitem = fulllist.substring(itemstart, itemend);
				itemlist=itemlist+1;
				if (itemlist != itemno) {
					newItemList = newItemList+'['+fulllist.substring(itemstart, itemend)+']';
				}
			}
		}
		self.location = "dynamic.php?action=delete&url=" + "cart.php&itemno=" + itemno;
	}

	function SvuotaCarrello() {
		if (confirm("Vuoi veramente rimuovere tutti gli articoli dal carrello?")) {
			self.location = "dynamic.php?action=empty&url=" + "cart.php";
		}
	}
//-->
