var cart = {};
var products = {};

function addToCart() {
	var itemid = arguments[0]
	var productname = arguments[1];
	var price = arguments[2];
	var shipping = arguments[3]
	var quantity = ((arguments.length<5)?1:arguments[4]);

	var nvPairs = [
		 'itemid='+encodeURIComponent(itemid)
		,'productname='+encodeURIComponent(productname)
		,'price='+encodeURIComponent(price)
		,'shipping='+encodeURIComponent(shipping)
		,'quantity='+encodeURIComponent(quantity)
	];
	if (arguments.length == 6) {
		nvPairs.push('mode='+encodeURIComponent(arguments[5]));
	}

	var url = '/store/cartentry.php';
	var querystring = nvPairs.join(String.fromCharCode(38))

	window.location = url+'?'+querystring;

	return(false);
}

function calculateAndAddToCart(item,qty) {
	//Does this item exist in the cart?  Are we adding it or re-setting it?
	for (cartItem in cart) {
		if (cartItem == item.id) {
			qty += parseInt(cart[cartItem].quantity);
		}
	}
	addToCart(item.id, item.name, item.calculatePriceEach(qty), item.calculateShippingEach(qty), qty, 'set');
}

