function vedicarrello() {
window.open('carrello.htm','Popup_Window','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=760,height=350');
}

function primavolta(codice, prezzo, quant) {
document.cookie = 'Lampade=#@'+codice+'@'+prezzo+'@'+quant+'##';
}

function cancella() {
document.cookie = "Lampade=0";
}

function aggiungi2(codice, prezzo, quant) {
var sost=0;
var sostflag=0;
var subpuntatore=0;
var string=document.cookie;
var puntatore=string.lastIndexOf("Lampade=#");
var lung=string.indexOf("##");
if (puntatore == -1) primavolta(codice, prezzo, quant);
	else {
	var newstring="Lampade=#";
	while (puntatore<=lung) {
		sost=0;
		if (string.charAt(puntatore) == "@") {
			puntatore++;
			subpuntatore=puntatore;
			while (string.charAt(puntatore) != "@") puntatore++;
			if (string.substring(subpuntatore, puntatore) == codice) sost=1;
			newstring+="@"+string.substring(subpuntatore, puntatore);
			puntatore++;
			subpuntatore=puntatore;
			while (string.charAt(puntatore) != "@") puntatore++;
			newstring+="@"+string.substring(subpuntatore, puntatore);
			puntatore++;
			subpuntatore=puntatore;
			while ((string.charAt(puntatore) != "@") && (string.charAt(puntatore) != "#")) puntatore++;
			if (sost == 1) {
				var somma=parseInt(quant);
				somma+=parseInt(string.substring(subpuntatore, puntatore));
				if (somma > 999) somma=999;
				newstring+="@"+somma;
				sost=0;
				sostflag=1;
				}
			else newstring+="@"+string.substring(subpuntatore, puntatore);
			puntatore--;
			}
		puntatore++;
		}
	if (sostflag == 1) newstring+="##";
		else newstring=string.substring(0,lung)+"@"+codice+"@"+prezzo+"@"+quant+"##";			
	}
document.cookie=newstring;	
}

function aggiungi(codice, prezzo) {
var quant=prompt("Inserire la quantità che si desidera aquistare",1);
if ((isNaN(quant)) || (quant<1) || (quant>999)) alert("Valore non valido");
	else {
	if (document.cookie.length > 0) aggiungi2(codice, prezzo, quant);
		else primavolta(codice, prezzo, quant);
		}
}