// Helpers for mailing list form
// J. Levy

// Show message and send Ajax request
function store_address(e) {
  var notice = $('signup_response');
  notice.update('Adding...');
  var params = { signup_address: $F('signup_address').strip(),
                 signup_name: $F('signup_name').strip(),
                 signup_comments: $F('signup_comments')
               };
  
  new Ajax.Request('/lily/mailing_list_handler.php', {    method: 'get',    onSuccess: function(transport) {
      var text = transport.responseText;      notice.update(text);
      // Reset form only if successful
      if(notice.descendants().any(function(o) { return o.hasClassName("success-message") })) {
        $("signup_form").reset();
      }
    },
    parameters: params
  });
  // Stop form from submitting when JavaScript enabled
  Event.stop(e);
}

// Attach handler to window load event
Event.observe(window, 'load', function () {
  if($("signup_form")) {
    Event.observe('signup_form', 'submit', store_address);
  }
});


