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) {
				$(messages).removeClass('erro').addClass('sucesso').html(data).show();
			}

			$(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) {
		   $(loading).hide();
		   if(messages) {
			   $(messages).removeClass('sucesso').addClass('erro').html(xmlhttp.responseText).show();
		   }
		   $(form).show();
		}
	}

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

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

