<!-- 
function checkEnterForm(user, checkCC, shipping, checkEmail) {
	
	fname = document.address.elements['fname'].value;
	lname = document.address.elements['lname'].value;
	jobtitle = document.address.elements['jobtitle'].value;
	company = document.address.elements['company'].value;
	country = document.address.elements['country'].value;
	address = document.address.elements['address'].value;
	city = document.address.elements['city'].value;
	state = document.address.elements['billStateSelect'].value;
	zip = document.address.elements['zip'].value;
	phone = document.address.elements['phone'].value;
	
	if (checkEmail == "hasEmail") {
		email = document.address.elements['email'].value;
	}
	
	if (fname == '') {
		alert("Please enter your First Name.");
		document.address.elements['fname'].focus();
		return false;
	} else if (lname == '') {
		alert("Please enter your Last Name.");
		document.address.elements['lname'].focus();
		return false;
	} else if (jobtitle == '') {
		alert("Please enter your Job Title.");
		document.address.elements['jobtitle'].focus();
		return false;
	} else if (company == '') {
		alert("Please enter your Company Name.");
		document.address.elements['company'].focus();
		return false;
	} else if (country == '') {
		alert("Please select a Country.");
		document.address.elements['country'].focus();
		return false;	
	} else if (address == '') {
		alert("Please enter your Address.");
		document.address.elements['address'].focus();
		return false;
	} else if (city == '') {
		alert("Please enter your City or Town.");
		document.address.elements['city'].focus();
		return false;
	} else if (state == '') {
		alert("Please enter your State/Province.");
		document.address.elements['billStateSelect'].focus();
		return false;
	} else if (zip == '') {
		alert("Please enter your ZIP/Postal Code.");
		document.address.elements['zip'].focus();
		return false;
	} else if ( country== "US" && zip.length != 5 ){
		alert("Please enter a valid 5-digit ZIP/Postal Code for your billing information.");
		document.address.elements['zip'].focus();
		return false;
	} else if ( country!= "US" && zip.length > 11 ){
			alert("Please enter a valid ZIP/Postal Code for non US resident. It must be less than 11 characters.");
			document.address.elements['ziptoship'].focus();
			return false;	
	} else if (country == "US") {
		if (validZip(zip)) {
			alert("This ZIP/Postal Code does not appear to be valid.");
			document.address.elements['zip'].focus();
			return false;
		}
	}  
	
	if ( phone == '' ) {		
		alert("Please enter your Phone number.");
		document.address.elements['phone'].focus();
		return false;			
	} else if (country == "US" && phone.length < 11) {
		alert("This Phone number does not appear to be valid.");
		document.address.elements['phone'].focus();
		return false;	
	}

	
	if (checkEmail == "hasEmail") {
		if (email == '' && checkCC == "checkCC") {
			// since only billing form has checkCC function, that indicate that this is a billing form
			// email address is required for billing form, check if it is empty here
			alert("Please enter your Email address.");
			document.address.elements['email'].focus();
			return false;
		} else if (email != '' && !validateEmail(email)) {
			alert("Your Email address does not seem to be valid.");
			document.address.elements['email'].focus();
			return false;
		}
	}
	
	
	// HAS SHIPPING ADDRESS
	if (shipping == "useshipping") {			
		fnametoship = document.address.elements['fnametoship'].value;
		mitoship = document.address.elements['mitoship'].value;
		lnametoship = document.address.elements['lnametoship'].value;
		jobtitletoship = document.address.elements['jobtitletoship'].value;
		companytoship = document.address.elements['companytoship'].value;
		countrytoship = document.address.elements['countrytoship'].value;
		addresstoship = document.address.elements['addresstoship'].value;
		citytoship = document.address.elements['citytoship'].value;
		statetoship = document.address.elements['shipStateSelect'].value;
		ziptoship = document.address.elements['ziptoship'].value;
		phonetoship = document.address.elements['phonetoship'].value;
		emailtoship = document.address.elements['emailtoship'].value;
		
		if (fnametoship == '') {
			alert("Please enter a First Name under Shipping Information.");
			document.address.elements['fnametoship'].focus();
			return false;
		} else if (lnametoship == '') {
			alert("Please enter a Last Name under Shipping Information.");
			document.address.elements['lnametoship'].focus();
			return false;
		} else if (jobtitletoship == '') {
			alert("Please enter Job Title under Shipping Information.");
			document.address.elements['jobtitletoship'].focus();
			return false;
		} else if (companytoship == '') {
			alert("Please enter Company Name under Shipping Information.");
			document.address.elements['companytoship'].focus();
			return false;
		} else if (countrytoship == '') {
			alert("Please select the Country your order will be shipped to.");
			document.address.elements['countrytoship'].focus();
			return false;				
		} else if (addresstoship == '') {
			alert("Please enter the Shipping Address.");
			document.address.elements['addresstoship'].focus();
			return false;
		} else if (citytoship == '') {
			alert("Please enter the Shipping City.");
			document.address.elements['citytoship'].focus();
			return false;
		} else if (statetoship == '') {
			alert("Please enter the Shipping State.");
			document.address.elements['shipStateSelect'].focus();
			return false;
		} else if (ziptoship == '') {
			alert("Please enter the ZIP/Postal Code your order will be shipped to.");
			document.address.elements['ziptoship'].focus();
			return false;
		} else if ( countrytoship== "US" && ziptoship.length != 5 ){
			alert("Please enter a valid 5-digit ZIP/Postal Code for your shipping information.");
			document.address.elements['ziptoship'].focus();
			return false;
		} else if ( countrytoship!= "US" && ziptoship.length >= 10 ){
			alert("Please enter a valid ZIP/Postal Code for non US resident. It must be less or equal than 10 characters.");
			document.address.elements['ziptoship'].focus();
			return false;
		}  else if ( countrytoship== "US" ) {
			if ( validZip(ziptoship) ) {
				alert("This Shipping ZIP/Postal Code does not appear to be valid for your shipping information.");
				document.address.elements['ziptoship'].focus();
				return false;
			}		
		/*} else if (emailtoship == '') {
			alert("Please enter your shipping Email address.");
			document.address.elements['emailtoship'].focus();
			return false;*/
		} else if (emailtoship != '' && !validateEmail(emailtoship)) {
			alert("Your shipping Email address does not seem to be valid.");
			document.address.elements['emailtoship'].focus();
			return false;
		}
		
		if (phonetoship == '') {
			alert("Please enter your shipping Phone number.");
			document.address.elements['phonetoship'].focus();
			return false;	
		} else if (country == "US" && phonetoship.length < 11) {
			alert("This Phone number does not appear to be valid for your shipping information.");
			document.address.elements['phonetoship'].focus();
			return false;	
		}
	}
	
	// Check credit card information
	if (checkCC == "checkCC") {
		cardnum = document.address.elements['cardnum'].value;
		frombillform = document.address.elements['frombillform'].value;
				
		// frombillform = 1, this comes from billingform.php and billingform_noshipping.php, have to validate form
		if(frombillform == 1) {
			if (!validateCC()) {
				return false;
			}
		} else if(frombillform == 0) {
		// frombillform = 0, this comes from _edit_billAddr.php
			backto = document.address.elements['backto'].value;
			if (cardnum != "") {
				if (!validateCC()) {
					return false;
				}
			} else { 
				if(backto == "checkout-now"){
				// If from checkout-now.php, it will always check the credit card info
					if (!validateCC()) {
							return false;
					}
				}else{
				// This will backto account info ,billingform.php or billingform_noshipping.php
					// if ccdonotsave is not checked, that means user want to save credit card, 
					// then we need to validate the form
					if(!(document.address.elements['donotsavecc'].checked)){
						if (!validateCC()) {
							return false;
						}
					}
				}
			}
		} 
	}

	// customer would like to register, validate the email and password 
	if (user == "newreguser" || user == "newuser") {
		member_email = document.address.elements['member_email'].value;
		password = document.address.elements['password'].value;
		password2 = document.address.elements['password2'].value;
		
		// newreguser only use in _register.php, customer have to type in login email and password, so we need to validate here
		if (member_email == "" && user == "newreguser") {
			// only _register.php will use this case
			alert("Please enter an Email address for creating an account.");
			document.address.elements['member_email'].focus();
			return false;
		} else if (member_email != "") { // validate email and password if they exist
			// both _register.php, _billingform.php & _billingform_noshipping.php will use whenever the email exists
			return validateRegister(member_email, password, password2);
		} 
	}
		
	return true;
}

function existCC(tmpcardnum, backto) {
	if (backto == "checkout") {
		if (tmpcardnum == "") {
			alert("You have not saved credit card information to this billing address.\nPlease click edit to add your credit card information to this address and continue your checkout.");
			return false;
		}
	}	
	return true;
}

function existAddr(checkCC, shipping) {
	
	hasBillAddr = document.address.elements['hasBillAddr'].value;
	
	if (shipping == "useshipping") {
		
		hasShipAddr = document.address.elements['hasShipAddr'].value;
		if(hasBillAddr==0) {
			alert("Please add a billing address under Billing Information.");
			document.address.elements['hasBillAddr'].focus();
			return false;
		}	
		if(hasShipAddr==0) {
			alert("Please add a shipping address under Shipping Information.");
			document.address.elements['hasShipAddr'].focus();
			return false;
		}
		
		// Check credit card information
		if (checkCC == "checkCC") {
			if (!validateCC()) {
				return false;
			} 
		}
	} else if (shipping == "noshipping") {
		// only billingform_noshipping will use this case
		// hasBillAddr = 1 means billing address exist, just check Credit card info only
		if (checkCC == "checkCC" && hasBillAddr == 1) {
			if (!validateCC()) {
				return false;
			} 
		}
	}
	
	return true;
}

function load()
{
	if (document.address.elements['country'].value == 'US') {
		document.address.elements['pobox'].disabled=false;
	} else {
		document.address.elements['pobox'].checked=false;
		document.address.elements['pobox'].disabled=true;
	}
	
	// HAS SHIPPING ADDRESS
	if (shipping == "useshipping") {
		if (document.address.elements['countrytoship'].value == 'US') {
			document.address.elements['poboxtoship'].disabled=false;
		} else {
			document.address.elements['poboxtoship'].checked=false;
			document.address.elements['poboxtoship'].disabled=true;
		}
	}	
}

function validateEmail(a_string) {
	if (validEMail(trim(a_string)) == false) {
		return false;
	}
	return true;	
}

function validEMail(a_string) {     
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(a_string)) {
		return true;
	} else {
		return false;
	}
}

function validateRegister(member_email, password, password2) {
	if (!validateEmail(member_email)) {
		alert("Your Create an Account email address does not seem to be valid.");
		document.address.elements['member_email'].focus();
		return false;
	} else if (password == '') {
		alert("Please enter your password.");
		document.address.elements['password'].focus();
		return false;
	} else if(password2 == ''){
		alert("Please enter the same password in both Password fields.");
		document.address.elements['password2'].focus();
		return false;
	} else if(validPWD(password)){	
		alert("Your password pattern does not seem to be valid.");
		document.address.elements['password'].focus();
		return false;
	} else if(validPWD(password2)){
		alert("Please enter the same password in both Password fields.");
		document.address.elements['password2'].focus();
		return false;
	}
	if (password != password2) {
		alert("Please enter the same password in both Password fields.");
		document.address.elements['password'].focus();
		return false;
	}
}

function make_blank() {
	document.address.cardnum.value ="";
}

function validateCC() {
	cardnum = document.address.elements['cardnum'].value;
	cardtype = document.address.elements['cardtype'].value;
	expmonth = document.address.elements['expmonth'].value;
	expyear = document.address.elements['expyear'].value;
	
	if (cardtype == 0) { 
		//errorMessage = errorMessage + "Please select the Card Type of your credit card.\n\r"; 
		alert("Please select the Card Type of your credit card.");
		document.address.elements['cardtype'].focus();
		return false;
	}  

	if (cardnum == "") { 
		//errorMessage = errorMessage + "Please select the Card Type of your credit card.\n\r"; 
		alert("Please enter the Card Number of your credit card.");
		document.address.elements['cardnum'].focus();
		return false;
	} 
		
	if (cardnum.substring(0,8) != "********" ) {
		if (cardtype == 1) {
			//Visa
			if(cardnum.length != 13 && cardnum.length != 16){
				alert("Please enter 13 or 16 digits for your Visa Card.");
				document.address.elements['cardtype'].focus();
				return false;
			}
		} else if(cardtype == 2){
			//Master
			if(cardnum.length != 16){
				alert("Please enter 16 digits for your Master Card.");
				document.address.elements['cardtype'].focus();
				return false;
			}	
		} else if(cardtype == 3){
			//American Express
			if(cardnum.length != 15){
				alert("Please enter 15 digits for your American Express Card.");
				document.address.elements['cardtype'].focus();
				return false;
			}
		}
		
		if (!validateCCnum(cardtype, cardnum)) {
			alert("Your Card Number does not match your card type.\nPlease make sure you have entered the correct credit card information.");
			return false;		
		}
	}	
												
	if (expmonth == "NULL") { 
		//errorMessage = errorMessage + "Please select the Card Type of your credit card.\n\r"; 
		alert("Please select the Expiration Month of your credit card.");
		document.address.elements['expmonth'].focus();
		return false;
	}

	if (expyear == "NULL") { 
		//errorMessage = errorMessage + "Please select the Card Type of your credit card.\n\r"; 
		alert("Please select the Expiration Year of your credit card.");
		document.address.elements['expyear'].focus();
		return false;
	}
	return true;
}

function trim(str) {
	return( (""+str).replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/,'$1') ); 
}
function validPWD(a_string)
{       
	//var filter  = /[a-zA-Z0-9]{4,8}/;
	var filter = /^(?=.*[0-9]+.*)(?=.*[a-zA-Z]+.*)[0-9a-zA-Z]{6,10}$/;
	if (filter.test(a_string)) {
		return false;
	} else {
		return true;
	}
	//$regexp = "/^[^0-9][A-z0-9_]+([.][A-z0-9_]+)*[@][A-z0-9_]+([.][A-z0-9_]+)*[.][A-z]{2,4}$/"; email
}
function validZip(a_string)
{       
	//var filter  = /[a-zA-Z0-9]{4,8}/;
	var filter  = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
	if (filter.test(a_string)) {
		return false;
	} else {
		return true;
	}
	//$regexp = "/^[^0-9][A-z0-9_]+([.][A-z0-9_]+)*[@][A-z0-9_]+([.][A-z0-9_]+)*[.][A-z]{2,4}$/"; email
}

function validateCCnum(type, ccnum) {
	if (type == 1) {  // Visa: length 16, prefix 4, dashes optional.      
		var num = /^4[0-9]{12}(?:[0-9]{3})?$/;				
	} else if (type == 2) {  // Mastercard: length 16, prefix 51-55, dashes optional.
		var num = /^5[1-5][0-9]{14}$/;		
	} else if (type == 3) {  // American Express: length 15, prefix 34 or 37.     
		var num = /^3[47][0-9]{13}$/;		
	}
	//Checking if the number that pass in match our regular expression
	if (!num.test(ccnum)) return false; else return true;

	return true;
}


function blockfill() {
	if (document.address.samewithbilling.value == "on") {

		document.address.fnametoship.value = document.address.fname.value;
		document.address.mitoship.value = document.address.mi.value;
		document.address.lnametoship.value = document.address.lname.value;
		document.address.jobtitletoship.value = document.address.jobtitle.value;
		document.address.companytoship.value = document.address.company.value; 
		document.address.countrytoship.value = document.address.country.value;
		document.address.addresstoship.value = document.address.address.value;
		document.address.address2toship.value = document.address.address2.value;
		document.address.poboxtoship.checked = document.address.pobox.checked;
		document.address.citytoship.value = document.address.city.value; 
				
		updateStatetoship( "shipCountrySelect" );
		
		document.address.shipStateSelect.value = document.address.billStateSelect.value;
		document.address.ziptoship.value = document.address.zip.value;
		document.address.phonetoship.value = document.address.phone.value;
		document.address.exttoship.value = document.address.ext.value;
		document.address.emailtoship.value = document.address.email.value;
		
	} 

}
-->
