/* Onlilne Boosters copyright 2011, SuburbanSkies.com, Inc.*/
/* Version 5.0 */

function showBoosterAlt()
{
	/* tested successfully for SRS 09-14-08 */
	var altBox = document.getElementById('showAltBooster');
	if (altBox.checked == true)
	{
		document.getElementById('boosterAlt').style.display = 'block';
		document.getElementById('boosterAltAddress').style.display = 'block';
	}
	else if (altBox.checked == false)
	{
		document.getElementById('boosterAlt').style.display = 'none';
		document.getElementById('boosterAltAddress').style.display = 'none';
	}
}

function copyToEmerA()
{
	/* revised for SRS on 9-14-08 */
	var emerBox = document.getElementById('copyBoosterA'); 
	if (emerBox.checked == true)
	{
		var f = document.newBooster.firstnameA.value;
		var l = document.newBooster.lastnameA.value;
		var p = document.newBooster.phoneA.value;
		var c = document.newBooster.mobileA.value;
		document.newBooster.emer_first.value = f;
		document.newBooster.emer_last.value = l;
		document.newBooster.emer_phone.value = p;
		document.newBooster.emer_mobile.value = c;		
	} 
	else if (emerBox.checked == false)
	{
		document.newBooster.emer_first.value = "";
		document.newBooster.emer_last.value = "";
		document.newBooster.emer_phone.value = "";
		document.newBooster.emer_mobile.value = "";
	}
}
function copyToEmerB()
{
	/* revised for SRS on 9-14-08 */
	var emerBox = document.getElementById('copyBoosterB'); 
	if (emerBox.checked == true)
	{
		var f = document.newBooster.firstnameB.value;
		var l = document.newBooster.lastnameB.value;
		var p = document.newBooster.phoneB.value;
		var c = document.newBooster.mobileB.value;
		document.newBooster.emer_first.value = f;
		document.newBooster.emer_last.value = l;
		document.newBooster.emer_phone.value = p;
		document.newBooster.emer_mobile.value = c;		
	} 
	else if (emerBox.checked == false)
	{
		document.newBooster.emer_first.value = "";
		document.newBooster.emer_last.value = "";
		document.newBooster.emer_phone.value = "";
		document.newBooster.emer_mobile.value = "";
	}
}
function copyToBAdd()
{
	/* revised for SRS on 9-14-08 */
	var addBox = document.getElementById('copyBoosterAAdd'); 
	if (addBox.checked == true)
	{
		var sn = document.newBooster.stNumA.value;
		var sr = document.newBooster.streetA.value;
		var cy = document.newBooster.cityA.value;
		var ct = document.newBooster.countyA.value;
		var st = document.newBooster.stateA.value;
		var zip = document.newBooster.zipA.value;
		document.newBooster.stNumB.value = sn;
		document.newBooster.streetB.value = sr;
		document.newBooster.cityB.value = cy;
		document.newBooster.countyB.value = ct;		
		document.newBooster.stateB.value = st;		
		document.newBooster.zipB.value = zip;		
	} 
	else if (addBox.checked == false)
	{
		document.newBooster.stNumB.value = "";
		document.newBooster.streetB.value = "";
		document.newBooster.cityB.value = "";
		document.newBooster.countyB.value = "";		
		document.newBooster.stateB.value = "";		
		document.newBooster.zipB.value = "";		
	}
}

function newRegister(theForm)
{
	/* check for all the mandatory fields... */
	var reason = "";
	reason += validateBoosterAFirstName(theForm.firstnameA);
	reason += validateBoosterALastName(theForm.lastnameA);
	reason += validatePhoneCheck(theForm.phoneA);
	reason += validatePhoneCheck(theForm.mobileA);
	
	reason += validateBoosterBFirstName(theForm.firstnameB);
	reason += validateBoosterBLastName(theForm.lastnameB);
	reason += validatePhoneCheckB(theForm.phoneB);	
	reason += validatePhoneCheckB(theForm.mobileB);	

	reason += validateClean(theForm.relationshipA, 'the relationship field of the primary booster.');

	reason += validateStNum(theForm.stNumA);
	reason += validateClean(theForm.streetA, 'the street name for the primary booster.');
	reason += validateClean(theForm.cityA, 'the city for the primary booster.');
	reason += validateClean(theForm.countyA, 'the county name for the primary booster.');
	reason += validateEmpty(theForm.stateA, "State");
	reason += validateClean(theForm.zipA, 'the zipcode for the primary booster.');
	
	reason += validateEmerFirstName(theForm.emer_first);
	reason += validateEmerLastName(theForm.emer_last);
	reason += validatePhoneCheck(theForm.emer_phone);	
	reason += validatePhoneCheck(theForm.emer_mobile);	
	reason += validateClean(theForm.relationshipC, 'the relationship field of the emergency contact.');
	
	reason += validateClean(theForm.orgList), 'your Primary Club where you will be playing.';		
	
	reason += validate18box(theForm.of_age);
	reason += validateEmail(theForm.myusername);

	reason += validatePassword(theForm.password);
	reason += validatePasswordConfirm(theForm.confirm_password);

	reason += validateClean(theForm.secret_word, 'your security phrase, in case you forget your password.');

	reason += validateAltEmail(theForm.alt_email);
	reason += validateAltEmail(theForm.alt_email2);
	reason += validateAltEmail(theForm.alt_email3);
	
	if (reason != "") {
		alert("Some fields need correction:\n" + reason);
	}
	else
	{
		if (theForm.password.value == theForm.confirm_password.value)
		{
			alert("Congratulations! Thank You! All the information we need has been provided, and we are saving your membership now. You will be sent a confirmation e-mail with your account information for safe keeping. Now, we will go to the login page to get started!");
			
			var recdata = "";
			recdata += "firstnameA=" + theForm.firstnameA.value + ":";
			recdata += "lastnameA=" + theForm.lastnameA.value + ":";
			recdata += "phoneA=" + theForm.phoneA.value + ":";
			recdata += "mobileA=" + theForm.mobileA.value + ":";
			recdata += "firstnameB=" + theForm.firstnameB.value + ":";
			recdata += "lastnameB=" + theForm.lastnameB.value + ":";
			recdata += "phoneB=" + theForm.phoneB.value + ":";
			recdata += "mobileB=" + theForm.mobileB.value + ":";
			recdata += "relationshipA=" + theForm.relationshipA.value + ":";
			recdata += "relationshipB=" + theForm.relationshipB.value + ":";
			recdata += "stNumA=" + theForm.stNumA.value + ":";
			recdata += "streetA=" + theForm.streetA.value + ":";
			recdata += "cityA=" + theForm.cityA.value + ":";
			recdata += "countyA=" + theForm.countyA.value + ":";
			recdata += "stateA=" + theForm.stateA.value + ":";
			recdata += "zipA=" + theForm.zipA.value + ":";
			recdata += "stNumB=" + theForm.stNumB.value + ":";
			recdata += "streetB=" + theForm.streetB.value + ":";
			recdata += "cityB=" + theForm.cityB.value + ":";
			recdata += "countyB=" + theForm.countyB.value + ":";
			recdata += "stateB=" + theForm.stateB.value + ":";
			recdata += "zipB=" + theForm.zipB.value + ":";
			recdata += "emer_first=" + theForm.emer_first.value + ":";
			recdata += "emer_last=" + theForm.emer_last.value + ":";
			recdata += "emer_phone=" + theForm.emer_phone.value + ":";
			recdata += "emer_mobile=" + theForm.emer_mobile.value + ":";
			recdata += "relationshipC=" + theForm.relationshipC.value + ":";	
			recdata += "of_age=" + "over18" + ":";	
			recdata += "myusername=" + theForm.myusername.value + ":";	
			recdata += "password=" + theForm.password.value + ":";	
			recdata += "secret_word=" + theForm.secret_word.value + ":";	
			recdata += "primary_club=" + theForm.orgList.value + ":";
			recdata += "alt_email=" + theForm.alt_email.value + ":";
			recdata += "alt_email2=" + theForm.alt_email2.value + ":";
			recdata += "alt_email3=" + theForm.alt_email3.value + ":";
			
			/* alert(escape(recdata)); */
			
			var url = "/src/CreateMember.php";
			request.open("POST", url, true);
			request.onreadystatechange = CreateMemberResults;
			request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			request.send("dataset=" + escape(recdata));	
		} 
		else 
		{
			alert("Your password and confirmation do not match. Please correct this and re-submit the form.");
		}
	}
	
}

function CreateMemberResults()
{
  if (request.readyState == 4) {
    if (request.status == 200) {
      /* Get the response from the server */
      var results = request.responseText;
      if(results != "") {
      	if(results == "duplicate") {
      		alert("This e-mail already exists in the system. If you need to have your password sent to you, please use the password reminder form to have your password sent to your e-mail address. You can register with a different address by changing the e-mail address to something new. Remember, the e-mail address you use must be a valid, working e-mail address.");
      	} else {
			/* alert(results); */
			window.location = '/boosters';
	  		}
	  } else {
	  	
	  	alert("The server is busy at the moment, please try again.");
	  }
	  
    } else {
      alert("Error! Request status is " + request.status);
	}
  }
}

function TestCreateMemberResults()
{
  if (request.readyState == 4) {
    if (request.status == 200) {
      /* Get the response from the server */
      var results = request.responseText;
      if(results != "") {
      	
      	alert(results);
	  		
	  } else {
	  	alert("The server is busy at the moment, please try again.");
	  }
	  
    } else {
      alert("Error! Request status is " + request.status);
	}
  }
}



function doUpdateBooster(theForm)
{
		/* check for all the mandatory fields... */
		var reason = "";
		reason += validateBoosterAFirstName(theForm.firstnameA);
		reason += validateBoosterALastName(theForm.lastnameA);
		reason += validatePhoneCheck(theForm.phoneA);
		reason += validatePhoneCheck(theForm.mobileA);
		
		reason += validateBoosterBFirstName(theForm.firstnameB);
		reason += validateBoosterBLastName(theForm.lastnameB);
		reason += validatePhoneCheckB(theForm.phoneB);	
		reason += validatePhoneCheckB(theForm.mobileB);	
	
		reason += validateIllegal(theForm.relationshipA, 'the relationship field of the primary booster.');
		reason += validateIllegal(theForm.relationshipA, 'the relationship field of the alternate booster.');
	
		reason += validateStNum(theForm.stNumA);
		reason += validateIllegal(theForm.streetA, 'the street name for the primary booster.');
		reason += validateIllegal(theForm.cityA, 'the city for the primary booster.');
		reason += validateCounty(theForm.countyA, 'the county name for the primary booster.');
		reason += validateEmpty(theForm.stateA, "State");
		reason += validateIllegal(theForm.zipA, 'the zipcode for the primary booster.');
		
		reason += validateEmerFirstName(theForm.emer_first);
		reason += validateEmerLastName(theForm.emer_last);
		reason += validatePhoneCheck(theForm.emer_phone);	
		reason += validatePhoneCheck(theForm.emer_mobile);	
		reason += validateIllegal(theForm.relationshipC, 'the relationship field of the emergency contact.');
		
		/* reason += validateIllegal(theForm.orgList), 'your Primary Club where you will be playing.';		*/
	
		reason += validateAltEmail(theForm.altEmail);
		reason += validateAltEmail(theForm.altEmail2);
		reason += validateAltEmail(theForm.altEmail3);
	
     
	if (reason != "") {
		alert("Some fields need correction:\n" + reason);
	}
	else
	{
			var recdata = "me=" + theForm.me.value + ":";
			if (document.getElementById('optout').checked == true) {
					var optout = "1";
			}
			else {
				var optout = "0";
			}
			
			recdata += "firstnameA=" + theForm.firstnameA.value + ":";
			recdata += "lastnameA=" + theForm.lastnameA.value + ":";
			recdata += "phoneA=" + theForm.phoneA.value + ":";
			recdata += "mobileA=" + theForm.mobileA.value + ":";
			recdata += "firstnameB=" + theForm.firstnameB.value + ":";
			recdata += "lastnameB=" + theForm.lastnameB.value + ":";
			recdata += "phoneB=" + theForm.phoneB.value + ":";
			recdata += "mobileB=" + theForm.mobileB.value + ":";
			recdata += "relationshipA=" + theForm.relationshipA.value + ":";
			recdata += "relationshipB=" + theForm.relationshipB.value + ":";
			recdata += "stNumA=" + theForm.stNumA.value + ":";
			recdata += "streetA=" + theForm.streetA.value + ":";
			recdata += "cityA=" + theForm.cityA.value + ":";
			recdata += "countyA=" + theForm.countyA.value + ":";
			recdata += "stateA=" + theForm.stateA.value + ":";
			recdata += "zipA=" + theForm.zipA.value + ":";
			recdata += "stNumB=" + theForm.stNumB.value + ":";
			recdata += "streetB=" + theForm.streetB.value + ":";
			recdata += "cityB=" + theForm.cityB.value + ":";
			recdata += "countyB=" + theForm.countyB.value + ":";
			recdata += "stateB=" + theForm.stateB.value + ":";
			recdata += "zipB=" + theForm.zipB.value + ":";
			recdata += "emer_first=" + theForm.emer_first.value + ":";
			recdata += "emer_last=" + theForm.emer_last.value + ":";
			recdata += "emer_phone=" + theForm.emer_phone.value + ":";
			recdata += "emer_mobile=" + theForm.emer_mobile.value + ":";
			recdata += "relationshipC=" + theForm.relationshipC.value + ":";	
			recdata += "email=" + theForm.email.value + ":";
			recdata += "primary_club=" + theForm.orgList.value + ":";
			recdata += "alt_email=" + theForm.altEmail.value + ":";
			recdata += "alt_email2=" + theForm.altEmail2.value + ":";
			recdata += "alt_email3=" + theForm.altEmail3.value + ":";
			recdata += "optout=" + optout;
			
			/* alert(recdata); */
			 
			var url = "/src/UpdateBooster.php";
			request.open("POST", url, true);
			request.onreadystatechange = UpdateBoosterResults;
			request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			request.send("dataset=" + escape(recdata));	
			

	}
	
}
function UpdateBoosterResults()
{
  if (request.readyState == 4) {
    if (request.status == 200) {
      /* Get the response from the server */
      var results = request.responseText;
      if(results != "") {
      		window.location = '/profileEdit';
	  } else {
	  	
	  	alert("The server is busy at the moment, please try again.");
	  }
	  
    } else {
      alert("Error! Request status is " + request.status);
	}
  }
}

function changeBPW(theForm)
{
	/* check for all the mandatory fields... */
	var reason = "";
	reason += validatePassword(theForm.password);
	reason += validatePasswordConfirm(theForm.confirm_password);
	reason += validateEmail(theForm.myusername);     
	if (reason != "") {
		alert("Some fields need correction:\n" + reason);
	}
	else
	{	
		if (theForm.password.value == theForm.confirm_password.value) {	
			alert("Congratulations! All the information we need has been provided - saving your changes.");	
			var recdata = "me=" + theForm.me.value + ":";
			recdata += "username=" + theForm.myusername.value + ":";
			recdata += "password=" + theForm.confirm_password.value + ":";	
			recdata += "secretWord=" + theForm.secret_word.value + ":";
			recdata += "oldEmail=" + theForm.oldUsername.value;
			
			/* alert(recdata); */
			var url = "/src/ChangeBoosterPassword.php";
			request.open("POST", url, true);
			request.onreadystatechange = ChangeBoosterPasswordResults;
			request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			request.send("dataset=" + escape(recdata));	
		}
	}
}

function ChangeBoosterPasswordResults()
{
  if (request.readyState == 4) {
    if (request.status == 200) {
      /* Get the response from the server */
      var results = request.responseText;
      if(results != "") {
      	alert(results);
      		window.location = '/myProfile';
	  	} else {
	  		alert("The server is busy at the moment, please try again.");
	  	} 
    } else {
      alert("Error! Request status is " + request.status);
		}
  }
}



/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ADMIN FUNCTIONS updated 08022011~~~~~~~~~~~~~ */

function adminRegister(theForm)
{
	/* check for all the mandatory fields... */
	var reason = "";
	reason += validateBoosterAFirstName(theForm.firstnameA);
	reason += validateBoosterALastName(theForm.lastnameA);
	reason += validatePhoneCheck(theForm.phoneA);
	reason += validatePhoneCheck(theForm.mobileA);
	reason += validateIllegal(theForm.relationshipA, 'the relationship field of the primary booster.');

	reason += validateStNum(theForm.stNumA);
	reason += validateIllegal(theForm.streetA, 'the street name for the primary booster.');
	reason += validateIllegal(theForm.cityA, 'the city for the primary booster.');
	reason += validateIllegal(theForm.countyA, 'the county name for the primary booster.');
	reason += validateEmpty(theForm.stateA, "State");
	reason += validateIllegal(theForm.zipA, 'the zipcode for the primary booster.');


	reason += validateEmerFirstName(theForm.emer_first);
	reason += validateEmerLastName(theForm.emer_last);
	reason += validatePhoneCheck(theForm.emer_phone);	
	reason += validatePhoneCheck(theForm.emer_mobile);	
	reason += validateIllegal(theForm.relationshipC, 'the relationship field of the emergency contact.');
	
	reason += validateIllegal(theForm.orgList), 'your Primary Club where you will be playing.';		
	
	reason += validate18box(theForm.of_age);
	reason += validateEmail(theForm.myusername);

	reason += validatePassword(theForm.password);
	reason += validatePasswordConfirm(theForm.confirm_password);

	reason += validateIllegal(theForm.secret_word, 'your security phrase, in case you forget your password.');

	reason += validateAltEmail(theForm.alt_email);
	reason += validateAltEmail(theForm.alt_email2);
	reason += validateAltEmail(theForm.alt_email3);
      
	if (reason != "") {
		alert("Some fields need correction:\n" + reason);
	}
	else
	{
		if (theForm.password.value == theForm.confirm_password.value)
		{
			alert("Congratulations! All the information we need has been provided - saving the new membership.");
			var recdata = "";
			recdata += "firstnameA=" + theForm.firstnameA.value + ":";
			recdata += "lastnameA=" + theForm.lastnameA.value + ":";
			recdata += "phoneA=" + theForm.phoneA.value + ":";
			recdata += "mobileA=" + theForm.mobileA.value + ":";
			recdata += "firstnameB=" + theForm.firstnameB.value + ":";
			recdata += "lastnameB=" + theForm.lastnameB.value + ":";
			recdata += "phoneB=" + theForm.phoneB.value + ":";
			recdata += "mobileB=" + theForm.mobileB.value + ":";
			recdata += "relationshipA=" + theForm.relationshipA.value + ":";
			recdata += "relationshipB=" + theForm.relationshipB.value + ":";
			recdata += "stNumA=" + theForm.stNumA.value + ":";
			recdata += "streetA=" + theForm.streetA.value + ":";
			recdata += "cityA=" + theForm.cityA.value + ":";
			recdata += "countyA=" + theForm.countyA.value + ":";
			recdata += "stateA=" + theForm.stateA.value + ":";
			recdata += "zipA=" + theForm.zipA.value + ":";
			recdata += "stNumB=" + theForm.stNumB.value + ":";
			recdata += "streetB=" + theForm.streetB.value + ":";
			recdata += "cityB=" + theForm.cityB.value + ":";
			recdata += "countyB=" + theForm.countyB.value + ":";
			recdata += "stateB=" + theForm.stateB.value + ":";
			recdata += "zipB=" + theForm.zipB.value + ":";
			recdata += "emer_first=" + theForm.emer_first.value + ":";
			recdata += "emer_last=" + theForm.emer_last.value + ":";
			recdata += "emer_phone=" + theForm.emer_phone.value + ":";
			recdata += "emer_mobile=" + theForm.emer_mobile.value + ":";
			recdata += "relationshipC=" + theForm.relationshipC.value + ":";	
			recdata += "of_age=" + "over18" + ":";	
			recdata += "myusername=" + theForm.myusername.value + ":";	
			recdata += "password=" + theForm.password.value + ":";	
			recdata += "secret_word=" + theForm.secret_word.value + ":";	
			recdata += "primary_club=" + theForm.orgList.value + ":";
			
			/* alert(escape(recdata)); */
			
			var url = "/src/AdminCreateMember.php";
			request.open("POST", url, true);
			request.onreadystatechange = AdminCreateMemberResults;
			request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			request.send("dataset=" + escape(recdata));	
		} 
		else 
		{
			alert("Your password and confirmation do not match. Please correct this and re-submit the form.");
		}
	}
	
}
function AdminCreateMemberResults()
{
  if (request.readyState == 4) {
    if (request.status == 200) {
      /* Get the response from the server */
      var results = request.responseText;
      if(results != "") {
      	if(results == "duplicate") {
      		alert("This e-mail already exists in the system. If this email is correct, try using the Quick Booster Lookup tool to work on this booster. Otherwise, change the e-mail address and try again.");
      	} else {
					/* alert(results); */
					window.location = '/boosterHome';
	  		}
	  } else {
	  	
	  	alert("The server is busy at the moment, please try again.");
	  }
	  
    } else {
      alert("Error! Request status is " + request.status);
	}
  }
}


function validateEmpty(fld, name) {
    var error = "";
    if (fld.value.length == 0) {
        fld.style.background = 'Yellow'; 
        error = "You didn't enter a value in the field for " + name + ".\n";
    } else {
        fld.style.background = 'White';
    }
    return error;  
}
function validateBoosterAFirstName(fld) {
    var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 
    if (fld.value == "") {
        fld.style.background = 'Yellow'; 
        error = "You didn't enter a first name for the Primary Booster.\n";
    } else if ((fld.value.length < 2) || (fld.value.length > 30)) {
        fld.style.background = 'Yellow'; 
        error = "Please use between 2 and 30 characters for your first name.\n";
    } else if (illegalChars.test(fld.value)) {
        fld.style.background = 'Yellow'; 
        error = "The name you entered contains illegal characters. Please re-enter your first name.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}
function validateBoosterALastName(fld) {
    var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 
    if (fld.value == "") {
        fld.style.background = 'Yellow'; 
        error = "You didn't enter a last name for the Primary Booster.\n";
    } else if ((fld.value.length < 2) || (fld.value.length > 40)) {
        fld.style.background = 'Yellow'; 
        error = "Please use between 2 and 40 characters for your last name.\n";
    } else if (illegalChars.test(fld.value)) {
        fld.style.background = 'Yellow'; 
        error = "Your last name contains illegal characters. Please re-enter your last name.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}


function validateBoosterBFirstName(fld) {
    var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 
    if (fld.value == "") {
        fld.style.background = 'White'; 
    } else if ((fld.value.length < 2) || (fld.value.length > 30)) {
        fld.style.background = 'Yellow'; 
        error = "Please use between 2 and 30 characters for your first name.\n";
    } else if (illegalChars.test(fld.value)) {
        fld.style.background = 'Yellow'; 
        error = "The name you entered contains illegal characters. Please re-enter your first name.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}
function validateBoosterBLastName(fld) {
    var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 
    if (fld.value == "") {
        fld.style.background = 'White'; 
    } else if ((fld.value.length < 2) || (fld.value.length > 40)) {
        fld.style.background = 'Yellow'; 
        error = "Please use between 2 and 40 characters for your last name.\n";
    } else if (illegalChars.test(fld.value)) {
        fld.style.background = 'Yellow'; 
        error = "Your last name contains illegal characters. Please re-enter your last name.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}


function validatePassword(fld) {
    var error = "";
    var illegalChars = /[\W_]/; // allow only letters and numbers 
 
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "You didn't enter a password.\n";
    } else if ((fld.value.length < 7) || (fld.value.length > 15)) {
        error = "The password is the wrong length. \n";
        fld.style.background = 'Yellow';
    } else if (illegalChars.test(fld.value)) {
        error = "The password contains illegal characters.\n";
        fld.style.background = 'Yellow';
    } else if (!((fld.value.search(/(a-z)+/)) && (fld.value.search(/(0-9)+/)))) {
        error = "The password must contain at least one numeral.\n";
        fld.style.background = 'Yellow';
    } else {
        fld.style.background = 'White';
    }
   return error;
}  
function validatePasswordConfirm(fld) {
    var error = "";
    var illegalChars = /[\W_]/; // allow only letters and numbers 
 
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "You didn't enter a password confirmation.\n";
    } else if ((fld.value.length < 7) || (fld.value.length > 15)) {
        error = "The password is the wrong length. \n";
        fld.style.background = 'Yellow';
    } else if (illegalChars.test(fld.value)) {
        error = "The password contains illegal characters.\n";
        fld.style.background = 'Yellow';
    } else if (!((fld.value.search(/(a-z)+/)) && (fld.value.search(/(0-9)+/)))) {
        error = "The password must contain at least one numeral.\n";
        fld.style.background = 'Yellow';
    } else {
        fld.style.background = 'White';
    }
   return error;
}  
function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}
function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "You didn't enter an email address - this is your username!\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = 'Yellow';
        error = "Please enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = 'Yellow';
        error = "The email address contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}
function validatePhoneCheck(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    

   if (fld.value == "") {
        error = "You didn't enter a phone number.\n";
        fld.style.background = 'Yellow';
    } else if (isNaN(parseInt(stripped))) {
        error = "The phone number contains illegal characters.\n";
        fld.style.background = 'Yellow';
    } else if (!(stripped.length == 10)) {
        error = "The phone number is the wrong length. Make sure you included an area code.\n";
        fld.style.background = 'Yellow';
    }
    return error;
}
function validatePhoneCheckB(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    

   if (fld.value == "") {
        fld.style.background = 'White';
    } else if (isNaN(parseInt(stripped))) {
        error = "The phone number contains illegal characters.\n";
        fld.style.background = 'Yellow';
    } else if (!(stripped.length == 10)) {
        error = "The phone number is the wrong length. Make sure you included an area code.\n";
        fld.style.background = 'Yellow';
    }
    return error;
}
function validate18box(fld) {
    var error = "";
 
    if (fld.checked == false) {
        fld.style.background = 'Yellow'; 
        error = "Please verify that you are at least 18 years of age by checking the box.\n"
    } else {
        fld.style.background = 'White';
    }
    return error;  
}
function validateStNum(fld) {
    var error = "";
    var onlynumbers = "/[0-9]/g";    
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    

   if (fld.value == "") {
        error = "You didn't enter a street number.\n";
        fld.style.background = 'Yellow';
    } else if (isNaN(parseInt(stripped))) {
        error = "The street number contains illegal characters. Be sure to only put numbers in this field.\n";
        fld.style.background = 'Yellow';
    }
    return error;
}
function validateStNumB(fld) {
    var error = "";
    var onlynumbers = "/[0-9]/g";    
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    

   if (fld.value == "") {
        fld.style.background = 'White';
    } else if (isNaN(parseInt(stripped))) {
        error = "The street number contains illegal characters. Be sure to only put numbers in this field.\n";
        fld.style.background = 'Yellow';
    }
    return error;
}
function validateClean(fld, fldName) {
    var error = "";
    var illegalChars=/^\d{1,2}\/\d{1,2}\/\d{4}$/ ;
    if (fld.value == "") {
	    fld.style.background = 'Yellow'; 
        error = "You didn't enter a value in the field for " + fldName + ".\n";
    } else if (illegalChars.test(fld.value)) {
        error = "A field contains illegal characters. Please review each section and remove any characters that are not letters or numbers.\n";
        fld.style.background = 'Yellow';
    } else {
        fld.style.background = 'White';
    }
    
   return error;
}
function validateCleanB(fld, fldName) {
    var error = "";
    var illegalChars=/^\d{1,2}\/\d{1,2}\/\d{4}$/ ;
    if (fld.value == "") {
	    fld.style.background = 'Yellow'; 
        error = "You didn't enter a value in the field for " + fldName + ".\n";
    } else if (illegalChars.test(fld.value)) {
        error = "A field contains illegal characters. Please review each section and remove any characters that are not letters or numbers.\n";
        fld.style.background = 'Yellow';
    } else {
        fld.style.background = 'White';
    }
    
   return error;
} 

function validateEmerFirstName(fld) {
    var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 
    if (fld.value == "") {
        fld.style.background = 'Yellow'; 
        error = "You didn't enter a first name for Booster A.\n";
    } else if ((fld.value.length < 2) || (fld.value.length > 30)) {
        fld.style.background = 'Yellow'; 
        error = "Please use between 2 and 30 characters for your first name.\n";
    } else if (illegalChars.test(fld.value)) {
        fld.style.background = 'Yellow'; 
        error = "The name you entered contains illegal characters. Please re-enter your first name.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}
function validateEmerLastName(fld) {
    var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 
    if (fld.value == "") {
        fld.style.background = 'Yellow'; 
        error = "You didn't enter a last name for Booster A.\n";
    } else if ((fld.value.length < 2) || (fld.value.length > 40)) {
        fld.style.background = 'Yellow'; 
        error = "Please use between 2 and 40 characters for your last name.\n";
    } else if (illegalChars.test(fld.value)) {
        fld.style.background = 'Yellow'; 
        error = "Your last name contains illegal characters. Please re-enter your last name.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}
function validateAltEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
	  var st2 = new RegExp("@");
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
    /* alert("the field was "+tfld); */
    
    if (tfld == "") {
    /* alert("the field was blank"); */
    fld.style.background = 'White';

    } else {
    	/* alert("the field was not blank..."); */
	    if (!st2.test(tfld)) {              //test email for illegal characters
	        fld.style.background = 'Yellow';
	        error = "Please enter a valid email address, or leave blank if you have no alternate e-mail address.\n";
	    } else if (fld.value.match(illegalChars)) {
	        fld.style.background = 'Yellow';
	        error = "The email address contains illegal characters.\n";
	    } else {
	        fld.style.background = 'White';
	    }
	}
    return error;
}

function validateIllegal(fld, fldName) {
	var error = "";
	var illegalChars=/[\(\)\<\>\,\;\:\\\/\"\'\[\]]/;
	
	if (illegalChars.test(fld.value)) {
	   error = "The " + fldName + " contains illegal characters.\n";
	   fld.style.background = 'Yellow';
	}
	
	return error;
}

function validateCounty(fld, fldName) {
	var error = "";
	if (fld.value == "Select a county") {
	   error = "The " + fldName + " has not been selected. Please confirm your county of residence.\n";
	   fld.style.background = 'Yellow';
	}
	
	return error;
}
