﻿$(document).ready(function () {

    $("ul#topnav li a.conheca").hover(function () { //Hover over event on list item
        $(this).find("span").show(); //Show the subnav
    }, function () { //on hover out...
        //$(this).css({ 'background' : '#url(imagens/menu/bot-conheca-menu.gif)'}); //Ditch the background
        $(this).find("span").hide(); //Hide the subnav

    });

    $('.banner').hover(
    function () {
        $(this).next().slideToggle();
    });

    $("#ctl00_conteudoInterna_txtValor").focus(function () {
        $("input[name=valor][type=radio]").filter(":last").click();
    });

    $("input[name=valor][type=radio]").filter(":last").click(function () {
        setValorDoacao($("#ctl00_conteudoInterna_txtValor").val());
    });

});

// JavaScript Document
function limpaInputs(nomeinput, valor) {
    if (nomeinput.value == valor) {
        nomeinput.value = '';
    }
}

function voltaInputs(nomeinput, valor) {
    if (nomeinput.value == '') {
        nomeinput.value = valor;
    }
}
//#################################################################################################################

Cufon.replace('h2');
Cufon.replace('h3');
Cufon.replace('h3 > a');
Cufon.replace('h4');
Cufon.replace('h5');
Cufon.replace('h6');
Cufon.replace('.cufon');

$(function () {
    $("select").uniform();
});


function tWeet(url, txtShare) {

    var twUrl = "http://twitter.com/share?url=";
    var shareUrl = twUrl + encodeURIComponent(url) + "&text=" + encodeURIComponent(txtShare + ' (via @MSF_brasil)')

    window.open(shareUrl, "Twitter", "width=640,height=355");

}

function sHare(url) {
    var shareUrl = url //+ encodeURIComponent(params);
    window.open(shareUrl, "Share", "width=640,height=480");
}

function URLencode(sStr) {
    return escape(sStr).
		 replace(/\+/g, '%2B').
			replace(/\"/g, '%22').
			   replace(/\'/g, '%27').
				 replace(/\//g, '%2F');
}

function getId(id) {
    return document.getElementById(id);
}

function getByTagName(tag) {
    return document.getElementsByTagName(tag);
}

function addBody(elem) {
    return document.body.appendChild(elem);
}

function removeBody(elem) {
    return document.body.removeChild(elem);
}

function criarTextNode(texto) {
    return document.createTextNode(texto);
}

function criarElem(elem) {
    return document.createElement(elem);
}

function removeChilds(param) {
    for (var i = 0, elem; elem = param.childNodes[i]; i++) {
        elem.parentNode.removeChild(elem);
    }
}

function showDiv(idDiv) {
    javascript: document.getElementById(idDiv).style.display = 'block';
}


// validação de email
function checkMail(mail) {
    var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
    if (typeof (mail) == "string") {
        if (er.test(mail)) { return true; }
    }
    else if (typeof (mail) == "object") {
        if (er.test(mail.value)) { return true; }
    }
    else {
        return false;
    }
}

function isNum(event) {
    var Key = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
    if (Key == 8 || Key == 13 || Key == 44 || Key == 127 || (Key >= 48 && Key <= 57)) return true;
    else return false;
}

function isNum2(event) {
    var Key = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
    if (Key == 8 || Key == 13 || Key == 127 || (Key >= 48 && Key <= 57)) return true;
    else return false;
}

// Função para retirar os espaços em branco do início e do fim da string.
function Trim(strTexto) {
    // Substitúi os espaços vazios no inicio e no fim da string por vazio.
    return strTexto.replace(/^\s+|\s+$/g, '');
}

// validação de CEP.
function checkCep(strCEP, blnVazio) {
    // Caso o CEP não esteja nesse formato ele é inválido!
    var objER = /^[0-9]{2}\.[0-9]{3}-[0-9]{3}$/;

    strCEP = Trim(strCEP)
    if (strCEP.length > 0) {
        if (objER.test(strCEP))
            return true;
        else
            return false;
    }
    else
        return blnVazio;
}


//validação de CPF

function checkCpf(cpf) {
    var numeros, digitos, soma, i, resultado, digitos_iguais;
    digitos_iguais = 1;
    if (cpf.length < 11)
        return false;
    for (i = 0; i < cpf.length - 1; i++)
        if (cpf.charAt(i) != cpf.charAt(i + 1)) {
            digitos_iguais = 0;
            break;
        }
    if (!digitos_iguais) {
        numeros = cpf.substring(0, 9);
        digitos = cpf.substring(9);
        soma = 0;
        for (i = 10; i > 1; i--)
            soma += numeros.charAt(10 - i) * i;
        resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
        if (resultado != digitos.charAt(0))
            return false;
        numeros = cpf.substring(0, 10);
        soma = 0;
        for (i = 11; i > 1; i--)
            soma += numeros.charAt(11 - i) * i;
        resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
        if (resultado != digitos.charAt(1))
            return false;
        return true;
    }
    else
    return false;
}

function countDown(textarea) {
    if (textarea.value.length >= 600) { textarea.value = textarea.value.substring(0, 600) }
    else {
        var restantes = (600 - textarea.value.length);
        var exibe = document.getElementById("count-down");
        exibe.innerHTML = restantes;
    }
}

function limpaInputs(nomeinput, valor) {
    if (nomeinput.value == valor) {
        nomeinput.value = '';
    }
}

function voltaInputs(nomeinput, valor) {
    if (nomeinput.value == '') {
        nomeinput.value = valor;
    }
}

function mostraLinhaTempo() {
    $('#ucLinhaTempo').show();
    $('#imgTimeLine').hide();
}

function showHide(vID) {
    //Apagar todos os divs;
    document.getElementById('id1').style.display = "none";
    document.getElementById('id2').style.display = "none";
    document.getElementById('id3').style.display = "none";

    //Imprimir apenas o div que foi passado em vID;
    document.getElementById(vID).style.display = "block";
}

function showTv() {
    document.getElementById('div_rbl_tv').style.display = "block";
    //document.getElementById('rbl_item_radio').style.margin = "130px 7px 0 0";
    //document.getElementById('rbl_item_tv').style.height = "160px";
    //document.getElementById('rbl_item_radio').style.height = "22px";
    document.getElementById('rbl_item_outros').style.margin = "130px 7px 0 0";
}

function HideTv() {
    document.getElementById('div_rbl_tv').style.display = "none";
    //document.getElementById('rbl_item_radio').style.margin = "0 7px 0 0";
    document.getElementById('rbl_item_outros').style.margin = "0 7px 0 0";
    document.getElementById('rbl_item_tv').style.height = "22px";
}

function showRadio() {
    document.getElementById('div_rbl_radio').style.display = "block";
    document.getElementById('rbl_item_radio').style.height = "112px";
    //document.getElementById('rbl_item_outros').style.margin = "80px 7px 10px 0";
}

function HideRadio() {
    document.getElementById('div_rbl_radio').style.display = "none";
    document.getElementById('rbl_item_outros').style.margin = "0 7px 10px 0";
}

function setValorDoacao(valor) {
    var hdnValor = getId("ctl00_conteudoInterna_hdnValor");
    hdnValor.value = valor + "00";
}

function ValorDoacao(valor) {
    var hdnValor = getId("ctl00_conteudoInterna_hdnValor");
    hdnValor.value = valor;
}

function corrigeValorDoacao() {
    var hdnValor = getId("ctl00_conteudoInterna_hdnValor");
    hdnValor.value = hdnValor.value + "00";
}


function setValorDoacaoDouble(valor) {
    var hdnValor = getId("ctl00_conteudoInterna_hdnValor");
    hdnValor.value = valor + "0";
}

function setFormaPagto(forma) {
    var hdnFormaPagto = getId("ctl00_conteudoInterna_hdnFormaPagto");
    hdnFormaPagto.value = forma;

}

function limitaTamTxt(campo) {
    var maxLimit = 0;
    var banco = getId("ctl00_conteudoInterna_hdnBanco").value;
    if (banco == "237") {
        $(campo).attr("maxlength", 6);
        //return txtBoxFormat(campo, '9999-9', evt);
    } else if (banco == "341") {
        $(campo).attr("maxlength", 4);
//    } else {
//        $(campo).attr("maxlength", 4);
    }
}

function limitaTamTxtCt(campo) {
    var maxLimit = 0;
    var banco = getId("ctl00_conteudoInterna_hdnBanco").value;
    if (banco == "237") {
        $(campo).attr("maxlength", 10);
        return txtBoxFormat(campo, '9999-9', evt);
    } else if (banco == "341") {
//        $(campo).attr("maxlength", 7);
//    } else {
        $(campo).attr("maxlength", 7);
    }
}

function cleanFormaPagto() {
    //getId("ctl00_conteudoInterna_hdnBanco").value = ""
    getId("ctl00_conteudoInterna_txtAgencia").value = "Agência";
    getId("ctl00_conteudoInterna_txtTitular").value = "Titular do cartão";
    getId("ctl00_conteudoInterna_txtNumeroCartao").value = "Número do cartão";
    getId("ctl00_conteudoInterna_txtCodigoSeguranca").value = "";
    getId("ctl00_conteudoInterna_txtConta").value = "Conta Corrente";
    document.aspnetForm.ctl00_conteudoInterna_ddlBandeiraCartao.options[0].value = 0;
    getId("ctl00_conteudoInterna_ddlMesCartao").value = "0";
    getId("ctl00_conteudoInterna_ddlAnoCartao").value = "0";
    document.getElementById('ctl00_conteudoInterna_ddlBandeiraCartao').value = '0';
}

function setBanco(banco) {
    var hdnBanco = getId("ctl00_conteudoInterna_hdnBanco");
    hdnBanco.value = banco;
}

function imprimeBoleto(idBoleto) {
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open('https://mup.comercioeletronico.com.br/sepsBoletoRet/004539877/prepara_pagto.asp?MerchantId=004539877&OrderId="+ idBoleto + "', '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=0,width=700,height=632');");
}

function abreUrlPais() {

    day = new Date();
    id = day.getTime();

    var pais = document.getElementById("ddlPaises");

    eval("page" + id + " = window.open('"+ pais.value +"', '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=0,width=700,height=632');");
    
    //window.open(pais.value);
}

function setQuantidadeCalendaros(qtd) {

    var hdnQtd = getId("ctl00_conteudoInterna_hdnQtdCalendarios");

    hdnQtd.value = qtd;

}


function preencheQtdCalendarios(input) {

    var qtdCalendarios = 0;
    //var valorCalendario = 22;
    var valorCalendario = document.getElementById("ctl00_conteudoInterna_hdnValorCalendario");

    var i = 0;

    var option_saida = "";

    if (input.value != ""){
        if (input.value != 0) {
            qtdCalendarios = parseInt(input.value / valorCalendario.value);
        }
    }

    
    for (i = 0; i <= qtdCalendarios; i++) {
        option_saida = option_saida + '<option value="' + i + '">' + i + '</option>';
        //alert(i);
    }

    $("#ddlCalendario").html(option_saida);
}

function resetDDLCalendarios() {

    var valorCalendario = document.getElementById("ctl00_conteudoInterna_hdnValorCalendario");
    //var ddlCalendario = document.getElementById("ctl00_conteudoInterna_ddlCalendario");

    var txtValor = document.getElementById("ctl00_conteudoInterna_txtValor");

    var option_saida = '<option value="0">0</option>';

    $("#ddlCalendario").html(option_saida);
    //$("#ctl00_conteudoInterna_ddlCalendario").value(0);
    txtValor.value = "";

}


function addOpcaoPresenteado(chk) {

    exibeCamposPresenteado("presenteado1");

}

function remOpcaoPresenteado() {

    document.getElementById("presenteado1").style.display = 'none';
    document.getElementById("presenteado2").style.display = 'none';
    document.getElementById("presenteado3").style.display = 'none';
    document.getElementById("presenteado4").style.display = 'none';
    document.getElementById("presenteado5").style.display = 'none';
    document.getElementById("presenteado6").style.display = 'none';
    document.getElementById("presenteado7").style.display = 'none';
    document.getElementById("presenteado8").style.display = 'none';
    document.getElementById("presenteado9").style.display = 'none';
    document.getElementById("presenteado10").style.display = 'none';

}

function remBotsProximo() {

    document.getElementById("addPresenteado2").style.display = 'none';
    document.getElementById("addPresenteado3").style.display = 'none';
    document.getElementById("addPresenteado4").style.display = 'none';
    document.getElementById("addPresenteado5").style.display = 'none';
    document.getElementById("addPresenteado6").style.display = 'none';
    document.getElementById("addPresenteado7").style.display = 'none';
    document.getElementById("addPresenteado8").style.display = 'none';
    document.getElementById("addPresenteado9").style.display = 'none';
    document.getElementById("addPresenteado10").style.display = 'none';

}

function habilitaBotsProximo() {

    document.getElementById("addPresenteado2").style.display = 'block';
    document.getElementById("addPresenteado3").style.display = 'block';
    document.getElementById("addPresenteado4").style.display = 'block';
    document.getElementById("addPresenteado5").style.display = 'block';
    document.getElementById("addPresenteado6").style.display = 'block';
    document.getElementById("addPresenteado7").style.display = 'block';
    document.getElementById("addPresenteado8").style.display = 'block';
    document.getElementById("addPresenteado9").style.display = 'block';
    document.getElementById("addPresenteado10").style.display = 'block';

}


function remOpcaoPresenteadoException(idException) {

        document.getElementById("presenteado1").style.display = 'none';
        document.getElementById("presenteado2").style.display = 'none';
        document.getElementById("presenteado3").style.display = 'none';
        document.getElementById("presenteado4").style.display = 'none';
        document.getElementById("presenteado5").style.display = 'none';
        document.getElementById("presenteado6").style.display = 'none';
        document.getElementById("presenteado7").style.display = 'none';
        document.getElementById("presenteado8").style.display = 'none';
        document.getElementById("presenteado9").style.display = 'none';
        document.getElementById("presenteado10").style.display = 'none';

        document.getElementById("presenteado" + idException).style.display = 'block';

}

function remOpcaoProximoPresenteado(idUltimo) {

    var i = 0;
    for (i = 0; i >= 10; i++) {
        
        if (i > idUltimo){
           document.getElementById("presenteado"+ i).style.display = 'none';
        }
    
    }
}

function exibeCamposPresenteado(idBloco) {

    var blocoPresenteado = document.getElementById(idBloco);

    blocoPresenteado.style.display = 'block';

}

function checkRbtOutro() {
    var rbt = document.getElementById("rbtOutro");

    rbt.checked = true;
}

function habilitaCampoCodDoador() {
    var Doador = jQuery("div[id*=divDoador]");

    if (document.getElementById("ctl00_conteudoInterna_chkDoador").checked) {
        Doador.show();
    } else {
        Doador.hide();
    }
}


