﻿function InscricaoNaoEncontrada() {
    if (confirm("Inscrição não encontrada.\nDeseja se inscrever?"))
        window.location = window.location;
}

function ListadeEspera(Elemento) {
    if (Elemento.checked) {
        Elemento.checked = confirm("Não há vaga.\nDeseja se inscrever na lista de espera?");
    }
}

function InscricaoCurso() {
    alert("Você fez a inscrição no curso.\nFavor entrar em contato com a SDB-MG.");
    window.location = window.location;
}

function InscricaoAprovacao() {
    alert("Você fez a inscrição, porém ela ainda não foi liberada.\nFavor entrar em contato com a SDB-MG.");
    window.location = window.location;
}

function InscricaoPagamento() {
    alert("Você fez a inscrição, porém o pagamento ainda não foi confirmado.\nFavor entrar em contato com a SDB-MG.");
    window.location = window.location;
}

function Erro(Erro) {
    alert(Erro);
}

function InscricaoReserva(CPF, Inscricao) {
    if (!confirm("Você já fez uma reserva em um curso.\nDeseja cancelar a reserva e se inscrever em outro curso?"))
        window.location = window.location + "&CPF="+ CPF + "&Inscricao=" + Inscricao;
}

function desabilitarCursos() {
    document.getElementById('liCursos').style.display = 'none';
}

function habilitarCursos() {
    document.getElementById('liCursos').style.display = 'block';
}

function MostraCursos() {
    if (document.getElementById('liCursos'))
        document.getElementById('liCursos').style.display = 'block';

    if (document.getElementById('rblCursos'))
        document.getElementById('rblCursos').style.display = 'block';

    if (document.getElementById('rblCursosNaoAssociado'))
        document.getElementById('rblCursosNaoAssociado').style.display = 'none';

    if (document.getElementById('rblCursosResidente'))
        document.getElementById('rblCursosResidente').style.display = 'none';
}


function MostraNaoAssociadoCursos() {
    if (document.getElementById('liCursos'))
        document.getElementById('liCursos').style.display = 'block';

    if (document.getElementById('rblCursos'))
        document.getElementById('rblCursos').style.display = 'none';

    if (document.getElementById('rblCursosNaoAssociado'))
        document.getElementById('rblCursosNaoAssociado').style.display = 'block';

    if (document.getElementById('rblCursosResidente'))
        document.getElementById('rblCursosResidente').style.display = 'none';
}


function EscondeCursos() {
    if (document.getElementById('liCursos'))
        document.getElementById('liCursos').style.display = 'none';

    if (document.getElementById('rblCursos'))
        document.getElementById('rblCursos').style.display = 'none';

    if (document.getElementById('rblCursosNaoAssociado'))
        document.getElementById('rblCursosNaoAssociado').style.display = 'none';

    if (document.getElementById('rblCursosResidente'))
        document.getElementById('rblCursosResidente').style.display = 'none';
}


function MostraResidenteCursos() {
    if (document.getElementById('liCursos'))
        document.getElementById('liCursos').style.display = 'block';

    if (document.getElementById('rblCursos'))
        document.getElementById('rblCursos').style.display = 'none';

    if (document.getElementById('rblCursosNaoAssociado'))
        document.getElementById('rblCursosNaoAssociado').style.display = 'none';

    if (document.getElementById('rblCursosResidente'))
        document.getElementById('rblCursosResidente').style.display = 'block';
}


var isNN = (navigator.appName.indexOf("Netscape") != -1);

function AtivaEnter(evento, NomeBotao) {
    var botao = document.getElementById(NomeBotao);
    var keyCode = (isNN) ? evento.which : evento.keyCode;

    if (keyCode == 13) {
        evento.preventDefault ? evento.preventDefault() : evento.returnValue = false;
        botao.click();
    }
}

function ValidaCategoria(source, arguments) {
    valor = arguments.Value;
    arguments.IsValid = true;

    if (!document.getElementById("rCategoriaAssociado").checked && !document.getElementById("rCategoriaResidente").checked && !document.getElementById("rCategoriaHonorario").checked) {
        //document.getElementById("rCategoriaAssociado").focus();
        arguments.IsValid = false;
    }
}

function ValidaCategoriaSemAcadeENaoAssoc(source, arguments) {
    valor = arguments.Value;
    arguments.IsValid = true;

    if (!document.getElementById("rCategoriaAssociado").checked && !document.getElementById("rCategoriaResidente").checked && !document.getElementById("rCategoriaHonorario").checked) {
        //document.getElementById("rCategoriaAssociado").focus();
        arguments.IsValid = false;
    }
}

function ValidaCategoriaSemNaoAssoc(source, arguments) {
    valor = arguments.Value;
    arguments.IsValid = true;

    if (!document.getElementById("rCategoriaAssociado").checked && !document.getElementById("rCategoriaResidente").checked && !document.getElementById("rCategoriaNaoAssociado").checked && !document.getElementById("rCategoriaHonorario").checked) {
        //document.getElementById("rCategoriaAssociado").focus();
        arguments.IsValid = false;
    }
}

function ValidaCategoriaSemAcade(source, arguments) {
    valor = arguments.Value;
    arguments.IsValid = true;

    if (!document.getElementById("rCategoriaAssociado").checked && !document.getElementById("rCategoriaResidente").checked && !document.getElementById("rCategoriaAcademico").checked && !document.getElementById("rCategoriaHonorario").checked) {
        //document.getElementById("rCategoriaAssociado").focus();
        arguments.IsValid = false;
    }
}

function ValidaCategoriaTodos(source, arguments) {
    valor = arguments.Value;
    arguments.IsValid = true;

    if (!document.getElementById("rCategoriaAssociado").checked && !document.getElementById("rCategoriaResidente").checked && !document.getElementById("rCategoriaNaoAssociado").checked && !document.getElementById("rCategoriaAcademico").checked && !document.getElementById("rCategoriaHonorario").checked) {
        //document.getElementById("rCategoriaAssociado").focus();
        arguments.IsValid = false;
    }
}

function ValidaCategoria2(source, arguments) {
    valor = arguments.Value;
    arguments.IsValid = true;

    if (!document.getElementById("rCategoriaAssociado").checked && !document.getElementById("rCategoriaResidente").checked && !document.getElementById("rCategoriaAcademico").checked && !document.getElementById("rCategoriaHonorario").checked) {
        //document.getElementById("rCategoriaAssociado").focus();
        arguments.IsValid = false;
    }
}

function ValidaConvite(source, arguments) {
    valor = arguments.Value;
    arguments.IsValid = true;

    if (!document.getElementById("rConviteSim").checked && !document.getElementById("rConviteNao").checked) {
        //document.getElementById("rConviteSim").focus();
        arguments.IsValid = false;
    }
}

function ValidaCPF(source, arguments) {
    valor = arguments.Value;
    arguments.IsValid = true;

    if (!isCPF(valor)) arguments.IsValid = false;
}


function isCPF(s) {
    s = s.replace('.', '')
    s = s.replace('.', '')
    s = s.replace('-', '')

    if (s == "00000000000" || s == "11111111111" || s == "22222222222" || s == "33333333333" || s == "44444444444" || s == "55555555555" || s == "66666666666" || s == "77777777777" || s == "88888888888" || s == "99999999999") {
        return false;
    }

    var i;
    var c = s.substr(0, 9);
    var dv = s.substr(9, 2);
    var d1 = 0;

    for (i = 0; i < 9; i++) {
        d1 += c.charAt(i) * (10 - i);
    }

    if (d1 == 0) {
        return false;
    }

    d1 = 11 - (d1 % 11);

    if (d1 > 9) d1 = 0;
    if (dv.charAt(0) != d1) {
        return false;
    }

    d1 *= 2;

    for (i = 0; i < 9; i++) {
        d1 += c.charAt(i) * (11 - i);
    }

    d1 = 11 - (d1 % 11);

    if (d1 > 9) d1 = 0;

    if (dv.charAt(1) != d1) {
        return false;
    }

    return true;
}

function ContaCaracteres(Campo, CampoExibir, Maximo) {
    if (Campo == null) {
        return;
    }

    if (Campo.value.length > Maximo) {
        alert("Por favor, digite no máximo de " + Maximo + " caracteres!");
        Campo.value = Campo.value.substring(0, Maximo);
    }

    document.getElementById(CampoExibir).innerHTML = Maximo - Campo.value.length;
}

function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; }
    }
}

function MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}

function MM_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}

function abrir(URL) {

    var width = 640;
    var height = 680;

    var left = 99;
    var top = 99;

    window.open(URL, 'Galeria', 'width=' + width + ', height=' + height + ', top=' + top + ', left=' + left + ', scrollbars=yes, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=yes, fullscreen=no');

}

var DivServico = "";

function HabilitaServicos(Div) {
    if (DivServico != Div) {
        EscondeServicos();
        DivServico = Div;
        document.getElementById(Div).style.display = "block";
    }
    else
        EscondeServicos();

}

function EscondeServicos() {
    DivServico = "";
    document.getElementById("DivEntidades").style.display = "none";
    document.getElementById("DivSocAcaCol").style.display = "none";
    document.getElementById("DivRevPedJor").style.display = "none";
    document.getElementById("DivPesquisa").style.display = "none";
    document.getElementById("DivGuia").style.display = "none";
    document.getElementById("DivBuscas").style.display = "none";
}
