$(function()
{
	var license = $("#license");
	var refund = $("#refund");
	var purchase = $("#purchase");

	purchase.click(function()
	{
		if(license.attr("checked") && refund.attr("checked"))
		{
			return true;
		}
		else
		{
			esyndicat.error("You have to accept terms of use");
			return false;
		}
	});

	$("a[id^='del_']").click(function()
	{
		var id_prod = $(this).attr("id").split("_")[1];
		var price = $(this).attr("id").split("_")[2];
		var total = $("#total").text();
		var question = 'Are you sure you wish to remove this product from cart?';

		newval = parseInt(total) - parseInt(price);
		
		jConfirm(question, 'Confirm', function(r)
		{
			if (r)
			{
				$.ajax({type: "POST", url: "ajax.php", data: "id_product=" + id_prod + "&action=remove_from_cart", async: false, success: function(msg)
					{
						if (newval == 0)
						{
							document.location.href = '/shopping-cart.html';
							return true;
						}
						$("#prod_id_" + id_prod).attr('disabled', true);
						$("#prod_price_" + id_prod).attr('disabled', true);
						$("#prod_qty_" + id_prod).attr('disabled', true);
						$("#line_" + id_prod).hide();
						$("#total").html(newval);
					}
				});
			}
		});
	});
});
