jQuery(document).ready(function($){
	$("#payment_method_id").change( function(){
		if($("#payment_method_id").val() == '1'){
			$("#bacs").show();
			$("#cheque_payable_to").val("");
			$("#cheque").hide();
		}else if($("#payment_method_id").val() == '2'){
			$("#cheque").show();
			$("#account_holder").val("");
			$("#account_number").val("");
			$("#sort_code").val("");
			$("#bacs").hide();
		}else{
			$("#cheque").hide();
			$("#bacs").hide();
		}
	});
	if($(".metal_prices").length>0){
		var metals = new Array('g9','g10','g14','g15','g18','g22','plat');
		$.getJSON("prices_ajax.php?ajaction=getprices", function(data){
			$.each(metals, function(index, value){
				$(".pricebox #"+value).html('&pound;'+data[value]);
			});
			$("#plat").html('&pound;'+data.plat);
		});


	$("#gtype").change(function(){
		$(".lct").removeClass("labelred");
	});
	$("#metalwt").change(function(){
		$(".lwt").removeClass("labelred");
	});
	$("#metalsubmit p").click(function(){
		var err = 0;
		if($("#gtype").val().length==0){
			$(".lct").addClass("labelred");
			err++;
		}else{
			$(".lct").removeClass("labelred");
		}
		if($("#metalwt").val().length==0){
			$(".lwt").addClass("labelred");
			err++;
		}else{
			$(".lwt").removeClass("labelred");
		}

		if(err==0){
			$(".lwt").removeClass("labelred");
			$(".lct").removeClass("labelred");
			$.getJSON("prices_ajax.php?ajaction=calc&type="+$("#gtype").val()+"&wt="+$("#metalwt").val(), function(data){
				$(".calc #calcmetalprice").html('<p style="margin-top: 8px;font-size:16px;color: #000;text-align: center">Today we would pay</p><p style="font-size: 16px; color: #000; text-align: center;font-weight: bold;">&pound;'+data.price+'</p>');
			});
		}
	});
	}
});

