/*
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('kontaktForm', 'submit', storeKontakt);
}

function storeKontakt(e) {
  // Update user interface
  $('response').innerHTML = 'Senden...';
  // Prepare query string and send AJAX request
  var pars = 'kontaktanrede=' + escape($F('kontaktanrede')) + '&kontaktname=' + escape($F('kontaktname')) + '&kontaktemail=' + escape($F('kontaktemail')) + '&kontakttelefon=' + escape($F('kontakttelefon')) + '&kontaktfirma=' + escape($F('kontaktfirma')) + '&kontaktkopie=' + escape($F('kontaktkopie')) + '&kontaktnachricht=' + escape($F('kontaktnachricht')) + '&kontaktdate=' + escape($F('kontaktdate')) + '&ID=' + escape($F('ID')) + '&Codeeingabe=' + escape($F('Codeeingabe'));
  var myAjax = new Ajax.Updater('response', 'ajaxServer.php', {method: 'get', parameters: pars});
  // Stop form from submitting when JavaScript is enabled
  Event.stop(e);
}