function removeFromCart(num) {
	var remove = false;
	var conf_str = "Really delete?";
	if (num=='all') {conf_str = "Really remove all items from the Shopping Cart?";}
	if (confirm(conf_str)) {
		if (num=='all') {
			emptyCart()
			document.location.href="clear.asp"
		} else {
			$.post("cartjax.asp?a=delete&n="+num, function(){updateRHCCartBox();});
			// store product total
			var original_total = deformatCurrency($("tr#cart-row-"+num+" td.product-total").text());
			
			// set cart total
			var cart_total = deformatCurrency($("tr#cart-total-row td.cart-total").text());
			cart_total = cart_total - original_total;
			$("tr#cart-total-row td.cart-total").text(formatCurrency((cart_total).toString()));
			
			$("tr#cart-row-"+num).fadeOut('slow', function(){
				$(this).remove();
				var rows = 0;
				$("table.cart-table tbody tr").each(function(){rows++;});
				if (rows <= 1) {
					emptyCart();
				}
				hasPOA();
			});
		}
	}
}

function emptyCart() {
	$("table.cart-table").replaceWith("<p>There are no items in your shopping cart.</p>");
	$("#cart-buttons-clear,#cart-buttons-proceed").attr("disabled", "disabled");
}

function hasPOA() {
	$("#POA").text("");
	$(".cart-table td.product-price").each(function(){
		if ($(this).text().toLowerCase().replace(/\s/g,'') == "poa") {
			$("#POA").text(" + POA");
		}
	});
}

function updateCart(num, field, value, isPOA) {
	$('#cart-buttons-proceed').attr('disabled','disable');
	$.post("cartjax.asp?a=update&n="+num+"&f="+field+"&v="+value, function(){updateRHCCartBox();});
	if (field == "quantity") {
		var quantity = value;
		if (quantity == 0) {quantity = 1;}
		
		if (isPOA == "POA") {
		} else {
			// store product total
			var original_total = deformatCurrency($("tr#cart-row-"+num+" td.product-total").text());
			
			// calc product total
			var price = deformatCurrency($("tr#cart-row-"+num+" td.product-price").text());
			quantity = Math.floor(Number(quantity)+0.50000000001);
			$("tr#cart-row-"+num+" td.product-total").text(formatCurrency((price*quantity).toString()));
			
			// set cart total
			var cart_total = deformatCurrency($("tr#cart-total-row td.cart-total:first").text());
			cart_total = ((price*quantity) - original_total) + cart_total;
			$("tr#cart-total-row td.cart-total:first").text(formatCurrency((cart_total).toString()));
		}
		$('#cart-buttons-proceed').attr('disabled','');
		return quantity;
	}
	if (field == "option") {
		// nothing much to do here
		$('#cart-buttons-proceed').attr('disabled','');
		return true;
	}
	$('#cart-buttons-proceed').attr('disabled','');
}

function updateRHCCartBox(){
	var cartData;

	$.ajax({
		type: "POST",
		url: "../cart/ajaxcartbox.asp",
		data: "",
		success: function(msg){
			cartData = msg;
		},
		async: false
	});
	$('#headercart').html(cartData);
}