function validateForm(formName) {

	var frm = eval('document.' + formName);
	var checkEmail = false;
	var checkEmailConfirm = false;

	if (isBlankField(frm.firstName)) {
		alert(frm.firstName.title + " is required.");
		frm.firstName.focus();
		return false;
	}

	if (isBlankField(frm.lastName)) {
		alert(frm.lastName.title + " is required.");
		frm.lastName.focus();
		return false;
	}

	if (isBlankField(frm.email1)) {
		alert(frm.email1.title + " is required.");
		frm.email1.focus();
		return false;
	}

	if(isEmailValid(frm.email1.value) == false){
		alert("Please enter a valid e-mail address");
		frm.email1.focus();
		return false;
	}

	if (isBlankField(frm.email2)) {
		alert(frm.email2.title + " is required.");
		frm.email2.focus();
		return false;
	}

	if(isEmailValid(frm.email2.value) == false){
		alert("Please enter a valid e-mail address");
		frm.email2.focus();
		return false;
	}

	if (frm.email1.value != frm.email2.value) {
		alert("Your confirm email does not match the email entered.  Please try again");
		frm.email1.focus();
		return false;
	}

	if(validateDate(frm.dobYear, frm.dobMonth, frm.dobDay) == false){
		return false;
	}/*else{
		if(isOfAge(frm.dobYear, frm.dobMonth, frm.dobDay) == false)
			return false;
	}*/

	var myOption = -1;
	for (i=frm.gender.length-1; i > -1; i--) {
		if (frm.gender[i].checked) {
			myOption = i; i = -1;
		}
	}

	if (myOption == -1) {
		alert("Gender is required.");
		return false;
	}

	if (isBlankField(frm.address1)) {
		alert(frm.address1.title + " is required.");
		frm.address1.focus();
		return false;
	}

	if (isBlankField(frm.city)) {
		alert(frm.city.title + " is required.");
		frm.city.focus();
		return false;
	}

	if (isBlankField(frm.state)) {
		alert(frm.state.title + " is required.");
		frm.state.focus();
		return false;
	}

	if(! isNumeric(frm.zip.value)){
		alert("Please enter numeric data for " + frm.zip.title);
		frm.zip.focus();
		return false;
	}

	frm.zip.value = trim(frm.zip.value);
	if(frm.zip.value.length < 5){
		alert("Please enter the correct " + frm.zip.title);
		return false;
	}

	if(checkBrushBrand(frm.brushBrand) == false)
		return false;


}
	function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
	}

	function readCookie(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}

	function isBlankField(field) {
		if (field.type == "checkbox") {
			if (field.checked) {
				return false;
			} else {
				return true;
			}
		}else if(field.type == "select-one"){
			if(field[field.selectedIndex].text == "" || field[field.selectedIndex].value == ""){
				return true;
			}else{
				return false;
			}
		} else {
			field.value = trim(field.value);
			if (field.value=="" || field.value==null)
				return true;
			else
				return false;
		}
	}

	function trim(strText) {
  // this will get rid of leading spaces
  	while (strText.substring(0,1) == ' ') {
    	strText = strText.substring(1, strText.length);
    }

    // this will get rid of trailing spaces
    while (strText.substring(strText.length-1,strText.length) == ' ') {
    	strText = strText.substring(0, strText.length-1);
    }
  	return strText;
	}

	function isNumeric(val) {
		if (isNaN(parseFloat(val))) {
			return false;
	 	}
		return true;
	}

	function isEmailValid(val){
		var atPos = val.indexOf('@',0);
		// must contain an @
		if (atPos == -1) { return false; }
 		// must not start with @
		if (atPos == 0) { return false;	}
		// must contain only one @
		if (val.indexOf('@', atPos + 1) > - 1) { return false; }
		// must contain a period in the domain name
		if (val.indexOf('.', atPos) == -1) { return false; }
		// period must not immediately follow @ in email address
		if (val.indexOf('@.',0) != -1) { return false; }
		// period must not immediately precede @ in email address
		if (val.indexOf('.@',0) != -1){ return false; }
		// must not have 2 periods one after another
		if (val.indexOf('..',0) != -1) { return false; }
		// must have a valid primary domain in the email address
		var suffix = val.substring(val.lastIndexOf('.')+1);
		if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {return false;}
		return true;
	}

	function checkBrushBrand(field) {
		if (field.value == "" || field.value == "BATTERY/ELECTRIC TOOTHBRUSH" || field.value == "MANUAL TOOTHBRUSH"){
			alert("Please select a toothbrush");
			return false;
		} else {
			return true;
		}
	}

	function validateDate(year,month,day) {
    var val = month.value + "/" + day.value + "/" + year.value;
		var RegExPattern = /^(?=\d)(?:(?:(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})|(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))|(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2}))($|\ (?=\d)))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$/;
    var errorMessage = 'Please enter valid date as month, day, and four digit year.\nYou may use a slash, hyphen or period to separate the values.\nThe date must be a real date. 2-30-2000 would not be accepted.\nFormay mm/dd/yyyy.';
    if (val.match(RegExPattern)) {
        //
    } else {
    	alert("Please enter a valid Date of Birth.");
			return false;
    }
	}

	function isOfAge(year,month,day){
		var userDate=new Date(year.value,month.value-1,day.value)
		var todaysDate =  new Date();
		if(year.value!="" && month.value != "" && day.value != "") {
			todaysDate.setYear(todaysDate.getYear()-13)
			if(userDate > todaysDate){
				createCookie("underAge","true",30);
				document.location.href="error.asp?source=&error=age";
				//alert("You must be 13 years of age or older to continue.");
				return false;
			}else{
				return true;
			}
		}
	}




//Updates the Quantity Select to show only up to the maximum available quantity of the selected item, or 10, whichever is smaller
function updateSlave() {
options = new Array();

options[0] = new Array();
options[0][1] = "Select Type";

options[1] = new Array();
options[1][1] = "Flex";
options[1][2] = "Flex Direct";
options[1][3] = "Flex Tip";
options[1][4] = "Max Active";
options[1][5] = "Other";

options[2] = new Array();
options[2][1] = "Gum Base Brush";
options[2][2] = "Gum Brush";
options[2][3] = "Gum Micro Tip";
options[2][4] = "Gum Technique";
options[2][5] = "Gum Super Tip";
options[2][6] = "Tooth N Tongue";
options[2][7] = "Other";

options[3] = new Array();
options[3][1] = "360";
options[3][2] = "Active Angle";
options[3][3] = "Classic";
options[3][4] = "Kids";
options[3][5] = "Massager";
options[3][6] = "Motion";
options[3][7] = "Navigator";
options[3][8] = "Other (Battery Powered)";
options[3][9] = "Other (Manual)";
options[3][10] = "Plus";
options[3][11] = "Total";
options[3][12] = "Wave";
options[3][13] = "Whitening";

options[4] = new Array();
options[4][1] = "Clean Expressions";
options[4][2] = "Complete";
options[4][3] = "Deep Clean Active Clean";
options[4][4] = "Deep Clean Gum Care";
options[4][5] = "Deep Clean Sensitivity";
options[4][6] = "Deep Clean Whitening";
options[4][7] = "Flex Head";
options[4][8] = "Kids";
options[4][9] = "Massage Plus";
options[4][10] = "MultiCare";
options[4][11] = "Other (Manual)";
options[4][12] = "SpinBrush Classic";
options[4][13] = "SpinBrush Kids";
options[4][14] = "SpinBrush MultiAngle";
options[4][15] = "SpinBrush Other";
options[4][16] = "SpinBrush Pro";
options[4][17] = "SpinBrush Pro Whitening";
options[4][18] = "Triple Effect";

options[5] = new Array();
options[5][1] = "Base";
options[5][2] = "Other";
options[5][3] = "Procare";
options[5][4] = "White & Clean";

options[6] = new Array();
options[6][1] = "Professional Care";
options[6][2] = "Sonic Complete";
options[6][3] = "AdvancePower";
options[6][4] = "Advantage";
options[6][5] = "Advantage Arctica";
options[6][6] = "Advantage Breath Refresh";
options[6][7] = "Advantage Glide";
options[6][8] = "Advantage Plus";
options[6][9] = "Advantage Sensitive";
options[6][10] = "Advantage Tongue Cleaner";
options[6][11] = "Battery Brush";
options[6][12] = "CrossAction";
options[6][13] = "CrossAction Power";
options[6][14] = "CrossAction Vitalizer";
options[6][15] = "Indicator";
options[6][16] = "Indicator Deep Clean";
options[6][17] = "Other (Manual)";
options[6][18] = "Other (Electric)";
options[6][19] = "Pulsar";
options[6][20] = "Pulsar Pro-Health";
options[6][21] = "Stages";
options[6][22] = "Triumph";
options[6][23] = "Vitality";

options[7] = new Array();
options[7][1] = "Battery Toothbrush";
options[7][2] = "Electric Toothbrush";
options[7][3] = "Manual Toothbrush";

options[8] = new Array();
options[8][1] = "Advanced Design";
options[8][2] = "Base";
options[8][2] = "Clean and Whiten";
options[8][3] = "Max";
options[8][4] = "Max Brightener";
options[8][5] = "Max Fresh & Clean";
options[8][6] = "Max Tooth & Gum";
options[8][7] = "Other";
options[8][8] = "Plaque Sweeper";
options[8][9] = "Sponge Bob";
options[8][10] = "Ultra Clean";

options[9] = new Array();
options[9][1] = "Advance";
options[9][2] = "Elite";
options[9][3] = "Essence";
options[9][4] = "Intelliclean";
options[9][5] = "Other";


sel = document.getElementById('master').selectedIndex;
for (i=1; i<=50; i++) {
	document.getElementById('slave').remove(0);
}

for (i=1; i<options[sel].length; i++) {
	var o = document.createElement('option');
  	o.text = options[sel][i];

	  try
		{
		document.getElementById('slave').add(o, null); // standards compliant
		}
	  catch(ex)
		{
		document.getElementById('slave').add(o); // IE only
		}
}

document.getElementById('slave').selectedIndex = 0;
}
