﻿function querySt(ji) {
    hu = window.location.search.substring(1);
    gy = hu.split("&");
    for (i = 0; i < gy.length; i++) {
        ft = gy[i].split("=");
        if (ft[0] == ji) {
            return ft[1];
        }
    }
}

$(document).ready(function() {
    Mostra();

    var contato = querySt("contato");
    Esconde(contato);
    
    
    $("#enderecocontent").hide();
    $("#endereco").click(function() {
        $("#enderecocontent").slideToggle("slow")
                .siblings("#enderecocontent:visible").slideUp("slow");
    });


    $("#indique").click(function() {
        $("#indiquecontent").slideToggle("slow")
                .siblings("#contatocontent:visible").slideUp("slow");
    });
    $("#contato").click(function() {
        $("#contatocontent").slideToggle("slow")
                .siblings("#indiquecontent:visible").slideUp("slow");
    });



    $(".accordion h3:first").addClass("active");
    $(".accordion div:not(:first)").hide();

    $(".accordion h3").click(function() {
        $(this).next("div").slideToggle("slow")
		.siblings("div:visible").slideUp("slow");
        $(this).toggleClass("active");
        $(this).siblings("h3").removeClass("active");
    });
    
    $(".accordion2 div").hide();

    $(".accordion2 h3").click(function() {
        $(this).next("div").slideToggle("slow")
		.siblings("div:visible").slideUp("slow");
        $(this).toggleClass("active");
        $(this).siblings("h3").removeClass("active");
    });

});


function Mostra() {
    $("#panel").slideDown("slow");
    return false;
};

function Esconde(contato) {
    if (contato == 1) {
        $("#contatocontent").hide();
    }
    else {
        $("#indiquecontent").hide();
    }
}




function DisableCopyPaste() {
    // current pressed key
    var pressedKey = String.fromCharCode(event.keyCode).toLowerCase();

    if (event.ctrlKey && (pressedKey == "c" ||
                        pressedKey == "v")) {
        // disable key press porcessing
        event.returnValue = false;
    }

}


var popup = "Botão direito do mouse desabilidado";

function noway(go) {
    if (document.all) {
        if (event.button == 2) {
            alert(popup); return false;
        }
    }

    if (document.layers) {
        if (go.which == 3) {
            alert(popup);
            return false;
        }
    }
}
if (document.layers) {
    document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown = noway;


function validar_CPF(Ncampo) {
    erro = new String;
    cpf = document.getElementById(Ncampo);
    if (cpf.value.length == 14) {
        cpf.value = cpf.value.replace('.', '');
        cpf.value = cpf.value.replace('.', '');
        cpf.value = cpf.value.replace('-', '');

        var nonNumbers = /\D/;

        if (nonNumbers.test(cpf.value)) {
            erro = "A verificacao de CPF suporta apenas números!";
        }
        else {
            if (cpf.value == "00000000000" ||
								cpf.value == "11111111111" ||
								cpf.value == "22222222222" ||
								cpf.value == "33333333333" ||
								cpf.value == "44444444444" ||
								cpf.value == "55555555555" ||
								cpf.value == "66666666666" ||
								cpf.value == "77777777777" ||
								cpf.value == "88888888888" ||
								cpf.value == "99999999999") {

                erro = "Número de CPF inválido !"
            }


            var a = [];
            var b = new Number;
            var c = 11;

            for (i = 0; i < 11; i++) {
                a[i] = cpf.value.charAt(i);
                if (i < 9) b += (a[i] * --c);
            }

            if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11 - x }
            b = 0;
            c = 11;

            for (y = 0; y < 10; y++) b += (a[y] * c--);

            if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11 - x; }

            if ((cpf.value.charAt(9) != a[9]) || (cpf.value.charAt(10) != a[10])) {
                erro = "Número de CPF inválido.";
                //document.getElementById(Ncampo).value = cpf.value; 
            }
        }
    }
    else {
        if (cpf.value.length == 0) {
            document.getElementById('resposta' + Ncampo).innerHTML = "";
            return false;
        }
        else
            erro = "Número de CPF inválido.";
    }
    if (erro.length > 0) {
        alert(erro);
        document.getElementById(Ncampo).focus();

        if (cpf.value.length == 11) {
            str = cpf.value;
            str2 = cpf.value.substring(0, 3);
            str3 = cpf.value.substring(3, 6);
            str4 = cpf.value.substring(6, 9);
            str5 = cpf.value.substring(9, 12);
            result = str.replace(str, str2 + '.');
            result2 = str.replace(str, str3 + '.');
            result3 = str.replace(str, str4 + '-');
            document.getElementById(Ncampo).value = result + result2 + result3 + str5;
            document.getElementById(Ncampo).focus();
            return false;
        }

        document.getElementById(Ncampo).value = cpf.value;
        //document.getElementById(Ncampo).style.background = "red";
        //                document.getElementById(Ncampo).set_set_activeTabIndex(0);


        return false;
    }
    //document.getElementById(Ncampo).style.background = "#98EE84";
    //            document.getElementById('resposta' + Ncampo).innerHTML = "";
    str = cpf.value;
    str2 = cpf.value.substring(0, 3);
    str3 = cpf.value.substring(3, 6);
    str4 = cpf.value.substring(6, 9);
    str5 = cpf.value.substring(9, 12);
    result = str.replace(str, str2 + '.');
    result2 = str.replace(str, str3 + '.');
    result3 = str.replace(str, str4 + '-');
    document.getElementById(Ncampo).value = result + result2 + result3 + str5;

    return true;
}

function valida_email(email1, email2) {

    //    email = document.getElementById('ctl00$ContentPlaceHolder1$txEmail');
    //    emailconf = document.getElementById('ctl00$ContentPlaceHolder1$txEmailConf');

    email = document.getElementById(email2.id);
    emailconf = document.getElementById(email1.id);

    if (email.value != emailconf.value) {

        alert("Os emails não conferem !");
        emailconf.focus();
        //document.getElementById('ctl00$ContentPlaceHolder1$txEmail').focus();

    }
}

function txtBoxFormat(objeto, sMask, evtKeyPress) {
    var i, nCount, sValue, fldLen, mskLen, bolMask, sCod, nTecla;


    if (document.all) { // Internet Explorer
        nTecla = evtKeyPress.keyCode;
    } else if (document.layers) { // Nestcape
        nTecla = evtKeyPress.which;
    } else {
        nTecla = evtKeyPress.which;
        if (nTecla == 8) {
            return true;
        }
    }

    sValue = objeto.value;

    // Limpa todos os caracteres de formatação que
    // já estiverem no campo.
    sValue = sValue.toString().replace("-", "");
    sValue = sValue.toString().replace("-", "");
    sValue = sValue.toString().replace(".", "");
    sValue = sValue.toString().replace(".", "");
    sValue = sValue.toString().replace("/", "");
    sValue = sValue.toString().replace("/", "");
    sValue = sValue.toString().replace(":", "");
    sValue = sValue.toString().replace(":", "");
    sValue = sValue.toString().replace("(", "");
    sValue = sValue.toString().replace("(", "");
    sValue = sValue.toString().replace(")", "");
    sValue = sValue.toString().replace(")", "");
    sValue = sValue.toString().replace(" ", "");
    sValue = sValue.toString().replace(" ", "");
    fldLen = sValue.length;
    mskLen = sMask.length;

    i = 0;
    nCount = 0;
    sCod = "";
    mskLen = fldLen;

    while (i <= mskLen) {
        bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/") || (sMask.charAt(i) == ":"))
        bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

        if (bolMask) {
            sCod += sMask.charAt(i);
            mskLen++;
        }
        else {
            sCod += sValue.charAt(nCount);
            nCount++;
        }

        i++;
    }

    objeto.value = sCod;

    if (nTecla != 8) { // backspace
        if (sMask.charAt(i - 1) == "9") { // apenas números...
            return ((nTecla > 47) && (nTecla < 58));
        }
        else { // qualquer caracter...
            return true;
        }
    }
    else {
        return true;
    }
}


function limpa_string(S) {
    var Digitos = "0123456789";
    var temp = "";
    var digito = "";
    for (var i = 0; i < S.length; i++) {
        digito = S.charAt(i);
        if (Digitos.indexOf(digito) >= 0) { temp = temp + digito; }
    }
    return temp;
}