$(function(){
// Datepicker
$('#campo-data-de').datepicker({
changeMonth :true,
changeYear :true,
yearRange :'1900:2010'
});
$('#campo-data-a').datepicker({
changeMonth :true,
changeYear :true,
yearRange :'1900:2010'
});
//===========================================================
$("form").submit(function(eventObject){
removerAreaMensagem();
//Para corrigir problema ao fazer download de relat�rios, etc.
if($('#isRelatorio') == undefined || $('#isRelatorio').attr('value') == undefined || $('#isRelatorio').attr('value') == 'false'){
bloquearBrowser();
}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');
}
});
//Limitador de TextArea
jQuery.fn.maxLength = function(maxlength) {
return this.each(function() {
$(this).bind('keypress keyup change mouseover', function(e) {
var key,
max = maxlength ? maxlength : $(this).attr('maxlength'),
tam = this.value.length,
ie = (typeof window.ActiveXObject != 'undefined');
key = (ie) ? e.keyCode : e.which;
if (key >= 33 || key == 13 || key == 32) {
if (tam >= max) { e.preventDefault(); }
}
else if (tam > max) {
this.value = this.value.substring(0, max);
}
});
});
};
});
/**
* 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);
});
}
/*
* Remover a div de mensagens da popup
*/
function removerBarraMensagens(popup) {
$("#" + popup + " > div").remove();
}
function desabilitarInputsForm(){
$("input[type='text']").attr("disabled", true);
$("input[type='radio']").attr("disabled", true);
$("input[type='checkbox']").attr("disabled", true);
$("input[type='file']").attr("disabled", true);
$("select").attr("disabled", true);
$("textarea").attr("disabled", true);
//
$("#span_lupa_consulta_endereco").hide();
//Para o ckEditor
$(".cke_toolbar").css('display','none');
$(".cke_toolbox_collapser").css('display','none');
if(window.CKEDITOR != undefined && window.CKEDITOR != null){
CKEDITOR.config.readOnly = true
}
}
function habilitaInputsForm(){
$("input[type='text']").attr("disabled", false);
$("input[type='radio']").attr("disabled", false);
$("input[type='checkbox']").attr("disabled", false);
$("input[type='file']").attr("disabled", false);
$("select").attr("disabled", false);
$("textarea").attr("disabled", false);
}
function bloquearBrowser(){
//Para o caso de impress�es
if($('#isRelatorio') == undefined || $('#isRelatorio').attr('value') == undefined || $('#isRelatorio').attr('value') == 'false'){
$("#bloquerBrowser").show();
}else{
$('#isRelatorio').attr('value','false');
}
}
function desbloquearBrowser(){
$("#bloquerBrowser").hide();
}
function removerAreaMensagem(){
$('#area-mensagens').remove();
$('#areaMensagemDownload').html('');
}
function limitaTextArea(campo, tamanhoMaximo) {
var tamanho = campo.value.length;
var tex = campo.value;
if (tamanho >= tamanhoMaximo) {
campo.value = tex.substring(0, tamanhoMaximo);
}
return true;
}
function selecionarTodosComboMultiple(idCombo){
$("#"+idCombo +" option").each(function(){
$(this).attr('selected', true);
});
}
function adicionarItemCombo(select, value, text){
if(value != ''){
var naoAchou = true;
$("#"+select+" option").each(function() {
if($(this).attr("value") == value){
naoAchou = false;
}
});
if(naoAchou){
$("#"+select).append("");
}
}
}
function preencherListaCombo(idSelect, idSelectDestino){
var select = document.getElementById(idSelect);
for ( var i = 0; i < select.length; i++) {
if(select[i].selected) {
adicionarItemCombo(idSelectDestino, select[i].value, select[i].text);
}
}
$("#"+idSelect+" option:selected").remove();
$("#"+idSelectDestino).sortOptions();
}
function preencherTodosListaCombo(idSelect, idSelectDestino){
var select = document.getElementById(idSelect);
for ( var i = 0; i < select.length; i++) {
adicionarItemCombo(idSelectDestino, select[i].value, select[i].text);
}
$("#"+idSelect).attr("value",'');
$("#"+idSelect).empty();
$("#"+idSelectDestino).sortOptions();
}
function removerTodosListaCombo(idSelect){
$('#'+idSelect).children().remove();
}
function adicionarItemComboOfInputText(idInputText, idSelect){
var value = $('#'+idInputText).attr('value').trim();
if(value != ''){
var naoAchou = true;
$("#"+idSelect+" option").each(function() {
if($(this).attr("value") == value){
naoAchou = false;
}
});
if(naoAchou){
$("#"+idSelect).append("");
}
$('#'+idInputText).attr('value', '');
$("#"+idSelect).sortOptions();
}
}
function adicionarItemComboOfInputTextById(idInputText, idNmInputText, idSelect){
var value = $('#'+idInputText).attr('value').trim();
var dsValue = $('#'+idNmInputText).attr('value').trim();
if(value != ''){
var naoAchou = true;
$("#"+idSelect+" option").each(function() {
if($(this).attr("value") == value){
naoAchou = false;
}
});
if(naoAchou){
$("#"+idSelect).append("");
}
$('#'+idInputText).attr('value', '');
$('#'+idNmInputText).attr('value', '');
$("#"+idSelect).sortOptions();
}
}
function removerItemComboOf(idSelect){
$("#"+idSelect+" option:selected").remove();
}
function isInputCheckSelecionado(nameInputCheck){
var isChecked = false;
if($('input[name="'+nameInputCheck+'"]') != undefined){
$('input[name="'+nameInputCheck+'"]').each(function(){
if(this.checked){
isChecked = true;
}
});
}
return isChecked;
}
function getValueInputCheckSelecionado(nameInputCheck){
var values = new Array();
if($('input[name="'+nameInputCheck+'"]') != undefined){
$('input[name="'+nameInputCheck+'"]').each(function(){
if(this.checked){
values.push(this.value);
}
});
}
return values;
}
function mensagemSelecioneUmRegistro(){
$('#dialog-selecione-um-registro').dialog('open');
}
function chkBoxChildByName(objectCheck, nameChkChild){
var isChecked = !$(objectCheck).attr("checked");
$('input[name="'+nameChkChild+'"]').attr("checked", !isChecked);
return true;
}
function chkBoxChildByIdStartWith(objectCheck, startIdChkChild){
var isChecked = !$(objectCheck).attr("checked");
$('input[id^="'+startIdChkChild+'"]').attr("checked", !isChecked);
return true;
}
function ordenarPorCampoTable(campoOrdenacao, idCampo){
var campo = $('#'+idCampo).attr('src');
var TipoOrdenacao = "";
if (campo.indexOf("bg.gif") > -1){//default
$('#'+idCampo).attr('src', './img/asc.gif');
TipoOrdenacao = "ASC";
}else if (campo.indexOf("asc.gif") > -1){//Asc
$('#'+idCampo).attr('src', './img/desc.gif');
TipoOrdenacao = "DESC";
}else if (campo.indexOf("desc.gif") > -1){//Desc
$('#'+idCampo).attr('src', './img/asc.gif');
TipoOrdenacao = "ASC";
}
$("#nomeCampoOrdenacao").attr('value',campoOrdenacao);
$("#idColunaOrdenacao").attr('value',idCampo);
$("#tipoOrdenacao").attr('value',TipoOrdenacao);
}
function trataOrdenarPorCampoTable(){
var campoOrdenacao = $("#nomeCampoOrdenacao").val();
var tipoOrdenacao = $("#tipoOrdenacao").val();
var idColunaOrdenacao = $("#idColunaOrdenacao").val();
if (campoOrdenacao != ''){
if (tipoOrdenacao == 'ASC'){
$('#'+idColunaOrdenacao).attr('src', './img/asc.gif');
}else{
$('#'+idColunaOrdenacao).attr('src', './img/desc.gif');
}
}
}
function gerarRelatorio(){
$('#isRelatorio').attr('value','true');
removerAreaMensagem();
}
function abrirImpressaoHtml(url){
var w = window.open(url, "impressaoHTMLSIARP", "scrollbars=1,resizable=1,height=800,width=800,menubar=yes,toolbar=no, location=no");
w.focus();
}
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;
}
}
}
/**
* Ordena os valores de uma combo-box. Ou de um dual-list.
* Mesmo que os valores contenham acentuacao.
* @param id_componente
*/
function ordenarSelect(id_componente){
var selectToSort = jQuery('#' + id_componente);
var optionActual = selectToSort.val();
selectToSort.html(selectToSort.children('option').sort(function (a, b) {
return a.text.localeCompare(b.text);
})).val(optionActual);
}