//----------------------------------------------------- Colocar Mascára --------------------------------------------------------------------//
function MascaraCNPJ(cnpj)                                                                                                                  //
{                                                                                                                                           //
    if(mascaraInteiro(cnpj)== false)                                                                                                        //
    {                                                                                                                                       //
        event.returnValue = false;                                                                                                          //
    }                                                                                                                                       //
    return FormatarMascara(cnpj, '00.000.000/0000-00', event);                                                                              //
}                                                                                                                                           //
//<input type="text" name="cnpj" id="cnpj" maxlength="18" OnKeyPress="FormatarMascara(cnpj, '00.000.000/0000-00', event); return SomenteNumeros(event);">
                                                                                                                                            //
function MascaraCep(cep)                                                                                                                    //
{                                                                                                                                           //
    if(mascaraInteiro(cep)== false)                                                                                                         //
    {                                                                                                                                       //
        event.returnValue = false;                                                                                                          //
    }                                                                                                                                       //
    return FormatarMascara(cep, '00000-000', event);                                                                                        //
}                                                                                                                                           //
//<input type="text" name="cep" id="cep" maxlength="9" OnKeyPress="FormatarMascara(cep, '00000-000', event); return SomenteNumeros(event);">//
                                                                                                                                            //
function MascaraData(data)                                                                                                                  //
{                                                                                                                                           //
    if(mascaraInteiro(data)== false)                                                                                                        //
    {                                                                                                                                       //
        event.returnValue = false;                                                                                                          //
    }                                                                                                                                       //
    return FormatarMascara(data, '00/00/0000', event);                                                                                      //
}                                                                                                                                           //
//<input type="text" name="data" id="data" maxlength="10" OnKeyPress="FormatarMascara(data, '00/00/0000', event); return SomenteNumeros(event);" />
                                                                                                                                            //
function MascaraHora(hora)                                                                                                                  //
{                                                                                                                                           //
    if(mascaraInteiro(hora)== false)                                                                                                        //
    {                                                                                                                                       //
        event.returnValue = false;                                                                                                          //
    }                                                                                                                                       //
    return FormatarMascara(hora, '00:00', event);                                                                                           //
}                                                                                                                                           //
//<input type="text" name="hora" id="hora" maxlength="5" OnKeyPress="FormatarMascara(hora, '00:00', event); return SomenteNumeros(event);"> //
                                                                                                                                            //
function MascaraTelefone(telefone)                                                                                                          //
{                                                                                                                                           //
    if(mascaraInteiro(telefone)== false)                                                                                                    //
    {                                                                                                                                       //
        event.returnValue = false;                                                                                                          //
    }                                                                                                                                       //
    return FormatarMascara(telefone, '(00) 0000-0000', event);                                                                              //
}                                                                                                                                           //
//<input type="text" name="telefone" id="telefone" maxlength="14" OnKeyPress="FormatarMascara(telefone, '(00) 0000-0000', event); return SomenteNumeros(event);">
                                                                                                                                            //
function MascaraCPF(cpf)                                                                                                                    //
{                                                                                                                                           //
    if(mascaraInteiro(cpf)== false)                                                                                                         //
    {                                                                                                                                       //
        event.returnValue = false;                                                                                                          //
    }                                                                                                                                       //
    return FormatarMascara(cpf, '000.000.000-00', event);                                                                                   //
}                                                                                                                                           //
//<input type="text" name="cpf" id="cpf" maxlength="14" OnKeyPress="FormatarMascara(cpf, '000.000.000-00', event); return SomenteNumeros(event);" />
                                                                                                                                            //
function FormatarMascara(campo, Mascara, evento)                                                                                            //
{                                                                                                                                           //
    var boleanoMascara;                                                                                                                     //
                                                                                                                                            //
    var Digitato = evento.keyCode;                                                                                                          //
    exp = /\-|\.|\:|\/|\(|\)| /g                                                                                                            //
    campoSoNumeros = campo.value.toString().replace( exp, "" );                                                                             //
                                                                                                                                            //
    var posicaoCampo = 0;                                                                                                                   //
    var NovoValorCampo="";                                                                                                                  //
    var TamanhoMascara = campoSoNumeros.length;;                                                                                            //
                                                                                                                                            //
    if (Digitato != 8)                                                                                                                      //
    {   // backspace                                                                                                                        //
        for(i = 0; i <= TamanhoMascara; i++)                                                                                                //
        {                                                                                                                                   //
            boleanoMascara  = ((Mascara.charAt(i) == "-") || (Mascara.charAt(i) == ".") || (Mascara.charAt(i) == ":") || (Mascara.charAt(i) == "/"))
            boleanoMascara  = boleanoMascara || ((Mascara.charAt(i) == "(") || (Mascara.charAt(i) == ")") || (Mascara.charAt(i) == " "))    //
            if (boleanoMascara)                                                                                                             //
            {                                                                                                                               //
                NovoValorCampo += Mascara.charAt(i);                                                                                        //
                TamanhoMascara++;                                                                                                           //
            }                                                                                                                               //
            else                                                                                                                            //
            {                                                                                                                               //
                NovoValorCampo += campoSoNumeros.charAt(posicaoCampo);                                                                      //
                posicaoCampo++;                                                                                                             //
            }                                                                                                                               //
        }                                                                                                                                   //
        campo.value = NovoValorCampo;                                                                                                       //
        return true;                                                                                                                        //
    }                                                                                                                                       //
    else                                                                                                                                    //
    {                                                                                                                                       //
        return true;                                                                                                                        //
    }                                                                                                                                       //
}                                                                                                                                           //
//------------------------------------------------------------------------------------------------------------------------------------------//

//--------------------------------------------------- Máscara para Moedas ------------------------------------------------------------------//
function MascaraMoeda(id,tammax,teclapres)                                                                                                  //
{                                                                                                                                           //
    if(window.event) { // Internet Explorer                                                                                                 //
        var tecla = teclapres.keyCode;                                                                                                      //
    }                                                                                                                                       //
    else if(teclapres.which) { // Nestcape / firefox                                                                                        //
        var tecla = teclapres.which;                                                                                                        //
    }                                                                                                                                       //
                                                                                                                                            //
    vr = document.getElementById(id).value;                                                                                                 //
    vr = vr.toString().replace( "/", "" );                                                                                                  //
    vr = vr.toString().replace( "/", "" );                                                                                                  //
    vr = vr.toString().replace( ",", "" );                                                                                                  //
    vr = vr.toString().replace( ".", "" );                                                                                                  //
    vr = vr.toString().replace( ".", "" );                                                                                                  //
    vr = vr.toString().replace( ".", "" );                                                                                                  //
    vr = vr.toString().replace( ".", "" );                                                                                                  //
    tam = vr.length;                                                                                                                        //
                                                                                                                                            //
    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 <= 2){                                                                                                                      //
            document.getElementById(id).value = vr; }                                                                                       //
        if ((tam > 2) && (tam <= 5)){                                                                                                       //
            document.getElementById(id).value = vr.substr(0, tam - 2) + ',' + vr.substr(tam - 2, tam); }                                    //
        if ((tam >= 6) && (tam <= 8)){                                                                                                      //
            document.getElementById(id).value = vr.substr(0, tam - 5) + '.' + vr.substr(tam - 5, 3) + ',' + vr.substr(tam - 2, tam); }      //
        if ((tam >= 9) && (tam <= 11)){                                                                                                     //
            document.getElementById(id).value = vr.substr(0, tam - 8) + '.' + vr.substr(tam - 8, 3) + '.' + vr.substr(tam - 5, 3) + ',' + vr.substr(tam - 2, tam); }
        if ((tam >= 12) && (tam <= 14)){
            document.getElementById(id).value = vr.substr(0, tam - 11) + '.' + vr.substr(tam - 11, 3) + '.' + vr.substr(tam - 8, 3) + '.' + vr.substr(tam - 5, 3) + ',' + vr.substr(tam - 2, tam); }
        if ((tam >= 15) && (tam <= 17)){
            document.getElementById(id).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); }
    }                                                                                                                                       //
}                                                                                                                                           //
//<input type="text" name="moeda" id="moeda" OnKeyPress="MascaraMoeda(this.id, 10, event); return SomenteNumeros(event);" />                //
//------------------------------------------------------------------------------------------------------------------------------------------//

//------------------------------------------- Função para selecionar todos os checkbox de uma vez ------------------------------------------//
function chkAll(frm, arr, mark)                                                                                                             //
{                                                                                                                                           //
    for (i = 0; i <= frm.elements.length; i++) {                                                                                            //
        try {                                                                                                                               //
	        if(frm.elements[i].name == arr)                                                                                                 //
	            frm.elements[i].checked = mark;                                                                                             //
        }                                                                                                                                   //
        catch(er) {}                                                                                                                        //
    }                                                                                                                                       //
}                                                                                                                                           //
//<input type="checkbox" OnClick="chkAll(this.form, 'checkbox[]', this.checked)"> principal                                                 //
//<input type="checkbox" name="checkbox[]" id="checkbox[]" value="".$_POST['codigo'].""> exemplo de 1 checkbox                              //
//------------------------------------------------------------------------------------------------------------------------------------------//

//------------------------------------------------- Função para abrir imagens em miniaturas ------------------------------------------------//
function Thumbnail(imagem)                                                                                                                  //
{                                                                                                                                           //
    var html = '<img border="0" src="'+imagem+'" />';                                                                                       //
    return overlib(html)                                                                                                                    //
}                                                                                                                                           //
//<script type="text/javascript" src="../js/ajax/overlib.js"></script>                                                                      //
//------------------------------------------------------------------------------------------------------------------------------------------//

//------------------------------------------------- Bloquear Acentos e Caracteres Especiais ------------------------------------------------//
function naoPermiteAcento(obj)                                                                                                              //
{                                                                                                                                           //
    var str = new String(obj.value);                                                                                                        //
    var acentos   = new String('ËÉÈÊÚÙÜÛÏÍÌÎÕÓÒÖÔÑÄÃÁÀÂÇëéèêúùüûïíìîõóòôöñäåãáàâç®þß©¡²³¤€¼½¾‘’¥×«»¬ðø¶´æµ¿:+=<>`\'\"?|¦^&*~º°;&@%$#!(){}[]\\/, ');
    var SemAcento = new String('');                                                                                                         //
    var c = new String();                                                                                                                   //
    var i = new Number();                                                                                                                   //
    var x = new Number();                                                                                                                   //
    var res = '';                                                                                                                           //
                                                                                                                                            //
    for (i = 0; i<str.length; i++)                                                                                                          //
    {                                                                                                                                       //
        c = str.substring(i,i+1);                                                                                                           //
        for (x=0; x < acentos.length; x++)                                                                                                  //
        {                                                                                                                                   //
            if (acentos.substring(x,x+1) == c)                                                                                              //
            {                                                                                                                               //
                c = SemAcento.substring(x,x+1);                                                                                             //
            }                                                                                                                               //
        }                                                                                                                                   //
        res += c;                                                                                                                           //
    }                                                                                                                                       //
    obj.value = res;                                                                                                                        //
}                                                                                                                                           //
//<input type="text" name="" id="" OnKeyUp="javascript:naoPermiteAcento(this);" />                                                          //
//------------------------------------------------------------------------------------------------------------------------------------------//

//---------------------------------------------- Só é Possivel Digitar Números -------------------------------------------------------------//
function SomenteNumeros(evt)                                                                                                                //
{                                                                                                                                           //
    if (window.event) {                                                                                                                     //
        // Internet Explorer                                                                                                                //
        tecla = evt.keyCode;                                                                                                                //
    }                                                                                                                                       //
    else if(evt.which) {                                                                                                                    //
        // Mozila FF                                                                                                                        //
        tecla = evt.which;                                                                                                                  //
    }                                                                                                                                       //
    if ((tecla > 47 && tecla < 58) || (tecla == 8)) {                                                                                       //
        return true;                                                                                                                        //
    }                                                                                                                                       //
    else {                                                                                                                                  //
        return false;                                                                                                                       //
    }                                                                                                                                       //
}                                                                                                                                           //
//<input type="text" name="" id="" OnKeyPress="return SomenteNumeros(event);" />                                                            //
//------------------------------------------------------------------------------------------------------------------------------------------//

//----------------------------------------------------- Verificar Email --------------------------------------------------------------------//
function VerificarEmail(email)                                                                                                              //
{                                                                                                                                           //
    if ((email.length != 0) && ((email.indexOf("@") < 1) || (email.indexOf('.') < 7)))                                                      //
    {                                                                                                                                       //
        return false;                                                                                                                       //
    }                                                                                                                                       //
    return true;                                                                                                                            //
}                                                                                                                                           //
//------------------------------------------------------------------------------------------------------------------------------------------//

//----------------------------------------------------- Verificar Data ---------------------------------------------------------------------//
function VerificarData(data)                                                                                                                //
{                                                                                                                                           //
    var dia = data.substr(0,2)                                                                                                              //
    var mes = data.substr(3,2)                                                                                                              //
    var ano = data.substr(6,4)                                                                                                              //
                                                                                                                                            //
    if (ano > 0)                                                                                                                            //
    {                                                                                                                                       //
        if (mes >= 1 && mes <= 12)                                                                                                          //
        {                                                                                                                                   //
            dias = 31;                                                                                                                      //
            if (mes == 4 || mes == 6 || mes == 9 || mes == 11)                                                                              //
                dias = 30;                                                                                                                  //
            if (mes == 2)                                                                                                                   //
            {                                                                                                                               //
                dias = 28;                                                                                                                  //
                if (ano % 4 == 0)                                                                                                           //
                    if (ano % 100 == 0)                                                                                                     //
                        if (ano % 400 == 0)                                                                                                 //
                            dias = 29;                                                                                                      //
                        else                                                                                                                //
                            dias = 29;                                                                                                      //
            }                                                                                                                               //
            if (dia < 1 || dia > dias)                                                                                                      //
                return false;                                                                                                               //
        }                                                                                                                                   //
        else                                                                                                                                //
            return false;                                                                                                                   //
    }                                                                                                                                       //
    else                                                                                                                                    //
        return false;                                                                                                                       //
                                                                                                                                            //
    return true;                                                                                                                            //
}                                                                                                                                           //
//------------------------------------------------------------------------------------------------------------------------------------------//

//------------------------------------------------------ Verificar CPF ---------------------------------------------------------------------//
function VerificarCPF(cpf)                                                                                                                  //
{                                                                                                                                           //
    with(cpf)                                                                                                                               //
    {                                                                                                                                       //
        cpf = cpf.replace (".","");                                                                                                         //
        cpf = cpf.replace (".","");                                                                                                         //
        cpf = cpf.replace ("-","");                                                                                                         //
        cpf = cpf.replace ("/","");                                                                                                         //
    }                                                                                                                                       //
                                                                                                                                            //
    if (cpf.length != 11 ||                                                                                                                 //
        cpf == "00000000000" ||                                                                                                             //
        cpf == "11111111111" ||                                                                                                             //
        cpf == "22222222222" ||                                                                                                             //
        cpf == "33333333333" ||                                                                                                             //
        cpf == "44444444444" ||                                                                                                             //
        cpf == "55555555555" ||                                                                                                             //
        cpf == "66666666666" ||                                                                                                             //
        cpf == "77777777777" ||                                                                                                             //
        cpf == "88888888888" ||                                                                                                             //
        cpf == "99999999999"                                                                                                                //
       )                                                                                                                                    //
       return false;                                                                                                                        //
                                                                                                                                            //
    add = 0;                                                                                                                                //
    for (i=0; i < 9; i ++)                                                                                                                  //
        add += parseInt(cpf.charAt(i)) * (10 - i);                                                                                          //
                                                                                                                                            //
    rev = 11 - (add % 11);                                                                                                                  //
    if (rev == 10 || rev == 11)                                                                                                             //
        rev = 0;                                                                                                                            //
                                                                                                                                            //
    if (rev != parseInt(cpf.charAt(9)))                                                                                                     //
        return false;                                                                                                                       //
                                                                                                                                            //
    add = 0;                                                                                                                                //
    for (i = 0; i < 10; i ++)                                                                                                               //
        add += parseInt(cpf.charAt(i)) * (11 - i);                                                                                          //
                                                                                                                                            //
    rev = 11 - (add % 11);                                                                                                                  //
    if (rev == 10 || rev == 11)                                                                                                             //
        rev = 0;                                                                                                                            //
                                                                                                                                            //
    if (rev != parseInt(cpf.charAt(10)))                                                                                                    //
        return false;                                                                                                                       //
                                                                                                                                            //
    return true;                                                                                                                            //
}                                                                                                                                           //
//------------------------------------------------------------------------------------------------------------------------------------------//
