
function validMemberNumber(theForm) {
  if (theForm.number.value.length < 4)
  {
   	alert("Please enter at least four digits for the member number.");
 	theForm.number.focus();
   	return (false);
  }
  if (theForm.number.value.length > 8)
  {
   	alert("Please enter at most eight digits for the member number.");
   	theForm.number.focus();
   	return (false);
  }

  var checkOK = "0123456789";
  var checkStr = theForm.number.value;
  var allValid = true;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
   	ch = checkStr.charAt(i);
   	for (j = 0;  j < checkOK.length;  j++) {
   	  if (ch == checkOK.charAt(j)) break;
    }	
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    allNum += ch;
  }
  if (!allValid)
  {
    alert("Please enter only digits for the member number.");
   	theForm.number.focus();
    return (false);
  }
  return (true);
}

function validPersonsName(name, minLen, maxLen, required) {

	if (!validField(name, minLen, maxLen, "name", required)) {
		return (false);
	}
	if (required || name.value.length > 0) {
		var patt = /^[a-zA-Z '.-]+$/;
		if (!patt.test(name.value)) {
			alert("The name may consist only of letters, spaces, periods, hypens, and apostrophe characters.");
			name.focus();
			return (false);
		}
	}
	return (true);
}

function validEmailAddress(theField) {
  if (theField.value == "")
  {
   	alert("Please enter a full e-mail address.");
	theField.focus();
    return (false);
  }
  if (theField.value.length < 6)
  {
    alert("Please enter at least six(6) characters for the e-mail address.");
    theField.focus();
    return (false);
  }
  if (theField.value.length > 60)
  {
    alert("The e-mail address must be 60 characters or less in length.");
    theField.focus();
    return (false);
  }
  
  // Do this simple check, to catch a common error of missing domain name
  
  if (theField.value.indexOf("@") < 0)
  {
  	alert("E-mail address is missing at-sign.");
  	theField.focus();
  	return (false);
  }
  var patt = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[(2([0-4]\d|5[0-5])|1?\d{1,2})(\.(2([0-4]\d|5[0-5])|1?\d{1,2})){3} \])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
  // var patt = /^[a-z0-9]([.-][a-z0-9]+)*\@[a-z0-9]([.-][a-z0-9]+)*\.[a-z]{2,6}$/i;
  if (!patt.test(theField.value)) {
  	alert("The e-mail address does not appear to be well-formed. Please enter an e-mail address with full domain name.");
  	theField.focus();
  	return (false);
  }
  
  /*
  if (theField.value.indexOf("/") > -1)
  {
  	alert("Invalid character in e-mail address.");
  	theField.focus();
  	return (false);
  }
  if (theField.value.indexOf(",") > -1)
  {
  	alert("Invalid character in e-mail address.");
  	theField.focus();
  	return (false);
  }
  if (theField.value.indexOf(":") > -1)
  {
  	alert("Invalid character in e-mail address.");
  	theField.focus();
  	return (false);
  }
  if (theField.value.indexOf(";") > -1)
  {
  	alert("Invalid character in e-mail address.");
  	theField.focus();
  	return (false);
  }
  if (theField.value.indexOf("@") < 1)
  {
  	alert("E-mail address need characters before at-sign.");
  	theField.focus();
  	return (false);
  }
  if (theField.value.indexOf("\.") < 0)
  {
  	alert("E-mail address is missing at least one period.");
  	theField.focus();
  	return (false);
  }
  */
  return (true);
}

function validSecurityCode(theForm) {
  if (theForm.antispam.value == "")
  {
    alert("Please enter the security code value shown in the image.");
    theForm.antispam.focus();
    return (false);
  }
  if (theForm.antispam.value.indexOf(" ") > -1)
  {
    alert("Please do not enter spaces shown the security code image.");
    theForm.antispam.focus();
    return (false);
  }
  if (theForm.antispam.value.length != 6)
  {
    alert("Please enter the six characters (no spaces) from the security code image.");
    theForm.antispam.focus();
    return (false);
  }
  return (true);
}

function validField(field, min, max, what, required)
{
    if (field.value == "") {
      if (!required) {
        return (true);
      }
      alert("You must enter in a " + what);
      field.focus();
      return (false);
    }
  	var actual_len = field.value.length;
  	
    if (actual_len < min) {
      alert("The " + what + " is too short (minimum is " + min + ")");
      field.focus();
  	  return (false);
    }

 	if (actual_len > max) {
      alert("The " + what + " is too long(maximum is " + max + ", actual is " + actual_len + ")");
      field.focus();
  	  return (false);
    }
    return (true);
}
