﻿function abreConsulta() {
    document.getElementById('boxConsulta').style.display = 'block';
    document.getElementById('botFirma').style.backgroundImage = 'url(images/bot_firma_over.gif)';
    document.getElementById('botFirma').style.color = '#4f6880';
    document.getElementById('contFirma').style.display = 'block';
    fechaNascimento();
    fechaCasamento();
    fechaObito();
}

function abreNascimento() {
    document.getElementById('botNascimento').style.backgroundImage = 'url(images/bot_certidao_over.gif)';
    document.getElementById('botNascimento').style.color = '#4f6880';
    document.getElementById('contNascimento').style.display = 'block';
    fechaConsulta();
    fechaCasamento();
    fechaObito();
}

function abreCasamento() {
    document.getElementById('botCasamento').style.backgroundImage = 'url(images/bot_casamento_over.gif)';
    document.getElementById('botCasamento').style.color = '#4f6880';
    document.getElementById('contCasamento').style.display = 'block';
    fechaConsulta();
    fechaNascimento();
    fechaObito();
}

function abreObito() {
    document.getElementById('botObito').style.backgroundImage = 'url(images/bot_obito_over.gif)';
    document.getElementById('botObito').style.color = '#4f6880';
    document.getElementById('contObito').style.display = 'block';
    fechaConsulta();
    fechaNascimento();
    fechaCasamento();
}

function fechaConsulta() {
    document.getElementById('botFirma').style.backgroundImage = 'url(images/bot_firma.gif)';
    document.getElementById('botFirma').style.color = '#ffffff';
    document.getElementById('contFirma').style.display = 'none';
}

function fechaNascimento() {
    document.getElementById('botNascimento').style.backgroundImage = 'url(images/bot_certidao.gif)';
    document.getElementById('botNascimento').style.color = '#ffffff';
    document.getElementById('contNascimento').style.display = 'none';
}

function fechaCasamento() {
    document.getElementById('botCasamento').style.backgroundImage = 'url(images/bot_casamento.gif)';
    document.getElementById('botCasamento').style.color = '#ffffff';
    document.getElementById('contCasamento').style.display = 'none';
}

function fechaObito() {
    document.getElementById('botObito').style.backgroundImage = 'url(images/bot_obito.gif)';
    document.getElementById('botObito').style.color = '#ffffff';
    document.getElementById('contObito').style.display = 'none';
}

function fechaDisplay() {
    document.getElementById('boxConsulta').style.display = 'none';
}


function mascara(o, f) {
    v_obj = o
    v_fun = f
    setTimeout("execmascara()", 1)
}

function execmascara() {
    v_obj.value = v_fun(v_obj.value)
}

function leech(v) {
    v = v.replace(/o/gi, "0")
    v = v.replace(/i/gi, "1")
    v = v.replace(/z/gi, "2")
    v = v.replace(/e/gi, "3")
    v = v.replace(/a/gi, "4")
    v = v.replace(/s/gi, "5")
    v = v.replace(/t/gi, "7")
    return v
}

function Data(v) {
    v = v.replace(/\D/g, "")
    v = v.replace(/(\d{2})(\d)/, "$1/$2")
    v = v.replace(/(\d{2})(\d)/, "$1/$2")
    return v
}

function cep(v) {
    v = v.replace(/\D/g, "")                //Remove tudo o que não é dígito
    v = v.replace(/^(\d{5})(\d)/, "$1-$2") //Esse é tão fácil que não merece explicações
    return v
}

function validaData(e) {
    var divisor = '/'
    var data = e.value
    var dataAtual = ''

    if (data.match(/^(0[1-9]|[12][0-9]|3[01]).?(0[1-9]|1[012]).?([12][0-9]{3}|[0-9]{2})$/)) {
        data = data.replace(/[^0-9]/g, '')
        dataAtual = data.substr(0, 2) + divisor + data.substr(2, 2) + divisor
        if (data.substr(4).length == 4) dataAtual += data.substr(4)
        else dataAtual += (data.substr(4) > 30 ? '19' : '20') + data.substr(4)
    }
    if (dataAtual != '') {
        x = dataAtual.split(divisor)
        confere = new Date(x[2], x[1] - 1, x[0])
        confere2 = (confere.getDate() < 10 ? '0' : '') + confere.getDate()
        confere2 += divisor + ((confere.getMonth() + 1) < 10 ? '0' : '') + (confere.getMonth() + 1)
        confere2 += divisor + confere.getFullYear()
        if (confere2 != dataAtual) dataAtual = ''
    }
    e.value = dataAtual
}

function soNumeros(v) {
    return v.replace(/\D/g, "")
}

function validarEmail(campo) {
    var str = document.getElementById("ctl00_ContentPlaceHolder1_" + campo).value;
    if (str != '') {
        var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
        if (filter.test(str))
            valido = true;
        else if (str == '') {
            alert("Por Favor Preencha o Email!");
            document.getElementById("ctl00_ContentPlaceHolder1_" + campo).focus();
            valido = false;
        }
        else {
            alert("Este endereço de e-mail não é válido!");
            document.getElementById("ctl00_ContentPlaceHolder1_" + campo).focus();
            valido = false;
        }

    }
    else {
        valido = true;
    }
    return valido;
}

function Valor(v) {
    v = v.replace(/\D/g, "") //Remove tudo o que não é dígito
    v = v.replace(/^([0-9]{3}\.?){3}-[0-9]{2}$/, "$1.$2");
    //v=v.replace(/(\d{3})(\d)/g,"$1,$2")
    v = v.replace(/(\d)(\d{2})$/, "$1,$2") //Coloca ponto antes dos 2 últimos digitos
    return v
}

function cpf(v) {
    v = v.replace(/\D/g, "")                    //Remove tudo o que não é dígito
    v = v.replace(/(\d{3})(\d)/, "$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
    v = v.replace(/(\d{3})(\d)/, "$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
    //de novo (para o segundo bloco de números)
    v = v.replace(/(\d{3})(\d{1,2})$/, "$1-$2") //Coloca um hífen entre o terceiro e o quarto dígitos
    return v
}

function telefone(v) {
    v = v.replace(/\D/g, "")                 //Remove tudo o que não é dígito
    v = v.replace(/^(\d\d)(\d)/g, "($1) $2") //Coloca parênteses em volta dos dois primeiros dígitos
    v = v.replace(/(\d{4})(\d)/, "$1-$2")    //Coloca hífen entre o quarto e o quinto dígitos
    return v
}

function loadFlashInnerHTML(objUrl, objWidth, objHeight, objCreate, objInner) {
    var varInnerHTML = '';
    varInnerHTML += '<object id="' + objCreate + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + objWidth + '" height="' + objHeight + '">';
    varInnerHTML += '<param name="movie" value="' + objUrl + '" />';
    varInnerHTML += '<param name="quality" value="high" />';
    varInnerHTML += '<param name="swfversion" value="6.0.65.0" />';
    varInnerHTML += '<!-- This param tag prompts users with Flash Player 6.0 r65 and higher to download the latest version of Flash Player. Delete it if you don’t want users to see the prompt. -->';
    varInnerHTML += '<param name="expressinstall" value="Scripts/expressInstall.swf" />';
    varInnerHTML += '<!-- Next object tag is for non-IE browsers. So hide it from IE using IECC. -->';
    varInnerHTML += '<!--[if !IE]>-->';
    varInnerHTML += '<object type="application/x-shockwave-flash" data="' + objUrl + '" width="' + objWidth + '" height="' + objHeight + '" id="' + objCreate + '">';
    varInnerHTML += '<!--<![endif]-->';
    varInnerHTML += '<param name="quality" value="high" />';
    varInnerHTML += '<param name="wmode" value="opaque" />';
    varInnerHTML += '<param name="swfversion" value="6.0.65.0" />';
    varInnerHTML += '<param name="expressinstall" value="Scripts/expressInstall.swf" />';
    varInnerHTML += '<!-- The browser displays the following alternative content for users with Flash Player 6.0 and older. -->';
    varInnerHTML += '<div>';
    varInnerHTML += '<h4>Content on this page requires a newer version of Adobe Flash Player.</h4>';
    varInnerHTML += '<p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" width="112" height="33" /></a></p>';
    varInnerHTML += '</div>';
    varInnerHTML += '<!--[if !IE]>-->';
    varInnerHTML += '</object>';
    varInnerHTML += '<!--<![endif]-->';
    varInnerHTML += '</object>';
    document.getElementById(objInner).innerHTML = varInnerHTML;
}
