var Shop =
{
	/*addToCart: function(products_id, color, size, embroidered_name, quantity)
	{
		var a=new Ajax(true, 'txt');
		var url = '/tabmin/modules/products/ajax.php';
		try
		{
			a.post(url, 'verb=add_to_cart&products_id='+parseInt(products_id)+'&color='+encodeURIComponent(color)+'&size='+encodeURIComponent(size)+'&embroidered_name='+encodeURIComponent(embroidered_name)+'&quantity='+parseInt(quantity), function()
			{
				if(a.ready())
				{
					if(a.status()==200)
					try
					{
						var resp = JSON.parse(a.response());
						if(resp.success)
						{
							Shop.updateCartCount(resp.cart_count);
						}
						AlertSet.addJSON(resp).show();
					}
					catch(err){}

					else if(a.status()!=0)
						AlertSet.add(AlertSet.Error('Couldn\'t load page: HTTP Error '+ a.status() +'<br /><br />'+ a.response())).show();

					this._ready=true;
				}
			}.bind(this));
		}
		catch(err)
		{
			div.innerHTML = 'Couldn\'t load page: AJAX Error ('+ err.name +') - '+ err.message;
		}
	},
	*/
	updateCartCount: function(val)
	{
		var div=document.getElementById('cart_items');
		if(!!div)
		{
			while(div.childNodes.length > 0)
				div.removeChild(div.childNodes[0]);
			div.appendChild(document.createTextNode(Math.max(parseInt(val), 0)));
		}
		
		div=document.getElementById('cart_total_items');
		if(!!div)
		{
			while(div.childNodes.length > 0)
				div.removeChild(div.childNodes[0]);
	
			div.appendChild(document.createTextNode(Math.max(parseInt(val), 0)));
		}
	},
	
	updateCartTotal: function(val)
	{
		var div=document.getElementById('cart_total');
		if(!!div)
		{
			while(div.childNodes.length > 0)
				div.removeChild(div.childNodes[0]);
	
			div.appendChild(document.createTextNode(val));
		}
	},
	
	updateQuantities: function(quantities)
	{
		var quantity, total=0, tr, input, td;
		
		for(quantity in quantities)
		{
			total+=parseInt(quantities[quantity]);
			tr=document.getElementById('tr'+quantity);
			if(quantities[quantity]==0)
				tr.parentNode.removeChild(tr);
		}
		
		/*if(total==0)
		{
			var form=document.getElementById('product_form');
			if(form.getElementsByTagName('td').length > 0)
				return;
			tr=document.createElement('tr');
			td=document.createElement('td');
			td.setAttribute('colSpan', '8');
			td.appendChild(document.createTextNode('You have no items in your shopping cart.'));
			tr.appendChild(td);
			form.getElementsByTagName('tbody')[0].insertBefore(tr, null);
		}*/
	}
};

