﻿function UR_Start() {

    var mydate = new Date()
    var year = mydate.getYear()
    if (year < 1000)
        year += 1900
    var day = mydate.getDay()
    var month = mydate.getMonth()
    var daym = mydate.getDate()
    if (daym < 10)
        daym = "0" + daym
    var dayarray = new Array("domingo", "Segunda-Feira", "Terça-Feira", "Quarta-Feira", "Quinta-Feira", "Sexta-Feira", "Sábado")
    var montharray = new Array("Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro")

    UR_Nu = new Date;
    UR_Indhold = showFilled(UR_Nu.getHours()) + ":" + showFilled(UR_Nu.getMinutes()) + ":" + showFilled(UR_Nu.getSeconds());
    document.getElementById("ur").innerHTML = dayarray[day] + ", " + daym + " de " + montharray[month] + " de " + year + " - " + UR_Indhold;
    setTimeout("UR_Start()", 1000);
}
function showFilled(Value) {
    return (Value > 9) ? "" + Value : "0" + Value;
}


function setbg(o) {
    o.style.background = '#eefeff';
}
function resetbg(o) {

    o.style.background = 'none';
}

//function Validar(theCPF) {

//    if (theCPF.value == "") {
//        alert("Campo inválido. É necessário informar o CPF ou CNPJ");
//        theCPF.focus();
//        return (false);
//    }
//    if (((theCPF.value.length == 11) && (theCPF.value == 11111111111) || (theCPF.value == 22222222222) || (theCPF.value == 33333333333) || (theCPF.value == 44444444444) || (theCPF.value == 55555555555) || (theCPF.value == 66666666666) || (theCPF.value == 77777777777) || (theCPF.value == 88888888888) || (theCPF.value == 99999999999) || (theCPF.value == 00000000000))) {
//        alert("CPF/CNPJ inválido.");
//        theCPF.focus();
//        return (false);
//    }


//    if (!((theCPF.value.length == 11) || (theCPF.value.length == 14))) {
//        alert("CPF/CNPJ inválido.");
//        theCPF.focus();
//        return (false);
//    }

//    var checkOK = "0123456789";
//    var checkStr = theCPF.value;
//    var allValid = true;
//    var allNum = "";
//    for (i = 0; i < checkStr.length; i++) {
//        ch = checkStr.charAt(i);
//        for (j = 0; j < checkOK.length; j++)
//            if (ch == checkOK.charAt(j))
//            break;
//        if (j == checkOK.length) {
//            allValid = false;
//            break;
//        }
//        allNum += ch;
//    }
//    if (!allValid) {
//        alert("Favor preencher somente com dígitos o campo CPF/CNPJ.");
//        theCPF.focus();
//        return (false);
//    }

//    var chkVal = allNum;
//    var prsVal = parseFloat(allNum);
//    if (chkVal != "" && !(prsVal > "0")) {
//        alert("CPF zerado !");
//        theCPF.focus();
//        return (false);
//    }

//    if (theCPF.value.length == 11) {
//        var tot = 0;

//        for (i = 2; i <= 10; i++)
//            tot += i * parseInt(checkStr.charAt(10 - i));

//        if ((tot * 10 % 11 % 10) != parseInt(checkStr.charAt(9))) {
//            alert("CPF/CNPJ inválido.");
//            theCPF.focus();
//            return (false);
//        }

//        tot = 0;

//        for (i = 2; i <= 11; i++)
//            tot += i * parseInt(checkStr.charAt(11 - i));

//        if ((tot * 10 % 11 % 10) != parseInt(checkStr.charAt(10))) {
//            alert("CPF/CNPJ inválido.");
//            theCPF.focus();
//            return (false);
//        }
//    }
//    else {
//        var tot = 0;
//        var peso = 2;

//        for (i = 0; i <= 11; i++) {
//            tot += peso * parseInt(checkStr.charAt(11 - i));
//            peso++;
//            if (peso == 10) {
//                peso = 2;
//            }
//        }

//        if ((tot * 10 % 11 % 10) != parseInt(checkStr.charAt(12))) {
//            alert("CPF/CNPJ inválido.");
//            theCPF.focus();
//            return (false);
//        }

//        tot = 0;
//        peso = 2;

//        for (i = 0; i <= 12; i++) {
//            tot += peso * parseInt(checkStr.charAt(12 - i));
//            peso++;
//            if (peso == 10) {
//                peso = 2;
//            }
//        }

//        if ((tot * 10 % 11 % 10) != parseInt(checkStr.charAt(13))) {
//            alert("CPF/CNPJ inválido.");
//            theCPF.focus();
//            return (false);
//        }
//    }
//    return (true);
//}


function isCPFCNPJ(campo, pType) {
    if (isEmpty(campo)) { return false; }

    var campo_filtrado = "", valor_1 = " ", valor_2 = " ", ch = "";
    var valido = false;

    for (i = 0; i < campo.length; i++) {
        ch = campo.substring(i, i + 1);
        if (ch >= "0" && ch <= "9") {
            campo_filtrado = campo_filtrado.toString() + ch.toString()
            valor_1 = valor_2;
            valor_2 = ch;
        }
        if ((valor_1 != " ") && (!valido)) valido = !(valor_1 == valor_2);
    }
    if (!valido) campo_filtrado = "12345678912";

    if (campo_filtrado.length < 11) {
        for (i = 1; i <= (11 - campo_filtrado.length); i++) { campo_filtrado = "0" + campo_filtrado; }
    }

    if (pType <= 1) {
        if ((campo_filtrado.substring(9, 11) == checkCPF(campo_filtrado.substring(0, 9))) && (campo_filtrado.substring(11, 12) == "")) { return true; }
    }

    if ((pType == 2) || (pType == 0)) {
        if (campo_filtrado.length >= 14) {
            if (campo_filtrado.substring(12, 14) == checkCNPJ(campo_filtrado.substring(0, 12))) { return true; }
        }
    }

    return false;
}

function checkCNPJ(vCNPJ) {
    var mControle = "";
    var aTabCNPJ = new Array(5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2);
    for (i = 1; i <= 2; i++) {
        mSoma = 0;
        for (j = 0; j < vCNPJ.length; j++)
            mSoma = mSoma + (vCNPJ.substring(j, j + 1) * aTabCNPJ[j]);
        if (i == 2) mSoma = mSoma + (2 * mDigito);
        mDigito = (mSoma * 10) % 11;
        if (mDigito == 10) mDigito = 0;
        mControle1 = mControle;
        mControle = mDigito;
        aTabCNPJ = new Array(6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3);
    }
    return ((mControle1 * 10) + mControle);
}

function checkCPF(vCPF) {
    var mControle = ""
    var mContIni = 2, mContFim = 10, mDigito = 0;
    for (j = 1; j <= 2; j++) {
        mSoma = 0;
        for (i = mContIni; i <= mContFim; i++)
            mSoma = mSoma + (vCPF.substring((i - j - 1), (i - j)) * (mContFim + 1 + j - i));
        if (j == 2) mSoma = mSoma + (2 * mDigito);
        mDigito = (mSoma * 10) % 11;
        if (mDigito == 10) mDigito = 0;
        mControle1 = mControle;
        mControle = mDigito;
        mContIni = 3;
        mContFim = 11;
    }
    return ((mControle1 * 10) + mControle);
}
function formata(src, mask) {
    var i = src.value.length;
    var saida = mask.substring(0, 1);
    var texto = mask.substring(i)
    if (texto.substring(0, 1) != saida) {
        src.value += texto.substring(0, 1);
    }
}
