/*

Amazing Javascript Shopping Basket
(C) John Pye 2002
john.pye@usa.net

*/

// you must load cookie.js first

var basket=new Cookie(document,"creambasket",0.5, '/');

function Basket(name,timeout){
	this.cookie=new Cookie(document,name,timeout,'/');
	this.add=Basket_add;
	this.remove=Basket_remove;
	this.removereload=Basket_removereload;
	//this.dump=Basket_dump;
	this.addreload=Basket_addreload;
}

function Basket_add(productid,number){
	this.addreload(productid,number,0);
}

function Basket_addreload(productid,number,reloadflag){
	this.cookie.load();
	
	if(reloadflag==null)reloadflag=1;
	if(!number)number=1+0;
	
	if(!this.cookie[productid])this.cookie[productid]=0;
	
	this.cookie[productid]=parseInt(this.cookie[productid])+number;
	
	//alert(this.cookie[productid]);
	
	this.cookie.store();
	
	if(reloadflag)location.reload();
}

function Basket_remove(productid,number){
	this.removereload(productid,number,0)
}

function Basket_removereload(productid,number,reloadflag){
	if(reloadflag==null)reloadflag=1;
	
	if(number!=null)number=parseInt(number);
	
	if(this.cookie.load()){
		if(this.cookie[productid]){
			if(number==null)
				this.cookie[productid]=0;
			else
				this.cookie[productid]=parseInt(this.cookie[productid])-number;
		}
		this.cookie.store();
	}
	
	if(reloadflag)location.reload();
}
