﻿//caso CPF esteja em branco este continua válido
function funCpfValido(param_cpf) {

    var cpf = param_cpf;
    cpf = cpf.replace(".", "");
    cpf = cpf.replace(".", "");
    cpf = cpf.replace(".", "");
    cpf = cpf.replace(".", "");
    cpf = cpf.replace(".", "");
    cpf = cpf.replace("-", "");
    cpf = cpf.replace("-", "");
    cpf = cpf.replace("-", "");

    if (cpf == "00000000000") return false;
    if (cpf == "12345678901") return false;
    if (cpf == "11111111111") return false;
    if (cpf == "22222222222") return false;
    if (cpf == "33333333333") return false;
    if (cpf == "44444444444") return false;
    if (cpf == "55555555555") return false;
    if (cpf == "66666666666") return false;
    if (cpf == "77777777777") return false;
    if (cpf == "88888888888") return false;
    if (cpf == "99999999999") return false;

    if (cpf == '') return true;

    x = 0;
    soma = 0;
    dig1 = 0;
    dig2 = 0;
    texto = "";
    cpf1 = "";
    len = cpf.length; x = len - 1;

    if (len != 11)
        return false;

    for (var i = 0; i <= len - 3; i++) {
        y = cpf.substring(i, i + 1);
        soma = soma + (y * x);
        x = x - 1;
        texto = texto + y;
    } //for

    dig1 = 11 - (soma % 11);

    if (dig1 == 10) dig1 = 0;

    if (dig1 == 11) dig1 = 0;

    cpf1 = cpf.substring(0, len - 2) + dig1;

    x = 11; soma = 0;

    for (var i = 0; i <= len - 2; i++) {

        soma = soma + (cpf1.substring(i, i + 1) * x);

        x = x - 1;

    } //for

    dig2 = 11 - (soma % 11);

    if (dig2 == 10) dig2 = 0;

    if (dig2 == 11) dig2 = 0;

    //alert ("Digito Verificador : " + dig1 + "" + dig2);
    if ((dig1 + "" + dig2) == cpf.substring(len, len - 2)) {
        return true;
    } //if

    return false;

} //function

function EhNumero(paramEvento) {
    var nTecla = 0;
    if (document.all) {
        nTecla = paramEvento.keyCode;
    } // Internet Explorer
    else if (document.layers && navigator.appName.indexOf("Mozilla") == -1) {
        nTecla = paramEvento.which;
    }  //Netscape
    else {
        nTecla = paramEvento.which;
    } // Mozilla / FireFox / Opera
    
    if ((nTecla > 47 && nTecla < 58) || nTecla == 8 || nTecla == 0)
        return true;
    else
        return false;
}

function selecionarTodosCheckBoxsGeral(paramObj) {
    var selecionado = paramObj.checked;

    var itens = document.getElementsByTagName("INPUT");

    for (var i = 0; i < itens.length; i++)

        if (itens[i].type == "checkbox" && itens[i].id != paramObj.id && itens[i].id.indexOf(paramObj.id) >= 0 && !itens[i].disabled)
        itens[i].checked = selecionado;
} //function

function IsValidURL(url) {
    var RegExp = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;
    if (RegExp.test(url)) {
        return true;
    } else {
        return false;
    }
}