Basket=new function(){};
Basket=
{
	CookieNamePrefix:"basketItem_",

	Clear:function()
	{
		var list=this.GetAll();
		for (var a=0;a<list.length;a++)
			this.Delete(list[a].Id);
	},
	
	Get:function(id)
	{
		var temp=Cookies.Get(this.cn(id));
		if (temp==null)
			return null;
		
		return this.c2o(temp);
	},
	
	GetAll:function()
	{
		var result=new Array();
		
		var list=Cookies.GetWithPrefix(this.cn(0));
		for (var a=0;a<list.length;a++)
			result[a]=this.c2o(list[a]);
		
		return result;
	},

	New:function()
	{
		var result={Id:0,Name:"",Amount:1,Price:0};
		return result;
	},
	
	Delete:function(id)
	{
		Cookies.Delete(this.cn(id));
	},
	
	Save:function(item)
	{
		var cname=this.cn(item.Id);
		var cvalue=item.Id+"|"+item.Amount+"|"+item.Price+"|"+item.Name;
		Cookies.Save(cname,cvalue);
	},
	
	cn:function(id)
	{
		if (id==0)
			return this.CookieNamePrefix;
		
		return this.CookieNamePrefix+id;
	},
	
	c2o:function(c)
	{
		var parts=c.value.split("|");
		var item=Basket.New();
		item.Id=parts[0]*1;
		item.Amount=parts[1]*1;
		item.Price=parts[2]*1;
		item.Name=parts[3];
		return item;
	}
}
