$(function() {	//DOM done loading
	$shipMeth = $('#ShipMethod');	//ShipMethod dropdown used multiple times

	//hookup event handlers
	// forms
	$('form#Calculate').bind('submit', function () { return validationZip(this); });
	$('form#frmCheckout').bind('submit', function () { return checkShipping(); });
	$('form#ppec').bind('submit', function () { return checkShipping(); });
	$('form#gckt').bind('submit', function () { return checkShipping(); });

	// form fields
	$shipMeth.bind('change', setShipPrice);

	//rather than focus-footwork, we've set the fields to readonly
	//$('#Shipping').bind('focus', function () { $shipMeth.focus(); });
	//$('#Total').bind('focus', function () { $shipMeth.focus(); });

});//DOM done loading

function checkShipping() {
	if ($('#checkship').val() === 'false') {
		alert('Please enter your zip code to get your shipping charges.');
		$('shipzip').focus();
		return false;
	}

	return true;
}//checkShipping()

function setShipPrice() {
	var $frm = $('form#frmShipMethod');
	var subtotal = $frm.find('#subtotal').val() - 0;
	var shipping = $frm.find('select#ShipMethod > option:selected').val() - 0;
	var truck = $('#truck').val() - 0;
	if (isNaN(truck)) {
		truck = 0;
	}
	var total = Math.round((subtotal + shipping + truck) * 100) / 100;

	$frm.find('#Shipping').val('$' + shipping.toFixed(2))
	$frm.find('#Total').val('$' + total.toFixed(2));
	$('#ppecPaymentAmount').val(total);	//express checkout total
}//setShipPrice()

function validationZip($frm) {
	if ($('#shipzip', $frm).val() === '') {
		alert('Please enter your zip code.');
		$('#shipzip', $frm).focus();
		return false;
	}

	return true;
}//validationZip()

