function isFilled(elm) {
  // check that this form element has a value
  if (elm.value == "" || elm.value == null) return false;
  else return true;
}

function isEmail(elm) {
  // check that the provided address has an @ sign and at least one . and no spaces
  if (elm.value.indexOf("@") != "-1" && elm.value.indexOf(".") != "-1" && elm.value.indexOf(" ") == "-1") return true;
  else return false;
}

function isReady() {
  // check that a message was provided
  if (isFilled(contact.Message) == false) {
    alert("Please include a message.");
    contact.Message.focus();
    return false;
  }
  // check that the e-mail address looks valid, only if one is provided
  if (isFilled(contact.Email) == true && isEmail(contact.Email) == false) {
    alert("E-mail address invalid.");
    contact.Email.focus();
    return false;
  }
  // return true to have the form continue processing
  return true;
}

// add javascript handling to the form, if possible
if (contact = document.getElementById('contactform')) {
  contact.onsubmit = isReady;
}
