$(function() { $().ajaxStart(function() { $("#bloquerBrowser").show(); }); $().ajaxComplete(function() { $("#bloquerBrowser").hide(); }); $().ajaxSuccess(function(evnt, request, settings) { $("#bloquerBrowser").hide(); }); $().ajaxError(function(request, settings, exception) { $("#bloquerBrowser").hide(); }); $("form").submit( function(eventObject) { $('#area-mensagens').hide(); // Solução encontrada para Corrigir problema ao fazer download // de relatorios, etc. if ($('#isRelatorio') == undefined || $('#isRelatorio').attr('value') == undefined || $('#isRelatorio').attr('value') == 'false') { try { selecionaItensTodasListas(); } catch (err) { } $("#bloquerBrowser").show(); } else { $('#isRelatorio').attr('value', 'false'); } // } }); $("input[type='submit']") .click( function(eventObject) { if (($(this).attr('value').toUpperCase() == 'CONSULTAR') || ($(this).attr('value').toUpperCase() == 'CONSULTA')) { $("input[name='paginaAtual']").attr('value', '1'); } }); // Dialog exemplo $('#dialog-exemplo').dialog({ autoOpen : false, modal : true, width : 600, height : 400, resizable : false }); // Dialog exemplo link $('#dialog-exemplo-link').click(function() { $('#dialog-exemplo').dialog('open'); return false; }); // Dialog confirm $('#dialog-confirm').dialog({ autoOpen : false, modal : true, resizable : false, buttons : { "Não" : function() { $(this).dialog("close"); }, "Sim" : function() { submeter(); $(this).dialog("close"); } } }); // Dialog confirm link $('#dialog-confirm-link').click(function() { $('#dialog-confirm').dialog('open'); return false; }); // Dialog fun��es gerais $('#dialog-funcoes').dialog({ autoOpen : false, modal : true, width : 600, height : 400, resizable : false }); // Dialog fiun��es gerais link $('#dialog-funcoes-link').click(function() { $('#dialog-funcoes').dialog('open'); return false; }); // Dialog fiun��es gerais link $('#dialog-situacao-link').click(function() { $('#dialog-situacao').dialog('open'); return false; }); // Datepicker $('#campo-data-de').datepicker({ changeMonth : true, changeYear : true, yearRange : '1900:2010' }); $('#campo-data-a').datepicker({ changeMonth : true, changeYear : true, yearRange : '1900:2010' }); }); function dwrErrorHandler(mensagem, exception) { desbloquearBrowser(); if (exception.javaClassName == 'br.gov.mapa.arquitetura.exception.BusinessExceptionAlert') { adicionarMensagem(mensagem, 'A'); } else if (exception.javaClassName == 'br.gov.mapa.arquitetura.exception.BusinessExceptionInfo') { adicionarMensagem(mensagem, 'S'); } else { adicionarMensagem(mensagem, 'E'); } } function adicionarMensagem(mensagem, tipo) { exibirMensagem("area-mensagens", mensagem, tipo); } function exibirMensagem(id, mensagem, tipo) { if (tipo == 'A') { $('#'+id).html( ""); } else if (tipo == 'S') { $('#'+id).html( ""); } else { $('#'+id).html( ""); } $('#'+id).show(); $('html, body').animate({ scrollTop: 0 }, 'slow'); } function bloquearBrowser() { $("#bloquerBrowser").show(); } function desbloquearBrowser() { $("#bloquerBrowser").hide(); } // function chkBoxChildByName(objectCheck, nameChkChildArquivo) { // var isChecked = !$(objectCheck).attr("checked"); // $("input[name='" + nameChkChildArquivo + "']").attr("checked", !isChecked); // return true; // } function chkBoxChildByName(objectCheck, nameChkChildArquivo) { var isChecked = !$(objectCheck).attr("checked"); $("input[name='" + nameChkChildArquivo + "']").each( function() { if ($(this).attr('disabled') == null || $(this).attr('disabled') == '') { $(this).attr("checked", !isChecked); } }); return true; } /* * Remover a div de mensagens da popup */ function removerBarraMensagens(popup) { $("#" + popup + " > div").remove(); } /** * M�todo exclusivamente utilizando para remover valores de input type text, * select e textarea * * @return */ function removerValoresInputs() { $("input[type='text']").attr("value", ""); $("textarea").val(""); $("select").each(function(sel) { $(this).attr("selectedIndex", 0); }); } function abrirManualUsuario(ref) { window .open( 'paginas/manualusuario/MAPA-SIGEP_Manual_do_Usuário.htm#' + ref, 'SIGEP_AJUDA', 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=800,height=400'); } function desabilitarInputsForm() { $("input[type='text']").attr("disabled", true); $("input[type='radio']").attr("disabled", true); $("input[type='checkbox']").attr("disabled", true); $("select").attr("disabled", true); $("textarea").attr("disabled", true); } function habilitaInputsForm() { $("input[type='text']").attr("disabled", false); $("input[type='radio']").attr("disabled", false); $("input[type='checkbox']").attr("disabled", false); $("select").attr("disabled", false); $("textarea").attr("disabled", false); } function limparParametroOrdenacao() { $("input[name='paginaAtual']").attr('value', '1'); $("input[name='parametrosConsulta.parametroAscDesc']").val(''); $("input[name='parametrosConsulta.parametroOrdenacao']").val(''); } // Habilita os inputs/object/element de todos os filhos do elemento pai(passando // o id do element pai). // IdElement parent, isHabilitar (false or true) function habilitaDesabilitaInputsChildsForm(idElement, isHabilitar) { var pegaTodos = { pega : function(maiorDeTodos) { var filho; // Passo por todos os controles. $(maiorDeTodos) .children() .each( function(i) { filho = $(this); var nomeTag = $.trim($(filho).attr("tagName")); if ($(filho).attr('type') != undefined && $.trim($(filho).attr('type') .toLowerCase()) != 'text/javascript' && $.trim($(filho).attr('type') .toLowerCase()) != 'hidden' && $.trim(nomeTag.toLowerCase()) != 'script') { if ($(filho).attr("disabled") == !isHabilitar) { $(filho).attr("disabled", isHabilitar); } if ($(filho).css("display") == 'hidden' || $(filho).css("display") == 'none' || $(filho).css("visibility") == 'hidden') { if (isHabilitar) { $(filho).show(); } else { $(filho).hide(); } } } if ($(filho).children().length != 0) { pegaTodos.pega($(filho)); } }); } }; pegaTodos.pega($("#" + idElement)); } function removerAreaMensagem() { $('#area-mensagens').hide(); } function isListaCheckBoxPreenchida(nomeLista) { return ($("input[name=\'" + nomeLista + "\']:checked").val() != undefined); /* * var tam = $("input[name=\'" + nomeLista + "\']").length; * * for(var i = 0; i < tam; i++){ if($("input[name=\'" + nomeLista + * "\']")[i].checked){ return true; break; } } * * return false; */ } /* * Bloquear ctrl + v * */ function noCopy(event) { var tecla = String.fromCharCode(event.keyCode).toLowerCase(); if (event.ctrlKey && (tecla == "c" || tecla == "v")) { window.event ? event.returnValue = false : event.preventDefault(); return false; } } function noEnter(event) { var tecla = event.keyCode || event.witch; if (tecla == 13) { return false; } else { return true; } } function noSubmit(event) { var tecla = event.keyCode || event.witch; if (tecla == 13) { return false; } } function htmlFocus(elemento) { if (document.getElementById(elemento) != undefined && document.getElementById(elemento).disabled == false) document.getElementById(elemento).focus(); } function htmlFocusFistInputEmpty(idForm){ $('#'+idForm+' input[type=text]:visible,#'+idForm+' select:visible,#'+idForm+' textarea:visible').each(function() { if ($(this).val() == '') { this.focus(); return false; } }); } function selecionarItensLista(idLista) { var objectSelect = document.getElementById(idLista); if (objectSelect != null) { for ( var i = 0; i < objectSelect.options.length; i++) { objectSelect.options[i].selected = true; } } } function tirarSelecaoItensLista(idLista) { var objectSelect = document.getElementById(idLista); if (objectSelect != null) { for ( var i = 0; i < objectSelect.options.length; i++) { objectSelect.options[i].selected = false; } } } function OnDivScroll(idListaObjetos) { if (idListaObjetos.options.length > 8) { idListaObjetos.size = idListaObjetos.options.length; } else { idListaObjetos.size = 8; } } function retiraOpcoesLista(idLista, idListaSelecionados) { var i = 0; selecionarItensLista(idLista); selecionarItensLista(idListaSelecionados); var lista = dwr.util.getValue(idLista); var listaSelecionados = dwr.util.getValue(idListaSelecionados); while (listaSelecionados.length > 0 && i < listaSelecionados.length) { var id = listaSelecionados[i]; var existeLista = false; for ( var j = 0; j < lista.length; j++) { if (id == lista[j]) { existe = true; break; } } var existeListaSelecionados = false; for ( var j = 0; j < listaSelecionados.length; j++) { if (id == listaSelecionados[j]) { existe = true; break; } } if (!existeLista) { $("#" + idListaSelecionados + " option[value='" + id + "']") .remove(); } else { if (existeListaSelecionados) { $("#" + idLista + " option[value='" + id + "']").remove(); } } i++; } tirarSelecaoItensLista(idLista); tirarSelecaoItensLista(idListaSelecionados); } function limitarTextArea(limitField, limitNum) { var length = 0; for ( var i = 0; i < limitField.value.length; i++) { if (limitField.value[i] == '\r' || limitField.value[i] == '\n') { length += 2; if (i < limitNum) { limitNum = limitNum - 1; } } else { length++; } } if (length > limitNum) { limitField.value = limitField.value.substring(0, limitNum); } } function validaData(digData) { var bissexto = 0; var data = digData.value; var tam = data.length; if (tam == 10) { var dia = data.substr(0, 2) var mes = data.substr(3, 2) var ano = data.substr(6, 4) if ((ano > 1900) || (ano < 2100)) { switch (mes) { case '01': case '03': case '05': case '07': case '08': case '10': case '12': if (dia <= 31) { return true; } break case '04': case '06': case '09': case '11': if (dia <= 30) { return true; } break case '02': /* Validando ano Bissexto / fevereiro / dia */ if (ano % 400 == 0) { bissexto = 1; } else if (ano % 100 == 0) { bissexto = 0; } else if (ano % 4 == 0) { bissexto = 1; } if ((bissexto == 1) && (dia <= 29)) { return true; } if ((bissexto != 1) && (dia <= 28)) { return true; } break } } digData.value = ''; } else { digData.value = ''; } return false; } function validaTamanhoCampo(campo, tamanhoPermitido) { var tamanho = campo.value.length; if (tamanho != tamanhoPermitido) { campo.value = ''; } } function maxValorCemPorcento(campo) { var valor = campo.val(); if (valor != '' && parseFloat(valor) > parseFloat(100)) { campo.val(valor.substring(0, 5)); campo.setMask({ mask : "99.99" }); campo.unsetMask(); } } function maxlengthTextarea(textarea,limit){ $(textarea).keypress(function(e){ if(this.value.length >= limit){ return false; } return true; }).keyup(function(e){ validarMaxlength(this,limit); }).mouseout(function(e){ validarMaxlength(this,limit); }).blur(function(e){ validarMaxlength(this,limit); }); } function validarMaxlength(campo,lengthTextArea){ if(campo.value.length >= lengthTextArea){ campo.value = campo.value.substr(0, lengthTextArea); } } function campoNumerico(e){ if((e.which == 8) ||(e.which >= 96 && e.which <= 105)){ return true; } return !isNaN(String.fromCharCode(e.which)); } function defineMascaraCPF() { //CNPJ com 18 dígitos com as pontuações if($("#idCpfCnpj").val().length > 14){ $("#idCpfCnpj").val(''); //Limpa para suportar a máscara CPF } $("#idCpfCnpj").setMask({mask:"999.999.999-99"}); htmlFocus('idCpfCnpj'); } function defineMascaraCNPJ() { //CPF com 14 dígitos com as pontuações if($("#idCpfCnpj").val().length <= 14){ $("#idCpfCnpj").val(''); //Limpa para suportar a máscara CNPJ } $("#idCpfCnpj").setMask({mask: "99.999.999/9999-99"}); htmlFocus('idCpfCnpj'); }