﻿function padLeft(campo, size) {
    var hdnBanco = getId("ctl00_conteudoInterna_hdnBanco")

    if (hdnBanco.value == "237") {
        var s = campo.value + "";
        while (s.length < size) s = "0" + s;
        campo.value = s;
    }

    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 isEmpty(pStrText) {
    var len = pStrText.length;
    var pos;
    var vStrnewtext = "";

    for (pos = 0; pos < len; pos++) {
        if (pStrText.substring(pos, (pos + 1)) != " ") {
            vStrnewtext = vStrnewtext + pStrText.substring(pos, (pos + 1));
        }
    }

    if (vStrnewtext.length > 0)
        return false;
    else
        return true;
}


function validaCPFDoador(){
    if ($("#ctl00_conteudoInterna_txtCpf").val() != "" && $("#ctl00_conteudoInterna_txtCpf").val() != "CPF" && $("#ctl00_conteudoInterna_txtCpf").val() != "CPF*") {
        if (!isCPFCNPJ($("#ctl00_conteudoInterna_txtCpf").val(), 1)) {
            $("#ctl00_conteudoInterna_lblStatus").html("CPF Inválido; Favor conferir!");
            $("#ctl00_conteudoInterna_lblStatus").show();
            return false;
        }
        else {
            return true;
        }
    } else {
        return true;
    }
}

function validaContato() {

    //d = document.contato;

    var nome = document.getElementById("txtNome");
    var email = document.getElementById("txtEmail");
    var telefone = document.getElementById("txtTelefone");
    var msg = document.getElementById("txtMensagem");
    var captcha = document.getElementById("txtCaptcha");

    if ((nome.value == "") || (nome.value == "Nome completo")) {
        alert("Digite seu nome!");
        nome.focus();
        return false;
    }
    if ((email.value == "") || (email.value == "E-mail")) {
        alert("Digite seu e-mail!");
        email.focus();
        return false;
    }
    if (!checkMail(email.value)) {
        alert('E-mail inválido, verifique o email digitado!');
        email.focus();
        return false;
    }
    if ((telefone.value == "") || (telefone.value == "Telefone")) {
        alert("Digite seu telefone!");
        telefone.focus();
        return false;
    }

    if ((msg.value == "") || (msg.value == "Mensagem")) {
        alert("Digite sua mensagem!");
        msg.focus();
        return false;
    }

    if ((captcha.value == "") || (captcha.value == "Digite o código acima")) {
        alert("Digite o código de segurança!");
        msg.focus();
        return false;
    }
}

function validaIndicacao() {

    var nome = document.getElementById("ctl00_colunaEsquerda_formIndiquePagina_txtNomeRemetente");
    var email = document.getElementById("ctl00_colunaEsquerda_formIndiquePagina_txtEmailRemetente");
    var emailDestinatario = document.getElementById("ctl00_colunaEsquerda_formIndiquePagina_txtEmailDestinatario");
    //var comentario = document.getElementById("txtComentario");

    if ((nome.value == "") || (nome.value == "Seu nome")) {
        alert("Digite seu nome!");
        nome.focus();
        return false;
    }
    if ((email.value == "") || (email.value == "Seu e-mail")) {
        alert("Digite seu e-mail!");
        email.focus();
        return false;
    }
    if (!checkMail(email.value)) {
        alert('E-mail inválido, por favor verifique o email digitado!');
        email.focus();
        return false;
    }
    if ((emailDestinatario.value == "") || (emailDestinatario.value == "E-mail do destinatário")) {
        alert("Digite o email do destinatário!");
        emailDestinatario.focus();
        return false;
    }

    if (!checkMail(emailDestinatario.value)) {
        alert('E-mail destinatário inválido, por favor verifique o email digitado!');
        emailDestinatario.focus();
        return false;
    }

}

function validaNewsLetterHome() {

    var nome = document.getElementById("txtNome");
    var email = document.getElementById("txtEmail");
    var uf = document.getElementById("txtUF");
    var cidade = document.getElementById("txtCidade");

    if ((nome.value == "") || (nome.value == "Nome completo")) {
        alert("Digite seu nome!");
        nome.focus();
        return false;
    }
    if ((email.value == "") || (email.value == "E-mail")) {
        alert("Digite seu e-mail!");
        email.focus();
        return false;
    }
    if (!checkMail(email.value)) {
        alert('E-mail inválido, por favor verifique o email digitado!');
        email.focus();
        return false;
    }
    if ((uf.value == "") || (uf.value == "UF")) {
        alert("Digite sua UF!");
        uf.focus();
        return false;
    }

    if ((cidade.value == "") || (cidade.value == "Cidade")) {
        alert("Digite sua cidade!");
        cidade.focus();
        return false;
    }

}

function validaNewsLetter() {

    var nome = document.getElementById("ctl00_conteudoInterna_txtNome");
    var email = document.getElementById("ctl00_conteudoInterna_txtEmail");
    var uf = document.getElementById("ctl00_conteudoInterna_txtUF");
    var cidade = document.getElementById("ctl00_conteudoInterna_txtCidade");

    if ((nome.value == "") || (nome.value == "Nome completo")) {
        alert("Digite seu nome!");
        nome.focus();
        return false;
    }
    if ((email.value == "") || (email.value == "E-mail")) {
        alert("Digite seu e-mail!");
        email.focus();
        return false;
    }
    if (!checkMail(email.value)) {
        alert('E-mail inválido, por favor verifique o email digitado!');
        email.focus();
        return false;
    }
    if ((uf.value == "") || (uf.value == "UF")) {
        alert("Digite sua UF!");
        uf.focus();
        return false;
    }

    if ((cidade.value == "") || (cidade.value == "Cidade")) {
        alert("Digite sua cidade!");
        cidade.focus();
        return false;
    }
}

function getCheckedRadio(radio) {
    var radioButtons = document.getElementsByName(radio);
    for (var x = 0; x < radioButtons.length; x ++) {
        if (radioButtons[x].checked) {
            return true;
        }
    }
    return false;
}

function valueCheckedRadio(radio) {
    var radioButtons = document.getElementsByName(radio);
    for (var x = 0; x < radioButtons.length; x ++) {
        if (radioButtons[x].checked) {
            return radioButtons[x].value;
        }
    }
}

function checkdateformat(userinput) {
    var dateformat = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/
    return dateformat.test(userinput)
}

function validaTelefone(tel) {
    var tamanho = 0;
    for (i = 0; i < tel.length; i++) {
        tamanho++;
    }
    if (tamanho < 12) {
        return false
    } else {
        return true
    }
}

function validaCep(cep) {
    var tamanho = 0;
    for (i = 0; i < cep.length; i++) {
        tamanho++;
    }
    if (tamanho < 8) {
        return false
    } else {
        return true
    }
}

function somenteLetras(str){  
   var er = new RegExp(/^[a-zA-Z]+$/);
   if(typeof(str) == "string") {
       if(er.test(str)) {
           return true;
       }
   }
   else if(typeof(str) == "object") {
       if(er.test(str.value)) {
           return true;
       }
   }
   else {
       return false;
   }
}

function somenteNumeros(str) {
    var er = new RegExp(/^[0-9]+$/);
    if (typeof (str) == "string") {
        if (er.test(str)) {
            return true;
        }
    }
    else if (typeof (str) == "object") {
        if (er.test(str.value)) {
            return true;
        }
    }
    else {
        return false;
    }
}

function validaFormDoacao() {    
    var tipoForm = false;

    var hdnTipoForm = getId("ctl00_conteudoInterna_hdnTipoForm");

    if (hdnTipoForm != null && hdnTipoForm.value == "atualizar") {
        tipoForm = true;
    }

    var hdnValor = getId("ctl00_conteudoInterna_hdnValor");
    var hdnFormaPagto = getId("ctl00_conteudoInterna_hdnFormaPagto");
    var hdnBanco = getId("ctl00_conteudoInterna_hdnBanco")
   
    //Dados pessoais
    var txtNome = getId("ctl00_conteudoInterna_txtNome");
    var txtSobrenome = getId("ctl00_conteudoInterna_txtSobrenome");
    var txtEmail = getId("ctl00_conteudoInterna_txtEmail");
    var txtSenha = getId("ctl00_conteudoInterna_txtSenha");
    var txtCEP = getId("ctl00_conteudoInterna_txtCEP");
    var txtRua = getId("ctl00_conteudoInterna_txtRua");
    var txtNum = getId("ctl00_conteudoInterna_txtNum");
    var txtBairro = getId("ctl00_conteudoInterna_txtBairro");
    var txtUF = getId("ctl00_conteudoInterna_txtUF");
    var txtCidade = getId("ctl00_conteudoInterna_txtCidade");
    var txtCPF = getId("ctl00_conteudoInterna_txtCPF");
    var txtTelefone = getId("ctl00_conteudoInterna_txtTelefone");
    var txtTelefoneCel = getId("ctl00_conteudoInterna_txtTelefoneCel");
    var txtCelular = getId("ctl00_conteudoInterna_txtCelular");
    var lblaviso = getId("ctl00_conteudoInterna_lbl_status");
    var txtNascimento = getId("ctl00_conteudoInterna_txtNascimento");

    //cartão de crédito
    var txtTitular = getId("ctl00_conteudoInterna_txtTitular");
    var txtNumeroCartao = getId("ctl00_conteudoInterna_txtNumeroCartao");
    var txtCodigoSeguranca = getId("ctl00_conteudoInterna_txtCodigoSeguranca");
    var ddlBandeiraCartao = getId("ctl00_conteudoInterna_ddlBandeiraCartao");
    var ddlMesCartao = getId("ctl00_conteudoInterna_ddlMesCartao");
    var ddlAnoCartao = getId("ctl00_conteudoInterna_ddlAnoCartao");

    var ddlConheceu = getId("ctl00_conteudoInterna_rblConheceu");
    var chkDoador = getId("ctl00_conteudoInterna_chkDoador");
    var txtCodigoDoador = getId("ctl00_conteudoInterna_txtCodigoDoador");

    //Débito Automático
    var txtAgencia = getId("ctl00_conteudoInterna_txtAgencia");
    var txtConta = getId("ctl00_conteudoInterna_txtConta");

    if (tipoForm == false) {
        if (hdnValor.value == 0) {
            alert("Por favor informe o valor de sua doação!");
            return false;
        } else {
            if (hdnValor.value < 1000) {
                alert("O valor mínimo de doação é R$10,00.");
                return false;
            }
        }

        if (chkDoador == null) {
            if (txtCodigoDoador != null) {
                if ((txtCodigoDoador.value == "Código de Doador") || (txtCodigoDoador.value == "")) {
                    alert("Se você é doador, informe seu código!");
                    return false;
                } else {
                    if (txtCodigoDoador.value.length < 6) {
                        alert("O código de doador informado é inválido!");
                        return false;
                    } else if ((txtCodigoDoador.value.charAt(0) != "1") && (txtCodigoDoador.value.charAt(0) != "2") && (txtCodigoDoador.value.charAt(0) != "3")) {
                        alert("O código de doador informado é inválido!");
                        return false;
                    }
                }
            }
        } else {
            if (chkDoador.checked) {
                if ((txtCodigoDoador.value == "Código de Doador") || (txtCodigoDoador.value == "")) {
                    alert("Se você é doador, informe seu código!");
                    return false;
                } else {
                    if (txtCodigoDoador.value.length < 6) {
                        alert("O código de doador informado é inválido!");
                        return false;
                    } else if ((txtCodigoDoador.value.charAt(0) != "1") && (txtCodigoDoador.value.charAt(0) != "2") && (txtCodigoDoador.value.charAt(0) != "3")) {
                        alert("O código de doador informado é inválido!");
                        return false;
                    }
                }
            }
        }

        if (ddlConheceu != null) {
            if (!getCheckedRadio("ctl00$conteudoInterna$rblConheceu")) {
                alert("Informe como conheceu MSF!");
                return false;
            } else {
                if (valueCheckedRadio("ctl00$conteudoInterna$rblConheceu") == "TV") {
                    if (!getCheckedRadio("ctl00$conteudoInterna$rbl_tv")) {
                        alert("Informe como conheceu MSF pela TV!");
                        return false;
                    }
                }
            }
        }

        if ((txtNome.value == "") || (txtNome.value == "Primeiro Nome")) {
            alert("Digite seu nome!");
            txtNome.focus();
            return false;
        }

        if ((txtSobrenome.value == "") || (txtSobrenome.value == "Sobrenome")) {
            alert("Digite seu sobrenome!");
            txtSobrenome.focus();
            return false;
        }

        if ((txtCPF.value == "CPF") || (txtCPF.value == "") || (txtCPF.value == "CPF*")) {
            alert("Informe seu CPF!");
            txtCPF.focus();
            return false;
        } else {
            if (!vercpf(txtCPF.value)) {
                alert("O CPF informado não é válido!");
                txtCPF.focus();
                return false;
            }
        }

        if ((txtEmail.value == "") || (txtEmail.value == "E-mail")) {
            alert("Digite seu e-mail!");
            txtEmail.focus();
            return false;
        } else {
            if (!checkMail(txtEmail.value)) {
                alert('E-mail inválido, por favor verifique o email digitado!');
                txtEmail.focus();
                return false;
            }
        }

        if (txtNascimento != null) {
            if ((txtNascimento.value == "") || (txtNascimento.value == "Data de nascimento")) {
                alert("Informe a data de seu nascimento!");
                txtNascimento.focus();
                return false;
            } else {
                if (!checkdateformat(txtNascimento.value)) {
                    alert("Data de nascimento no formato inválido!");
                    txtNascimento.focus();
                    return false;
                } else {
                    var data = txtNascimento.value;
                    var arrData = data.split("/");

                    if (arrData[0] > 31 || arrData[1] > 12) {
                        alert("Data de nascimento no formato inválido!");
                        txtNascimento.focus();
                        return false;
                    }
                }
            }
        }
        
//        if (txtTelefoneCel == null) {
//            if (txtTelefone != null) {
//                if ((txtTelefone.value == "") || (txtTelefone.value == "Telefone (ex.:21 9999-9999)")) {
//                    alert("Digite um telefone fixo válido!");
//                    txtTelefone.focus();
//                    return false;
//                } else {
//                    if ((txtTelefone.value.charAt(3) == "8") || (txtTelefone.value.charAt(3) == "9")) {
//                        alert("O telefone fixo não pode ser iniciado com ( 8 ou 9 )! ");
//                        txtTelefone.value = "";
//                        txtTelefone.focus();
//                        return false;
//                    }
//                }
//            }
//        } else {
//            if ((txtTelefoneCel.value == "") || (txtTelefoneCel.value == "Telefone (ex.:21 9999-9999)")) {
//                if ((txtCelular.value == "") || (txtCelular.value == "Celular (ex.:21 9999-9999)*")) {
//                    alert("Digite um telefone fixo válido!");
//                    txtTelefoneCel.focus();
//                    return false;
//                }
//            } else {
//                if ((txtTelefoneCel.value.charAt(3) == "8") || (txtTelefoneCel.value.charAt(3) == "9")) {
//                    alert("O telefone fixo não pode ser iniciado com ( 8 ou 9 )! ");
//                    txtTelefoneCel.value = "";
//                    txtTelefoneCel.focus();
//                    return false;
//                }
//            }
        //        }

        if ((txtTelefone != null) && (txtCelular != null)) {
            if (((txtTelefone.value == "") || (txtTelefone.value == "Telefone (ex.:21 9999-9999)")) && ((txtCelular.value == "") || (txtCelular.value == "Celular (ex.:21 9999-9999)*"))) {
                alert("Digite um telefone fixo ou celular válido!");
                txtTelefone.focus();
                return false;
            } else {
                if ((txtTelefone.value != "") && (txtTelefone.value != "Telefone (ex.:21 9999-9999)")) {
                    if ((txtTelefone.value.charAt(3) == "8") || (txtTelefone.value.charAt(3) == "9")) {
                        alert("O telefone fixo não pode ser iniciado com ( 8 ou 9 )! ");
                        txtTelefone.value = "";
                        txtTelefone.focus();
                        return false;
                    }
                    if (!validaTelefone(txtTelefone.value)) {
                        alert("O telefone fixo informado não é válido! ");
                        txtTelefone.value = "";
                        txtTelefone.focus();
                        return false;
                    }
                }

                if ((txtCelular.value != "") && (txtCelular.value != "Celular (ex.:21 9999-9999)*")) {
                    if ((txtCelular.value.charAt(3) != "6") && (txtCelular.value.charAt(3) != "7") && (txtCelular.value.charAt(3) != "8") && (txtCelular.value.charAt(3) != "9")) {
                        alert("O telefone celular deve ser iniciado com ( 6, 7, 8 ou 9 )! ");
                        txtCelular.value = "";
                        txtCelular.focus();
                        return false;
                    }
                    if (!validaTelefone(txtCelular.value)) {
                        alert("O celular informado não é válido! ");
                        txtTelefone.value = "";
                        txtTelefone.focus();
                        return false;
                    }
                }
            }
        }

//        if (txtCelular != null) {
//            if (txtCelular.value != "Celular (ex.:21 9999-9999)*") {
//                if ((txtCelular.value.charAt(3) != "6") && (txtCelular.value.charAt(3) != "7") && (txtCelular.value.charAt(3) != "8") && (txtCelular.value.charAt(3) != "9")) {
//                    alert("O telefone celular deve ser iniciado com ( 6, 7, 8 ou 9 )! ");
//                    txtCelular.value = "";
//                    txtCelular.focus();
//                    return false;
//                }
//            }
//        }

        if (txtCEP != null) {
            if ((txtCEP.value == "") || (txtCEP.value == "CEP")) {
                alert("Digite seu CEP!");
                txtCEP.focus();
                return false;
            } else {
                if (!validaCep(txtCEP.value)) {
                    alert("Digite seu CEP válido!");
                    txtCEP.focus();
                    return false;
                }
            }

            if ((txtRua.value == "") || (txtRua.value == "Rua")) {
                alert("Digite o nome da sua rua!");
                txtRua.focus();
                return false;
            }

            if ((txtNum.value == "") || (txtNum.value == "Nº")) {
                alert("Digite o número da sua casa!");
                txtNum.focus();
                return false;
            }

            if ((txtBairro.value == "") || (txtBairro.value == "Bairro")) {
                alert("Digite seu bairro!");
                txtBairro.focus();
                return false;
            }

            if ((txtUF.value == "") || (txtUF.value == "UF")) {
                alert("Digite sua UF!");
                txtUF.focus();
                return false;
            } else {
                if (!somenteLetras(txtUF.value)) {
                    alert("UF deve possuir somente letras!");
                    txtUF.focus();
                    return false;
                }
            }

            if ((txtCidade.value == "") || (txtCidade.value == "Cidade")) {
                alert("Informe a sua cidade!");
                txtCidade.focus();
                return false;
            }
        }

        if (hdnFormaPagto.value == 0) {
            alert("Por favor informe a forma de pagamento!");
            return false;
        }

        if (hdnFormaPagto.value == 1) {
            if ((txtTitular.value == "") || (txtTitular.value == "Titular do cartão")) {
                alert("Informe o titular do cartão!");
                txtTitular.focus();
                return false;
            }

            if (ddlBandeiraCartao.value == 0) {
                alert("Selecione a bandeira do seu cartão!");
                ddlBandeiraCartao.focus();
                return false;
            } else {
                if ((ddlBandeiraCartao.value == "American Express") && (txtNumeroCartao.value.charAt(0) != "3")) {
                    alert("O número informado não é válido para cartões American Express!");
                    txtNumeroCartao.focus();
                    return false;
                }
                if ((ddlBandeiraCartao.value == "Mastercard") && (txtNumeroCartao.value.charAt(0) != "5")) {
                    alert("O número informado não é válido para cartões Mastercard!");
                    txtNumeroCartao.focus();
                    return false;
                }
                if ((ddlBandeiraCartao.value == "Visa") && (txtNumeroCartao.value.charAt(0) != "4")) {
                    alert("O número informado não é válido para cartões Visa!");
                    txtNumeroCartao.focus();
                    return false;
                }
            }

            if ((txtNumeroCartao.value == "") || (txtNumeroCartao.value == "Número do cartão")) {
                alert("Informe o número do cartão!");
                txtNumeroCartao.focus();
                return false;
            } else {
                if (txtNumeroCartao.value.length < 14) {
                    alert("O número do cartão informado é inválido!");
                    txtNumeroCartao.focus();
                    return false;
                }
            }

            if (ddlMesCartao.value == 0) {
                alert("Selecione o mês da validade do seu cartão!");
                ddlMesCartao.focus();
                return false;
            }

            if (ddlAnoCartao.value == 0) {
                alert("Selecione o ano da validade do seu cartão!");
                ddlAnoCartao.focus();
                return false;
            }

            if (txtCodigoSeguranca.value == "") {
                alert("Informe o código de segurança");
                txtCodigoSeguranca.focus();
                return false;
            } else {
                if ((txtCodigoSeguranca.value.length < 3) || (txtCodigoSeguranca.value.length > 4)) {
                    alert("O código de segurança é inválido!");
                    txtNumeroCartao.focus();
                    return false;
                }
            }
        }

        if (hdnFormaPagto.value == 3) {
            if (hdnBanco.value == "0") {
                alert("Informe o banco!");
                return false;
            }

            if ((txtAgencia.value == "") || (txtAgencia.value == "Agência")) {
                alert("Informe o número da agência!");
                txtAgencia.focus();
                return false;
            } else {
                if (!somenteNumeros(txtAgencia.value)) {
                    alert("Informe um número válido para agência!");
                    txtAgencia.focus();
                    return false;
                }
            }

            if ((txtConta.value == "") || (txtConta.value == "Conta Corrente")) {
                alert("Informe o número da Conta Corrente!");
                txtConta.focus();
                return false;
            }

            if (txtCPF.value == "CPF*") {
                alert("Para esta forma de pagamento o CPF é obrigatório!");
                txtCPF.focus();
                return false;
            }

            if ((txtCPF.value != "CPF*")) {
                if (!vercpf(txtCPF.value)) {
                    alert("O CPF informado não é válido!");
                    txtCPF.focus();
                    return false;
                }
            }

            if (hdnBanco.value == "237") {
                if ((txtAgencia.value).length > 6) {
                    alert("O número da Agência informado é inválido!");
                    txtAgencia.focus();
                    return false;
                }

                if ((txtConta.value).length > 9) {
                    alert("O número da Conta informado é inválido!");
                    txtConta.focus();
                    return false;
                } else {
                    if (!verCtBradesco(txtConta.value)) {
                        //alert("O número da Conta informado é inválido! Por favor, insira o número de uma conta válida. \n Contas com MENOS DE 8 DÍGITOS, completar com Zeros à esquerda!");
                        alert("O número da Conta informado é inválido! Por favor, insira o número de uma conta válida.");
                        txtAgencia.focus();
                        return false;
                    }
                }
            } else if (hdnBanco.value == "341") {
                if ((txtAgencia.value).length > 4) {
                    alert("O número da Agência informado é inválido!");
                    txtAgencia.focus();
                    return false;
                }

                if ((txtConta.value).length > 7) {
                    alert("O número da Conta informado é inválido!");
                    txtConta.focus();
                    return false;
                }
            } else if (hdnBanco.value == "104") {
                if ((txtAgencia.value).length > 4) {
                    alert("O número da Agência informado é inválido!");
                    txtAgencia.focus();
                    return false;
                }

                if ((txtConta.value).length > 14) {
                    alert("O número da Conta informado é inválido!");
                    txtConta.focus();
                    return false;
                }
            }
        }
    } else {
        if ((txtCPF.value != "") && (txtCPF.value != "CPF") && (txtCPF.value != "CPF*")) {
            if (!vercpf(txtCPF.value)) {
                alert("O CPF informado não é válido!");
                txtCPF.focus();
                return false;
            }
        }

        if ((txtEmail.value != "") || (txtEmail.value != "E-mail")) {
            if (!checkMail(txtEmail.value)) {
                alert('E-mail inválido, por favor verifique o email digitado!');
                txtEmail.focus();
                return false;
            }
        }

        if ((txtTelefone.value != "") || (txtTelefone.value != "Telefone (ex.:21 9999-9999)")) {
            if ((txtTelefone.value.charAt(3) == "8") || (txtTelefone.value.charAt(3) == "9")) {
                alert("O telefone fixo não pode ser iniciado com ( 8 ou 9 )! ");
                txtTelefone.value = "";
                txtTelefone.focus();
                return false;
            }
        }

        if (txtCelular.value != "Celular (ex.:21 9999-9999)*") {
            if ((txtCelular.value.charAt(3) != "7") && (txtCelular.value.charAt(3) != "8") && (txtCelular.value.charAt(3) != "9")) {
                alert("O telefone celular deve ser iniciado com ( 7, 8 ou 9 )! ");
                txtCelular.value = "";
                txtCelular.focus();
                return false;
            }
        }
    }

    lblaviso.style.display = "block";
}

function verAgBradesco(agencia) {
    var digito = new Array();
    //var i;
    var mult = 5;
    var verificador = 0;
    for (i = 0; i <= 3; i++) {
        digito[i] = parseInt(agencia.charAt(i)) * mult;
        mult -= 1;
        verificador += digito[i];
    }

    verificador = verificador % 11;
    if (verificador == 10) {
        verificador = 0;
    }

    if (verificador == agencia.charAt(5)) {
        return true;
    } else {
        return false;
    }
}

function verCtBradesco(conta) {
    var aux;
    if (conta.length == 8) {
        if (conta.charAt(0) == 0) {
            conta = "0" + conta;
        }
    } else {
        var acompletar = 8 - conta.length
        aux = conta;
        conta = "";
        for (i = 0; i <= acompletar; i++) {
            conta += "0";
        }
        conta += aux;
    }
    var digito = new Array();
    mult = 8;
    verificador = 0;
    for (i = 0; i <= 6; i++) {
        digito[i] = parseInt(conta.charAt(i)) * mult;
        mult -= 1;
        verificador += digito[i];
    }

    verificador = 11 - (verificador % 11);
    if (verificador == 10) {
        verificador = 0;
    }

    if (verificador == conta.charAt(8)) {
        return true;
	} else {
        return false;
    }
}


function verCtCaixa(conta) {
    var digito = new Array();
    //var i;
    mult = 13;
    verificador = 0;
    for (i = 0; i <= 12; i++) {
        digito[i] = parseInt(conta.charAt(i)) * mult;
        mult -= 1;
        verificador += digito[i];
    }

    verificador = verificador % 11;
    if (verificador == 10) {
        verificador = 0;
    }

    if (verificador == conta.charAt(8)) {
        return true;
    } else {
        return false;
    }

}

//#####################################################################################################

function vercpf(cpf) {
if (cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999")
    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)))
            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)))
            return false;
//alert('O CPF INFORMADO É VÁLIDO.');
return true;
}

function valida_buscaCep(){
    var txtCEP = getId("ctl00_conteudoInterna_txtCEP");
    
    if ((txtCEP.value == "") || (txtCEP.value == "CEP")) {
        alert("Digite um CEP para consultar!");
        txtCEP.focus();
        return false;
    }

    if (txtCEP.value.length != 8) {
       alert("O CEP deve conter 8 dígitos para consultar!");
       txtCEP.focus();
       return false;
   }

}

function validaQtdCalendarios(qtd, proxPresenteado) {

    //var botAddPresenteado = document.getElementById("addPresenteado" + proxPresenteado);
    var qtdCalendario = document.getElementById("ddlCalendario");
    var qtdCalendarioEntrega = document.getElementById("ctl00_conteudoInterna_qtdCalendarioEntrega");
    var hdnQtdCalendarios = document.getElementById("ctl00_conteudoInterna_hdnQtdCalendarios");
    var botDoar = document.getElementById("ctl00_conteudoInterna_btnDoar");

    var calPresenteado1 = verificaQtdCalendarios(1);
    var calPresenteado2 = verificaQtdCalendarios(2);
    var calPresenteado3 = verificaQtdCalendarios(3);
    var calPresenteado4 = verificaQtdCalendarios(4);
    var calPresenteado5 = verificaQtdCalendarios(5);
    var calPresenteado6 = verificaQtdCalendarios(6);
    var calPresenteado7 = verificaQtdCalendarios(7);
    var calPresenteado8 = verificaQtdCalendarios(8);
    var calPresenteado9 = verificaQtdCalendarios(9);
    var calPresenteado10 = verificaQtdCalendarios(10);

    var totalCalendarios = parseInt(calPresenteado1) + parseInt(calPresenteado2) + parseInt(calPresenteado3) + parseInt(calPresenteado4) + parseInt(calPresenteado5) +
    parseInt(calPresenteado6) + parseInt(calPresenteado7) + parseInt(calPresenteado8) + parseInt(calPresenteado9) + parseInt(calPresenteado10);

    if (parseInt(qtd.value) == 0) {
        botDoar.style.display = 'none';
        //botAddPresenteado.style.display = 'none';
        remBotsProximo();
        alert("Quantidade de calendários inválida, Por favor verifique!");
        qtd.focus();
        return false;
    }

    if (hdnQtdCalendarios.value == 0) {
        //botAddPresenteado.style.display = 'none';
        remBotsProximo();
        botDoar.style.display = 'none';
        alert("Informe a quantidade de calendários que deseja ganhar!");
        qtd.focus();
        return false;
    }
    else {
        //botAddPresenteado.style.display = 'block';
        habilitaBotsProximo();
        botDoar.style.display = 'block';
    }

    if (parseInt(totalCalendarios) > parseInt(hdnQtdCalendarios.value)) {
        botDoar.style.display = 'none';
        remBotsProximo();
        //botAddPresenteado.style.display = 'none';
        alert("Quantidade de calendários excedida, Por favor verifique!");
        $("#spanAmigos").show();
        $("#spanCasa").show();
        $("#totalCalendariosAmigos").html("INVÁLIDO, FAVOR VERIFICAR!");
        $("#totalCalendariosCasa").html("INVÁLIDO, FAVOR VERIFICAR!");
        qtd.focus();
        return false;
    }
    else {
        //botAddPresenteado.style.display = 'block';
        habilitaBotsProximo();
        botDoar.style.display = 'block';
        $("#spanAmigos").show();
        $("#spanCasa").show();
        $("#totalCalendariosAmigos").html(totalCalendarios);
        $("#totalCalendariosCasa").html(parseInt(hdnQtdCalendarios.value) - parseInt(totalCalendarios));
    }

}

function validaQtdCalendarios2(presenteadoAtual) {

    var proxPresenteado = parseInt(presenteadoAtual) + parseInt(1);

    var botAddPresenteado = document.getElementById("addPresenteado" + proxPresenteado);
    var botDoar = document.getElementById("ctl00_conteudoInterna_btnDoar");

    var hdnQtdCalendarios = document.getElementById("ctl00_conteudoInterna_hdnQtdCalendarios");


    var calPresenteado1 = verificaQtdCalendarios(1);
    var calPresenteado2 = verificaQtdCalendarios(2);
    var calPresenteado3 = verificaQtdCalendarios(3);
    var calPresenteado4 = verificaQtdCalendarios(4);
    var calPresenteado5 = verificaQtdCalendarios(5);
    var calPresenteado6 = verificaQtdCalendarios(6);
    var calPresenteado7 = verificaQtdCalendarios(7);
    var calPresenteado8 = verificaQtdCalendarios(8);
    var calPresenteado9 = verificaQtdCalendarios(9);
    var calPresenteado10 = verificaQtdCalendarios(10);

    var totalCalendarios = parseInt(calPresenteado1) + parseInt(calPresenteado2) + parseInt(calPresenteado3) + parseInt(calPresenteado4) + parseInt(calPresenteado5) +
    parseInt(calPresenteado6) + parseInt(calPresenteado7) + parseInt(calPresenteado8) + parseInt(calPresenteado9) + parseInt(calPresenteado10);

    if (hdnQtdCalendarios.value == 0) {
        botAddPresenteado.style.display = 'none';
        botDoar.style.display = 'none';
        alert("Informe a quantidade de calendários que deseja ganhar!");
        qtd.focus();
        return false;
    }
    else {
        botAddPresenteado.style.display = 'block';
        botDoar.style.display = 'block';
        $("#spanAmigos").show();
        $("#spanCasa").show();
        $("#totalCalendariosAmigos").html(totalCalendarios);
        $("#totalCalendariosCasa").html(parseInt(hdnQtdCalendarios.value) - parseInt(totalCalendarios));
    }

    if (parseInt(totalCalendarios) > parseInt(hdnQtdCalendarios.value)) {
        botDoar.style.display = 'none';
        botAddPresenteado.style.display = 'none';
        alert("Quantidade de calendários excedida, Por favor verifique!");
        $("#spanAmigos").show();
        $("#spanCasa").show();
        $("#totalCalendariosAmigos").html("INVÁLIDO, FAVOR VERIFICAR!");
        $("#totalCalendariosCasa").html("INVÁLIDO, FAVOR VERIFICAR!");
        qtd.focus();
        return false;
    }
    else {
        botAddPresenteado.style.display = 'block';
        botDoar.style.display = 'block';
    }

}

function verificaQtdCalendarios(numPresenteado) {

    var nome = document.getElementById("ctl00_conteudoInterna_txtNome" + numPresenteado);
    var cep = document.getElementById("ctl00_conteudoInterna_txtCEP" + numPresenteado);
    var num = document.getElementById("ctl00_conteudoInterna_txtNum" + numPresenteado);
    var nCal = document.getElementById("ctl00_conteudoInterna_txtNcal" + numPresenteado);

    if (nome.value != "Nome") {
        if (nCal.value != "Nº de calendários") {
            return parseInt(nCal.value);
        }
        else {
            return parseInt(0);
        }
    }
    else {
        return parseInt(0);
    }

}


function verificaPresenteados() {

    var presenteado1 = document.getElementById("ctl00_conteudoInterna_txtNome1");
    var presenteado2 = document.getElementById("ctl00_conteudoInterna_txtNome2");
    var presenteado3 = document.getElementById("ctl00_conteudoInterna_txtNome3");
    var presenteado4 = document.getElementById("ctl00_conteudoInterna_txtNome4");
    var presenteado5 = document.getElementById("ctl00_conteudoInterna_txtNome5");
    var presenteado6 = document.getElementById("ctl00_conteudoInterna_txtNome6");
    var presenteado7 = document.getElementById("ctl00_conteudoInterna_txtNome7");
    var presenteado8 = document.getElementById("ctl00_conteudoInterna_txtNome8");
    var presenteado9 = document.getElementById("ctl00_conteudoInterna_txtNome9");
    var presenteado10 = document.getElementById("ctl00_conteudoInterna_txtNome10");

    if (presenteado1.value != "Nome") {
        validaPresenteados(1);
    }

    if (presenteado2.value != "Nome") {
        validaPresenteados(2);
    }

    if (presenteado3.value != "Nome") {
        validaPresenteados(3);
    }

    if (presenteado4.value != "Nome") {
        validaPresenteados(4);
    }

    if (presenteado5.value != "Nome") {
        validaPresenteados(5);
    }

    if (presenteado6.value != "Nome") {
        validaPresenteados(6);
    }

    if (presenteado7.value != "Nome") {
        validaPresenteados(7);
    }

    if (presenteado8.value != "Nome") {
        validaPresenteados(8);
    }

    if (presenteado9.value != "Nome") {
        validaPresenteados(9);
    }

    if (presenteado10.value != "Nome") {
        validaPresenteados(10);
    }

}

function validaPresenteados(numPresenteado) {

    if (document.getElementById("ctl00_conteudoInterna_txtSobrenome" + numPresenteado).value == "Sobrenome") {
        alert("Informe o sobrenome do presenteado " & numPresenteado);
        document.getElementById("ctl00_conteudoInterna_txtSobrenome" + numPresenteado).focus();
        return false;
    }

    if (document.getElementById("ctl00_conteudoInterna_txtNcal" + numPresenteado).value == "Nº de calendários") {
        alert("Informe a quantidade de calendários que o presenteado " & numPresenteado & " deve receber!");
        document.getElementById("ctl00_conteudoInterna_txtNcal1" + numPresenteado).focus();
        return false;
    }

    if (document.getElementById("ctl00_conteudoInterna_txtCEP" + numPresenteado).value == "CEP") {
        alert("Informe o CEP do presenteado " & numPresenteado);
        document.getElementById("ctl00_conteudoInterna_txtCEP" + numPresenteado).focus();
        return false;
    }

    if (document.getElementById("ctl00_conteudoInterna_txtRua" + numPresenteado).value == "Rua") {
        alert("Informe a rua do presenteado " & numPresenteado);
        document.getElementById("ctl00_conteudoInterna_txtRua" + numPresenteado).focus();
        return false;
    }

    if (document.getElementById("ctl00_conteudoInterna_txtNum" + numPresenteado).value == "Nº") {
        alert("Informe o número da residência do presenteado " & numPresenteado);
        document.getElementById("ctl00_conteudoInterna_txtNum" + numPresenteado).focus();
        return false;
    }

    if (document.getElementById("ctl00_conteudoInterna_txtUF" + numPresenteado).value == "UF") {
        alert("Informe a UF do presenteado " & numPresenteado);
        document.getElementById("ctl00_conteudoInterna_txtUF" + numPresenteado).focus();
        return false;
    }

    if (document.getElementById("ctl00_conteudoInterna_txtCidade" + numPresenteado).value == "Cidade") {
        alert("Informe a cidade do presenteado " & numPresenteado);
        document.getElementById("ctl00_conteudoInterna_txtCidade" + numPresenteado).focus();
        return false;
    }

}

function validaFormDoacaoCalendario() {

    var hdnValor = getId("ctl00_conteudoInterna_hdnValor");
    var hdnFormaPagto = getId("ctl00_conteudoInterna_hdnFormaPagto");
    var hdnBanco = getId("ctl00_conteudoInterna_hdnBanco")

    //Dados pessoais
    var txtNome = getId("ctl00_conteudoInterna_txtNome");
    var txtSobrenome = getId("ctl00_conteudoInterna_txtSobrenome");
    var txtEmail = getId("ctl00_conteudoInterna_txtEmail");
    var txtSenha = getId("ctl00_conteudoInterna_txtSenha");
    var txtCEP = getId("ctl00_conteudoInterna_txtCEP");
    var txtRua = getId("ctl00_conteudoInterna_txtRua");
    var txtNum = getId("ctl00_conteudoInterna_txtNum");
    var txtBairro = getId("ctl00_conteudoInterna_txtBairro");
    var txtUF = getId("ctl00_conteudoInterna_txtUF");
    var txtCidade = getId("ctl00_conteudoInterna_txtCidade");
    var txtCPF = getId("ctl00_conteudoInterna_txtCPF");
    var txtTelefone = getId("ctl00_conteudoInterna_txtTelefone");
    var txtCelular = getId("ctl00_conteudoInterna_txtCelular");
    var txtNascimento = getId("ctl00_conteudoInterna_txtNascimento");

    var chkDoador = getId("ctl00_conteudoInterna_chkDoador");
    var txtCodigoDoador = getId("ctl00_conteudoInterna_txtCodigoDoador");

    //cartão de crédito
    var txtTitular = getId("ctl00_conteudoInterna_txtTitular");
    var txtNumeroCartao = getId("ctl00_conteudoInterna_txtNumeroCartao");
    var txtCodigoSeguranca = getId("ctl00_conteudoInterna_txtCodigoSeguranca");
    var ddlBandeiraCartao = getId("ctl00_conteudoInterna_ddlBandeiraCartao");
    var ddlMesCartao = getId("ctl00_conteudoInterna_ddlMesCartao");
    var ddlAnoCartao = getId("ctl00_conteudoInterna_ddlAnoCartao");

    var ddlConheceu = getId("ctl00_conteudoInterna_ddlConheceu");

    //Débito Automático
    var txtAgencia = getId("ctl00_conteudoInterna_txtAgencia");
    var txtConta = getId("ctl00_conteudoInterna_txtConta");

    if (hdnValor.value == 0) {
        alert("Por favor informe o valor de sua doação!");
        return false;
    }

    if ((txtNome.value == "") || (txtNome.value == "Primeiro Nome")) {
        alert("Digite seu nome!");
        txtNome.focus();
        return false;
    }

    if ((txtNascimento.value == "") || (txtNascimento.value == "Data de nascimento")) {
        alert("Informe a data de seu nascimento!");
        txtNascimento.focus();
        return false;
    }

    if ((txtSobrenome.value == "") || (txtSobrenome.value == "Sobrenome")) {
        alert("Digite seu sobrenome!");
        txtSobrenome.focus();
        return false;
    }

    if ((txtCPF.value != "CPF*")) {
        if (!vercpf(txtCPF.value)) {
            alert("O CPF informado não é válido!");
            txtCPF.focus();
            return false;
        }
    }

    if ((txtEmail.value == "") || (txtEmail.value == "E-mail")) {
        alert("Digite seu e-mail!");
        txtEmail.focus();
        return false;
    }

    if (!checkMail(txtEmail.value)) {
        alert('E-mail inválido, por favor verifique o email digitado!');
        txtEmail.focus();
        return false;
    }

    //    if ((txtSenha.value == "") || (txtSenha.value == "Senha para área restrita")) {
    //        alert("Digite uma senha para área restrita!");
    //        txtSenha.focus();
    //        return false;
    //    }

    if ((txtTelefone.value == "") || (txtTelefone.value == "Telefone (ex.:21 9999-9999)")) {
        alert("Digite um telefone fixo válido!");
        txtTelefone.focus();
        return false;
    }

    if (txtTelefone.value != "Telefone (ex.:21 9999-9999)") {
        if ((txtTelefone.value.charAt(3) == "8") || (txtTelefone.value.charAt(3) == "9")) {
            alert("O telefone fixo não pode ser iniciado com ( 8 ou 9 )! ");
            txtTelefone.value = "";
            txtTelefone.focus();
            return false;
        }
    }

    if (txtCelular.value != "Celular (ex.:21 9999-9999)*") {
        if ((txtCelular.value.charAt(3) != "7") && (txtCelular.value.charAt(3) != "8") && (txtCelular.value.charAt(3) != "9")) {
            alert("O telefone celular deve ser iniciado com ( 7, 8 ou 9 )! ");
            txtCelular.value = "";
            txtCelular.focus();
            return false;
        }
    }

    if ((txtCEP.value == "") || (txtCEP.value == "CEP")) {
        alert("Digite seu CEP!");
        txtCEP.focus();
        return false;
    }

    if ((txtRua.value == "") || (txtRua.value == "Rua")) {
        alert("Digite o nome da sua rua!");
        txtRua.focus();
        return false;
    }

    if ((txtNum.value == "") || (txtNum.value == "Nº")) {
        alert("Digite o número da sua casa!");
        txtNum.focus();
        return false;
    }

    if ((txtBairro.value == "") || (txtBairro.value == "Bairro")) {
        alert("Digite seu bairro!");
        txtBairro.focus();
        return false;
    }

    if ((txtUF.value == "") || (txtUF.value == "UF")) {
        alert("Digite sua UF!");
        txtUF.focus();
        return false;
    }

    if ((txtCidade.value == "") || (txtCidade.value == "Cidade")) {
        alert("Informe a sua cidade!");
        txtCidade.focus();
        return false;
    }

//    if (ddlConheceu.value == "0") {
//        alert("Informe como conheceu MSF!");
//        ddlConheceu.focus();
//        return false;
//    }

    if (hdnFormaPagto.value == 0) {
        alert("Por favor informe a forma de pagamento!");
        return false;
    }

    if (hdnFormaPagto.value == 1) {
        if ((txtTitular.value == "") || (txtTitular.value == "Titular do cartão")) {
            alert("Informe o titular do cartão!");
            txtTitular.focus();
            return false;
        }

        if (ddlBandeiraCartao.value == 0) {
            alert("Selecione a bandeira do seu cartão!");
            ddlBandeiraCartao.focus();
            return false;
        } else {
            if ((ddlBandeiraCartao.value == "American Express") && (txtNumeroCartao.value.charAt(0) != "3")) {
                alert("O número informado não é válido para cartões American Express!");
                txtNumeroCartao.focus();
                return false;
            }
            if ((ddlBandeiraCartao.value == "Mastercard") && (txtNumeroCartao.value.charAt(0) != "5")) {
                alert("O número informado não é válido para cartões Mastercard!");
                txtNumeroCartao.focus();
                return false;
            }
            if ((ddlBandeiraCartao.value == "Visa") && (txtNumeroCartao.value.charAt(0) != "4")) {
                alert("O número informado não é válido para cartões Visa!");
                txtNumeroCartao.focus();
                return false;
            }
        }

        if ((txtNumeroCartao.value == "") || (txtNumeroCartao.value == "Número do cartão")) {
            alert("Informe o número do cartão!");
            txtNumeroCartao.focus();
            return false;
        } else {
        if (txtNumeroCartao.value.length < 14) {
            alert("O número do cartão informado é inválido!");
            txtNumeroCartao.focus();
            return false;
        } 
        }

        if (ddlMesCartao.value == 0) {
            alert("Selecione o mês da validade do seu cartão!");
            ddlMesCartao.focus();
            return false;
        }

        if (ddlAnoCartao.value == 0) {
            alert("Selecione o ano da validade do seu cartão!");
            ddlAnoCartao.focus();
            return false;
        }

        if (txtCodigoSeguranca.value == "") {
            alert("Informe o código de segurança");
            txtCodigoSeguranca.focus();
            return false;
        }
    }

    if (hdnFormaPagto.value == 3) {

        if (hdnBanco.value == "0") {
            alert("Informe o banco!");
            return false;
        }

        if ((txtAgencia.value == "") || (txtAgencia.value == "Agência")) {
            alert("Informe o número da agência!");
            txtAgencia.focus();
            return false;
        }

        if ((txtConta.value == "") || (txtConta.value == "Conta Corrente")) {
            alert("Informe o número da Conta Corrente!");
            txtConta.focus();
            return false;
        }

            if (txtCPF.value == "CPF*") {
                alert("Para esta forma de pagamento o CPF é obrigatório!");
                txtCPF.focus();
                return false;
            }

            if ((txtCPF.value != "CPF*")) {
                if (!vercpf(txtCPF.value)) {
                    alert("O CPF informado não é válido!");
                    txtCPF.focus();
                    return false;
                }
            }

            if (hdnBanco.value == "237") {
                if ((txtAgencia.value).length > 6) {
                    alert("O número da Agência informado é inválido!");
                    txtAgencia.focus();
                    return false;
                }

                if ((txtConta.value).length > 9) {
                    alert("O número da Conta informado é inválido!");
                    txtConta.focus();
                    return false;
                }
            } else if (hdnBanco.value == "341") {
                if ((txtAgencia.value).length > 4) {
                    alert("O número da Agência informado é inválido!");
                    txtAgencia.focus();
                    return false;
                }

                if ((txtConta.value).length > 7) {
                    alert("O número da Conta informado é inválido!");
                    txtConta.focus();
                    return false;
                }
            } else if (hdnBanco.value == "104") {
                if ((txtAgencia.value).length > 4) {
                    alert("O número da Agência informado é inválido!");
                    txtAgencia.focus();
                    return false;
                }

                if ((txtConta.value).length > 14) {
                    alert("O número da Conta informado é inválido!");
                    txtConta.focus();
                    return false;
                }
            }
        }

        if (chkDoador.checked) {
            if ((txtCodigoDoador.value == "Código de Doador") || (txtCodigoDoador.value == "")) {
                alert("Se você é doador, informe seu código!");
                return false;
            } else {
                if ((txtCodigoDoador.value.charAt(0) != "1") && (txtCodigoDoador.value.charAt(0) != "2") && (txtCodigoDoador.value.charAt(0) != "3") && (isNaN(txtCodigoDoador.value))) {
                    alert("O código de doador informado é inválido!");
                    return false;
                }
            }
        }

        alert("Por favor, aguarde enquanto processamos sua doação!");

    verificaPresenteados();
    validaQtdCalendarios();

}


















