function openAjaxDialog(title, url, options){
	dialog=null;
	if(typeof(options) == 'undefined') options = new Object();
	height =  (options.height != 'undefined') ? options.height : 400;
	width =  (options.width != 'undefined') ? options.width : 400;
	modal =  (options.modal != 'undefined') ? options.modal : false;

	if(typeof($('#tmpDiv').attr('id')) != 'undefined'){
		tmpDiv = $('#tmpDiv');
	}
	else{
		tmpDiv = $('<div/>');
		tmpDiv.attr('id','tmpDiv');
		tmpDiv.attr('style','display:none');
		$('body').append(tmpDiv);
	}

	dialog = $('#'+tmpDiv.attr("id")).dialog({height: height,width: width,modal: modal});

	ajaxUpdater(tmpDiv.attr("id"),url);

	return dialog;

}

function ajaxUpdater(target, url, options){

	$('#'+target).html("<img src='/images/loading.gif' align='top' /> Carregando...");

	var onSuccess = function(){};
	var data = new Array();

	if(typeof(options) != 'undefined') data = (options.data != 'undefined') ? options.data : null;
	if(typeof(options) != 'undefined') onSuccess = (options.onSuccess != 'undefined') ? options.onSuccess : function(){};

	$.ajax({
		type: "POST",
		url: url,
		data: data,
		success: function(content){
			$('#'+target).html(content);
			onSuccess;
		},
		error: function(jqXHR, textStatus, errorThrown){
			$('#'+target).html(errorThrown);
		}
	});
}

function ajaxRequest(url, options){

	var onSuccess = function(){};
	var data = new Array();

	if(typeof(options) != 'undefined') button = (options.button != 'undefined') ? options.button : null;
	if(typeof(options) != 'undefined') data = (options.data != 'undefined') ? options.data : null;
	if(typeof(options) != 'undefined') onSuccess = (options.onSuccess != 'undefined') ? options.onSuccess : function(){};
	if(typeof(options) != 'undefined') contentType = (options.contentType != 'undefined') ? options.contentType : 'text/html';

	if(button != null) {
		oldButtonContent = $('#'+button).html(); 
		$('#'+button).attr('disabled',true);
		$('#'+button).html("<img src='/images/loading.gif' align='top' /> Carregando...");
	}

	$.ajax({
		type: "POST",
		url: url,
		data: data,
		success: function(content){
			onSuccess;
			if(button != null) {
				$('#'+button).html(oldButtonContent);
				$('#'+button).attr('disabled',false);
			}
		},
		error: function(jqXHR, textStatus, errorThrown){
			alert(errorThrown);
			if(button != null) {
				$('#'+button).html(oldButtonContent);
				$('#'+button).attr('disabled',false);
			}
		}
	});
}
