var options = {  
	beforeSubmit:  function(formData, jqForm, options) {
		if (checkFormFields()) return true;
		return false;
	},
	success:  function (responseText, statusText, xhr, $form) {
		$('.content_active_flyer_content_titlebar_header').hide();
		$('.content_active_flyer_content_text').html(responseText);
		$('#content_active_flyer_content_form').hide();
		$('#answer').val('');
	}
}
$('#userAddForm').ajaxForm(options); //track and wait for a onsubmit event on "logiForm"

function checkFormFields() {
	var isOk = true;
	$('.mandatory').each(function(i) {
		if (($(this).attr('type') == 'text' && $(this).val() == '') || ($(this).attr('type') == 'checkbox' && $(this).is(':checked') == false)) {
			$(this).addClass('error');
			isOk = false;
		} else {
			$(this).removeClass('error');
		}
	});
	return isOk;
}

function resetFormFields() {
	$('.mandatory').each(function(i) {
		$(this).removeClass('error');
	});
}
