$(document).ready(function() {
	// append * to required fields
	$("input.required").parents("li").find("label").append("*");
	$("input.required").parent().siblings("td").append("*");
	
	// show/hide forms on the basis of checkout
	$("select.choose_payment_method").change(function() {
		choose_payment_method($(this).val());
	});

	// attach validation to the checkout form
	bindAddressValidator("checkout_form"); 
	//bindAddressValidator("view_cart_form");
	
});

function choose_payment_method(id) {
	$("div.pm_pane").hide();
	$("div.pm_" + id).show();
	$("select.choose_payment_method").val(id);
	if(id == "11") {
		$("div#vcContinue").hide();	
	} else {
		$("div#vcContinue").show();	
	}
}


function checkoutStep1() {
	var opts = new Object();
	opts.cart_callback = function () { 
		//if( cart_error.length == 0) {
			window.location.href='checkout.php'; 
		//}
	}
	//updateCart(opts);
	opts.cart_callback();
}

function checkoutStep2() {
	var opts = new Object();
	opts.cart_callback = function () { 
		if( /*cart_error.length == 0 && */ $("#checkout_form").valid() ) {
			$("#checkout_form").submit();
		}
	}
	//updateCart(opts);
	opts.cart_callback();
	return false;
}
//TODO: IDENTICAL TO STEP2 for the time being
function checkoutStep3() {
	var opts = new Object();
	opts.cart_callback = function () { 
		if( /*cart_error.length == 0 &&*/ $("#checkout_form").valid()) {
			$("#checkout_form").submit();
		}
	}
	opts.cart_callback
	/*if($("#checkout_form").valid()) {
		updateCart(opts);
	}*/
	return false;	
}
