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 += validateEmpty(theForm.lastnameA);
	reason += validatePassword(theForm.password);
	reason += validatePasswordConfirm(theForm.confirm_password);
	reason += validateEmail(theForm.myusername);
	reason += validatePhoneCheck(theForm.phoneA);
	/* reason += validatePhoneCheck(theForm.phoneB);	*/
	reason += validate18box(theForm.of_age);
	reason += validateStNum(theForm.stNumA);
	reason += validateEmpty(theForm.secret_word);
      
	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 = '/boosterLogin';
	  		}
	  } 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 += validatePhoneCheck(theForm.phoneA);
	reason += validateStNum(theForm.stNumA);
      
	if (reason != "") {
		alert("Some fields need correction:\n" + reason);
	}
	else
	{
			alert("Congratulations! All the information we need has been provided - saving your membership.");
			var recdata = "me=" + theForm.me.value + ":";
			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;

			
			/* 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 != "") {
      	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 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 ~~~~~~~~~~~~~ */

function adminRegister(theForm)
{
	/* check for all the mandatory fields... */
	var reason = "";
	reason += validateBoosterAFirstName(theForm.firstnameA);
	reason += validateEmpty(theForm.lastnameA);
	reason += validatePassword(theForm.password);
	reason += validatePasswordConfirm(theForm.confirm_password);
	reason += validateEmail(theForm.myusername);
	reason += validatePhoneCheck(theForm.phoneA);
	/* reason += validatePhoneCheck(theForm.phoneB);	*/
	reason += validate18box(theForm.of_age);
	reason += validateStNum(theForm.stNumA);
	reason += validateEmpty(theForm.secret_word);
	reason += validateEmpty(theForm.orgList);
      
	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) {
    var error = "";
    if (fld.value.length == 0) {
        fld.style.background = 'Yellow'; 
        error = "The required field has not been filled in.\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 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 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 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 validateBoosterBFirstName(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 B. Please enter NA for no name.\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 validateBoosterBLastName(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 B. Please enter NA for no name.\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 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 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;
}
