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() {
  // this check doesn't do form re-focusing, like the contact form does
  // check that a name was provided
  if (isFilled(form.contact_name) == false) {
    alert("You forgot to provide your name");
    return false;
  }
  // check that a valid e-mail address was provided
  if (isFilled(form.contact_email) == false) {
    alert("You forgot to provide your e-mail address");
    return false;
  }
  if (isEmail(form.contact_email) == false) {
    alert("The e-mail address you provided looks invalid");
    return false;
  }
  // check that the relation to the production was provided
  if (isFilled(form.contact_relation) == false) {
    alert("You forgot to provide your relation to the show");
    return false;
  }
  // check that a group name was provided
  if (isFilled(form.group) == false) {
    alert("You forgot to provide the group name");
    return false;
  }
  // check that a venue name was provided
  if (isFilled(form.venue) == false) {
    alert("You forgot to provide the show venue");
    return false;
  }
  // check that an address was provided
  if (isFilled(form.location_address) == false) {
    alert("You forgot to provide the street address of the venue");
    return false;
  }
  // check that a city was provided
  if (isFilled(form.location_city) == false) {
    alert("You forgot to provide the city or town");
    return false;
  }
  // check that a state was provided, if USA was selected as the country
  if (form.location_country[0].checked == true && isFilled(form.location_state) == false) {
    alert("You forgot to provide the state");
    return false;
  }
  // check that a country was provided
  if (form.location_country[0].checked == false && 
      form.location_country[1].checked == false && form.location_ukcountry.selectedIndex == 0 &&
      form.location_country[2].checked == false && isFilled(form.location_othcountry) == false) {
    alert("You forgot to select a country");
    return false;
  }
  if (form.location_country[2].checked == true && isFilled(form.location_othcountry) == false) {
    alert("You forgot to provide the country name");
    return false;
  }
  // return true to have the form continue processing
  return true;
}

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