function updateOrder(sel){
	var eSh = document.getElementById("shippingTotalLabel");
	var eTx = document.getElementById("taxTotalLabel");
	var eBl = document.getElementById("orderBalanceLabel");

	var val = sel.options[sel.selectedIndex].value;
	//var val = sel.options[sel.selectedIndex].text;
	
	if (shipping && shipping[val]){
	    var s = shipping[val];
	   
		var c = s.Cost;
		
		var tx = s.Tax;
		var bl = s.Balance;
		if (eSh) eSh.innerHTML = c;
		if (eTx) eTx.innerHTML = tx;
		if (eBl) eBl.innerHTML = bl;
		return;
	}
}

//	validation stuff.
function validate(f) {
    
	//	collect all the information on the form, and set the values.
	//	If not all the info is there, tell 'em.
	var b = true;
	var msg = [];
	
	//	let's start with the expedite, this will always have a value.
	var sel = document.getElementsByTagName("select");
	
	for (var i = 0; i < sel.length; i++) {
		if (sel[i].name == "shiptype"){
		    f.shiptype.value = sel[i].options[sel[i].selectedIndex].value;
		    
			break;
		}
}


//	check this only if there's a balance on the order.


	if (balanceDue && balanceDue > 0) {
		//	ok, on to the remitment, this is important.
		var rform = document.getElementById("remitmentForm");

		var key = -1;
		
		if (rform.remitment.length) {
			for (var i = 0; i < rform.remitment.length; i++){
				if (rform.remitment[i].checked) {
				    key = parseInt(rform.remitment[i].value);
				    
				}
			}
		} else key = 0;

		if (key < 0) {
			//	if we got here, the user didn't select a type of payment at all.
			alert("Please select a method of payment.");
			return false;
		}
		
		f.remitment.value = key;
		if (key == 0){
			//	new card, let's validate first
			var paymentType = "";
			var test = false;
			for (var i = 0; i < rform.paymentType.length; i++) {
				if (rform.paymentType[i].checked) {
					test = true;
					paymentType = rform.paymentType[i].value;
				}
			}
			if (!test){
				b = false;
				msg[msg.length] = "Please select a type of credit card.";
			}
			
			if (rform.accountNumber.value.IsEmpty() || !checkCreditCard(rform.accountNumber.value, paymentType)) {
				b = false;
				msg[msg.length] = "Please supply a valid account number.";
			}
			
			//if (rform.securityCode.value.IsEmpty()){
				//b = false;
			//	msg[msg.length] = "Please supply a CCV to verify your credit card.";
			//}
			if (rform.accountName.value.IsEmpty()){
				b = false;
				msg[msg.length] = "Please supply the name that is associated with the credit card number.";
			}
			
			var m = rform.expirationMonth.options[rform.expirationMonth.selectedIndex].value;
			var y = rform.expirationYear.options[rform.expirationYear.selectedIndex].value;
			
			if (parseInt(y) == new Date().getFullYear()
				&& (parseInt(m) - 1) < new Date().getMonth()
			){
				b = false;
				msg[msg.length] = "The expiration date you have entered is not valid.";
			}
			
			//	ok, if we didn't pass:
			if (!b) {
				alert("Please check the following:\n\n" + msg.join("\n"));
				return b;
			} else {
				//	ok, fill out the hidden form and let it go through
				f.paymentType.value = paymentType;
				f.accountNumber.value = rform.accountNumber.value;
//				f.securityCode.value = rform.securityCode.value;
				f.accountName.value = rform.accountName.value;
				
				f.expirationDate.value = m + "/" + y;

				
				if (rform.saveRemitment.checked) f.saveRemitment.value = "1";
				else f.saveRemitment.value = "0";

				return b;
				 
			}			
		}	
	}
	return b;
}

function onAccountChange(elm){
	elm.value = elm.value.Trim().replace(/-/gi, "").replace(/\s+/gi,"");
}

function paymentTypeOnClick(elm){
	var f = elm.form;
	for (var i = 0; i < f.remitment.length; i++){
		if (f.remitment[i].value == "0") f.remitment[i].checked = true;
	}
}