function recompute_prices() {
  var total = 0.00;
  var form = document.forms["app"];

  if (form.nonprofit[0].checked) {
    total -= 75.;
    document.getElementById("nonprofit_discount_subtotal").innerHTML =
      "-$75";
  } else {
    document.getElementById("nonprofit_discount_subtotal").innerHTML =
      "$0";
  }
  var chosen_booth_type =
    form.booth_type.options[form.booth_type.selectedIndex];
  var booth_fee = 250;
  if (chosen_booth_type.value == "normal") {
    booth_fee = 250.;
  } else if (chosen_booth_type.value == "premium") {
    booth_fee = 300.;
  }
  document.getElementById("booth_fee_subtotal").innerHTML = "$" + booth_fee;
  total += booth_fee;

  var v;
  var equipment_fee = 0;
  if ((v = parseInt(form.equip_canopy.value)) != NaN) {
    if (v < 0 || v > 1) {
      v = parseInt(form.equip_canopy.value = "1");
    }
    if (v == 0) {
      document.getElementById("canopy_subtotal").innerHTML = "-$50";
    } else {
      document.getElementById("canopy_subtotal").innerHTML = "$0";
    }
    equipment_fee += (1-v) * -50.;
  }
  if ((v = parseInt(form.equip_tables.value)) != NaN) {
    equipment_fee += v * 15.;
    document.getElementById("table_subtotal").innerHTML =
      "$" + v * 15;
  }
  if ((v = parseInt(form.equip_chairs.value)) != NaN) {
    equipment_fee += v/2 * 7.;
    document.getElementById("chairs_subtotal").innerHTML =
      "$" + v/2 * 7;
  }
  if ((v = parseInt(form.equip_parking.value)) != NaN) {
    equipment_fee += v * 10.;
    document.getElementById("parking_subtotal").innerHTML =
      "$" + v * 10;
  }
  total += equipment_fee;
  document.getElementById("equip_furniture_subtotal").innerHTML =
    "$" + equipment_fee;


  document.getElementById("grand_total").innerHTML =
    "<strong>$" + total + "</strong>";
}

function on_orgtype_change(input) {
  if (input.options[input.selectedIndex].value == "other") {
    document.getElementById("orgtype_other_entry").innerHTML =
      "<p><b>Type of organization (if \"other\"):</b><br>" +
      "<input name=\"org_type_other\" type=\"text\" size=\"40\" /></p>";
  } else if (input.options[input.selectedIndex].value == "artist" ||
             input.options[input.selectedIndex].value == "jeweler" ||
             input.options[input.selectedIndex].value == "clothing") {
    document.getElementById("artist_worksample_note").innerHTML =
      "<p class=\"form_notice\">To evaluate applications from artists," +
      " jewelers and" +
      " craftspeople, please supply us with photos and descriptions of your" +
      " work when submitting payment.  You can also refer us to your website" +
      " if that contains the same information -- use the \"Organization" +
      " website\" blank below.</p>";
  } else {
    document.getElementById("orgtype_other_entry").innerHTML = "";
    document.getElementById("artist_worksample_note").innerHTML = "";
  }
  on_mandatory_change(input);
}

function on_nonprofit_change(input) {
  if (input.value == "yes" && input.checked) {
    document.getElementById("nonprofit_notice").innerHTML =
      "<p class=\"form_notice\">A discount of $75 has been applied to" +
      " your exhibitor fee.  Proof of nonprofit status must be submitted" +
      " with payment.</p>";
  } else {
    document.getElementById("nonprofit_notice").innerHTML = "";
  }
  recompute_prices();
}


function on_canopy_change(input) {
  if (parseInt(input.value) == 0) {
    document.getElementById("no_canopy_note").innerHTML =
      "<p class=\"form_notice\">A discount of $50 has been applied to your" +
      " exhibitor fee.  Note that all booths are <em>required</em> to have" +
      " a canopy, so by selecting this option, you're agreeing to supply" +
      " your own.  Exhibit spaces require a 10x10' canopy.";
  } else {
    document.getElementById("no_canopy_note").innerHTML = "";
  }
  recompute_prices();
}

function on_equipment_change(input, dfl, max) {
  var i = parseInt(input.value);
  if (!(i >= 0 && i <= max)) {
    document.getElementById(input.name + '_msg').innerHTML =
      "<font class=\"form_notice\">Please enter a number between" +
      " 0 and " + max + ".</font>";
    input.style['border'] = "thin solid red";
    input.focus();
  } else {
    document.getElementById(input.name + '_msg').innerHTML = "";
    input.style['border'] = null;
    recompute_prices();
  }
}

function on_tandc_agree_change(input) {
  if (input.checked) {
    document.getElementById("tandc").style["border"] = "none";
  }
  on_mandatory_change(input);
}

/*
function validate_nonblank(form, input_name) {
  alert(input_name +"="+  form.elements[input_name].value);
  if (form.elements[input_name].value == "") {
    document.getElementById(input_name).style.class = "form_input_bad";
    return false;
  } else {
    document.getElementById(input_name).style.class = null;
    return true;
  }
}
*/

var broken_field = null;

function on_mandatory_change(input) {
  if (broken_field == input.name && input.value != "") {
    document.getElementById("form_errors").innerHTML = "";
    broken_field = null;
  }
}

function validate() {
  form = document.forms["app"];
  if (form.org_name.value == "") {
    broken_field = "org_name";
    document.getElementById("form_errors").innerHTML =
      "<p class=\"form_input_bad\">You must fill in your organization name;" +
      " if you're an individual artist exhibitor, simply enter your own name." +
      " Click <a href=\"#org_name\">here</a> to fix it.</p>";
      return false;
  } else if (form.org_type.value == "") {
    broken_field = "org_type";
    document.getElementById("form_errors").innerHTML =
      "<p class=\"form_input_bad\">You must select an organization type." +
      " Click <a href=\"#org_type\">here</a> to fix it.</p>";
      return false;
  } else if (form.org_brief_description.value == "") {
    broken_field = "org_brief_description";
    document.getElementById("form_errors").innerHTML =
      "<p class=\"form_input_bad\">You provide a brief description of your" +
      " organization.  Click <a href=\"#org_type\">here</a> to fix it.</p>";
      return false;
  } else if (form.org_contact.value == "") {
    broken_field = "org_contact";
    document.getElementById("form_errors").innerHTML =
      "<p class=\"form_input_bad\">You provide a contact person for your" +
      " organization.  Click <a href=\"#org_type\">here</a> to fix it.</p>";
      return false;
  } else if (form.org_contact_address.value == "") {
    broken_field = "org_contact_address";
    document.getElementById("form_errors").innerHTML =
      "<p class=\"form_input_bad\">You provide a mailing address for your" +
      " organization.  Click <a href=\"#org_type\">here</a> to fix it.</p>";
      return false;
  } else if (form.contact_phone.value == "") {
    broken_field = "contact_phone";
    document.getElementById("form_errors").innerHTML =
      "<p class=\"form_input_bad\">You provide a contact phone number." +
      " Click <a href=\"#org_type\">here</a> to fix it.</p>";
      return false;
  } else if (! form.tandc_agree.checked) {
    broken_field = "tandc_agree";
    document.getElementById("form_errors").innerHTML =
      "<p class=\"form_input_bad\">You must agree to the terms and" +
      " and conditions before applying.</p>";
    document.getElementById("tandc").style["border"] = "thin solid red";
    return false;
  } else {
    document.getElementById("form_errors").innerHTML = "";
  }
  //if (!validate_nonblank(form, "org_name")) return false;
  return true;
}

// vi: set ts=2 sw=2 et:
