function validAdoptForm(aForm) {
  if ((aForm.firstname.value == "") || (checkSpaces(aForm.firstname))) {
	alert("Please enter your first name");
	aForm.firstname.focus();
	return false;
  } else if ((aForm.lastname.value == "") || (checkSpaces(aForm.lastname))) {
	alert("Please enter your last name");
	aForm.lastname.focus();
	return false;
  }else if (!validateEmail(aForm.email)) {
  	  return false;
  } else if (!validateAddress(aForm)) {
  	  return false;
  }

  if ((aForm.phone.value == "") || (checkSpaces(aForm.phone))) {
	alert("Please enter a phone number");
	aForm.phone.focus();
	return false;
  }  
  if (!validatePhoneNumber(aForm.phone))
  	return false;
  else
    return true;

}

function validForm(aForm) {
  if ((aForm.firstname.value == "") || (checkSpaces(aForm.firstname))) {
	alert("Please enter your first name");
	aForm.firstname.focus();
	return false;
  } else if ((aForm.lastname.value == "") || (checkSpaces(aForm.lastname))) {
	alert("Please enter your last name");
	aForm.lastname.focus();
	return false;
  }else if (!validateEmail(aForm.email)) {
  	  return false;
  } else if (!validateAddress(aForm)) {
  	  return false;
  }

  if ((aForm.phone.value == "") || (checkSpaces(aForm.phone))) {
	alert("Please enter a phone number");
	aForm.phone.focus();
	return false;
  }


  if ((aForm.birthdate.value == "") || (checkSpaces(aForm.birthdate))) {
	alert("Please enter your birthdate");
	aForm.birthdate.focus();
	return false;
  } else if ((aForm.heardAboutExtreme.value == "") || (checkSpaces(aForm.heardAboutExtreme))) {
	alert("Please enter how you heard about Extreme.");
	aForm.heardAboutExtreme.focus();
	return false;
  }
  
  if (!validatePhoneNumber(aForm.phone))
  	return false;
  else
    return true;

}

function validPartnerForm(aForm) {
  if ((aForm.firstname.value == "") || (checkSpaces(aForm.firstname))) {
	alert("Please enter your first name");
	aForm.firstname.focus();
	return false;
  } else if ((aForm.lastname.value == "") || (checkSpaces(aForm.lastname))) {
	alert("Please enter your last name");
	aForm.lastname.focus();
	return false;
  }else if (!validateEmail(aForm.email)) {
  	  return false;
  } 
}

function validateAddress(aForm) {
  var stateChoice = aForm.state.selectedIndex;
  var is_valid = true;
 
  if ((aForm.address1.value == "") || (checkSpaces(aForm.address1))) {
	alert("Please enter street address 1");
	aForm.address1.focus();
	is_valid = false;
  }  
  else if ((aForm.city.value == "") || (checkSpaces(aForm.city))) {
	alert("Please enter your city name");
	aForm.city.focus();
	is_valid = false;
  }
  
	
  return is_valid;
}


function validatePhoneNumber(phone) {
  var is_valid = true;
  phone.value = trim(phone.value);
  if (phone.value != "") {
	for (i=0; i < phone.value.length; i++) {
	  if ((phone.value.charAt(i) < "0") || (phone.value.charAt(i) > "9")){
	    i = phone.value.length;
		alert("The telephone number must be numeric with no spaces. \nPlease re-enter the telephone number with only numbers");
		phone.focus();
		is_valid = false;
	  }
	} 
  }

  return is_valid;
}

function validateEmail(emailAddress) {
  var is_valid = true;
  var the_at = emailAddress.value.indexOf("@");
  var after_the_at = emailAddress.value.substring(the_at+1,emailAddress.value.length);
  var the_dot = after_the_at.indexOf(".");
  var the_space = emailAddress.value.indexOf(" ");

  if ((the_at == -1) ||
	  (the_at == 0) ||
	  (the_dot <= 0) ||
	  (the_dot >= after_the_at.length-1) ||
	  (the_space != -1)) {
    alert("Please verify your email address.  It must be filled in and of the form name@domain.ext");
	emailAddress.focus();
	is_valid = false;
  }
  
  return is_valid;
}

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 checkSpaces(field) {
  var noSpaces = false
  if (field.value.length > 0) {
    for (i=0; i<field.value.length; i++) {
	  if (field.value.charAt(i) != " ") {
		i = field.value.length
	    noSpaces = true
	  }
	} // end for
	
	if (!noSpaces) {
	  return true
	}
	else {
	  return false
	}
  } 
  else {
	return false
  }
}
