function isAnEmail(entry)
{
	var re = /^\w[\w\.\-\_]+@[\w\.\-\_]+(\.\w+)+$/;
	if (!(re.test(entry)))
		return false;
	return true;
}
function sub_contact(chk) {

	var name = chk['info.name'];
	if (name.value == "" || name.value == null)
	{
		window.alert("Please enter your Name.");
		return false;
	} else {
		return true;
	}

}

function sub_form(chk)
{
	var name = chk['creditCardPayment.firstname'];
	if (name) {
		if (name.value == "" || name.value == null)
		{
			$("fname").innerHTML = "Please enter your First Name.";
			name.focus();
			return false;
		}
	}

	var lastname = chk['creditCardPayment.lastname'];
	if (lastname) {
		if (lastname.value == "")
		{
			$("lname").innerHTML = "Please enter your Last Name.";
			lastname.focus();
			return false;
		}
	}

	var country = chk['creditCardPayment.countryCode'];
	if (country) {
		if (country.value == "netset")
		{
			$("country").innerHTML = "Please select your Country.";
			country.focus();
			return false;
		}
	}

	var city = chk['creditCardPayment.city'];
	if (city) {
		if (city.value == "" || city.value == null)
		{
			$("city").innerHTML = "Please enter your City.";
			city.focus();
			return false;
		}
	}

	var state = chk['creditCardPayment.state'];
	if (state) {
		if (state.value == "state")
		{
			$("state").innerHTML = "Please select your State.";
			state.focus();
			return false;
		}
	}

	var street = chk['creditCardPayment.street'];
	if (street) {
		if (street.value == "" || street.value == null)
		{
			$("street").innerHTML = "Please enter your Street address.";
			street.focus();
			return false;
		}
	}

	var zip = chk['creditCardPayment.zip'];
	if (zip) {
		if (zip.value == "" || zip.value == null)
		{
			$("zip").innerHTML = "Please enter your Zip Code/Postal Code.";
			zip.focus();
			return false;
		}
	}

	var retailStore = chk['creditCardPayment.retailStore'];
	if (retailStore) {
		if (retailStore != null) {
			if (retailStore.value == "")
			{
				$("retailStore").innerHTML = "Please select where you purchased the workbook.";
				retailStore.focus();
				return false;
			}
		}
	}

	var email = chk['creditCardPayment.email'];
	if (email) {
		if (email.value == "")
		{
			$("email").innerHTML = "Please enter your Email.";
			email.focus();
			return false;
		} else if (!isAnEmail(email.value))
		{
			$("email").innerHTML = "Invalid Email format.";
			email.focus();
			return false;
		}
	}

	var reconfirmemail = chk['reconfirmemail'];
	if (reconfirmemail) {
		if (reconfirmemail.value == '')
		{
			$("errorConfirmEmail").innerHTML = "Please confirm your Email.";
			reconfirmemail.focus();
			return false;
		}
		if (reconfirmemail.value != email.value)
		{
			$("errorConfirmEmail").innerHTML = "The Emails entered do not match.";
			reconfirmemail.focus();
			return false;
		}
	}

	var cardNo1 = chk['creditCardPayment.acct'];
	if (cardNo1) {
		var cardMatch = /^\d{16}$/;
		var cardNo = Trim(cardNo1.value)
		if (!cardNo.match(cardMatch))
		{
			$("errorCardNo").innerHTML = "Invalid Credit Card Number. Please enter 16 digits."
			cardNo1.focus();
			return false;
		}
		if (cardNo.value == "")
		{
			$("errorCardNo").innerHTML = "Please enter your Credit Card Number."
			cardNo1.focus();
			return false;
		}
	}

	var month = chk['epMonth'];
	if (month) {
		if (month.form.epMonth.value == 00)
		{
			$("errorMonth").innerHTML = "Please select the Month.";
			month.focus();
			return false;
		}
	}

	var year = chk['epYear'];
	if (year) {
		if (year.value == 0000)
		{
			$("errorYear").innerHTML = "Please select the Year.";
			year.focus();
			return false;
		}
	}
	
	return true;
}
//去除左边空格
function LTrim(str)
{
	var whitespace = new String("\t\n\r");
	var s = new String(str);

	if (whitespace.indexOf(s.charAt(0)) != -1)
	{
		var j = 0, i = s.length;
		while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
		{
			j++;
		}
		s = s.substring(j, i);
	}
	return s;
}

//去除右边空格
function RTrim(str)
{
	var whitespace = new String(" \t\n\r");
	var s = new String(str);

	if (whitespace.indexOf(s.charAt(s.length - 1)) != -1)
	{
		var i = s.length - 1;
		while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
		{
			i--;
		}
		s = s.substring(0, i + 1);
	}
	return s;
}
//去除两边的空格
function Trim(str)
{
	return RTrim(LTrim(str));
}
function checkFirstName(value)
{
	if (value != "")
	{
		$("fname").style.display = "none";
	}
	if (value == "")
	{
		$("fname").style.display = "block";
	}
}
function checkLastName(value)
{
	if (value != "")
	{
		$("lname").style.display = "none";
	}
	if (value == "")
	{
		$("lname").style.display = "block";
	}
}
function checkCountry(value)
{
	if (value != "netset")
	{
		$("country").style.display = "none";
	}
	if (value == "netset")
	{
		$("country").style.display = "block";
	}

	//	var stateList = $("creditCardPayment.state");
	//
	//	if (value == "US") {
	//		stateList.selectedIndex = 0;  // first element = Please select...
	//	}
	//	else {
	//		stateList.selectedIndex = stateList.length - 1;  // last element = Other
	//	}
}
function checkCity(value)
{
	if (value != "")
	{
		$("city").style.display = "none";
	}
	if (value == "")
	{
		$("city").style.display = "block";
	}
}
function checkState(value)
{
	if (value != "state")
	{
		$("state").style.display = "none";
	}
	if (value == "state")
	{
		$("state").style.display = "block";
	}
}
function checkStreet(value)
{
	if (value != "")
	{
		$("street").style.display = "none";
	}
	if (value == "")
	{
		$("street").style.display = "block";
	}
}
function checkZip(value)
{
	if (value != "")
	{
		$("zip").style.display = "none";
	}
	if (value == "")
	{
		$("zip").style.display = "block";
	}
}
function checkRetailStore(value)
{
	if (value != "")
	{
		$("retailStore").style.display = "none";
	}
	if (value == "")
	{
		$("retailStore").style.display = "block";
	}
}
function checkEmail(value)
{
	if (value != "" && isAnEmail(value))
	{
		$("email").style.display = "none";
	} else {
		$("email").style.display = "block";
	}
	//	if (!isAnEmail(value))
	//	{
	//		document.getElementById("email").style.display = "block";
	//	}
}
function checkAcct(value)
{
	var cardMatch = /^\d{16}$/;
	var v = Trim(value)
	if (value != "" && v.match(cardMatch))
	{
		$("errorCardNo").style.display = "none";
	} else
	{
		$("errorCardNo").style.display = "block";
	}
}
function checkReconfirmemail(confirmemail, email)
{
	if (confirmemail != "" && confirmemail == email)
	{
		$("errorConfirmEmail").style.display = "none";
	} else
	{
		$("errorConfirmEmail").style.display = "block";
	}
}
function checkMonth(value)
{
	if (value != 00)
	{
		$("errorMonth").style.display = "none";
	} else
	{
		$("errorMonth").style.display = "block";
	}
}
function checkYear(value)
{
	if (value != 0000)
	{
		$("errorYear").style.display = "none";
	} else
	{
		$("errorYear").style.display = "block";
	}
}