function check(f) {
  if (f.number.selectedIndex == 3) {
    alert("2.9, huh? That's great! But if it's okay with you, we'll just count you as 2.");
    f.number.selectedIndex = 2;
  }
  foodNumber = 0;
  if (f.dietAll.checked) { foodNumber += parseInt(f.dietAllNum.value); }
  if (f.dietFish.checked) { foodNumber += parseInt(f.dietFishNum.value); }
  if (f.dietVeggie.checked) { foodNumber += parseInt(f.dietVeggieNum.value); }
  if (f.name.value.search(/\w+/) < 0) {
    alert("You're going to have to tell us your name, at least."); 
    return false;
  } else if ((f.email.value.search(/\w+/) >= 0) && !emailValid(f.email.value)) {
    alert("That doesn't appear to be a valid email address.");
    return false;
  } else if (f.phone.value.search(/\d+/) < 0) {
    alert("We'd like your phone number, in case we need to verify anything, or maybe just to chat."); 
    return false;
  } else if (!f.coming[0].checked && !f.coming[1].checked) {
    alert("You didn't say if you're coming or not."); 
    return false;
  } else if (f.coming[0].checked && f.number.selectedIndex == 0) {
    alert("How many of you will be coming?"); 
    return false;
  } else if (f.coming[0].checked && !f.dietAll.checked && !f.dietFish.checked && !f.dietVeggie.checked) {
    alert("Let us know if you have any food requirements."); 
    return false;
  } else if (f.coming[0].checked && f.dietAll.checked && (f.dietAllNum.value.search(/[1-9]+/) < 0)) {
    alert("How many people fall into the \"no dietary requirements\" category?"); 
    return false;
  } else if (f.coming[0].checked && f.dietFish.checked && (f.dietFishNum.value.search(/[1-9]+/) < 0)) {
    alert("How many people fall into the \"vegetarian and fish only\" category?"); 
    return false;
  } else if (f.coming[0].checked && f.dietVeggie.checked && (f.dietVeggieNum.value.search(/[1-9]+/) < 0)) {
    alert("How many people fall into the \"vegetarian only\" category?"); 
    return false;
  } else if (f.coming[0].checked && f.number.value != foodNumber) {
    alert("Hmm. The number of people mentioned in your food requirements isn't the same as the number you said were coming."); 
    return false;
  } else if (f.coming[0].checked && f.tripHelp.checked && (f.email.value.search(/\w+/) < 0)) {
    alert("We need your email address to help with hotel or car sharing.");
    return false;
  } else {
    return true;
  }
}

function comeToggle(f) {
  sp = document.getElementById("howMany");
  fs = document.getElementById("foodShare");
  if (f.coming[0].checked) {
    sp.style.display = "inline";
    fs.style.display = "block";
  } else {
    f.dietAll.checked = true;
    f.tripHelp.checked = false;
    sp.style.display = "none";
    fs.style.display = "none";
  }
}

function emailValid(em) {
  if (em.search(/^['_a-z0-9-]+([&+\.]['_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.(([a-z]{2,3})|(aero|coop|info|museum|name))$/i) < 0) {
    return false;
  } else {
    return true;
  }
}