function ajax_post(form, loading, messages, hide, clean, update_div, callback) {
	if(update_div === undefined) {
		update_div = false;
	}
	var options = { 
		beforeSubmit:  function() {
			$(loading).width($(form).parent().width()).height($(form).parent().height()).show();
		},
		success: function(data) {
			if(messages) {
				var json = null;

				try {
					var json = eval('(' + data + ')');
				}
				catch(err) {
				}

				var message = (json !== null && json.messages != undefined) 
					? json.messages : data;

				$(messages).removeClass('erro').addClass('sucesso').html(message).show();

				$('.mensagem-campo').text('');
			}

			$(loading).hide();

			if(hide) {
				$(form).hide();
			}
			else {
				$(form).show();
			}

			if(clean) {
				$(form).find('input[type=text]').val('');
				$(form).find('textarea').val('');
				$(form).find('select').val('');
			}

			if(update_div) {
				$(update_div).html(data);
			}

			if(typeof callback === 'function') {
				callback();
			}
		},
		error: function(xmlhttp) {
		   var json = null;

		   try {
			   var json = eval('(' + xmlhttp.responseText + ')');
		   }
		   catch(err) {
		   }

		   $('.mensagem-campo').text('');

		   $(loading).hide();

		   var message = (json !== null && json.messages != undefined) 
  			           ? json.messages : xmlhttp.responseText;

		   if(messages) {
			   $(messages).removeClass('sucesso').addClass('erro').html(message).show();
		   }

		   if(typeof json == 'object') {
			   for(i in json) {
				   $('.mensagem-campo.' + i).text(json[i]);
			   }
		   }

		   $(form).show();
		}
	}

	$(form).live('submit', function() { 
		$(this).ajaxSubmit(options); 
		return false; 
	});

	if(messages) {
		$(form + ' input, ' + form + ' textarea, ' + form + ' select, ' + form + ' radio').focus(function(){
			$(messages).slideUp("slow");
		});
	}
}

