/*
Part of the code for the article "Use Ajax and PHP to Build Your Mailing List"
by Aarron Walter (aarron@aarronwalter.com)
http://www.sitepoint.com/article/use-ajax-php-build-mailing-list
*/

// Attach handler to window load event
Event.observe(window, 'load', init, false);

function init() {
  // Attach handler to form's submit event
  Event.observe('enquiryForm', 'submit', sendEnquiry);
}

function sendEnquiry(e) {
  // Update user interface
  $('response').innerHTML = 'Sending Enquiry';
  // Prepare query string and send AJAX request
  var pars = 'cboAltTrekkingStartDay=' + escape($F('cboAltTrekkingStartDay')) +'&cboAltTrekkingStartMonth=' + escape($F('cboAltTrekkingStartMonth')) +'&cboAltTrekkingStartYear=' + escape($F('cboAltTrekkingStartYear')) +'&cboArrivalStartDay=' + escape($F('cboArrivalStartDay')) +'&cboArrivalStartMonth=' + escape($F('cboArrivalStartMonth')) +'&cboArrivalStartYear=' + escape($F('cboArrivalStartYear')) +'&cboLengthOfStay=' + escape($F('cboLengthOfStay')) +'&cboPrefTrekkingStartDay=' + escape($F('cboPrefTrekkingStartDay')) +'&cboPrefTrekkingStartMonth=' + escape($F('cboPrefTrekkingStartMonth')) +'&cboPrefTrekkingStartYear=' + escape($F('cboPrefTrekkingStartYear')) +'&cboQuantity=' + escape($F('cboQuantity')) +'&chk1=' + escape($F('chk1')) +'&chk10=' + escape($F('chk10')) +'&chk11=' + escape($F('chk11')) +'&chk2=' + escape($F('chk2')) +'&chk3=' + escape($F('chk3')) +'&chk4=' + escape($F('chk4')) +'&chk6=' + escape($F('chk6')) +'&chk7=' + escape($F('chk7')) +'&chk8=' + escape($F('chk8')) +'&chk9=' + escape($F('chk9')) +'&txtComments=' + escape($F('txtComments')) +'&txtEmail=' + escape($F('txtEmail')) +'&txtFirstname=' + escape($F('txtFirstname')) +'&txtLastname=' + escape($F('txtLastname')) +'&txtLocation=' + escape($F('txtLocation')) +'&txtPhoneNumberHome=' + escape($F('txtPhoneNumberHome'))+'&txtPhoneNumberIreland=' + escape($F('txtPhoneNumberIreland'));
  var myAjax = new Ajax.Updater('response', 'enquiryServer.php', {method: 'get', parameters: pars});
  // Stop form from submitting when JavaScript is enabled
  Event.stop(e);
}
