function FormataMaiuscula(objCampo) { 
        objCampo.value = objCampo.value.toUpperCase(); 
} 

function ValidaTeclaMoeda(objCampo) { 
        var strTecla = String.fromCharCode(event.keyCode); 
        var blnRetorno = ValidaDigitoMoeda(strTecla); 
        if (event.keyCode == 44 && objCampo.value.search(',') >= 0) 
                event.returnValue = false; 
        else 
        {         
                if (objCampo.value.search(',') < 0 && (objCampo.maxLength - 1) == objCampo.value.length && document.selection != null && document.selection.type != 'None') 
                        event.returnValue = false; 
                else 
                        event.returnValue = blnRetorno; 
        } 
} 



function ValidaDigitoMoeda(strCaracter) { 
    return ("0123456789,".indexOf(strCaracter)>=0); 
} 

function ValidaTeclaInteiro() { 
        var strTecla = String.fromCharCode(event.keyCode); 
        var blnRetorno = ValidaDigitoInteiro(strTecla); 
        event.returnValue = blnRetorno; 
} 

function ValidaDigitoInteiro(strCaracter) { 
    return ("0123456789".indexOf(strCaracter)>=0); 
} 

function FormataMoedaFoco(objCampo) 
{ 
        objCampo.value = SoNumeroMoeda(objCampo.value); 
        objCampo.select(); 
} 

function MontaStringIgual(strCaracter, intTamanho) 
{ 
        var intContador; 
        var strString = ''; 
        for (intContador = 1; intContador <= intTamanho; intContador++) 
                strString += strCaracter; 
        return strString; 
} 

function FormataMoeda(objCampo, intTamDecimal) 
{ 
        var strValor = objCampo.value; 
        var intVirgula = strValor.search(','); 
        var strValorFormat = ''; 
        var intDecimal = intContador = intPosicao = 0; 

        if (strValor != '') 
        { 
                if (intVirgula == -1) 
                        strValor += "," + MontaStringIgual("0", intTamDecimal); 
                else 
                { 
                        intDecimal = (strValor.substr(intVirgula + 1)).length; 
                        if (intDecimal <= intTamDecimal) 
                                strValor += MontaStringIgual("0", intTamDecimal - intDecimal); 
                        else 
                        { 
                                alert ('Número de casas decimais (' + intDecimal + ') maior do que o permitido (' + intTamDecimal + ') !'); 
                                objCampo.focus(); 
                                return false; 
                        } 
                } 
                if (strValor.length > objCampo.maxLength) 
                { 
                        if (intVirgula == -1) 
                                alert ('Parte inteira (' + (objCampo.value.length - intDecimal) + ') maior do que o permitido (' + (objCampo.maxLength - intTamDecimal - 1) + ') !'); 
                        else 
                                alert ('Parte inteira (' + (objCampo.value.length - intDecimal - 1) + ') maior do que o permitido (' + (objCampo.maxLength - intTamDecimal - 1) + ') !'); 
                        objCampo.focus(); 
                        return false; 
                } 
                else 
                        objCampo.value = strValor; 

                if (strValor.substr(0,1) == ",") 
                        strValor = '0' + strValor; 

                intVirgula = strValor.search(','); 
                strValorFormat = strValor.substr(intVirgula); 
                for (intContador = intVirgula - 1; intContador >= 0; intContador--) 
                { 
                        if (intPosicao == 3) 
                        { 
                                strValorFormat = '.' + strValorFormat; 
                                intPosicao = 0; 
                        } 
                        strValorFormat = strValor.substr(intContador, 1) + strValorFormat; 
                        intPosicao++; 
                } 
                objCampo.value = strValorFormat; 
        } 
} 

function RetornaClipBoard() 
{ 
        return (window.clipboardData.getData('Text')).replace(/\t/g,''); 
} 

function LimpaClipBoard() 
{ 
        return window.clipboardData.setData('Text',''); 
} 

function ValidaPasteTexto(fld) 
{ 
        var strTexto = RetornaClipBoard(); 
        LimpaClipBoard(); 
        if (strTexto != '') 
        { 
                if (fld.maxLength > 0) 
                { 
                        if (fld.maxLength >= strTexto.length) 
                                fld.value = strTexto; 
                        else 
                                fld.value = strTexto.substr(0,fld.maxLength); 
                } 
                else 
                        fld.value = strTexto; 
        } 
} 

function SoNumeroMoeda(strTexto) 
{ 
        var intContador; 
        var strRetorno; 
        var blnVirgula = false; 
        strRetorno = ''; 
        for (intContador=0; intContador < strTexto.length; intContador++) 
        { 
                if ((!isNaN(strTexto.substr(intContador,1)) && strTexto.substr(intContador,1) != ' ') || strTexto.substr(intContador,1) == ',') 
                { 
                        if (strTexto.substr(intContador,1) == ',') 
                        { 
                                if (blnVirgula == false) 
                                { 
                                        blnVirgula = true; 
                                        strRetorno = strRetorno + strTexto.substr(intContador,1); 
                                } 
                        } 
                        else 
                                strRetorno = strRetorno + strTexto.substr(intContador,1); 
                } 
        } 
        return strRetorno; 
} 

function SoNumero(strTexto) 
{ 
        var intContador; 
        var strRetorno; 
        strRetorno = ''; 
        for (intContador=0; intContador < strTexto.length; intContador++) 
        { 
                if (!isNaN(strTexto.substr(intContador,1)) && strTexto.substr(intContador,1) != ' ') 
                        strRetorno = strRetorno + strTexto.substr(intContador,1); 
        } 
        return strRetorno; 
} 

function ValidaPasteData(fld) 
{ 
        var strTexto = RetornaClipBoard(); 
        LimpaClipBoard(); 
        if (strTexto != '') 
        { 
                strTexto = SoNumero(strTexto); 
                if (strTexto.length == 8) 
                        fld.value = strTexto.substr(0,2) + "/" + strTexto.substr(2,2) + "/" + strTexto.substr(4,4); 
                else 
                        fld.value = ''; 
        } 
} 

function ValidaPasteHora(fld) 
{ 
        var strTexto = RetornaClipBoard(); 
        LimpaClipBoard(); 
        if (strTexto != '') 
        { 
                strTexto = SoNumero(strTexto); 
                if (strTexto.length == 4) 
                        fld.value = strTexto.substr(0,2) + ":" + strTexto.substr(2,2); 
                else 
                        fld.value = ''; 
        } 
} 

function ValidaPasteMoeda(objCampo) 
{ 
        var strTexto = RetornaClipBoard(); 
        LimpaClipBoard(); 
        if (strTexto != '') 
        { 
                strTexto = SoNumeroMoeda(strTexto); 
                if (objCampo.maxLength > 0) 
                { 
                        if (objCampo.maxLength >= strTexto.length) 
                        { 
                                objCampo.value = strTexto; 
                        } 
                        else 
                        { 
                                objCampo.value = strTexto.substr(0, objCampo.maxLength); 
                        } 
                } 
                else 
                { 
                        objCampo.value = strTexto; 
                } 
        } 
} 

function ValidaPasteInteiro(objCampo) 
{ 
        var strTexto = RetornaClipBoard(); 
        LimpaClipBoard(); 
        if (strTexto != '') 
        { 
                strTexto = SoNumero(strTexto); 
                if (objCampo.maxLength > 0) 
                { 
                        if (objCampo.maxLength >= strTexto.length) 
                        { 
                                objCampo.value = strTexto; 
                        } 
                        else 
                        { 
                                objCampo.value = strTexto.substr(0, objCampo.maxLength); 
                        } 
                } 
                else 
                { 
                        objCampo.value = strTexto; 
                } 
        } 
} 

function ValidarCampos(strFRM) 
{ 
        var frm = eval("document." + strFRM);
        var blnOK = true; 
        var i; 
        for (i=0; i < frm.length; i++) 
        { 
                if (frm.item(i).required == 'true' || frm.item(i).required == 'verdadeiro') 
                { 
                        if (frm.item(i).value == "") 
                        { 
                                if (frm.item(i).NomeCampo == "") 
                                {
                                        alert("Preenchimento obrigatório deste campo !"); 
                                }
                                else 
                                {
                                    if (frm.item(i).NomeCampo == "Mes de Desligamento" || frm.item(i).NomeCampo == "Ano de Desligamento")
                                    {
                                        alert("O campo " + frm.item(i).NomeCampo + " é obrigatório ! Se você colocou a função atual, coloque a data de hoje como data de desligamento!"); 
                                    }
                                    else
                                    {
                                        alert("O campo " + frm.item(i).NomeCampo + " é obrigatório !"); 
                                    }      
                                } 
                                try 
                                {
									frm.item(i).focus(); 
								}
								catch (e){}
                                i = frm.length; 
                                blnOK = false; 
                        } 
                } 
        } 
        return blnOK; 
} 

function LimpaTela(strFRM) 
{ 
        var frm = eval('document.' + strFRM); 
        for (i=0;i<frm.length;i++) 
        { 
                if (frm.item(i).name.substring(0,3) == "txt") 
                        frm.item(i).value = ""; 
                if (frm.item(i).name.substring(0,3) == "lst" || frm.item(i).name.substring(0,3) == "cbo") 
                        frm.item(i).selectedIndex = -1; 
                if (frm.item(i).name.substring(0,3) == "chk") 
                        frm.item(i).checked = false; 
        } 
} 

function SubmetePagina(strFRM, strPagina) 
{ 
        var frm = eval("document." + strFRM); 
        frm.action = strPagina; 
        frm.submit(); 
} 

function ValidaCNPJ(objCampo) 
{ 
        objCampo.value = DesformataCNPJ_CPF(objCampo.value); 
        if (objCampo.value.length > 0) 
        { 
                if (objCampo.value.length != 14) 
                { 
                        alert("CNPJ inválido !"); 
                        objCampo.focus(); 
                        objCampo.select(); 
                        return false; 
                } 
                else 
                { 
                        if (ConsistirCNPJ_CPF(objCampo.value) != 0) 
                        { 
                                objCampo.value = FormataCNPJ(objCampo.value); 
                        } 
                        else 
                        { 
                                alert("CNPJ inválido !") 
                                objCampo.focus(); 
                                objCampo.select(); 
                                return false; 
                        } 
                } 
        } 
} 

function FormataCNPJ(strCNPJ) 
{ 
        if (strCNPJ.length == 0) 
        { 
                return ""; 
        } 
        var bytAuxCont; 
        var bytTamStr; 
        var strResultado = ''; 
        if (strCNPJ.length > 14) 
        { 
                strCNPJ = strCNPJ.substr(0,14); 
        } 
        else 
        { 
                if (strCNPJ.length < 14) 
                { 
                        bytTamStr = 14 - strCNPJ.length; 
                        for (bytAuxCont = 1; bytAuxCont <= bytTamStr; bytAuxCont++) 
                        { 
                                strCNPJ = '0' + strCNPJ; 
                        } 
                } 
        } 
        for (bytAuxCont = 0; bytAuxCont <= 13; bytAuxCont++) 
        { 
                if (bytAuxCont == 2 | bytAuxCont==5) 
                { 
                        strResultado = strResultado + '.'; 
                } 
                if (bytAuxCont == 8) 
                { 
                        strResultado = strResultado + '/'; 
                } 
                if (bytAuxCont == 12) 
                { 
                   strResultado = strResultado + '-'; 
                } 
                strResultado = strResultado + strCNPJ.substr(bytAuxCont,1); 
        } 
        return strResultado; 
} 

function DesformataCNPJ_CPF(strDocumento) 
{ 
        var lngTamString; 
        var bytAuxCont; 
        strDocumento = strDocumento.replace(".",""); 
        strDocumento = strDocumento.replace(".",""); 
        strDocumento = strDocumento.replace("/",""); 
        strDocumento = strDocumento.replace("-",""); 
        return strDocumento; 
} 

function ConsistirCNPJ_CPF(strDocumento) 
{ 
        var va_digito; 
        var numero = new Array(15); 
        var va_resto; 
        var va_resultado; 
        var as_somadigito10; 
        va_cnpj_cpf = strDocumento; 
        if (strDocumento.length != 14) 
        { 
                var tam_cgc_cpf = strDocumento.length; 
                for (tam_cgc_cpf; tam_cgc_cpf < 14; tam_cgc_cpf++) 
                { 
                        va_cnpj_cpf = '0' + va_cnpj_cpf; 
                } 
        } 
        va_digito = va_cnpj_cpf.substring(13,2); 
        numero[1] = parseInt(va_cnpj_cpf.substr(0,1)); 
        numero[2] = parseInt(va_cnpj_cpf.substr(1,1)); 
        numero[3] = parseInt(va_cnpj_cpf.substr(2,1)); 
        numero[4] = parseInt(va_cnpj_cpf.substr(3,1)); 
        numero[5] = parseInt(va_cnpj_cpf.substr(4,1)); 
        numero[6] = parseInt(va_cnpj_cpf.substr(5,1)); 
        numero[7] = parseInt(va_cnpj_cpf.substr(6,1)); 
        numero[8] = parseInt(va_cnpj_cpf.substr(7,1)); 
        numero[9] = parseInt(va_cnpj_cpf.substr(8,1)); 
        numero[10] = parseInt(va_cnpj_cpf.substr(9,1)); 
        numero[11] = parseInt(va_cnpj_cpf.substr(10,1)); 
        numero[12] = parseInt(va_cnpj_cpf.substr(11,1)); 
        numero[13] = parseInt(va_cnpj_cpf.substr(12,1)); 
        numero[14] = parseInt(va_cnpj_cpf.substr(13,1)); 
        if (strDocumento.length > 11) 
        { 
                if (parseInt(va_cnpj_cpf.substr(0,8)) == 0 || parseInt(va_cnpj_cpf.substr(8,4)) == 0) 
                { 
                        return false; 
                } 
                va_resultado = (numero[1]*5) + (numero[2]*4) + (numero[3]*3) + (numero[4]*2) + (numero[5]*9) + (numero[6]*8) + (numero[7]*7) + (numero[8]*6) + (numero[9]*5) + (numero[10]*4) + (numero[11]*3) + (numero[12]*2); 
        } 
        else 
        { 
                if (parseInt(va_cnpj_cpf.substr(0,9)) == 0) 
                { 
                        return false; 
                } 
                va_resultado = (numero[4]*10) + (numero[5]*9) + (numero[6]*8) + (numero[7]*7) + (numero[8]*6) + (numero[9]*5) + (numero[10]*4) + (numero[11]*3) + (numero[12]*2); 
        } 
        va_resto = 11 - (va_resultado % 11); 
        if (va_resto > 9) 
        { 
           va_resto = 0; 
        } 
        if (va_resto != numero[13]) 
        { 
           return false; 
        } 
        if (strDocumento.length > 11) 
        { 
                va_resultado = (numero[1]*6) + (numero[2]*5) + (numero[3]*4) + (numero[4]*3) + (numero[5]*2) + (numero[6]*9) + (numero[7]*8) + (numero[8]*7) + (numero[9]*6) + (numero[10]*5) + (numero[11]*4) + (numero[12]*3) + (numero[13]*2); 
        } 
        else 
        { 
            va_resultado = (numero[4]*11) + (numero[5]*10) + (numero[6]*9) + (numero[7]*8) + (numero[8]*7) + (numero[9]*6) + (numero[10]*5) + (numero[11]*4) + (numero[12]*3) + (numero[13]*2); 
        } 
        va_resto = 11 - (va_resultado % 11); 
        if (va_resto > 9) 
        { 
           va_resto = 0; 
        } 
        if (va_resto != numero[14]) 
        { 
           return false; 
        } 
        if (strDocumento.length > 11) 
        { 
                return 1; 
        } 
        else 
        { 
            return 2; 
        } 
} 

function ValidaCPF(objCampo) 
{ 
        objCampo.value = DesformataCNPJ_CPF(objCampo.value); 
        if (objCampo.value.length > 0) 
        { 
                if (objCampo.value.length != 11) 
                { 
                        alert("CPF inválido !"); 
                        objCampo.focus(); 
                        objCampo.select(); 
                        return false; 
                } 
                else 
                { 
                        if (ConsistirCNPJ_CPF(objCampo.value) != 0) 
                        { 
                                objCampo.value = FormataCPF(objCampo.value); 
                        } 
                        else 
                        { 
                                alert("CPF inválido !") 
                                objCampo.focus(); 
                                objCampo.select(); 
                                return false; 
                        } 
                } 
        } 
} 

function FormataCPF(strCPF) 
{ 
        if (strCPF.length == 0) 
        { 
                return ""; 
        } 
        var bytAuxCont; 
        var bytTamStr; 
        var strResultado =''; 
        if (strCPF.length > 11) 
        { 
                strCPF = strCPF.substr(0,11); 
        } 
        else 
        { 
                if (strCPF.length < 11) 
                { 
                        bytTamStr = 11 - strCPF.length; 
                        for (bytAuxCont = 1; bytAuxCont <= bytTamStr; bytAuxCont++) 
                        { 
                                strCPF = '0' + strCPF; 
                        } 
                } 
        } 
        for (bytAuxCont = 0; bytAuxCont <= 12; bytAuxCont++) 
        { 
                if (bytAuxCont == 3 | bytAuxCont == 6) 
                { 
                   strResultado = strResultado + '.'; 
                } 
                if (bytAuxCont == 9) 
                { 
                   strResultado = strResultado + '-'; 
                } 
            strResultado = strResultado + strCPF.substr(bytAuxCont,1); 
        } 
        return strResultado; 
} 

function FormataCEP(strCEP) 
{ 
        if (strCEP.length == 0) 
        { 
                return ""; 
        } 
        var bytAuxCont; 
        var bytTamStr; 
        var strResultado =''; 
        if (strCEP.length < 8) 
        { 
                bytTamStr = 8 - strCEP.length; 
                for (bytAuxCont = 1; bytAuxCont <= bytTamStr; bytAuxCont++) 
                { 
                        strCEP = '0' + strCEP; 
                } 
        } 
        for (bytAuxCont = 0; bytAuxCont <= 7; bytAuxCont++) 
        { 
                if (bytAuxCont == 5) 
                { 
                   strResultado = strResultado + '-'; 
                } 
            strResultado = strResultado + strCEP.substr(bytAuxCont,1); 
        } 
        return strResultado; 
} 

function DesformataCEP(strCEP) 
{ 
        var lngTamString; 
        var bytAuxCont; 
        strCEP = strCEP.replace("-",""); 
        return strCEP; 
} 

function ValidaCEP(objCampo) 
{ 
        var strCEP = DesformataCEP(objCampo.value); 
        if (strCEP.length > 0) 
        { 
                var va_cep = objCampo.value; 
                if (strCEP.length != 8) 
                { 
                        var tam_cep = strCEP.length; 
                        for (tam_cep; tam_cep < 8; tam_cep++) 
                        { 
                                va_cep = '0' + va_cep; 
                        } 
                } 
                if (parseFloat(va_cep.substr(0,5)) != 0 && parseFloat(va_cep.value) != 0) 
                { 
                        objCampo.value = FormataCEP(objCampo.value); 
                } 
                else 
                { 
                        alert("CEP inválido !") 
                        objCampo.focus(); 
                        objCampo.select(); 
                        return false; 
                } 
        } 
} 

function DesformataFone(strFone) 
{ 
        var lngTamString; 
        var bytAuxCont; 
        strFone = strFone.replace("(0",""); 
        strFone = strFone.replace(")",""); 
        strFone = strFone.replace("xx",""); 
        strFone = strFone.replace("-",""); 
        strFone = strFone.replace("_","0"); 
        return strFone; 
} 

function FormataFone(strFone) 
{ 
        if (strFone.length == 0) 
        { 
                return ""; 
        } 
        var bytAuxCont; 
        var bytTamStr; 
        var strResultado =''; 
        if (strFone.length < 8) 
        { 
                bytTamStr = 8 - strFone.length; 
                for (bytAuxCont = 1; bytAuxCont <= bytTamStr; bytAuxCont++) 
                { 
                        strFone = '0' + strFone; 
                } 
        } 
        for (bytAuxCont = 0; bytAuxCont <= 7; bytAuxCont++) 
        { 
                if (bytAuxCont == 4) 
                { 
                   strResultado = strResultado + '-'; 
                } 
                if (bytAuxCont == 0 && strFone.substr(bytAuxCont,1) == '0') 
                { 
                   strResultado = strResultado + '_'; 
                } 
                else 
                { 
                        strResultado = strResultado + strFone.substr(bytAuxCont,1); 
                } 
        } 
        return strResultado; 
} 

function ValidaFone(objCampo) 
{ 
        var strFone = DesformataFone(objCampo.value); 
        if (strFone.length > 0) 
        { 
                var va_fone = objCampo.value; 
                if (strFone.length != 8) 
                { 
                        var tam_fone = strFone.length; 
                        for (tam_fone; tam_fone < 8; tam_fone++) 
                        { 
                                va_fone = '0' + va_fone; 
                        } 
                } 
                if (parseInt(va_fone.substr(0,4)) != 0 && 
                        parseInt(va_fone.substr(1,3)) != 0 && 
                        parseInt(va_fone.substr(1,2)) != 0 && 
                        parseInt(va_fone.substr(1,1)) != 0 && 
                        parseInt(va_fone.value) != 0) 
                { 
                        objCampo.value = FormataFone(objCampo.value); 
                } 
                else 
                { 
                        alert("Telefone inválido !") 
                        objCampo.focus(); 
                        objCampo.select(); 
                        return false; 
                } 
        } 
} 

function ValidaFoneDDD(objCampo) 
{ 
        var strFone = DesformataFone(objCampo.value); 
        if (strFone.length > 0) 
        { 
                var va_fone = objCampo.value; 
                if (strFone.length != 10) 
                { 
                        var tam_fone = strFone.length; 
                        for (tam_fone; tam_fone < 10; tam_fone++) 
                        { 
                                va_fone = '0' + va_fone; 
                        } 
                } 
                if (parseInt(va_fone.substr(0,0)) != 0 && 
                        parseInt(va_fone.substr(0,1)) != 0 && 
                        parseInt(va_fone.substr(2,4)) != 0 && 
                        parseInt(va_fone.substr(3,3)) != 0 && 
                        parseInt(va_fone.substr(3,2)) != 0 && 
                        parseInt(va_fone.substr(3,1)) != 0 && 
                        parseInt(va_fone.value) != 0) 
                { 
                        objCampo.value = FormataFoneDDD(objCampo.value); 
                } 
                else 
                { 
                        alert("Telefone inválido !") 
                        objCampo.focus(); 
                        objCampo.select(); 
                        return false; 
                } 
        } 
} 

function FormataFoneDDD(strFone) 
{ 
        if (strFone.length == 0) 
        { 
                return ""; 
        } 
        var bytAuxCont; 
        var bytTamStr; 
        var strResultado =''; 
        if (strFone.length < 10) 
        { 
                bytTamStr = 10 - strFone.length; 
                for (bytAuxCont = 1; bytAuxCont <= bytTamStr; bytAuxCont++) 
                { 
                        strFone = '0' + strFone; 
                } 
        } 
        for (bytAuxCont = 0; bytAuxCont <= 9; bytAuxCont++) 
        { 
                if (bytAuxCont == 0) 
                { 
                   strResultado = strResultado + '(0xx'; 
                } 
                if (bytAuxCont == 2) 
                { 
                   strResultado = strResultado + ')'; 
                } 
                if (bytAuxCont == 6) 
                { 
                   strResultado = strResultado + '-'; 
                } 
                if (bytAuxCont == 2 && strFone.substr(bytAuxCont,1) == '0') 
                { 
                        strResultado = strResultado + '_'; 
                } 
                else 
                { 
                        strResultado = strResultado + strFone.substr(bytAuxCont,1); 
                } 
        } 
        return strResultado; 
}

function FormataTextArea(objCampo)
{
	if (objCampo.value.length > objCampo.maxlength)
	{
		objCampo.value = (objCampo.value).substr(0,objCampo.maxlength);
	}
}

function validaemail(email) {
  var objRegExp  = /^[A-Za-z]([\w\.]*)@([A-Za-z0-9\.]*)\.(([A-Za-z]{3}\.[A-Za-z]{2}$)|([A-Za-z]{3}$)|([a-z]{2}$))/i ;
  return objRegExp.test(email);
}

