
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 ScriviTotale(l,scl) {
		        
		var fulllist = basket;
		totprice = 0;
		totiva = 0;
		
		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 = unescape(fulllist.substring(itemstart, itemend));
				if (thequantity >= scq2 && scq2 > -1) {
					theprice = theprice * imp2;
					ivaitem = ivaitem * imp2;
				} else if (thequantity >= 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;
			} 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;
			}
		}
		scp = 1;
		if (scl > 0) {
			scp = 1 - scl;
			scp = Math.round(scp * 100) / 100;
		} else if (totprice > scimp[l] && scperc[l] < 1) {
			scp = scperc[l];
		}
		if (scp < 1) {
			newtotprice = totprice * scp;
			impsconto = totprice - newtotprice;
			totprice = newtotprice;
			newtotiva = totiva * scp;
			impscontoiva = totiva - newtotiva;
			totiva = newtotiva;
		}
		document.write(valuta+alterError(totprice));
		return parseFloat(totprice);
	}

function ScriviIva(l,scl) {
		
        var fulllist = basket;
		totprice = 0;
		totiva = 0;
		
		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 = unescape(fulllist.substring(itemstart, itemend));
				if (thequantity >= scq2 && scq2 > -1) {
					theprice = theprice * imp2;
					ivaitem = ivaitem * imp2;
				} else if (thequantity >= 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;
			} 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;
			}
		}
		scp = 1;
		if (scl > 0) {
			scp = 1 - scl;
			scp = Math.round(scp * 100) / 100;
		} else if (totprice > scimp[l] && scperc[l] < 1) {
			scp = scperc[l];
		}
		if (scp < 1) {
			newtotprice = totprice * scp;
			impsconto = totprice - newtotprice;
			totprice = newtotprice;
			newtotiva = totiva * scp;
			impscontoiva = totiva - newtotiva;
			totiva = newtotiva;
		}
		document.write(valuta+alterError(totiva));
		return parseFloat(totiva);
	}	

function ScriviQuantita(l,scl) {
		totQuant = 0;
        var fulllist = basket;
		totprice = 0;
		totiva = 0;
		
		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 = unescape(fulllist.substring(itemstart, itemend));
				totQuant = totQuant + thequantity * 1;
				itemlist=itemlist+1;
			} 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;
			}
		}
		
		document.write(totQuant);
		return totQuant;
	}	

/*function ScriviArticoli(l,scl) {
	var fulllist = basket;
	totprice = 0;
	totiva = 0;
	document.writeln('<br><table width="10" border="1" cellspacing="0" cellpadding="0" align="center">');
	document.writeln('<tr><td valign="top"><b>'+"Articolo"+'</b></td><td align="right"><b>' + "Prezzo Unitario"+ '</b></td></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 = unescape(fulllist.substring(itemstart, itemend));
			if (thequantity >= scq2 && scq2 > -1) {
				theprice = theprice * imp2;
				ivaitem = ivaitem * imp2;
			} else if (thequantity >= 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;
			document.write('<tr valign="top"><td><a href="' + artlink + '">' +theitem+'</a><br><br></td>');
			document.write('<td valign="top" align="right">'+alterError(eval(theprice))+'</td></tr>');
			itemlist=itemlist+1;
			if (sfondocarrello == '#FFFFEF') {
				sfondocarrello = '#FFFFFF';
			} else {
				sfondocarrello = '#FFFFEF';
			}
		} 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><td colspan="2">'+"(Il tuo carrello è vuoto)"+'</td></tr>');
	}
	document.writeln('</table>');

	scp = 1;
	if (scl > 0) {
		scp = 1 - scl;
		scp = Math.round(scp * 100) / 100;
	} else if (totprice > scimp[l] && scperc[l] < 1) {
		scp = scperc[l];
	}
	if (scp < 1) {
		newtotprice = totprice * scp;
		impsconto = totprice - newtotprice;
		totprice = newtotprice;
		newtotiva = totiva * scp;
		impscontoiva = totiva - newtotiva;
		totiva = newtotiva;
	}
}*/
