
function addToCart(ele) {
	var product = $("#product_select").val();
	var quantity = $("#quantity_select").val();
	var page = $("#product_page").val();
	
	if ((page == "pvip" && quantity < 500) && $(":checked").length > 0 ) {
		alert ('Upgrade not available for quantities less than 500');
		return false;
	}
	
	if (!product) {
		alert('Please Select a Product');
	} else if (!quantity) {
		alert('Please Select a Quantity');
	} else {
		$.ajax({
			type: "POST",
			beforeSend: function (XMLHttpRequest) {
				$(ele).val('adding...');
			},
			url: "inc/ajax/cart_controller.php",
			data:  $("#product_form").serialize(),
			dataType: "json",
			success: function(json) {
				if (json.success) {
					window.location.href = 'place-order.php';
				} else {
					alert ('oops');
				}
			}
		});
	}
}

function removeFromCart(ele) {
	var string = "";
	
	$(":checked").each(function(){
		string = string + "product[]=" + $(this).val() + "&"
	});
	
	if (string.length > 0) {	
		$.ajax({
			type: "POST",
			beforeSend: function (XMLHttpRequest) {
				$(ele).val('Processing...');
			},
			url: "inc/php/update_cart.php",
			data:  string,
			dataType: "json",
			success: function(json) {
				if (json.success) {
					window.location.href="place-order.php";
				} else {
					alert ('oops');
				}
			}
		});
	}

}

function checkout() {
	window.location.href = "https://secure.biz-mag.net/secure-checkout.php";
}
