$(document).ready(function() {

	// Apply price capture
	$(".pickup").click( function(){
		// Get the type of delivery method
		var param = 1;
		if (($(this).val() == "Payment on pickup") || ($(this).val() == "Bartercard collect"))
		{
			param = 0;
			$("#insurance").val("0");
			$("#insurance").attr("disabled", "disabled");
			updateAccount();
		} else {
			$("#insurance").attr("disabled", "");
			updateAccount();
		}

		// Get the new table
		$.get("refresh-cart.php",{ delivery: param}, function(j){
			$("#finalCart").html(j);
		});
	});

	$("input[type=radio]").click(function() {
		if ($(this).attr("name")=="paymethod") {
			if ($(this).val()=="Credit Card") {
				$("#carddetails").show();
				$("#pickupDetails").hide();
				$("#bartercarddetails2").hide();
				$("#bartercarddetails1").hide();
			} else if ($(this).val()=="Payment on pickup") {
				$("#pickupDetails").show();
				$("#carddetails").hide();
				$("#bartercarddetails2").hide();
				$("#bartercarddetails1").hide();
			} else if ($(this).val()=="Bartercard collect") {
				$("#bartercarddetails2").show();
				$("#pickupDetails").hide();
				$("#carddetails").hide();
				$("#bartercarddetails1").hide();
			} else if ($(this).val()=="Bartercard postage") {
				$("#bartercarddetails1").show();
				$("#bartercarddetails2").hide();
				$("#pickupDetails").hide();
				$("#carddetails").hide();
			} else {
				$("#carddetails").hide();
				$("#pickupDetails").hide();
				$("#bartercarddetails1").hide();
				$("#bartercarddetails2").hide();
			}
		}
	});

	function updateAccount() {
		$.post("update-account.php", { cust_id: $("#cust_id").val(), firstname: $("#firstname").val(), surname: $("#surname").val(), business: $("#business").val(), address: $("#address").val(), city: $("#city").val(), state: $("#state").val(), postcode: $("#postcode").val(), email: $("#email").val(), phone: $("#phone").val(), country: $("#country").val(), insurance: $("#insurance").val() }, function(data){
		});
	}
});
