function Basket(){
}

Basket.prototype.update = function(data){

	document.getElementById('loading').style.display='none';
	var objAjax= eval(data);
	var result= objAjax.toString();
	if (result.indexOf('insert_err')>0) {
		document.getElementById('risultatoCorpo').innerHTML="<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td align='center'><span class='altroNote'>"+result+"</span></td></tr></table>";
	} else if (result.indexOf('insert_ok')>0) {
		document.getElementById('risultatoCorpo').innerHTML="<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td align='center'><span class='altroNote'>"+result+"</span></td></tr></table>";
		document.getElementById('carrello').innerHTML="";
	} else {
		if(objAjax > 0){
			document.getElementById('carrello').innerHTML='&nbsp;('+objAjax+')';			
		}	
	}
}

function addToBasket(codice, qta){
	document.getElementById('loading').style.display='block';
	var basket = new Basket();
	var url="/ecommerce.php?command=Ecommerce-aggiungiCarrello&tpl=raw&codice="+codice+"&qta="+qta;
	var contentRetriever = new ContentRetriever(url);
	contentRetriever.attach(basket);
	contentRetriever.getContent();
}

function addToBasketSleep(codice, a){
	if(a < 10){
		if(document.getElementById(codice+'_'+a) != undefined){
			cod = document.getElementById(codice+'_'+a).name;
			qta = document.getElementById(codice+'_'+a).value;
			if(qta > 0){
				addToBasket(cod, qta);
			}
		}
		setTimeout(function () {
			  addToBasketSleep(codice, ++a);
		}, 100);	
	}

}

function addToBasketTC(codice){
	setTimeout(function () {
		  addToBasketSleep(codice, 0);
	}, 100);
}

/*
function addToBasketTC(codice){
	for(var a=0; a <=10; a++){
		if(document.getElementById(codice+'_'+a) != undefined){
			cod = document.getElementById(codice+'_'+a).name;
			qta = document.getElementById(codice+'_'+a).value;
			if(qta > 0){
				setTimeout(function () {
					  addToBasket(cod, qta);
				}, 500);
			}
		}
	}
}
*/



function emptyBasket(){
	document.getElementById('loading').style.display='block';
	var basket = new Basket();
	var url="/ecommerce.php?command=Ecommerce-svuotaCarrello&tpl=raw";
	var contentRetriever = new ContentRetriever(url);
	contentRetriever.attach(basket);
	contentRetriever.getContent();
	document.getElementById('risultatoCorpo').innerHTML="<table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td align='left'><span class='altroNote'>Tutti gli articoli sono stati eliminati dal carrello !!!</span></td></tr></table>";
	document.getElementById('carrello').innerHTML="";	
	//document.location.replace("ecommerce.php?command=Ecommerce-gestioneCarrello&label=CARRELLO");
}


