function cart_add_item(type, id, amount_field)
{
	if ((xml_request.readyState == 4) || (xml_request.readyState == 0))
	{
		// get the amount of cards selected
		if(document.getElementById(amount_field))
		{
			var amount_field = document.getElementById(amount_field);
			var amount = amount_field.value;
		}
		else
		{
			var amount = 1;
		}

		var post_variables = "t=" + encodeURIComponent(type) + "&id=" + encodeURIComponent(id) + "&a=" + encodeURIComponent(amount);

		xml_request.open("POST", "shopping_cart_add_item.php", true);
		xml_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xml_request.onreadystatechange = card_add_item_response;
		xml_request.send(post_variables);
	}
}

function card_add_item_response()
{
	// find the summary cart
	if(xml_request.readyState == 4)
	{
		var doc = xml_request.responseXML;

		if(doc == null)
		{
			alert("Error: The item could not be added to the shopping cart.");
		}
		else
		{
			var summary_cart = document.getElementById('shopping_cart_summary');

			var root_node = doc.documentElement;
			var child_nodes = root_node.childNodes;

			for(var i = 0; i < child_nodes.length; i++)
			{
				var node = child_nodes[i];
	
				if(node.nodeType == 1)
				{
					if(document.getElementById(node.tagName))
					{
						var sc_item = document.getElementById(node.tagName);

						sc_item.innerHTML = node.firstChild.nodeValue;
					}
				}
			}
		}
	}
}

function delete_item(item_id)
{
	var confirmed = confirm("Are you sure you wish to delete this item?");

	if(confirmed === true)
	{
		document.location.href = "cart.php?d=" + item_id;
	}
}
