function ship_checkout_continue() {
        checkoutShipStateCheck();
        check_rush_order();
        checkout_continue();
	return;
}
function fillShipState() {
        var df = document.CheckoutForm;
        var s = df.ship_state_select.value;
        if (s.length) {
                df.ship_state.value = s;
        }
	return;
}
function checkoutShipStateCheck() {
        var df = document.CheckoutForm;
        var s = df.ship_state.value;
        if (!s.length) {
                fillShipState();
        }
	return;
}

function formSubmit() {
	var df = document.CheckoutForm;
	df.submit();
	return;
}

function checkout_continue() {
	var df = document.CheckoutForm;
	df.process_cmd.value = 'continue';
	df.submit();
	return;
}

function update_total() {
	var df = document.CheckoutForm;
	df.process_cmd.value = 'update_cart';
	df.submit();
	return;
}

function remove_item(id) {
	var df = document.CheckoutForm;
	df.process_cmd.value = 'remove_item_'+id;
	df.submit();
	return;
}

function copyFromShipping() {
	var df = document.CheckoutForm;
	df.bill_firstname.value = df.ship_firstname.value;
	df.bill_lastname.value  = df.ship_lastname.value;
	df.bill_address.value   = df.ship_address.value;
	df.bill_address2.value  = df.ship_address2.value;
	df.bill_city.value      = df.ship_city.value;
	df.bill_state.value     = df.ship_state.value;
	df.bill_zip.value       = df.ship_zip.value;
	df.bill_country.value   = df.ship_country.value;
	return;
}

function searchQuerySubmit() {
	df = document.queryForm;
	df.submit();
}

function check_rush_order() {
	var df = document.CheckoutForm;
	if (df.ship_method[1].checked) {
		df.ship_rush_order.value = 1;
	}
	else {
		df.ship_rush_order.value = 0;
	}
}

function set_pay_method(payMethod) {
	df = document.CheckoutForm;
	df.bill_pay_method.value = payMethod;
}

$(function() {
	df = document.CheckoutForm;
	//if (df.store_step.value == 'billing') {

		if (df.bill_pay_method.value == 'cc') {
			showPayMethodBoxCC();
		}
		else if (df.bill_pay_method.value == 'pp') {
			showPayMethodBoxPP();
		}
	
		$("#btnPayCC").click( function() {
			showPayMethodBoxCC();
			return false;
		});
		$("#btnPayPP").click( function() {
			showPayMethodBoxPP();
			return false;
		});
	
		function showPayMethodBoxCC() {
			$('#payMethodBoxPP').addClass('hide');
			$('#payMethodBoxCC').removeClass('hide');
			$('#billInfoBoxCC').removeClass('hide');
			set_pay_method('cc');
		}
		function showPayMethodBoxPP() {
			$('#payMethodBoxCC').addClass('hide');
			$('#billInfoBoxCC').addClass('hide');
			$('#payMethodBoxPP').removeClass('hide');
			set_pay_method('pp');
		}
	
	
	
	
	    $('#btnPPCheckout').click(function() { 
	        $.blockUI({ 
	            theme:     true, 
	            title:    '<span style="color:#000000">Billing</span>', 
	            message:  '<p style="text-align: center;">Contacting PayPal...<img src="images/ajax-loader.gif" /> </p>' 
	        });
			$('.blockOverlay').click($.unblockUI);
			checkout_continue();
			return false;
	    });    
	//}

});
