function $(strElement) {
	return document.getElementById(strElement);
}

function changePaymentSubmitted() {
	$("checkoutSubmit").disabled = "disabled";
	$("checkoutChange").disabled = "disabled";
	$("paymentSubmitted").innerHTML = "Processing payment, this may take several seconds...";
	$("paymentSubmitted").className = "block vspace2 bold red small";
}

function formatPhone(field) {
	var temp = field.value.replace(/[^0-9_]/g, "");
	var cursor = temp.length;
	temp = temp.replace(/^([0-9_]{0,3})([0-9_]{0,3})([0-9_]{0,4})([0-9_]*)/, "($1) $2-$3 x $4");
	if (cursor < 11)
		temp = temp.replace(/\s*x\s*$/, "");
	if (cursor < 7)
		temp = temp.replace(/\-\s*$/, "");
	if (cursor < 3)
		temp = temp.replace(/\)\s*$/, "");
	if (! cursor)
		temp = "";
	field.value = temp;
	return true;
}

function checkState(objSel) {
	var objText = objSel.form[objSel.name + "Other"];
	if (objText) {
		if (objSel[objSel.selectedIndex].value == "OTHER") {
			objText.style.display = "inline";
		} else {
			objText.style.display = "none";
		}
	}
}

function validateFormField(blnValid, objFormField, strAlert) {
	if (blnValid) {
		if (objFormField) {
			if (objFormField.value.replace(" ", "") == "") {
				if (strAlert != "") { alert(strAlert); }
				objFormField.focus();
				return false;
			}
		}
	} else { return false; }
	return true;
}

function validateFormMatch(blnValid, objFormField, objFormField2, strAlert) {
	if (blnValid) {
		if (objFormField) {
			if (objFormField.value.replace(" ", "") != objFormField2.value.replace(" ", "")) {
				if (strAlert != "") { alert(strAlert); }
				objFormField.value = "";
				objFormField2.value = "";
				objFormField.focus();
				return false;
			}
		}
	} else { return false; }
	return true;
}

function validate(theForm) {
	var blnValid = true;
	if (theForm.submit.value == "cartContinue") {
		blnValid = validateFormField(blnValid, theForm.strFirstName, "Name is required!");
		blnValid = validateFormField(blnValid, theForm.strLastName, "Name is required!");
		blnValid = validateFormField(blnValid, theForm.strDayPhone, "Phone number is required!");
		blnValid = validateFormField(blnValid, theForm.strEmail, "Email address is required!");
		blnValid = validateFormField(blnValid, theForm.strCardNumber, "Credit card number is required!");
		blnValid = validateFormField(blnValid, theForm.strExpMonth, "Expiration date is required!");
		blnValid = validateFormField(blnValid, theForm.strExpYear, "Expiration date is required!");
		blnValid = validateFormField(blnValid, theForm.strBillAddress, "Billing address is required!");
		blnValid = validateFormField(blnValid, theForm.strBillCity, "Billing address is required!");
		blnValid = validateFormField(blnValid, theForm.strBillState, "Billing address is required!");
		blnValid = validateFormField(blnValid, theForm.strBillZip, "Billing address is required!");
		blnValid = validateFormField(blnValid, theForm.strShipFirstName, "Shipping name is required!");
		blnValid = validateFormField(blnValid, theForm.strShipLastName, "Shipping name is required!");
		blnValid = validateFormField(blnValid, theForm.strShipAddress, "Shipping address is required!");
		blnValid = validateFormField(blnValid, theForm.strShipCity, "Shipping address is required!");
		blnValid = validateFormField(blnValid, theForm.strShipState, "Shipping address is required!");
		blnValid = validateFormField(blnValid, theForm.strShipZip, "Shipping address is required!");
	}						
	return blnValid;
}

function useSameAddress(theForm) {
	if (theForm.blnSameAddress.checked) {
		theForm.strShipFirstName.value = theForm.strFirstName.value;
		theForm.strShipMiddleInitial.value = theForm.strMiddleInitial.value;
		theForm.strShipLastName.value = theForm.strLastName.value;
		theForm.strShipAddress1.value = theForm.strBillAddress1.value;
		theForm.strShipAddress2.value = theForm.strBillAddress2.value;
		theForm.strShipCity.value = theForm.strBillCity.value;
		theForm.strShipState.value = theForm.strBillState.value;
		//theForm.strShipStateOther.style.display = theForm.strBillStateOther.style.display;
		//theForm.strShipStateOther.value = theForm.strBillStateOther.value;
		theForm.strShipZip.value = theForm.strBillZip.value;
	}
}
