﻿function iniciaVerificaResolucao() {
    if (window.addEventListener) //DOM method for binding an event
        window.addEventListener("load", VerificaResolucao, false);
    else if (window.attachEvent) //IE exclusive method for binding an event
        window.attachEvent("onload", VerificaResolucao);
    else if (document.getElementById) //support older modern browsers
        window.onload = VerificaResolucao;
}

var EventoAdicionado = false;
function VerificaResolucao() {
    if (window.screen.width == 1024 && document.body.clientWidth >= 1003) {
        document.getElementsByTagName('html')[0].className = 'EscondeScroll';
    } else {
        if (document.body.clientWidth < 1003) {
            document.getElementsByTagName('html')[0].className = 'ExibeScroll';
        }
    }
    if (!EventoAdicionado) {
        AdicionaEventoResize();
    }
}

function AdicionaEventoResize() {
    if (window.addEventListener) //DOM method for binding an event
        window.addEventListener("resize", VerificaResolucao, false);
    else if (window.attachEvent) //IE exclusive method for binding an event
        window.attachEvent("onresize", VerificaResolucao);
    else if (document.getElementById) //support older modern browsers
        window.onresize = VerificaResolucao;
    EventoAdicionado = true;
}

function getEndereco(cep, CampoEndereco, CampoBairro) {
    if ($.trim(cep) != "") {
        $.getScript("http://republicavirtual.com.br/web_cep.php?formato=javascript&cep=" + cep, function() {
            if (resultadoCEP && resultadoCEP["resultado"]) {
                CampoEndereco.value = unescape(resultadoCEP['logradouro']);
                CampoBairro.value = unescape(resultadoCEP['bairro']);
                resultadoCEP = null;
            } else {
                CampoEndereco.value = '';
                CampoBairro.value = '';
            }
        });
    }
}

function ValidaCPF(custom, args) {
    var cpf = args.Value.replace(/\./g, '').replace(/\-/g, '');
    if (cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999") {
        args.IsValid = false;
        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))) {
        args.IsValid = false;
        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))) {
        args.IsValid = false;
        return false;
    }
}

function ValidaCNPJ(custom, args) {
    var numeros, digitos, soma, i, resultado, pos, tamanho, digitos_iguais;
    digitos_iguais = 1;
    cnpj = args.Value.replace(/\./g, '').replace(/\-/g, '').replace(/\//g, '');

    if (cnpj.length < 14 && cnpj.length < 15) {
        args.IsValid = false;
        return false;
    }
    for (i = 0; i < cnpj.length - 1; i++)
        if (cnpj.charAt(i) != cnpj.charAt(i + 1)) {
        digitos_iguais = 0;
        break;
    }
    if (!digitos_iguais) {
        tamanho = cnpj.length - 2
        numeros = cnpj.substring(0, tamanho);
        digitos = cnpj.substring(tamanho);
        soma = 0;
        pos = tamanho - 7;
        for (i = tamanho; i >= 1; i--) {
            soma += numeros.charAt(tamanho - i) * pos--;
            if (pos < 2)
                pos = 9;
        }
        resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
        if (resultado != digitos.charAt(0)) {
            args.IsValid = false;
            return false;
        }
        tamanho = tamanho + 1;
        numeros = cnpj.substring(0, tamanho);
        soma = 0;
        pos = tamanho - 7;
        for (i = tamanho; i >= 1; i--) {
            soma += numeros.charAt(tamanho - i) * pos--;
            if (pos < 2)
                pos = 9;
        }
        resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
        if (resultado != digitos.charAt(1)) {
            args.IsValid = false;
            return false;
        }
        return true;
    }
    else {
        args.IsValid = false;
        return false;
    }
}

function Twitter(){
    new TWTR.Widget({
        version: 2,
        type: 'profile',
        rpp: 2,
        interval: 6000,
        width: 966,
        height: 300,
        theme: {
            shell: {
                background: 'url(../../imagens/bg_twitter.gif)',
                color: '#ffffff'
            },
            tweets: {
                background: 'transparent',
                color: '#000000',
                links: '#941919'
            }
        },
        features: {
            scrollbar: false,
            loop: false,
            live: false,
            hashtags: true,
            timestamp: true,
            avatars: false,
            behavior: 'all'
        }
    }).render().setUser('cortez_editora').start();
}

function AbreAviseMe(ProdutoId) {
    lightbox.abreLightbox('AviseMe.aspx?ProdutoId=' + ProdutoId, '422px', '173px', false, false);
}
function fechaAviseMe() {
    lightbox.destroiObjetos();
}
