function cCarrello (dati) {


  this.numeroProdotti = 0;
	this.IDProdotto = new Array();
	this.quantita = new Array();
	this.dataString = dati;

	var i, count;
	var valore = new Array();

	 	valore = this.dataString.split(',');

	 	for (i = count = 0; i < valore.length; i++) {

	 		if 	((i % 2) == 0 )	this.IDProdotto[count]	= valore[i];
	 		else							{ this.quantita[count] 	= valore[i]; count++;}
	 	}
    this.numeroProdotti = count;
}

cCarrello.prototype.Aggiungi = function(id, qty) {

	if (arguments.length == 1) qty = 1;

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

	 	if (this.IDProdotto[i] == id)
	 		return(0);
	}

	this.IDProdotto[this.numeroProdotti] = id;
	this.quantita[this.numeroProdotti] = qty;

	if (this.numeroProdotti > 0) this.dataString += ',';
	this.dataString += (id + ',' + qty);

	this.numeroProdotti++;

	return(-1);
}
cCarrello.prototype.Elimina = function (id) {

	var i, ret;

		for (i = ret = 0; i < this.numeroProdotti; i++) {

			if (this.IDProdotto[i] == id) {

				for (var j = i; j < (this.numeroProdotti - 1); j++) {

					this.IDProdotto[j] = this.IDProdotto[j + 1];
					this.quantita[j] = this.quantita[j + 1];
				}
				this.IDProdotto.pop();
				this.quantita.pop();
				this.numeroProdotti--;

				this.dataString = '';
				for (var k = 0; k < this.numeroProdotti; k++) {

					if (k > 0) this.dataString += ',';
					this.dataString += (this.IDProdotto[k] + ',' + this.quantita[k]);
				}
				ret = -1;
				break;
			}
		}
		return(ret);
}
cCarrello.prototype.Modifica = function(id, qty) {

 var i, ret;

		for (i = ret = 0; i < this.numeroProdotti; i++) {

				if (this.IDProdotto[i] == id) {

					this.quantita[i] = qty;

					this.dataString = '';
					for (var k = 0; k < this.numeroProdotti; k++) {

						if (k > 0) this.dataString += ',';
						this.dataString += (this.IDProdotto[k] + ',' + this.quantita[k]);
					}
					ret = -1;
					break;
				}
		}
		return(ret);
}
cCarrello.prototype.Svuota = function() {

		for (var k = 0; k < this.numeroProdotti; k++) {

			this.IDProdotto.pop();
			this.quantita.pop();
		}
		this.dataString = '';
}



