﻿/* Função AbrirJanela() 
Onde,
bolPermirirRedimensionar: true/false para permitir se o usuario pode redimensionar o tamanho da nova janela.
bolExibirMenu: true/false para exibir o menu da nova janela.
intLargura: valor inteiro para o tamnho da largura da nova janela.
intaltura: valor inteiro para o tamnho da altura da nova janela.
bolCentralizar: para centralizar a nova janela na tela. */
function AbrirJanela(strUrl, bolPermitirRedimensionar, bolExibirMenu, intLargura, intAltura, bolCentralizar, intDistanciaTopo, intDistanciaEsquerda) {
    if (!intDistanciaEsquerda)
        intDistanciaEsquerda = 0;
    if (!intDistanciaTopo)
        intDistanciaTopo = 0;
    var intAlturaTela = SelecionarTamanhoTelaHeight();
    var intLarguraTela = SelecionarTamanhoTelaWidth();
    var intTop = (intAlturaTela > 0 ? (intAlturaTela - intAltura) / 2 : 0);
    var intLeft = (intLarguraTela > 0 ? (intLarguraTela - intAltura) / 2 : 0);
    window.open(strUrl,
                "window",
                "resizable=" + (bolPermitirRedimensionar ? "yes" : "no") + "," +
                "status=no,location=no,toolbar=no,scrollbars=yes,directories=no," +
                "menubar=" + (bolExibirMenu == true ? "yes" : "no") + "," +
                "width=" + intLargura + "," +
                "height=" + intAltura + "," +
                (bolCentralizar ? "left=intLeft,top=intTop,screenX=intLeft,screenY=intTop" : "left=" + intDistanciaEsquerda + ",top=" + intDistanciaTopo + ",screenX=" + intDistanciaEsquerda + ",screenY=" + intDistanciaTopo));
}

/* Função blink()
Habilita tag blink no IE */
function blink() {
    if (window.attachEvent) {
        window.attachEvent('onload',
        function() {
            var sAgent = navigator.userAgent.toLowerCase();
            if ((new RegExp("msie\ ")).test(sAgent)) {
                setInterval(function() {
                    var aBlink = document.getElementsByTagName('BLINK');
                    for (var i = 0; i < aBlink.length; i++) {
                        if (aBlink[i].style.visibility == 'hidden')
                            aBlink[i].style.visibility = 'visible';
                        else
                            aBlink[i].style.visibility = 'hidden';
                    }
                }, 500);
            }
        });
    }
}

/* Função blurMedia(Objeto, Percentual, Media, intQtdeCasasDecimais, NegativeNumber, Items, SetColor)
Calcula o percentual entre dois campos e faz a média */
function blurMedia(Objeto, Percentual, Media, Items, SetColor) {
    Objeto.value = passaDominio(Objeto.value, "0123456789");
    if ((Objeto.value == '') || (parseInt(Objeto.value) > 100)) {
        window.alert('O percentual deve variar entre 0 e 100%!');
        Objeto.value = "0";
        Objeto.focus();
    }
    var numSum = new Number();
    var numCount = new Number();
    numSum = 0;
    numCount = 0;
    for (i = 0; i < Items.length; i++) {
        numSum = numSum + ProgressValueGet(Items[i]);
        numCount++;
    }
    numSum = numSum - ProgressValueGet(Percentual);
    if (Objeto.value == "")
        ProgressValueSet(Percentual, 0, SetColor);
    else {
        ProgressValueSet(Percentual, Objeto.value, SetColor);
        // Calculando média
        numSum = numSum + parseInt(Objeto.value);
    }
    ProgressValueSet(Media, (numSum / numCount).toFixed(0), SetColor);
    return true;
}

/* Função blurMultiplicaSoma(Objeto, Multiplicador, Multiplicacao, Total, intQtdeCasasDecimais, intQtdeCasasDecimais2, NegativeNumber)
Executa a multiplicação entre dois campos e totaliza */
function blurMultiplicaSoma(Objeto, Multiplicador, Multiplicacao, Total, intQtdeCasasDecimais, intQtdeCasasDecimais2, NegativeNumber) {
    if (NegativeNumber)
        Objeto.value = passaDominio(Objeto.value, "-0123456789");
    else
        Objeto.value = passaDominio(Objeto.value, "0123456789");
    Objeto.value = FormatarDecimal(Objeto.value, parseInt(intQtdeCasasDecimais), true);
    var numTotal = new Number();
    numTotal = parseFloat(SubstituirTudo(SubstituirTudo(Total.innerText, ".", ""), ",", "."));
    numTotal = total.toFixed(intQtdeCasasDecimais2);
    if (Multiplicacao.innerText != "") {
        numTotal = parseFloat(total) - parseFloat(SubstituirTudo(SubstituirTudo(Multiplicacao.innerText, ".", ""), ",", "."));
        numTotal = numTotal.toFixed(intQtdeCasasDecimais2);
    }
    if ((Objeto.value == "") ||
        ((Multiplicador.type == null) &&
         (Multiplicador.innerText == "")) ||
        ((Multiplicador.type != null) &&
         (Multiplicador.value == ""))) {
        Multiplicacao.innerText = "";
    }
    else {
        // Calculando multiplicação
        var numMult = new Number();
        if (Multiplicador.type == null)
            numMult = parseFloat(SubstituirTudo(SubstituirTudo(Objeto.value, ".", ""), ",", ".")) * parseFloat(SubstituirTudo(SubstituirTudo(Multiplicador.innerText, ".", ""), ",", "."));
        else
            numMult = parseFloat(SubstituirTudo(SubstituirTudo(Objeto.value, ".", ""), ",", ".")) * parseFloat(SubstituirTudo(SubstituirTudo(Multiplicador.value, ".", ""), ",", "."));
        numMult = numMult.toFixed(intQtdeCasasDecimais2);
        if (NegativeNumber)
            Multiplicacao.innerText = passaDominio(numMult, "-0123456789");
        else
            Multiplicacao.innerText = passaDominio(numMult, "0123456789");
        Multiplicacao.innerText = FormatarDecimal(Multiplicacao.innerText, parseInt(intQtdeCasasDecimais2), true);
        // Totalizando multiplicação
        numTotal = parseFloat(numTotal) + parseFloat(numMult);
        numTotal = numTotal.toFixed(intQtdeCasasDecimais2);
    }
    if (NegativeNumber)
        Total.innerText = passaDominio(numTotal, "-0123456789");
    else
        Total.innerText = passaDominio(numTotal, "0123456789");
    Total.innerText = FormatarDecimal(Total.innerText, parseInt(intQtdeCasasDecimais2), true);
    return true;
}

/* Função blurMultiplicaSomaA(Objeto, Mult1, Mult2, Multiplicacao, Total, intQtdeCasasDecimais, intQtdeCasasDecimais2, NegativeNumber)
Executa a multiplicação entre dois ou mais campos e totaliza */
function blurMultiplicaSomaA(Objeto, Mult1, Mult2, Multiplicacao, Total, intQtdeCasasDecimais, intQtdeCasasDecimais2, NegativeNumber) {
    if (NegativeNumber)
        Objeto.value = passaDominio(Objeto.value, "-0123456789");
    else
        Objeto.value = passaDominio(Objeto.value, "0123456789");
    Objeto.value = FormatarDecimal(Objeto.value, parseInt(intQtdeCasasDecimais), true);
    var numTotal = new Number();
    numTotal = parseFloat(SubstituirTudo(SubstituirTudo(Total.innerText, ".", ""), ",", "."));
    numTotal = numTotal.toFixed(intQtdeCasasDecimais2);
    if (Multiplicacao.innerText != "") {
        numTotal = parseFloat(numTotal) - parseFloat(SubstituirTudo(SubstituirTudo(Multiplicacao.innerText, ".", ""), ",", "."));
        numTotal = numTotal.toFixed(intQtdeCasasDecimais2);
    }
    // Calculando multiplicadores
    var numMult1 = new Number();
    var numMult2 = new Number();
    numMult1 = 0;
    for (i = 0; i < Mult1.length; i++) {
        if (Mult1[i].value != "")
            numMult1 = numMult1 + parseFloat(SubstituirTudo(SubstituirTudo(Mult1[i].value, ".", ""), ",", "."));
    }
    numMult2 = 0;
    for (i = 0; i < Mult2.length; i++) {
        if (Mult2[i].value != "")
            numMult2 = numMult2 + parseFloat(SubstituirTudo(SubstituirTudo(Mult2[i].value, ".", ""), ",", "."));
    }
    if ((numMult1 == 0) || (numMult2 == 0))
        Multiplicacao.innerText = "";
    else {
        // Calculando multiplicação
        var numMult = new Number();
        numMult = numMult1 * numMult2;
        numMult = numMult.toFixed(intQtdeCasasDecimais2);
        if (NegativeNumber)
            Multiplicacao.innerText = passaDominio(numMult, "-0123456789");
        else
            Multiplicacao.innerText = passaDominio(numMult, "0123456789");
        Multiplicacao.innerText = FormatarDecimal(Multiplicacao.innerText, parseInt(intQtdeCasasDecimais2), true);
        // Totalizando multiplicação
        numTotal = parseFloat(numTotal) + parseFloat(numMult);
        numTotal = numTotal.toFixed(intQtdeCasasDecimais2);
    }
    if (NegativeNumber)
        Total.innerText = passaDominio(numTotal, "-0123456789");
    else
        Total.innerText = passaDominio(numTotal, "0123456789");
    Total.innerText = FormatarDecimal(Total.innerText, parseInt(intQtdeCasasDecimais2), true);
    return true;
}

/* Função blurPercentualMedia(Objeto, Dividendo, Divisor, Percentual, Percentual2, Media, Media2, intQtdeCasasDecimais, NegativeNumber, Items, SetColor)
Calcula o percentual entre dois campos e faz a média */
function blurPercentualMedia(Objeto, Dividendo, Divisor, Percentual, Percentual2, Media, Media2, intQtdeCasasDecimais, NegativeNumber, Items, SetColor) {
    if (NegativeNumber)
        Objeto.value = passaDominio(Objeto.value, "-0123456789");
    else
        Objeto.value = passaDominio(Objeto.value, "0123456789");
    Objeto.value = FormatarDecimal(Objeto.value, parseInt(intQtdeCasasDecimais), true);
    var numSum = new Number();
    var numCount = new Number();
    numSum = 0;
    numCount = 0;
    for (i = 0; i < Items.length; i++) {
        numSum = numSum + ProgressValueGet(Items[i]);
        numCount++;
    }
    numSum = numSum - ProgressValueGet(Percentual);
    var numDividendo = new Number();
    numDividendo = parseFloat(SubstituirTudo(SubstituirTudo(Dividendo.value, ".", ""), ",", "."));
    var numDivisor = new Number();
    numDivisor = parseFloat(SubstituirTudo(SubstituirTudo(Divisor.value, ".", ""), ",", "."));
    if ((Dividendo.value == "") || (numDividendo == 0) || (Divisor.value == "") || (numDivisor == 0)) {
        ProgressValueSet(Percentual, 0, SetColor);
        if (Percentual2 != null)
            Percentual2.value = 0;
    }
    else {
        // Calculando percentual
        var numPercentual = new Number();
        numPercentual = (numDividendo / numDivisor) * 100;
        if (numPercentual > 100)
            numPercentual = 100;
        numPercentual = numPercentual.toFixed(0);
        ProgressValueSet(Percentual, numPercentual, SetColor);
        if (Percentual2 != null)
            Percentual2.value = numPercentual;
        // Calculando média
        numSum = numSum + parseInt(numPercentual);
    }
    ProgressValueSet(Media, (numSum / numCount).toFixed(0), SetColor);
    if (Media2 != null)
        Media2.value = (numSum / numCount).toFixed(0);
    return true;
}

/* Função blurSoma(Objeto, Items, Resultado, intQtdeCasasDecimais, NegativeNumber)
Calcula a soma de uma coluna */
function blurSoma(Objeto, Items, Resultado, intQtdeCasasDecimais, NegativeNumber) {
    if (NegativeNumber)
        Objeto.value = passaDominio(Objeto.value, "-0123456789");
    else
        Objeto.value = passaDominio(Objeto.value, "0123456789");
    Objeto.value = FormatarDecimal(Objeto.value, parseInt(intQtdeCasasDecimais), true);
    var numSoma = new Number();
    numSoma = 0;
    for (i = 0; i < Items.length; i++) {
        if (Items[i].value != "")
            numSoma = parseFloat(numSoma) + parseFloat(SubstituirTudo(SubstituirTudo(Items[i].value, ".", ""), ",", "."));
    }
    if (NegativeNumber)
        Resultado.innerText = passaDominio(numSoma.toFixed(parseInt(intQtdeCasasDecimais)), "-0123456789");
    else
        Resultado.innerText = passaDominio(numSoma.toFixed(parseInt(intQtdeCasasDecimais)), "0123456789");
    Resultado.innerText = FormatarDecimal(Resultado.innerText, parseInt(intQtdeCasasDecimais), true);
    return true;
}

/* Cancelar evento de digitação */
function CancelarDigitacao(Evento) {
    if (Evento) {
        Evento.keyCode = 0;
        Evento.returnValue = false;
    } else if (window.event) {
        window.event.keyCode = 0;
        window.event.returnValue = false;
    }
}

/* Exibe mensagem de confirmação, antes de executar exclusão do registro */
function ConfirmarExclusao() {
    return confirm('Deseja realmente excluir este registro?');
}

/* Desabilita os eventos do botao direito do mouse dos campos */
function DesabilitarBotaoDireito() {
    if ((event.button == 2) || (event.button == 1 + 2) || (event.button == 2 + 1)) {
        alert('Não é permitido usar o botão direito do mouse para Copiar/Colar dados nos campos deste formulário.');
    }
}

/* Limita o componente textarea a uma qtde determinada de 
caracteres e exibe qtos faltam para o limite, caso haja um campo para isso */
function LimitarQtdeCaracter(objCampo, intQtdeLimite, objCampoInformaLimite) {
    var strText = objCampo.value;
    var intTamanhoText = objCampo.value.length;
    var objInforma = document.getElementById(objCampoInformaLimite);
    var msg = "";
    if (intTamanhoText >= intQtdeLimite) {
        msg = "Limite de " + (intQtdeLimite) + " caracteres excedido.";
        if (String(objInforma) != "undefined")
            objInforma.innerHTML = msg;
        else
            alert(msg);
        objCampo.value = strText.substr(0, intQtdeLimite);
        return false;
    } else {
        msg = "Você pode digitar " + (intQtdeLimite - intTamanhoText - 1) + " caracteres.";
        if (String(objInforma) != "undefined")
            objInforma.innerHTML = msg;
        return true;
    }
}

/* Limpa o valor e dá foco no campo */
function LimparFoco(Objeto) {
    Objeto.value = "";
    Objeto.focus();
}

/* Mostra em um objeto o texto selecionado completo do combo */
function MostrarDetalheSelect(obj, det) {
    var objDetalhe = document.getElementById(det);
    if ((obj) && (objDetalhe)) {
        objDetalhe.innerHTML = obj.options[obj.selectedIndex].innerHTML;
        objDetalhe.style.display = "block";
    }
}

/* Verifica o caracter digitado  */
function keyChar(Evento, Objeto) {
    if (Evento) {
        if (((Evento.keyCode >= 65) && (Evento.keyCode <= 90)) ||
	        ((Evento.keyCode >= 97) && (Evento.keyCode <= 122))) {
            return true;
        }
        CancelarDigitacao(Evento);
        return false;
    }
    else if (window.event) {
        if (((window.event.keyCode >= 65) && (window.event.keyCode <= 90)) ||
	        ((window.event.keyCode >= 97) && (window.event.keyCode <= 122))) {
            return true;
        }
        CancelarDigitacao(Evento);
        return false;
    }
    return true;
}

/* Verifica se esta digitando um caracter minusculo */
function keyLower(Evento, Objeto) {
    if (Evento) {
        if (((Evento.keyCode >= 65) && (Evento.keyCode <= 90)) ||
	        ((Evento.keyCode >= 192) && (Evento.keyCode <= 223) &&
	         (Evento.keyCode != 208) && (Evento.keyCode != 215) &&
	         (Evento.keyCode != 223))) {
            Evento.keyCode = Evento.keyCode + 32;
            Evento.returnValue = true;
            return true;
        }
    } else if (window.event) {
        if (((window.event.keyCode >= 65) && (window.event.keyCode <= 90)) ||
	        ((window.event.keyCode >= 192) && (window.event.keyCode <= 223) &&
	         (window.event.keyCode != 208) && (window.event.keyCode != 215) &&
	         (window.event.keyCode != 223))) {
            window.event.keyCode = window.event.keyCode + 32;
            window.event.returnValue = true;
            return true;
        }
    }
    return true;
}

/* Verifica se esta digitando um caracter numerico */
function keyNumber(Evento, Objeto) {
    if (Evento) {
        if ((Evento.keyCode < 48) || (Evento.keyCode > 57)) {
            CancelarDigitacao(Evento);
            return false;
        }
    } else if (window.event) {
        if ((window.event.keyCode < 48) || (window.event.keyCode > 57)) {
            CancelarDigitacao(Evento);
            return false;
        }
    }
    return true;
}

/* Verifica se o caracter digitado é maiusculo */
function keyUpper(Evento, Objeto) {
    if (Evento) {
        if (((Evento.keyCode >= 97) && (Evento.keyCode <= 122)) ||
	        ((Evento.keyCode >= 224) && (Evento.keyCode <= 255) && (Evento.keyCode != 240) && (Evento.keyCode != 247) && (Evento.keyCode != 255))) {
            Evento.keyCode = Evento.keyCode - 32;
            Evento.returnValue = true;
            return true;
        }
    }
    else if (window.event) {
        if (((window.event.keyCode >= 97) && (window.event.keyCode <= 122)) ||
	        ((window.event.keyCode >= 224) && (window.event.keyCode <= 255) && (window.event.keyCode != 240) && (window.event.keyCode != 247) && (window.event.keyCode != 255))) {
            window.event.keyCode = window.event.keyCode - 32;
            window.event.returnValue = true;
            return true;
        }
    }
    return true;
}

/* insere um objeto flash */
function loadFlashDocument(FilePath, Height, Width) {
    document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" height="' + Height + '" width="' + Width + '">');
    document.write('    <param name="movie" value="' + FilePath + '">');
    document.write('    <param name="quality" value="high">');
    document.write('    <param name="wmode" value="transparent" />');
    document.write('    <embed wmode="transparent" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" src="' + FilePath + '" height="' + Height + '" width="' + Width + '"></embed>');
    document.write('</object>');
}

/* */
function navegaAnterior(Objeto, Registro, Format) {
    if (Objeto == null)
        return false;
    var Linhas = Objeto.childNodes[0];
    for (i = 0; i < Linhas.childNodes.length; i++) {
        if (Linhas.childNodes[i].style.display == '') {
            if (i > 0) {
                Linhas.childNodes[i].style.display = 'none';
                Linhas.childNodes[i - 1].style.display = '';
                Registro.innerText = Format.replace("{0}", i).replace("{1}", Linhas.childNodes.length);
                return false;
            }
        }
    }
    return false;
}

/* */
function navegaProximo(Objeto, Registro, Format) {
    if (Objeto == null)
        return false;
    var Linhas = Objeto.childNodes[0];
    for (i = 0; i < Linhas.childNodes.length; i++) {
        if (Linhas.childNodes[i].style.display == '') {
            if (i < (Linhas.childNodes.length - 1)) {
                Linhas.childNodes[i].style.display = 'none';
                Linhas.childNodes[i + 1].style.display = '';
                Registro.innerText = Format.replace("{0}", (i + 2)).replace("{1}", Linhas.childNodes.length);
                return false;
            }
        }
    }
    return false;
}

/* Verificar se dado esta dentro do dominio passado */
function passaDominio(strDado, strDominio) {
    var i = 0, j = 0;
    var strCaracter = "";
    var strResult = "";
    for (i = 0; i < strDado.length; i++) {
        strCaracter = strDado.substr(i, 1);
        for (j = 0; j < strDominio.length; j++) {
            if (strCaracter == strDominio.substr(j, 1))
                break;
        }
        if (j < strDominio.length)
            strResult = strResult + strCaracter;
    }
    return strResult;
}

/* Posição inicial do objeto */
function position(Objeto) {
    if (document.selection) {
        Objeto.focus();
        var Sel = document.selection.createRange();
        Sel.moveStart('character', -Objeto.value.length);
        return Sel.text.length;
    } else if ((Objeto.selectionStart) || (Objeto.selectionStart == "0")) {
        return Objeto.selectionStart;
    }
    return 0;
}

/* Selecionar valor  */
function ProgressValueGet(Objeto) {
    return parseInt(SubstituirTudo(Objeto.childNodes[1].childNodes[0].childNodes[0].childNodes[0].innerText, "%", ""));
}

/* Atribuir valor  */
function ProgressValueSet(Objeto, Value, SetColor) {
    var Coluna1 = Objeto.childNodes[0].childNodes[0].childNodes[0].childNodes[0];
    var Coluna2 = Objeto.childNodes[0].childNodes[0].childNodes[0].childNodes[1];
    if (SetColor) {
        if (Value <= 30)
            Coluna1.style.background = "RGB(255, 106, 106)";
        else if ((Value > 30) && (Value <= 60))
            Coluna1.style.background = "RGB(255, 225, 108)";
        else if ((Value > 60) && (Value <= 99))
            Coluna1.style.background = "RGB(102, 204, 102)";
        else if (Value == 100)
            Coluna1.style.background = "RGB(70, 181, 255)";
    }
    Coluna1.style.width = Value + "%";
    Coluna2.style.width = (100 - Value) + "%";
    if (Value == 0)
        Coluna1.style.display = "none";
    else
        Coluna1.style.display = "";
    if (Value == 100)
        Coluna2.style.display = "none";
    else
        Coluna2.style.display = "";
    Objeto.childNodes[1].childNodes[0].childNodes[0].childNodes[0].innerText = Value + "%";
    return true;
}

/* */
function renameObject(Objeto, Contador) {
    var Count = 0;
    var Pos3 = -1;
    var Pos4 = -1;
    for (Pos = 0; Pos < Objeto.name.length; Pos++) {
        if (Objeto.name.substr(Pos, 1) == '$') {
            Count++;
            if (Count == 3)
                Pos3 = Pos;
            if (Count == 4)
                Pos4 = Pos;
        }
    }
    var contador;
    if (Contador < 10) {
        contador = '00' + Contador;
        contador = contador.substr(contador.length - 2);
    }
    else
        contador = Contador;
    Objeto.name = Objeto.name.substr(0, Pos3 + 4) + contador + Objeto.name.substr(Pos4);
    return true;
}

/* Retirar pontuacao desejada */
function RetirarPontuacao(textoLabel, pontuacao) {
    var strPontuacao = String(pontuacao);
    if (textoLabel.toString().indexOf(strPontuacao, 0) > -1) {
        textoLabel = textoLabel.toString().replace(strPontuacao, '');
    }
    return textoLabel;
}

/* Selecionar */
function Selecionar(Objeto) {
    var strSelectedString = "";
    if (window.getSelection)
        strSelectedString = window.getSelection();
    else if (document.all)
        strSelectedString = document.selection.createRange().text;
    else if (document.getSelection)
        strSelectedString = document.getSelection();
    return (strSelectedString != "");
}

/* Funcao SelecionarTamanhoTelaWidth()
Verifica o valor da largura da tela do usuario.  */
function SelecionarTamanhoTelaWidth() {
    var Width = 0;
    if ((window.innerWidth) && (typeof (window.innerWidth) == 'number')) {
        Width = window.innerWidth;
    }
    else if ((document.documentElement) && (document.documentElement.clientWidth)) {
        Width = document.documentElement.clientWidth;
    }
    else if ((document.body) && (document.body.clientWidth)) {
        Width = document.body.clientWidth;
    }
    else if ((document.body) && (document.body.style.width)) {
        Width = document.body.style.width;
    }
    else if ((document.body) && (document.body.offsetWidth)) {
        Width = document.body.offsetWidth;
    }
    else if ((window.screen) && (window.screen.width)) {
        Width = window.screen.width;
    }
    else if ((window.screen) && (window.screen.availWidth)) {
        Width = window.screen.availWidth;
    }
    else if ((self) && (self.innerWidth)) {
        Width = self.innerWidth;
    }
    else if ((screen) && (screen.width)) {
        Width = screen.width;
    }
    return Width;
}

/* Funcao SelecionarTamanhoTelaHeight()
Verifica o valor da altura da tela do usuario.  */
function SelecionarTamanhoTelaHeight() {
    var Height = 0;
    if ((window.innerHeight) && (typeof (window.innerHeight) == 'number')) {
        Height = window.innerHeight;
    }
    else if ((document.documentElement) && (document.documentElement.clientHeight)) {
        Height = document.documentElement.clientHeight;
    }
    else if ((document.body) && (document.body.clientHeight)) {
        Height = document.body.clientHeight;
    }
    else if ((document.body) && (document.body.style.height)) {
        Width = document.body.style.height;
    }
    else if ((document.body) && (document.body.offsetHeight)) {
        Height = document.body.offsetHeight;
    }
    else if ((window.screen) && (window.screen.height)) {
        Height = window.screen.height;
    }
    else if ((window.screen) && (window.screen.availHeight)) {
        Height = window.screen.availHeight;
    }
    else if ((self) && (self.innerHeight)) {
        Height = self.innerHeight;
    }
    else if ((screen) && (screen.Height)) {
        Height = screen.Height;
    }
    return Height;
}

/* Substituir todos. */
function SubstituirTudo(strDado, strDe, strPor) {
    var intIndexOf = strDado.indexOf(strDe);
    while (intIndexOf != -1) {
        strDado = strDado.replace(strDe, strPor);
        intIndexOf = strDado.indexOf(strDe);
    }
    return strDado;
}

/* Verifica se esta tentando copiar ou colar no campo */
function VerificarCopiarColar() {
    var bolCtrl = window.event.ctrlKey;
    var intTecla = window.event.keyCode;
    if (bolCtrl && intTecla == 67) {
        event.keyCode = 0;
        event.returnValue = false;
    }
    if (bolCtrl && intTecla == 86) {
        event.keyCode = 0;
        event.returnValue = false;
    }
}

MaskInput = function(f, m) {
    function mask(e) {
        var patterns = { "1": /[A-Z]/i, "2": /[0-9]/, "4": /[\xC0-\xFF]/i, "8": /./ },
            rules = { "a": 3, "A": 7, "9": 2, "C": 5, "c": 1, "*": 8 };
        function accept(c, rule) {
            for (var i = 1, r = rules[rule] || 0; i <= r; i <<= 1)
                if (r & i && patterns[i].test(c))
                break;
            return i <= r || c == rule;
        }
        var k, mC, r, c = String.fromCharCode(k = e.key), l = f.value.length;
        (!k || k == 8 ? 1 : (r = /^(.)\^(.*)$/.exec(m)) && (r[0] = r[2].indexOf(c) + 1) + 1 ?
            r[1] == "O" ? r[0] : r[1] == "E" ? !r[0] : accept(c, r[1]) || r[0]
            : (l = (f.value += m.substr(l, (r = /[A|9|C|\*]/i.exec(m.substr(l))) ?
            r.index : l)).length) < m.length && accept(c, m.charAt(l))) || e.preventDefault();
    }
    for (var i in !/^(.)\^(.*)$/.test(m) && (f.maxLength = m.length), { keypress: 0, keyup: 1 })
        addEvent(f, i, mask);
};

addEvent = function(o, e, f, s) {
    var r = o[r = "_" + (e = "on" + e)] = o[r] || (o[e] ? [[o[e], o]] : []), a, c, d;
    r[r.length] = [f, s || o], o[e] = function(e) {
        try {
            (e = e || event).preventDefault || (e.preventDefault = function() { e.returnValue = false; });
            e.stopPropagation || (e.stopPropagation = function() { e.cancelBubble = true; });
            e.target || (e.target = e.srcElement || null);
            e.key = (e.which + 1 || e.keyCode + 1) - 1 || 0;
        } catch (f) { }
        for (d = 1, f = r.length; f; r[--f] && (a = r[f][0], o = r[f][1], a.call ? c = a.call(o, e) : (o._ = a, c = o._(e), o._ = null), d &= c !== false));
        return e = null, !!d;
    }
};

removeEvent = function(o, e, f, s) {
    for (var i = (e = o["_on" + e] || []).length; i; )
        if (e[--i] && e[i][0] == f && (s || o) == e[i][1])
        return delete e[i];
    return false;
};
