jQuery(document).ready(function()
	{
	callUndo(".undo_nao_veio","modulos/administrar_caixa/undo_nao_veio_save.php","name");
	callUndo(".undo_sangria" ,"modulos/administrar_caixa/undo_sangria.php"	 	,"name");
	callUndo(".undo_payment" ,"modulos/administrar_caixa/undo_payment.php"		,"id");
	jQuery(".ui-effects-wrapper").css("position", "");
	});

function callUndo(class, url, atrrib)
	{
	jQuery(class).click(function()
		{
			
		jQuery.get(url, {value : jQuery(this).attr(atrrib)},
			function(data)
				{
				if(data == "ok")
					{
					load_url_caixa();
					buscaPendencia();
					}
				});
		});
	}
	
function load_url_caixa()
	{
	setTimeout("Loader(\"modulos/administrar_caixa/list_caixa_situacao.php\", \"div_operadores\")", 1000);
	setTimeout("Loader(\"modulos/administrar_caixa/list_recebimentos.php\", \"div_recebimentos\")", 1000);
	setTimeout("Loader(\"modulos/administrar_caixa/list.php\", \"listagem_div\")", 1000);
	setTimeout("Loader(\"modulos/administrar_caixa/total_receber.php\", \"div_receber\")", 1000);
	setTimeout("Loader(\"modulos/administrar_caixa/list_nao_veio.php\", \"div_list_nao_veio\")", 1000);
	setTimeout("Loader(\"modulos/administrar_caixa/list_sangria.php\", \"div_list_sangria\")", 1000);
	}
	
function startWait(type) {
    if (type == "modal") {
        jQuery("#waitMessage").bgiframe();
        jQuery("#waitMessage").css("position", "relative");
        jQuery.ui.dialog.defaults.bgiframe = true;
        jQuery("#waitMessage").dialog({ 
                                  modal: true,
                                  bgiframe: true,
                                  show: 'slide',
                                  hide: 'slide',
                                  title: 'AGUARDE...',
								  zIndex: 10,
                                  closeOnEscape: false
                              });
        jQuery(".ui-dialog-titlebar-close").css("display", "none");
        jQuery("#waitMessage").css("position", "relative");
    } else {
        jQuery("#waitMessage").css("position", "absolute");
        jQuery("#waitMessage").fadeIn(100);
        jQuery("#waitMessage").css("position", "absolute");
    }
}

function stopWait() {
    if (jQuery("#waitMessage").dialog('isOpen')) {
        jQuery("#waitMessage").dialog('destroy');
    }
    jQuery("#waitMessage").fadeOut(100);
}

function confirmScreen(msg)
	{
	//conteudo antigo
	jQuery("#confirmMessage").bgiframe();
	jQuery("#confirmMessage").css("position", "relative");
	jQuery.ui.dialog.defaults.bgiframe = true;
	jQuery("#confirmMessage").html("<center>" + msg + "</center>");
	jQuery("#confirmMessage").dialog({ 
							  modal: true,
							  bgiframe: true,
							  show: 'slide',
							  hide: 'slide',
							  title: 'Confirma&ccedil;&atilde;o',
							  zIndex: 10,
							  closeOnEscape: true,
							  buttons: 
							  	{
								'Fechar': function() 
									{
									if (jQuery("#confirmMessage").dialog('isOpen')) 
										{
										jQuery("#confirmMessage").dialog('destroy');
										}
									jQuery("#confirmMessage").fadeOut(100);
									}
								}
						  });
	jQuery(".ui-dialog-titlebar-close").css("display", "none");
	}

function checkRegexp(o,regexp,n) 
	{
	if(!( regexp.test( o.val()))) 
		{
		o.addClass('ui-state-error');
		updateTips(n);
		return false;
		} 
	else 
		{
		return true;
		}
	}

function checkLength(o,n,min,max) 
	{
	if (o.val().length > max || o.val().length < min) 
		{
		o.addClass('ui-state-error');
		updateTips("O tamanho do(a) " + n + " precisa ter entre "+min+" e "+max+" caracteres.");
		return false;
		} 
	else 
		{
		return true;
		}
	}
	
function setCalendar(fieldSelector, url, div) {
    jQuery.datepicker.setDefaults(jQuery.datepicker.regional['pt-BR']);
    jQuery(fieldSelector).datepicker({ 	
		numberOfMonths: [2,3],
		showButtonPanel: true,
		showCurrentAtPos:3,
		showOn: 'button', 
		buttonImage: '/imagens/icones/bt_calendar.gif', 
		buttonImageOnly: true,
		regional:'pt-BR',
		onSelect:function(dateText,inst)
			{
			Loader(url + "?data=" + dateText, div);
			}
                                            });
}