function isBlank(s) {
  if (s==null) {return true;}
  for (var i = 0; i < s.length; i++) {
    var c = s.charAt(i);
    if ((c != ' ') && (c != '\n') && (c != '\r')) return false;
  }
  return true;
}

function isNotBlank(s) {
  if (s.length>1) return true;
  else return false;
}

function isEmail(string) {
    return (string.search(/^\w+((-\w+)|(\.\w+)|('\w+))*\@[A-Za-z0-9_-]+(\.[A-Za-z0-9_-]+)+$/) != -1);
}


function trim(string) {
// removes spaces at the beginning of a string
    string = string.replace(/^\s*/, "");
// removes spaces anywhere else in the string
// (I'd rather only remove them at the end, but I can't
//  get that to work.)
    string = string.replace(/(\S*)\s*/g, "$1");

// This should work, but doesn't
//    string = string.replace(/\s$/, "");

    return string;
}


function isProper(string) {
    return (string.search(/^[a-zA-Z']+[a-zA-Z' -]*$/) != -1);
}
// Checks for at least 4 letters and numbers
function isProperFour(string) {
   if (string.search(/^\w\w\w\w+$/) == -1) return false;
   else return true;
}

function isWord(string) {
   if (string.search(/^[ a-zA-Z0-9_.;:,!@'-]+[ a-zA-Z0-9_.;:,!@'-]*$/) == -1) return false;
}

function isReady(form) {
  if (isBlank(form.Name.value)) {
    alert("Please enter your Name.");
        form.Name.focus();
        return false;
  }
  if (isProper(form.Name.value) == false) {
    alert(form.Name.value+" is not a valid value for Name.");
        form.Name.focus();
    return false;
  }
  if (isBlank(form.Email.value)) {
    alert("Please enter your Email address.");
        form.Email.focus();
    return false;
  }
  if (isNotBlank(form.Email.value)) {
    if (isEmail(form.Email.value) == false) {
      alert("'"+form.Email.value+"' is not a valid e-mail address.\n"+
              "Please enter a valid Email address.");
      form.Email.focus();
      return false;
    }
  }
  if (isBlank(form.Name1.value)) {
    alert("Please enter your colleague's Name.");
        form.Name1.focus();
        return false;
  }
  if (isProper(form.Name1.value) == false) {
    alert(form.Name1.value+" is not a valid value for Name.");
        form.Name1.focus();
    return false;
  }
  if (isBlank(form.Email1.value)) {
    alert("Please enter your colleague's Email address.");
        form.Email1.focus();
    return false;
  }
  if (isNotBlank(form.Email1.value)) {
    if (isEmail(form.Email1.value) == false) {
      alert("'"+form.Email1.value+"' is not a valid e-mail address.\n"+
              "Please enter a valid Email address.");
      form.Email1.focus();
      return false;
    }
  }
  return true;
}
