// v 2.1.4
// Codice sconto v. 20091007a

	var valuta="Euro ";
var valuta2="L ";
var exch= .000516457;
var SecVal= 0;
var sepmigl=".";
var sepdec=",";
var PutDec= 1;
var PutDec2= 0;

			
	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() {
        var sfondocarrello = '#E5F5EA';
		fulllist = "";
        index = document.cookie.indexOf("eDbasket");
		if (index > -1) {
			countbegin = (document.cookie.indexOf("=", index) + 1);
	        	countend = document.cookie.indexOf(";", index);
	        	if (countend == -1) {
	            		countend = document.cookie.length;
	        	}
			fulllist = document.cookie.substring(countbegin, countend);
		}
		totprice = 0;
		totiva = 0;
		document.writeln('<FORM NAME="updateform">');
		document.writeln('<div align="left">');
		document.writeln('<TABLE WIDTH=100% BORDER=0 CELLPADDING="2">');
		document.writeln('<TR BGCOLOR="#A8DDB9">');
		document.writeln('<TD><b><FONT COLOR="#333333" FACE="Arial,Helvetica" SIZE=-1>'+"Articolo"+'</FONT></b></TD>');
		document.writeln('<TD><b><FONT COLOR="#333333" FACE="Arial,Helvetica" SIZE=-1>'+"Varianti"+'</FONT></b></TD>');
		document.writeln('<TD align="right"><b><FONT COLOR="#333333" FACE="Arial,Helvetica" SIZE=-1>'+"Quantità"+'</FONT></b></TD>');
		document.writeln('<TD align="right"><b><FONT COLOR="#333333" FACE="Arial,Helvetica" SIZE=-1>'+"Prezzo unitario"+'</FONT></b></TD>');
		document.writeln('<td align="right"><b><FONT COLOR="#333333" FACE="Arial,Helvetica" SIZE=-1>'+"Prezzo totale"+'</FONT></b></TD>');
		document.writeln('<td align="right"><b><FONT COLOR="#333333" FACE="Arial,Helvetica" SIZE=-1>'+"Sconto"+'</FONT></b></TD>');
		document.writeln('<TD>&nbsp;</TD>');
		document.writeln('</TR>');
		itemlist = 0;
		for (var i = 0; i <= fulllist.length; i++) {
			if (fulllist.substring(i,i+1) == '[') {
				itemstart = i+1;
				thisitem = 1;
			} else if (fulllist.substring(i,i+1) == ']') {
				itemend = i;
				thequantity = fulllist.substring(itemstart, itemend);
				itemtotal = 0;
				itemtotal = (eval(theprice*thequantity));
				itemtotaliva = 0;
				itemtotaliva = (eval(ivaitem*thequantity));
				
				itemlist=itemlist+1;
				document.write('<tr valign="top"BGCOLOR="'+sfondocarrello+'">');
				document.write('<td><FONT COLOR="#333333" FACE="Arial,Helvetica" SIZE=-1>'+theitem+'</FONT></td>');
				option123 = '';
				if (option1 != '') {
					option123 = '<sup>1</sup>&nbsp;' + option1;
				}
				if (option2 != '') {
					if (option123 != '') {
						option123 = option123 + '<BR>';
					}
					option123=option123 + '<sup>2</sup>&nbsp;' + option2;
				}
				if (option3 != '') {
					if (option123 != '') {
						option123 = option123 + '<BR>';
					}
					option123=option123 + '<sup>3</sup>&nbsp;' + option3;
				}
				document.write('<td><FONT COLOR="#333333" FACE="Arial,Helvetica" SIZE=-1>'+option123+'</FONT></td>');
				document.write('<td valign="top" align="right"><INPUT TYPE=TEXT NAME="quant'+itemlist+'" VALUE="'+thequantity+'" SIZE=3></td>');
				document.write('<td valign="top" align="right"><FONT COLOR="#333333" FACE="Arial,Helvetica" SIZE=-1>'+alterError(eval(theprice))+'</FONT></td>');
				document.write('<td valign="top" align="right"><FONT COLOR="#333333" FACE="Arial,Helvetica" SIZE=-1>'+alterError(itemtotal)+'</FONT></td>');
				if (parseInt(dscitem) == 0) {
					dsc = 0;
					dsciva = 0;
					document.write('<td valign="top" align="right"><FONT COLOR="#333333" FACE="Arial,Helvetica" SIZE=-1>&nbsp;</FONT></td>');
				}
				else {
					dsc = parseFloat(theprice*thequantity) * parseInt(dscitem)/100;
					dsciva = parseFloat(ivaitem*thequantity) * parseInt(dscitem)/100;
					document.write('<td valign="top" align="right"><FONT COLOR="#333333" FACE="Arial,Helvetica" SIZE=-1>-'+alterError(dsc)+'</FONT></td>');
				}
				document.write('<td align="center" valign="top"><a href="javascript:EliminaArt('+itemlist+')" onMouseOver="window.status=\'\'; return true"><FONT COLOR="#333333" FACE="Arial,Helvetica" SIZE=-1>'+"Elimina"+'</FONT></a><BR><a href="javascript:ModificaArt('+itemlist+',document.updateform.quant'+itemlist+'.value)" onMouseOver="window.status=\'\'; return true"><FONT COLOR="#333333" FACE="Arial,Helvetica" SIZE=-1>'+"Aggiorna"+'</FONT></a></td>');
				document.write('</tr>');
				
				temptotal = itemtotal * 100;
				totprice = totprice + itemtotal - dsc;
				totiva = totiva + itemtotaliva - dsciva;

                if (sfondocarrello == '#E5F5EA') {
                	sfondocarrello = '#FFFFFF';
                }
				else {
                	sfondocarrello = '#E5F5EA';
                }

			} else if (fulllist.substring(i,i+1) == '|') {
				if (thisitem==1) theitem = fulllist.substring(itemstart, i);
				if (thisitem==2) option1 = fulllist.substring(itemstart, i);
				if (thisitem==3) option2 = fulllist.substring(itemstart, i);
				if (thisitem==4) option3 = fulllist.substring(itemstart, i);
				if (thisitem==5) pesoitem = fulllist.substring(itemstart, i);
				if (thisitem==6) theprice = fulllist.substring(itemstart, i);
				if (thisitem==7) ivaitem = fulllist.substring(itemstart, i);
				if (thisitem==8) dscitem = fulllist.substring(itemstart, i);
				thisitem++;
				itemstart=i+1;
			}
		}

		if (itemlist==0) {
			document.writeln('<TR BGCOLOR="#E5F5EA">');
			document.writeln('<TD colspan="7"><FONT COLOR="#333333" FACE="Arial,Helvetica" SIZE=-1>'+"(Il tuo carrello attualmente è vuoto)"+'</FONT></TD>');
			document.writeln('</TR>');
		}

		document.writeln('<tr BGCOLOR="#A8DDB9">');
		document.writeln('<td colspan="4"><b><FONT COLOR="#333333" FACE="Arial,Helvetica" SIZE=-1>'+"Totale Ordine"+'</FONT></b></td>');
		document.writeln('<td align="right" colspan="2" nowrap><b><FONT COLOR="#333333" FACE="Arial,Helvetica" SIZE=-1>'+valuta+alterError(totprice)+'</FONT></b></td>');
		document.writeln('<td>&nbsp;</td>');
		document.writeln('</tr>');
		if (0 == 0) {
			document.writeln('<tr BGCOLOR="#A8DDB9">');
			document.writeln('<td colspan="4"><b><FONT COLOR="#333333" FACE="Arial,Helvetica" SIZE=-1>'+"IVA"+'</FONT></b></td>');
			document.writeln('<td align="right" colspan="2" nowrap><b><FONT COLOR="#333333" FACE="Arial,Helvetica" SIZE=-1>'+valuta+alterError(totiva)+'</FONT></b></td>');
			document.writeln('<td>&nbsp;</td>');
			document.writeln('</tr>');
		}
		document.writeln('</TABLE><cr>');
		document.writeln('</div>');
		document.writeln('</FORM>');
	}
		
	function ModificaArt(itemno, newquant) {
		if (isNaN(newquant)) {
			newquant=0;
		}
		newquant=Math.floor(newquant);
		if (newquant <= 0) {
			rc = alert("Inserire una quantità corretta!");
		} else {
			newItemList = null;
			itemlist = 0;
			for (var i = 0; i <= fulllist.length; i++) {
				if (fulllist.substring(i,i+1) == '[') {
					thisitem = 1;
					itemstart = i+1;
					fullstart = i+1;
				} else if (fulllist.substring(i,i+1) == ']') {
					itemend = i;
					itemlist=itemlist+1;
					if (itemlist != itemno) {
						newItemList = newItemList+'['+fulllist.substring(fullstart, itemend)+']';
					} else {
						newItemList = newItemList + '['+theitem+'|'+option1+'|'+option2+'|'+option3+'|'+pesoitem+'|'+theprice+'|'+ivaitem+'|'+dscitem+'|'+newquant+']';
					}
				} else if (fulllist.substring(i,i+1) == '|') {
					if (thisitem==1) theitem = fulllist.substring(itemstart, i);
					if (thisitem==2) option1 = fulllist.substring(itemstart, i);
					if (thisitem==3) option2 = fulllist.substring(itemstart, i);
					if (thisitem==4) option3 = fulllist.substring(itemstart, i);
					if (thisitem==5) pesoitem = fulllist.substring(itemstart, i);
					if (thisitem==6) theprice = fulllist.substring(itemstart, i);
					if (thisitem==7) ivaitem = fulllist.substring(itemstart, i);
					if (thisitem==8) dscitem = fulllist.substring(itemstart, i);
					thisitem++;
					itemstart=i+1;
				}
			}
			index = document.cookie.indexOf("eDbasket");
			document.cookie="eDbasket="+newItemList;
			self.location = "cart.htm";
		}

	}

	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)+']';
				}
			}
		}
		index = document.cookie.indexOf("eDbasket");
		document.cookie="eDbasket="+newItemList;
		self.location = "cart.htm";
	}

	function SvuotaCarrello() {
		if (confirm("Vuoi veramente rimuovere tutti gli articoli dal carrello?")) {
			index = document.cookie.indexOf("eDbasket");
			document.cookie="eDbasket=.";
			self.location = "cart.htm";
		}
	}

