 
   createAjaxEvent: (step) ->
     ajax =
-      url: @form.attr("action"),
-      dataType: "json",
-      beforeSubmit: (data) =>
-        # console.log "Sending these data to the server: #{JSON.stringify(data)}"
-        true
-      success: (response) =>
-        # console.log "Successful form POST; got #{JSON.stringify(response)}"
-        if response.metadata?
-          this.setAction(response.metadata.url, response.metadata.method)
-        $.extend(window.hatTrick, response) # merge new data with hatTrick
-      error: (event) =>
-        console.log "Error response: #{event.responseText}"
+      url: @form.attr("action")
+      dataType: "json"
+      success: (serverData) =>
+        this.handleServerData serverData
+        # console.log "Successful form POST; got #{JSON.stringify(serverData)}"
+      error: (event, status, errorThrown) =>
+        console.log "Error response: #{event.status} #{status} - #{errorThrown} - #{event.responseText}"
         try
           appErrors = eval "(#{event.responseText})"
         catch err
-          # TODO: Make this notify us when an error occurs.
-          appErrors = model: { unknown: ["A weird error has occurred."] }
+          appErrors =
+            model:
+              unknown: [
+                "There was an error communicating with the server. TurboVote staff have been notified."
+              ]
         this.clearErrors()
         this.addErrorItem value[0] for key, value of appErrors.model
     ajax

      inDuration: 0,
      linkClass: ".#{@linkClass}",
      remoteAjax: this.ajaxEvents(),
      formOptions:
        success: (data) =>
          # console.log "Successful form POST"
          true
        beforeSubmit: (data) =>
          console.log "Sending these data to the server: #{JSON.stringify(data)}"
    this.formwizardEnabled = true

  setHiddenInput: (name, value, id, classes = "", scope = @form) ->

    # prevent submitting the step that happens to be the last fieldset
    this.addFakeLastStep()
    this.addDefaultButtons()
    this.setButtonMetadataForCurrentStep()
    this.setupButtonsForAllSteps()
    this.enableFormwizard()
    this.setupButtonsForCurrentStep()
    this.setCurrentStepField()
    this.bindEvents()

