function defaultFormSubmitHandler (form, additionalParams) {
	var $form = $j(form);

	var customHandlers = this.settings.customHandlers
	
	if (customHandlers.beforeSubmit) {
		customHandlers.beforeSubmit.call(this, $form);
	}
	
	if (customHandlers.submit) {
		customHandlers.submit.call(this, $form, additionalParams);
	}
}



var defaultFormHandlers = {
	beforeSubmit: function ($form) {
		$j(":submit", $form).attr('disabled', 'disabled');
	},

	submit: function ($form, additionalParams) {
		var that = this;
		$j.post(
			$form.attr('action'),
			$form.serialize() + '&' + additionalParams,
			function (response) {
				if (response && that.settings.customHandlers.submitSuccess) {
					that.settings.customHandlers.submitSuccess.call(that, $form, response);
				}
			},
			'json'
		)
	},

	submitSuccess: function ($form, response) {
		var that = this;
		var prefix = this.settings.prefix;

		$j(":submit", $form).removeAttr('disabled');
		
		if (response.captcha) {
			$j('#' + prefix + '_captcha_img').attr('src', response.captcha[0]);
			$form.get(0).md5.value = response.captcha[1];
			$form.get(0).captcha.value = '';
		}

		
		if (!(response.error == false || response.error == true)) { return; }
		
		if (response.error) {
			var ajaxErrorMessages = {};
			
			$j.each(response.messages, function (k, v) {
				ajaxErrorMessages[k] = that.settings.messages[k][v];
			});
			
			this.showErrors(ajaxErrorMessages);
		} else {
			$form.hide();
			$form.get(0).reset();
			var $doneContainer = $j('#' + prefix + '_done');
			$doneContainer.show();


			if (that.settings.customHandlers.renewForm) {
				$j('#' + prefix + '_renew').click(function (e) {
					e.preventDefault();
					
					that.settings.customHandlers.renewForm.call(that, $form, $doneContainer);
					
					$j(this).unbind();
				});
			}
		}
	},

	preloadCaptcha: function () {
		this.settings.submitHandler.call(this, this.currentForm, 'newform=true');
	},

	renewForm: function ($form, $doneContainer) {
		$doneContainer.hide();
		$form.show();
		this.preloadCaptcha();
	}
};


