﻿function valida_cpf(cpf) {
    var digCpf = cpf.value;
    digCpf = remove_chars(digCpf, ".", "");
    digCpf = remove_chars(digCpf, "-", "");
    var numeros, digitos, soma, i, resultado, digitos_iguais;
    digitos_iguais = 1;
    if ((digCpf.length > 0) && (digCpf.length < 11)) {
        window.document.getElementById(cpf.id).focus();
        alert("Faltam dígitos.");
        return false;
    }
    else {
        if (digCpf.length > 0) {
            for (i = 0; i < digCpf.length - 1; i++)
                if (digCpf.charAt(i) != digCpf.charAt(i + 1)) {
                digitos_iguais = 0;
                break;
            }
            if (!digitos_iguais) {
                numeros = digCpf.substring(0, 9);
                digitos = digCpf.substring(9);
                soma = 0;
                for (i = 10; i > 1; i--)
                    soma += numeros.charAt(10 - i) * i;
                resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
                if (resultado != digitos.charAt(0)) {
                    window.document.getElementById(cpf.id).focus();
                    alert("CPF inválido!");
                    return false;
                }
                numeros = digCpf.substring(0, 10);
                soma = 0;
                for (i = 11; i > 1; i--)
                    soma += numeros.charAt(11 - i) * i;
                resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
                if (resultado != digitos.charAt(1)) {
                    window.document.getElementById(cpf.id).focus();
                    alert("CPF inválido!");
                    return false;
                }
                return true;
            }
            else {
                window.document.getElementById(cpf.id).focus();
                alert("CPF inválido!");
                return false;
            }
        }
        return true;
    }
};

function valida_cnpj(textBox) {
    var cnpj = textBox.value;
    cnpj = remove_chars(cnpj, ".", "");
    cnpj = remove_chars(cnpj, "-", "");
    cnpj = remove_chars(cnpj, "/", "");
    var numeros, digitos, soma, i, resultado, pos, tamanho, digitos_iguais;
    digitos_iguais = 1;

    if ((cnpj.length > 0) && (cnpj.length < 14)) {
        window.document.getElementById(textBox.id).focus();
        alert("Faltam dígitos.");
        return false;
    }
    else {
        if (cnpj.length > 0) {
            for (i = 0; i < cnpj.length - 1; i++) {
                if (cnpj.charAt(i) != cnpj.charAt(i + 1)) {
                    digitos_iguais = 0;
                    break;
                }
            }
            if (!digitos_iguais) {
                tamanho = cnpj.length - 2
                numeros = cnpj.substring(0, tamanho);
                digitos = cnpj.substring(tamanho);
                soma = 0;
                pos = tamanho - 7;
                for (i = tamanho; i >= 1; i--) {
                    soma += numeros.charAt(tamanho - i) * pos--;
                    if (pos < 2)
                        pos = 9;
                }
                resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
                if (resultado != digitos.charAt(0)) {
                    window.document.getElementById(textBox.id).focus();
                    alert("CNPJ inválido!");
                    return false;
                }
                tamanho = tamanho + 1;
                numeros = cnpj.substring(0, tamanho);
                soma = 0;
                pos = tamanho - 7;
                for (i = tamanho; i >= 1; i--) {
                    soma += numeros.charAt(tamanho - i) * pos--;
                    if (pos < 2)
                        pos = 9;
                }
                resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
                if (resultado != digitos.charAt(1)) {
                    window.document.getElementById(textBox.id).focus();
                    alert("CNPJ inválido!");
                    return false;
                }
                return true;
            }
            else {
                window.document.getElementById(textBox.id).focus();
                alert("CNPJ inválido!");
                return false;
            }
        }
        return true;
    }
};

function formata_data(x, tecla) {
    // Por Tiago Araujo Silva (tiago@tiagoaraujo.com)

    separador = "/"; // Você pode definir o separador. Ex: "/" ou "-" ou "."

    tecla = tecla.keyCode; // Identifica a tecla, caso seja backspace

    valor = x.value.split(''); // Pega o valor do campo e transforma cada caractere em uma string
    formatado = ""; // Variável para carregar formatação temporariamente

    i = 0; // variável de controle

    while (i < valor.length) { // Loop para cada caractere do campo
        caractere = valor[i]; // Seleciona um caractere para ser formatado
        numeros = /^\d+$/; // Variavel contendo números positivos
        // Verifica se é número ou "barra"
        if (numeros.test(caractere) || caractere == separador) { formatado += String(caractere); }
        // Verifica se precisa de barra, se a tecla for backspace, então a barra não é adicionada
        // Se for para adicionar barra, aumenta ++ variável de controle "i" para pular a barra adicionada
        if ((formatado.length == 2 || formatado.length == 5) && tecla != 8) { formatado += separador; i++; }

        i++; // Se houver, passa para o próximo caractere
    }

    x.value = formatado; // Atribui o valor formatado ao campo
};

function AbreJanela(url, altura, largura, top, left) {
    window.open(url, altura, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, menubar=no, top=' + window.screen.availHeight / 3.9 + ', left=' + window.screen.availWidth / 3 + ', width=' + largura + ', height=' + altura);
};

function AbreJanelaScrol(url, altura, largura, top, left) {
    window.open(url, altura, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, menubar=no, top=' + window.screen.availHeight / 3.9 + ', left=' + window.screen.availWidth / 3 + ', width=' + largura + ', height=' + altura);
};

function validaDropDownVazio(valor) {
    alert(valor);
    if (valor == '0')
        return false;
    else
        return true;
};

function botoesDefault()
{
    document.getElementById('btn_ok').className = "botao_ok";
    
    document.getElementById('btn_alt').className = "botao_alt_disabled";
    document.getElementById('btn_exc').className = "botao_exc_disabled";
};

function botoesPesquisa()
{
    document.getElementById('btn_ok').className = "botao_ok_disabled";
    
    document.getElementById('btn_alt').className = "botao_alt";
    document.getElementById('btn_exc').className = "botao_exc";
};




/*MÁSCARAS
COMO USAR:
	
NO EVENTO PAGE_LOAD DO WEBFORM (NO ARQUIVO DE CÓDIGO C#):
xxxxxx.Attributes.Add("OnKeyPress","javascript:return(FUNCAOMASCARA(event,this))");
EX.:tbMoeda.Attributes.Add("OnKeyPress","javascript:return(MaskMoeda(event,this))");   
*/

function MaskMoeda(event, objeto) {
    var milSep = '.';
    var decSep = ',';
    var sep = 0;
    var key = '';
    var i = j = 0;
    var len = len2 = 0;
    var strCheck = '0123456789';
    var aux = aux2 = '';

    var whichCode;

    if (Navegador() == "IE") {
        whichCode = event.keyCode;
    }
    else // Netscape/Firefox/Opera
    {
        whichCode = event.which;
    }
    if (whichCode == 13 || whichCode == 8 || whichCode == 46)
        return true;

    if (whichCode == 9 && objeto.value.length == 0)
        return true;
    else {
        if (whichCode == 9) {
            window.event.keyCode = 13;
            return true;
        } 
    }
    if ((whichCode >= 96) && (whichCode <= 105))
        whichCode = whichCode - 48;
        
    key = String.fromCharCode(whichCode);
    if (strCheck.indexOf(key) == -1)
        return false;

    len = objeto.value.length;
    for (i = 0; i < len; i++)
        if ((objeto.value.charAt(i) != '0') && (objeto.value.charAt(i) != decSep))
        break;
    aux = '';
    for (; i < len; i++)
        if (strCheck.indexOf(objeto.value.charAt(i)) != -1)
        aux += objeto.value.charAt(i);
    aux += key;
    len = aux.length;
    if (len == 0)
        objeto.value = '';
    if (len == 1) {
        objeto.value = '0' + decSep + '0' + aux;
    }

    if (len == 2) {
        objeto.value = '0' + decSep + aux;
    }

    if (len > 2) {
        aux2 = '';
        for (j = 0, i = len - 3; i >= 0; i--) {
            if (j == 3) {
                aux2 += milSep;
                j = 0;
            }
            aux2 += aux.charAt(i);
            j++;
        }
        objeto.value = '';
        len2 = aux2.length;
        for (i = len2 - 1; i >= 0; i--)
            objeto.value += aux2.charAt(i);
        objeto.value += decSep + aux.substr(len - 2, len); ;
    }
    return false;
};

function MaskDataHoraSeg(event, objeto) {
    var retorno = false;

    separador = '/';
    separador2 = ' ';
    separador3 = ':';

    var whichCode;

    if (Navegador() == "IE") {
        whichCode = event.keyCode;
    }
    else // Netscape/Firefox/Opera
    {
        whichCode = event.which;
    }

    if ((whichCode == 13) || (whichCode == 8))
        return true;

    if ((whichCode >= 48) && (whichCode <= 57)) {
        var tam = 19;

        conjunto1 = 2;
        conjunto2 = 5;
        conjunto3 = 10;
        conjunto4 = 13;
        conjunto5 = 16;

        if (objeto.value.length == conjunto1) {
            objeto.value = objeto.value + separador;
            retorno = true;
        }
        if (objeto.value.length == conjunto2) {
            objeto.value = objeto.value + separador;
            retorno = true;
        }
        if (objeto.value.length == conjunto3) {
            objeto.value = objeto.value + separador2;
            retorno = true;
        }
        if (objeto.value.length == conjunto4) {
            objeto.value = objeto.value + separador3;
            returno = true;
        }
        if (objeto.value.length == conjunto5) {
            objeto.value = objeto.value + separador3;
            returno = true;
        }
        else {
            var pos = GetPosCarroTextBox(objeto);
            var range = objeto.createTextRange();
            range.collapse(true);

            if ((pos == conjunto1) || (pos == conjunto2) || (pos == conjunto3) ||
  					    (pos == conjunto4) || (pos == conjunto5)) {
                range.moveStart('character', pos + 1);
                range.moveEnd('character', 1);
                range.select();
                retorno = true;
            }
            else if (pos < tam) {
                if ((objeto.value.substr(pos, 1) == separador) ||
						    (objeto.value.substr(pos, 1) == separador2) ||
						    (objeto.value.substr(pos, 1) == separador3)
						    ) {
                    range.moveStart('character', pos);
                    range.moveEnd('character', 0);
                    range.select();

                }
                else {
                    range.moveStart('character', pos);
                    range.moveEnd('character', 1);
                    range.select();
                }

                retorno = true;
            }
            else retorno = false;
        }
    }
    return retorno;
};

function MaskData(event, objeto) {
    var whichCode;

    if (Navegador() == "IE") {
        whichCode = event.keyCode;
    }
    else // Netscape/Firefox/Opera
    {
        whichCode = event.which;
    }

    if ((whichCode == 13) || (whichCode == 8))
        return true;

    if (whichCode == 9) {
        window.event.keyCode = 13;
        return true;
    }
    if ((whichCode >= 96) && (whichCode <= 105))
        whichCode = whichCode - 48;

    if ((whichCode >= 48) && (whichCode <= 57)) {
        separador = '/';
        conjunto1 = 2;
        conjunto2 = 5;
        //DIA
        if (objeto.value.length == 0 && whichCode <= 51)
            return true;
            
        if (objeto.value.length == 1 && ((objeto.value == '3' && whichCode <= 49) || ((objeto.value == '0' && whichCode > 48) 
            || (objeto.value == '1' || objeto.value == '2'))))
            return true;
        //MÊS
        if (objeto.value.length == conjunto1) {
            objeto.value = objeto.value + separador;
            if (objeto.value.length == 3 && whichCode <= 49)
                return true;
            return false;
        }
        if (objeto.value.length == 3 && whichCode <= 49)
            return true;

        if ((objeto.value.length == 4 && objeto.value.substr(objeto.value.length - 1, 1) == '0' && whichCode >= 49) ||
            (objeto.value.length == 4 && objeto.value.substr(objeto.value.length - 1, 1) == '1' && whichCode <= 50))
            return true;
            
        //ANO
        if (objeto.value.length == conjunto2) {
            objeto.value = objeto.value + separador;
            if (objeto.value.length == 6 && (whichCode == 49 || whichCode == 50))
                return true;
            return false;
        }
        if (objeto.value.length == 6 && (whichCode == 49 || whichCode == 50))
            return true;
            
        if(objeto.value.length == 7 && ((objeto.value.substr(objeto.value.length - 1, 1) == '1' && whichCode == 57 ) || 
            (objeto.value.substr(objeto.value.length - 1, 1) == '2')))
            return true;
            
        if (objeto.value.length >= 8 && objeto.value.length < 10)
            return true;
        else
            return false;
    }
    return false;
};

function MaskHora(event, objeto) {

    var whichCode;

    if (Navegador() == "IE") {
        whichCode = event.keyCode;
    }
    else // Netscape/Firefox/Opera
    {
        whichCode = event.which;
    }

    if ((whichCode == 13) || (whichCode == 8))
        return true;

    if ((whichCode >= 48) && (whichCode <= 57)) {
        separador = ':';
        conjunto1 = 2;
        if (objeto.value.length == conjunto1)
            objeto.value = objeto.value + separador;
        return true;
    }
    return false;
};

function MaskCEP(event, objeto) {

    var whichCode;

    if (Navegador() == "IE") {
        whichCode = event.keyCode;
    }
    else // Netscape/Firefox/Opera
    {
        whichCode = event.which;
    }

    if ((whichCode == 13) || (whichCode == 8))
        return true;

    if ((whichCode >= 48) && (whichCode <= 57)) {
        separador = '-';
        conjunto1 = 5;
        if (objeto.value.length == conjunto1 && objeto.value.length == 9)
            objeto.value = objeto.value + separador;
        return true;
    }
    return false;
};

function MaskContaBanco(event, objeto) {

    var whichCode;

    if (Navegador() == "IE") {
        whichCode = event.keyCode;
    }
    else // Netscape/Firefox/Opera
    {
        whichCode = event.which;
    }

    if ((whichCode == 13) || (whichCode == 8))
        return true;

    if (whichCode == 9) {
        window.event.keyCode = 13;
        return true;
    }

    if ((whichCode >= 48) && (whichCode <= 57) && (objeto.value.length < 8)) {
        separador = '-';
        conjunto1 = 6;
        if (objeto.value.length == conjunto1)
            objeto.value = objeto.value + separador;
        return true;
    }
    return false;
};

function MaskCPF(event, objeto) {

    var whichCode;

    if (Navegador() == "IE") {
        whichCode = event.keyCode;
    }
    else // Netscape/Firefox/Opera
    {
        whichCode = event.which;
    }

    if ((whichCode == 13) || (whichCode == 8))
        return true;
    if (whichCode == 9) {
        window.event.keyCode = 13;
        return true;
    }
    if ((whichCode >= 96) && (whichCode <= 105))
        whichCode = whichCode - 48;
    if ((whichCode >= 48) && (whichCode <= 57)) {
        caracteres = '01234567890';
        separacoes = 3;
        separacao1 = '.';
        separacao2 = '-';
        conjuntos = 4;
        conjunto1 = 3;
        conjunto2 = 7;
        conjunto3 = 11;
        conjunto4 = 14;
        if ((caracteres.search(String.fromCharCode(whichCode)) != -1) && objeto.value.length < (14)) {
            if (objeto.value.length == conjunto1)
                objeto.value = objeto.value + separacao1;
            else if (objeto.value.length == conjunto2)
                objeto.value = objeto.value + separacao1;
            else if (objeto.value.length == conjunto3)
                objeto.value = objeto.value + separacao2;
            return true;
        }
        else
            return false;
    }
    return false;
};

function MaskRG(event, objeto) {
    var whichCode;

    if (Navegador() == "IE") {
        whichCode = event.keyCode;
    }
    else // Netscape/Firefox/Opera
    {
        whichCode = event.which;
    }

    if ((whichCode == 13) || (whichCode == 8))
        return true;

    if ((whichCode >= 48) && (whichCode <= 57)) {
        caracteres = '01234567890';
        separacoes = 3;
        separacao1 = '.';
        separacao2 = '-';
        conjuntos = 3;
        conjunto1 = 2;
        conjunto2 = 6;
        conjunto3 = 10;
        conjunto4 = 13;
        if ((caracteres.search(String.fromCharCode(whichCode)) != -1) && objeto.value.length <
				(conjunto4)) {
            if (objeto.value.length == conjunto1)
                objeto.value = objeto.value + separacao1;
            else if (objeto.value.length == conjunto2)
                objeto.value = objeto.value + separacao1;
            else if (objeto.value.length == conjunto3)
                objeto.value = objeto.value + separacao2;
        }
        return true;
    }
    return false;
};


function MaskCNPJ(event, objeto) {
    var whichCode;
    
    if (Navegador() == "IE") {
        whichCode = event.keyCode;
    }
    else // Netscape/Firefox/Opera
    {
        whichCode = event.which;
    }
    if ((whichCode == 13) || (whichCode == 8))
        return true;
        
    if (whichCode == 9) {
        window.event.keyCode = 13;
        return true;
    }
    if ((whichCode >= 96) && (whichCode <= 105))
        whichCode = whichCode - 48;
    if ((whichCode >= 48) && (whichCode <= 57)) {
        caracteres = '01234567890';
        separacoes = 4;
        separacao1 = '.';
        separacao2 = '/';
        separacao3 = '-';
        conjuntos = 5;
        conjunto1 = 2;
        conjunto2 = 6;
        conjunto3 = 10;
        conjunto4 = 15;
        conjunto5 = 18;
        if ((caracteres.search(String.fromCharCode(whichCode)) != -1) && objeto.value.length < (conjunto5)) {
            if (objeto.value.length == conjunto1)
                objeto.value = objeto.value + separacao1;
            else if (objeto.value.length == conjunto2)
                objeto.value = objeto.value + separacao1;
            else if (objeto.value.length == conjunto3)
                objeto.value = objeto.value + separacao2;
            else if (objeto.value.length == conjunto4)
                objeto.value = objeto.value + separacao3;
            return true;
        }
        else
            return false;
    }
    return false;
};
function Navegador() {

    if (navigator.appName == "Microsoft Internet Explorer")
        return ("IE")
    else if (navigator.appName == "Netscape")
        return ("Mozila")
    else return ("Outros");
};

function float2moeda(num) {

    x = 0;

    if (num < 0) {
        num = Math.abs(num);
        x = 1;
    }
    if (isNaN(num)) num = "0";
    cents = Math.floor((num * 100 + 0.5) % 100);

    num = Math.floor((num * 100 + 0.5) / 100).toString();

    if (cents < 10) cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
        num = num.substring(0, num.length - (4 * i + 3)) + '.'
               + num.substring(num.length - (4 * i + 3));
    ret = num + ',' + cents;
    if (x == 1) ret = ' - ' + ret; return ret;

};
function Limpar(valor, validos) {
    // retira caracteres invalidos da string
    var result = "";
    var aux;
    for (var i = 0; i < valor.length; i++) {
        aux = validos.indexOf(valor.substring(i, i + 1));
        if (aux >= 0) {
            result += aux;
        }
    }
    return result;
};
function moedavalor(num) {
    x = 0;

    if (num < 0) {
        num = Math.abs(num);
        x = 1;
    } if (isNaN(num)) num = "0";
    cents = Math.floor((num * 100 + 0.5) % 100);

    num = Math.floor((num * 100 + 0.5) / 100).toString();

    if (cents < 10) cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
        num = num.substring(0, num.length - (4 * i + 3)) + '.'
               + num.substring(num.length - (4 * i + 3)); ret = num + ',' + cents; if (x == 1) ret = ' - ' + ret; return ret;

};
function remove_chars(str, de, para) {
    try {
        var pos = str.indexOf(de);
        while (pos > -1) {
            str = str.replace(de, para);
            pos = str.indexOf(de);
        }
        return (str);
    }
    catch (err) {
        return (str);
    }
};

function MaskFone(event, objeto) {
    var whichCode;
    if (Navegador() == "IE") {
        whichCode = event.keyCode;
    }
    else // Netscape/Firefox/Opera
    {
        whichCode = event.which;
    }
    if ((whichCode == 13) || (whichCode == 8))
        return true;
    if ((whichCode >= 96) && (whichCode <= 105))
        whichCode = whichCode - 48;
    if ((whichCode >= 48) && (whichCode <= 57) && (objeto.value.length < 13)) {
        if (objeto.value.length == 0)
            objeto.value = '(' + objeto.value;
        if (objeto.value.length == 3)
            objeto.value = objeto.value + ')';
        if (objeto.value.length == 8)
            objeto.value = objeto.value + '-';
        return true;
    }
    return false;
};

function Formata(campo, tammax, teclapres, decimal) {
    var tecla = teclapres.keyCode;
    vr = Limpar(campo.value, "0123456789");
    tam = vr.length;
    dec = decimal

    if (tam < tammax && tecla != 8) { tam = vr.length + 1; }

    if (tecla == 8)
    { tam = tam - 1; }

    if (tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105) {

        if (tam <= dec)
        { campo.value = vr; }

        if ((tam > dec) && (tam <= 5)) {
            campo.value = vr.substr(0, tam - 2) + "," + vr.substr(tam - dec, tam);
        }
        if ((tam >= 6) && (tam <= 8)) {
            campo.value = vr.substr(0, tam - 5) + "." + vr.substr(tam - 5, 3) + "," + vr.substr(tam - dec, tam);
        }
        if ((tam >= 9) && (tam <= 11)) {
            campo.value = vr.substr(0, tam - 8) + "." + vr.substr(tam - 8, 3) + "." + vr.substr(tam - 5, 3) + "," + vr.substr(tam - dec, tam);
        }
        if ((tam >= 12) && (tam <= 14)) {
            campo.value = vr.substr(0, tam - 11) + "." + vr.substr(tam - 11, 3) + "." + vr.substr(tam - 8, 3) + "." + vr.substr(tam - 5, 3) + "," + vr.substr(tam - dec, tam);
        }
        if ((tam >= 15) && (tam <= 17)) {
            campo.value = vr.substr(0, tam - 14) + "." + vr.substr(tam - 14, 3) + "." + vr.substr(tam - 11, 3) + "." + vr.substr(tam - 8, 3) + "." + vr.substr(tam - 5, 3) + "," + vr.substr(tam - 2, tam);
        }
    }

};

function bloqueiaEnter(input) {
    if (window.event.keyCode == 13) {
        window.event.keyCode = 9;
    }
};

function MaskMedida(event, objeto) {
    var milSep = '.';
    var decSep = ',';
    var sep = 0;
    var key = '';
    var i = j = 0;
    var len = len2 = 0;
    var strCheck = '0123456789';
    var aux = aux2 = '';

    var whichCode;

    if (Navegador() == "IE") {
        whichCode = event.keyCode;
    }
    else // Netscape/Firefox/Opera
    {
        whichCode = event.which;
    }
    if (whichCode == 13 || whichCode == 46)
        return true;
    if (whichCode == 8) {

        return true;
    }
    if (whichCode == 9) {
        window.event.keyCode = 13;
        return true;
    }
    if ((whichCode >= 96) && (whichCode <= 105))
        whichCode = whichCode - 48;

    key = String.fromCharCode(whichCode);
    if (strCheck.indexOf(key) == -1)
        return false;

    len = objeto.value.length;
    for (i = 0; i < len; i++)
        if ((objeto.value.charAt(i) != '0') && (objeto.value.charAt(i) != decSep))
        break;
    aux = '';
    for (; i < len; i++)
        if (strCheck.indexOf(objeto.value.charAt(i)) != -1)
        aux += objeto.value.charAt(i);
    aux += key;
    len = aux.length;
    if (len == 0)
        objeto.value = '';
    if (len == 1) {
        objeto.value = '0' + decSep + '00' + aux;

    }
    if (len == 2) {
        objeto.value = '0' + decSep + '0' + aux;
    }

    if (len == 3) {
        objeto.value = '0' + decSep + aux;
    }
    if (len > 3) {
        aux2 = '';
        for (j = 0, i = len - 4; i >= 0; i--) {
            if (j == 3) {
                aux2 += milSep;
                j = 0;
            }
            aux2 += aux.charAt(i);
            j++;
        }
        objeto.value = '';
        len2 = aux2.length;
        for (i = len2 - 1; i >= 0; i--)
            objeto.value += aux2.charAt(i);
        objeto.value += decSep + aux.substr(len - 3, len); ;
    }
    return false;
};

function MaskGenerica(event, objeto, mascara) {
    var whichCode;
    var key = '';
    var strCheck = '0123456789';
    
    if (Navegador() == "IE") {
        whichCode = event.keyCode;
    }
    else // Netscape/Firefox/Opera
    {
        whichCode = event.which;
    }
    if (whichCode == 8)
        return true;
        
    if (whichCode == 9) {
        window.event.keyCode = 13;
        return true;
    }    
    if ((whichCode >= 96) && (whichCode <= 105))
        whichCode = whichCode - 48;

    if ((whichCode >= 48) && (whichCode <= 57) && (objeto.value.length < mascara.length)) {
        do{
            var pos = objeto.value.length;
            key = mascara.substring(pos, pos + 1);
            if (strCheck.indexOf(key) == -1) {
                objeto.value = objeto.value + key;
            }
        }
        while (strCheck.indexOf(key) < 0);
        
        key = key.charCodeAt(0);
            
        if (whichCode > key)
            return false;
        return true;
    }
    return false;
};

function addData(input, qtde) {
    var ObjData = new Date();
    var DataAdd = ObjData;
    var dia = input.value;
    vet = dia.split("/");
    var quemChamou = input.id.split('_')[1];
    DataAdd.setDate(vet[0]);
    DataAdd.setMonth(vet[1] - 1);
    DataAdd.setFullYear(vet[2]);
    if (quemChamou == 1) {
        for (i = 2; i <= qtde; i++) {
            DataAdd.setMonth(DataAdd.getMonth() + 1);
            document.getElementById("txtVencimento_" + i).value = DataAdd.format("dd/MM/yyyy");
        }
    }
};

/// <summary>
///Transforma moeda em numero e faz arredondamento sempre para cima.
/// </summary>
/// <param name="valor">valor no formato de moeda</param>
/// <param name="casaDecimais">Quantidade de casas Decimais</param>
/// <returns>numero e faz arredondamento sempre para cima.</returns>
function deixaNum(valor, casaDecimais) {
    try {
        if (valor == '' || valor == null) {
            valor = 0;
        }
        else {
            valor = remove_chars(valor, '.', '');
            valor = remove_chars(valor, ',', '.');
            valorAntigo = valor * 1;
            if (valorAntigo > 0) {
                valorCasas = 1;
                for (i = 1; i <= casaDecimais; i++) {
                    valorCasas = valorCasas * 10;
                }
                valor = (parseInt(valor * valorCasas)) / valorCasas;
                if (valorAntigo > valor) {
                    valor = valor + (1 / valorCasas);
                }
                if (IsNumeric(valor) == false) {
                    valor = 0;
                }
            }
            else {
                valor = 0;
            }
        }
    }
    catch (err) {
        valor = 0;
    }
    return valor;
};

function valPro(valor, porc) {
    valor = (porc * valor) / 100;

    return valor
};

function IsNumeric(sText) {
    var ValidChars = "0123456789.";
    var IsNumber = true;
    var Char;


    for (i = 0; i < sText.length && IsNumber == true; i++) {
        Char = sText.charAt(i);
        if (ValidChars.indexOf(Char) == -1) {
            IsNumber = false;
        }
    }
    return IsNumber;

};

function converteMoedaAmerica(valor) {
    valor = remove_chars(valor, ".", "");
    valor = remove_chars(valor, ",", ".");
    return valor;
};

function digitaNada(Text) {
    return false;
};

function convertFloat(valor) {
    try {
        valor = parseFloat(converteMoedaAmerica(valor));
        if (isNaN(valor))
            valor = 0;
    }
    catch (e) {
        valor = 0;
    }
    return valor;
};

function maximizaTela() {
    window.moveTo(0, 0);
    if (document.all) {
        top.window.resizeTo(screen.availWidth, screen.availHeight);
    }
    else if (document.layers || document.getElementById) {
        if (top.window.outerHeight < screen.availHeight || top.window.outerWidth < screen.availWidth) {
            top.window.outerHeight = screen.availHeight;
            top.window.outerWidth = screen.availWidth;
        }
    }
};

function getWidth() {
    return window.innerWidth ? window.innerWidth : /* For non-IE */
    document.documentElement ? document.documentElement.clientWidth : /* IE 6+ (Standards Compilant Mode) */
    document.body ? document.body.clientWidth : /* IE 4 Compatible */
    window.screen.width; /* Others (It is not browser window size, but screen size) */
};

function getHeight() {
    return window.innerHeight ? window.innerHeight : /* For non-IE */
    document.documentElement ? document.documentElement.clientHeight : /* IE 6+ (Standards Compilant Mode) */
    document.body ? document.body.clientHeight : /* IE 4 Compatible */
    window.screen.height; /* Others (It is not browser window size, but screen size) */
};


