function addProduct(productId, element) {
	jQuery.ajax({
		    url: '/cart.php',
		    type: 'GET',
		    data: "action=add&productid=" + productId,
		    error: function(){
		        alert('Error adding product to cart.');
		    },
		    success: function(response){
		    	howManyItemsInCart();
		    	orderTotal();
		       	jQuery(element).replaceWith("<a id='productAdd'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;In Cart&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a>");
		    }
	});
}

	
function deleteProductFromCart(productId,productIndex, element) {

	jQuery.ajax({
		    url: '/cart.php',
		    type: 'GET',
		    data: "action=delete&productindex=" + productIndex,
		    error: function(){
		        alert('Error removing product from cart.');
		    },
		    success: function(response){

		    	var num = jQuery('#numItemsInCart');
		       	var e = jQuery('#cartItem'+productId);

		       	howManyItemsInCart();
		       orderTotal();
		       	e.fadeOut();
		       	//replaceWith("<span id='productAdd' onclick='addProduct("+productId+", this)'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Add to Cart&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>");
		    }
	});
}

function howManyItemsInCart() {
	jQuery.ajax({
		    url: '/cart.php',
		    type: 'GET',
		    data: "action=count",
		    error: function(){
		        alert('Error getting item count.');
		    },
		    success: function(response){
		    	var num = jQuery('#numItemsInCart');
		       	num.html(response);
		    }
	});
}

function orderTotal() {
	jQuery.ajax({
		    url: 'cart.php',
		    type: 'GET',
		    data: "action=cartTotal",
		    error: function(){
		        alert('Error getting cart item count.');
		    },
		    success: function(response){
		    	var orderTotal = jQuery('#orderTotal');
		       	orderTotal.html(response);
		    }
	});
}
