//Controls high-level operations, such as adding or removing an item from the basket.

function addItem(itemid, itemname, itemprice, itemquant) {
	
	//First, verify that everything is correctly formatted.
	itemid = parseInt(itemid);
	itemprice = parseFloat(itemprice).toFixed(2);
	itemquant = parseInt(itemquant);
	
	var replacereg = /’/g;
	itemname = itemname.replace(replacereg, "'");
	
	if (itemquant <= 0) {
		alert("Please choose a numeric quantity greater than zero.");
		return;
	}
	
	//Adds the item with the given ID to the cart.
	var cartitems = (readCookie("CartItems") != null) ? parseInt(readCookie("CartItems")) : 0;
		
	createCookie("ItemID" + cartitems, itemid, 365);
	createCookie("CartItems", ++cartitems, 365);	//Increment the number of items.
		
	createCookie("ItemName" + itemid, itemname, 365);
	createCookie("ItemPrice" + itemid, itemprice, 365);
	createCookie("ItemQuant" + itemid, itemquant, 365);
	
	alert(itemname + " was added to your basket.");
}
