function formHelper(attachTo) {
    this.attachTo = attachTo;
}

formHelper.prototype = {
    initListeners: function() {
        this.attachTo.observe('submit', function(e) {
            e.stop();
            var form = e.findElement(form);
            var settings = {
                method: form.method,
                parameters: form.serialize(),
                onSuccess: function(o) {
                    clearErrors(form);
                    this.attachTo.fire('validation:success', { validator: this, response: o.responseJSON });
                }.bind(this),
                onFailure: function(o) {
                    this.attachTo.fire('validation:fail', { validator: this, errors: o.responseJSON.errors, response: o.responseJSON });
                    clearErrors(form);
                    displayErrors(o.responseJSON.errors);
                }.bind(this)
            };
            new Ajax.Request(form.action, settings);
        }.bind(this));
    }
};

