function valCCForm(frmName) {
	var bad = '';
	if (document.infoform.creditcardname.value=='') { bad+='You must specify the name on your credit card.\n'; }
	if (document.infoform.creditcardnumber.value=='') { bad+='You must specify your credit card number.\n'; }
	if (document.infoform.creditcardexpdate.value=='') { bad+='You must specify the expiration date of your credit card.\n'; }
	if (document.infoform.creditcardzipcode.value=='') { bad+='You must specify the billing ZIP code on your credit card for validation.\n'; }
	if (bad != '') {
		alert(bad);
		return false
	} else { return true }
}

function valEmail(email) {
	// Requires user@domain.extension
    var em_val = /^\w+@\w+(\.\w+?)/;
    return em_val.test(email)
}

function valSocial(social) {
	// Requires no spaces
    var tempNum = Math.floor(social / 10000);
    var tempNum1 = Math.floor(tempNum / 1000);
    var tempNum2 = Math.floor(tempNum1 / 100);
    var tempNum3 = Math.floor(tempNum2 / 10);
    if ((social.length < 9) || (social.length > 9) || (tempNum3 != 0)) return false
    else if ((f.length == 9) || (tempNum3 == 0)) return true
		else return false
}

function valExpDate(expDate) {
	// Requires format of nn-nn
	var exp_val = /\d{2}\/\d{2}/;
	return exp_val.test(expDate)
}

function valUSPhone(USPhone) {
	// Requires format of nnn-nnn-nnnn
	var ph_val = /\d{3}-\d{3}-\d{4}/;
	return ph_val.test(USPhone)
}

function valIntlPhone(intlphone) {
	// Requires format of +[2-4 digits] [3-5 dig] [3-5 dig] [3-5 dig]
	var intl_val = /\+\d{2,4}.\d{3,5}.\d{3,5}.\d{3,5}/
	return intl_val.test(intlphone)
}

function valPhone(phonenum) {
	return (valIntlPhone(phonenum) || valUSPhone(phonenum))
}

function valCreditCardNumber(ccnum) {
	// requires format of nnnnnnnnnnnnnnnn (no dashes)
	var cc_val = /\d{16}/
	return cc_val.test(ccnum)
}

function valOrderForm(frmName) {
	// Validates the order form.
	var bad = '';
	// Billing first
	if (isBlank(frmName.custfirstname.value)) { bad += 'Billing first name was not specified.\n'; }
	if (isBlank(frmName.custlastname.value)) { bad += 'Billing last name was not specified.\n'; }
	if (isBlank(frmName.custaddress.value)) { bad += 'Billing address was not specified.\n'; }
	if (isBlank(frmName.custcity.value)) { bad += 'Billing city or region was not specified.\n'; }
	if (isBlank(frmName.custstate.value)) { bad += 'Billing state or province was not specified.\n'; }
	if (isBlank(frmName.custzipcode.value)) { bad += 'Billing postal or ZIP code was not specified.\n'; }
	if (isBlank(frmName.custcountry.value)) { bad += 'Billing country was not specified.\n'; }
	if (isBlank(frmName.custphonenumber.value) || !valPhone(frmName.custphonenumber.value)) { bad += 'Invalid billing phone number specified.  Please use xxx-xxx-xxxx format.\n'; }
	if (isBlank(frmName.custemail.value) || !valEmail(frmName.custemail.value)) { bad += 'Invalid billing email address specified.\n'; }
	// Now shipping...
	if (isBlank(frmName.shipfirstname.value)) { bad += 'Shipping first name was not specified.\n'; }
	if (isBlank(frmName.shiplastname.value)) { bad += 'Shipping last name was not specified.\n'; }
	if (isBlank(frmName.shipaddress.value)) { bad += 'Shipping address was not specified.\n'; }
	if (isBlank(frmName.shipcity.value)) { bad += 'Shipping city or region was not specified.\n'; }
	if (isBlank(frmName.shipstate.value)) { bad += 'Shipping state or province was not specified.\n'; }
	if (isBlank(frmName.shipzipcode.value)) { bad += 'Shipping postal or ZIP code was not specified.\n'; }
	if (isBlank(frmName.shipcountry.value)) { bad += 'Shipping country was not specified.\n'; }
	if (isBlank(frmName.shipphonenumber.value) || !valPhone(frmName.shipphonenumber.value)) { bad += 'Invalid shipping phone number specified.  Please use xxx-xxx-xxxx format.\n'; }
	//if (isBlank(frmName.shipemail.value) || !valEmail(frmName.shipemail.value)) { bad += 'Invalid shipping email address specified.\n'; }
	// Now check to see if anything was bad...
	if (bad != '') {
		bad = 'Your information could not be submitted due to errors.  Please correct the following information and try again.\n\n' + bad;
		alert(bad);
		return false	
	} else {
		// disable the buttons
		frmName.btnCancel.enabled = false;
		frmName.btnNext.enabled = false;
		return true
	}
}

function fillField(srcfield, destfield) { 
	// copies contents from one form field into another.
	if (document.infoform.shippingsame != null) {
		if (document.infoform.shippingsame.checked == true) { 
			destfield.value = srcfield.value; 
		} 
	}
}

function isBlank(field) {
	// checks to see if a field is blank
	return (field == '')
}

function fillAllFields(frmName) {
	// Copies values from one field into another for
	// all standard shipping and billing form fields.
	// Used on checkout page.
	if (document.infoform.shippingsame != null) {
		if (document.infoform.shippingsame.checked) { 
			fillField(document.infoform.custfirstname, document.infoform.shipfirstname);
			fillField(document.infoform.custlastname, document.infoform.shiplastname);
			fillField(document.infoform.custcompany, document.infoform.shipcompany);
			fillField(document.infoform.custaddress, document.infoform.shipaddress);
			fillField(document.infoform.custaddress2, document.infoform.shipaddress2);
			fillField(document.infoform.custcity, document.infoform.shipcity);
			fillField(document.infoform.custstate, document.infoform.shipstate);
			fillField(document.infoform.custprov, document.infoform.shipprov);
			fillField(document.infoform.custcountry, document.infoform.shipcountry);
			fillField(document.infoform.custzipcode, document.infoform.shipzipcode);
			fillField(document.infoform.custphonenumber, document.infoform.shipphonenumber);
			fillField(document.infoform.custfaxnumber, document.infoform.shipfaxnumber);
			fillField(document.infoform.custemail, document.infoform.shipemail);
		}else{
			document.infoform.shipfirstname.value = '';
			document.infoform.shiplastname.value = '';
			document.infoform.shipcompany.value = '';
			document.infoform.shipaddress.value = '';
			document.infoform.shipaddress2.value = '';
			document.infoform.shipcity.value = '';
			document.infoform.shipstate.value = '';
			document.infoform.shipprov.value = '';
			document.infoform.shipcountry.value = '';
			document.infoform.shipzipcode.value = '';
			document.infoform.shipphonenumber.value = '';
			document.infoform.shipfaxnumber.value = '';
			document.infoform.shipemail.value = '';
		}
	}		
}

function wsRegForm(frmName) {
	// Validates the order form.
	var bad = '';
	// Billing first
	if (isBlank(frmName.taxid.value)) { bad += 'Tax ID was not specified.\n'; }
	if (isBlank(frmName.firstname.value)) { bad += 'First name was not specified.\n'; }
	if (isBlank(frmName.lastname.value)) { bad += 'Last name was not specified.\n'; }
	if (isBlank(frmName.address.value)) { bad += 'Address was not specified.\n'; }
	if (isBlank(frmName.city.value)) { bad += 'City or region was not specified.\n'; }
	if (isBlank(frmName.state.value) && isBlank(frmName.province.value)) { bad += 'State or province was not specified.\n'; }
	if (isBlank(frmName.zipcode.value)) { bad += 'Postal or ZIP code was not specified.\n'; }
	if (isBlank(frmName.country.value)) { bad += 'Country was not specified.\n'; }
	if (isBlank(frmName.phone.value)) { bad += 'Phone number was not specified.\n'; }
	if (isBlank(frmName.emailaddress.value)) { bad += 'Email address was not specified.\n'; }
	if (isBlank(frmName.password.value)) { bad += 'A password was not specified.\n'; }
	if (frmName.password.value != frmName.confirmpassword.value) { bad += 'Passwords do not match.\n'; }
	// Now check to see if anything was bad...
	if (bad != '') {
		bad = 'Your information could not be submitted due to errors.  Please correct the following information and try again.\n\n' + bad;
		alert(bad);
		return false	
	} else {
		// disable the buttons
		frmName.btnNext.enabled = false;
		return true
	}
}

