function validateCreditForm() {
	var isError = false;
	var curDate = new Date();
	var ccTypes = new Array();
	ccTypes[0] = "NA";
	ccTypes[1] = "Visa";
	ccTypes[2] = "MasterCard";
	ccTypes[3] = "AmEx";
	ccTypes[4] = "Discover";


	if( document.getElementById('CVV').value.length == 0 || !isCCVNumber(document.getElementById('CVV').value) ) {
		isError = true;
		document.getElementById('RequiredTextValidator9').style.visibility = 'visible';
	} else {
		document.getElementById('RequiredTextValidator9').style.visibility = 'hidden';
	}

	if( document.getElementById('CCNumber').value.length == 0 || !isNumber(document.getElementById('CCNumber').value) ) {
		isError = true;
		document.getElementById('RequiredTextValidator8').style.visibility = 'visible';
	} else {
		document.getElementById('RequiredTextValidator8').style.visibility = 'hidden';
	}

	if( ccTypes[document.getElementById('ddlCardType').options[document.getElementById('ddlCardType').selectedIndex].value] == "NA" ) {
		isError = true;
		document.getElementById('SelectedIndexValidator1').style.visibility = 'visible';
	} else {
		document.getElementById('SelectedIndexValidator1').style.visibility = 'hidden';
	}

	if( document.getElementById('tbCardNameOn').value.length == 0 ) {
		isError = true;
		document.getElementById('RequiredTextValidator7').style.visibility = 'visible';
	} else {
		document.getElementById('RequiredTextValidator7').style.visibility = 'hidden';
	}

	if( !isError ) {
		if( !checkCreditCard(document.getElementById('CCNumber').value, ccTypes[document.getElementById('ddlCardType').options[document.getElementById('ddlCardType').selectedIndex].value] ) ) {
			isError = true;
			document.getElementById('RequiredTextValidator8').style.visibility = 'visible';
		} else {
			document.getElementById('RequiredTextValidator8').style.visibility = 'hidden';
		}
	}

	var formYear = parseInt("20"+document.getElementById('ddlCardExpYear').options[document.getElementById('ddlCardExpYear').selectedIndex].value);
	var formMonth = parseInt(document.getElementById('ddlCardExpMonth').options[document.getElementById('ddlCardExpMonth').selectedIndex].value);
	//alert('year: ' + formYear + ', month: '+formMonth + ', '+document.getElementById('ddlCardExpYear').options[document.getElementById('ddlCardExpYear').selectedIndex].value+', '+parseInt(document.getElementById('ddlCardExpYear').options[document.getElementById('ddlCardExpYear').selectedIndex].value));
	if( parseInt(formYear) < curDate.getFullYear() ) {
		isError = true;
		document.getElementById('RequiredTextValidator23').style.visibility = 'visible';
	} else {
		if( parseInt(formYear) == curDate.getFullYear() ) {
			if( parseInt(formMonth) < (curDate.getMonth() + 1) ) {
				isError = true;
				document.getElementById('RequiredTextValidator23').style.visibility = 'visible';
			} else {
				// everything is ok
				document.getElementById('RequiredTextValidator23').style.visibility = 'hidden';
			}
		} else {
			// everything is ok
			document.getElementById('RequiredTextValidator23').style.visibility = 'hidden';
		}
	}

	if( document.getElementById('txt_password').value.length < 6 || document.getElementById('txt_confirm').value.length < 6 ) {
		isError = true;
		document.getElementById('RequiredTextValidator20').style.visibility = 'visible';
		document.getElementById('RequiredTextValidator21').style.visibility = 'visible';
	} else {
		//if( document.getElementById('txt_password').value != document.getElementById('txt_confirm').value ) {
		//	isError = true;
		//	document.getElementById('RequiredTextValidator20').style.visibility = 'visible';
		//	document.getElementById('RequiredTextValidator21').style.visibility = 'visible';
		//} else {
			document.getElementById('RequiredTextValidator20').style.visibility = 'hidden';
			document.getElementById('RequiredTextValidator21').style.visibility = 'hidden';
		//}
	}

	if( document.getElementById('txt_firstName').value.length == 0 ) {
		document.getElementById('RequiredTextValidator31').style.visibility = "visible";
		isError = true;
	} else {
		document.getElementById('RequiredTextValidator31').style.visibility = "hidden";
	}

	/* Validate the last name field, this just makes sure we have something in this field */
	if( document.getElementById('txt_lastName').value.length == 0 ) {
		document.getElementById('Requiredtextvalidator32').style.visibility = "visible";
		isError = true;
	} else {
		document.getElementById('Requiredtextvalidator32').style.visibility = "hidden";	
	}

	/* Validate the address field, this just makes sure we have something in this field */
	if( document.getElementById('txt_address1').value.length == 0 ) {
		document.getElementById('Requiredtextvalidator33').style.visibility = "visible";
		isError = true;
	} else {
		document.getElementById('Requiredtextvalidator33').style.visibility = "hidden";
	}

	/* Validate the city field, this just makes sure we have something in this field */
	if( document.getElementById('txt_city').value.length == 0 ) {
		document.getElementById('Requiredtextvalidator34').style.visibility ="visible";
		isError = true;
	} else {
		document.getElementById('Requiredtextvalidator34').style.visibility ="hidden";
	}

	if( document.getElementById('txt_zip').value.length == 0 || !isValidZip(document.getElementById('txt_zip').value) ) {
		document.getElementById('Requiredtextvalidator36').style.visibility = "visible";
		isError = true;
	} else {
		document.getElementById('Requiredtextvalidator36').style.visibility = "hidden";
	}

	if( !isValidPhone(document.getElementById('txt_phoneArea').value, document.getElementById('txt_phoneDir').value, document.getElementById('txt_phone2').value) ) {
		document.getElementById('MultiConditionValidator32').style.visibility = "visible";
		isError = true;
	} else {
		document.getElementById('MultiConditionValidator32').style.visibility = "hidden";
		document.getElementById('Phone1').value = document.getElementById('txt_phoneArea').value+"-"+document.getElementById('txt_phoneDir').value+"-"+document.getElementById('txt_phone2').value;
	}

	if( !isValidEmail(document.getElementById('txt_email').value) ) {
		document.getElementById('Requiredtextvalidator37').style.visibility = "visible";
		isError = true;
	} else {
		document.getElementById('Requiredtextvalidator37').style.visibility = "hidden";
	}

	if( document.getElementById('ddl_state').options[document.getElementById('ddl_state').selectedIndex].value == "NA" ) {
		document.getElementById('Requiredtextvalidator310').style.visibility = "visible";
		isError = true;
	} else {
		document.getElementById('Requiredtextvalidator310').style.visibility = "hidden";
	}

	return !isError;
}

function validateForm() {
	var isError = false;

	/* Validate the first name field, this just makes sure we have something in this field */
	if( document.getElementById('txt_firstName').value.length == 0 ) {
		document.getElementById('RequiredTextValidator1').style.visibility = "visible";
		isError = true;
	} else {
		document.getElementById('RequiredTextValidator1').style.visibility = "hidden";
	}

	/* Validate the last name field, this just makes sure we have something in this field */
	if( document.getElementById('txt_lastName').value.length == 0 ) {
		document.getElementById('Requiredtextvalidator2').style.visibility = "visible";
		isError = true;
	} else {
		document.getElementById('Requiredtextvalidator2').style.visibility = "hidden";	
	}

	/* Validate the address field, this just makes sure we have something in this field */
	if( document.getElementById('txt_address1').value.length == 0 ) {
		document.getElementById('Requiredtextvalidator3').style.visibility = "visible";
		isError = true;
	} else {
		document.getElementById('Requiredtextvalidator3').style.visibility = "hidden";
	}

	/* Validate the city field, this just makes sure we have something in this field */
	if( document.getElementById('txt_city').value.length == 0 ) {
		document.getElementById('Requiredtextvalidator4').style.visibility ="visible";
		isError = true;
	} else {
		document.getElementById('Requiredtextvalidator4').style.visibility ="hidden";
	}

	if( document.getElementById('txt_zip').value.length == 0 || !isValidZip(document.getElementById('txt_zip').value) ) {
		document.getElementById('Requiredtextvalidator6').style.visibility = "visible";
		isError = true;
	} else {
		document.getElementById('Requiredtextvalidator6').style.visibility = "hidden";
	}

	if( !isValidPhone(document.getElementById('txt_phoneArea').value, document.getElementById('txt_phoneDir').value, document.getElementById('txt_phone2').value) ) {
		document.getElementById('MultiConditionValidator2').style.visibility = "visible";
		isError = true;
	} else {
		document.getElementById('MultiConditionValidator2').style.visibility = "hidden";
	}

	if( !isValidEmail(document.getElementById('txt_email').value) ) {
		document.getElementById('Requiredtextvalidator7').style.visibility = "visible";
		isError = true;
	} else {
		document.getElementById('Requiredtextvalidator7').style.visibility = "hidden";
	}

	if( document.getElementById('ddl_state').options[document.getElementById('ddl_state').selectedIndex].value == "NA" ) {
		document.getElementById('Requiredtextvalidator10').style.visibility = "visible";
		isError = true;
	} else {
		document.getElementById('Requiredtextvalidator10').style.visibility = "hidden";
	}
	//alert("ERROR!");
	return !isError;
}


function validateForm2() {
	var isError = false;

	/* Validate the first name field, this just makes sure we have something in this field */
	if( document.getElementById('txt_firstName').value.length == 0 ) {
		document.getElementById('RequiredTextValidator1').style.visibility = "visible";
		isError = true;
	} else {
		document.getElementById('RequiredTextValidator1').style.visibility = "hidden";
	}

	if( !isValidEmail(document.getElementById('txt_email').value) ) {
		document.getElementById('Requiredtextvalidator7').style.visibility = "visible";
		isError = true;
	} else {
		document.getElementById('Requiredtextvalidator7').style.visibility = "hidden";
	}
	//alert("ERROR!");
	return !isError;
}


function isCCVNumber(value) {
	var re = /^\d{3}$/;
	var re4 = /^\d{4}$/;
	if( value.length > 4 || value.length < 3 ) {
		return false;
	}
	return (re.test(value) || re4.test(value));
}

function isNumber(value) {
	var re = /^\d+$/;
	return (re.test(value));
}

function isValidZip(value) {
   var re = /^\d{5}([\-]\d{4})?$/;
   return (re.test(value));
}

function isValidPhone(p1, p2, p3) {
	var re3 = /^\d{3}$/;
	var re4 = /^\d{4}$/;
	return (re3.test(p1) && re3.test(p2) && re4.test(p3));
}

function isValidEmail(str){
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	return reg.test(str);
}

