﻿
var carregando;
var loading;
var sistemaExterno = 'institucional';
var publicidadeExterna = 'publicidade_1';
var segundoExterno = 0;
var i = 0;
var direcao;

jQuery(document).ready(function() {
    jQuery('#carouselPub').jcarousel({
        wrap: 'circular',
        auto: 10
    });
});

function bt_enviar() {
    var box = document.getElementById("box");
    box.style.display="none";
}
 
function enableClick() {
    var flechaE = document.getElementById("setaBannerEsquerda");
    var flechaD = document.getElementById("setaBannerDireita");
    flechaE.onclick = anteriorPasso;
    flechaD.onclick = proximoPasso;
}

function disableClick() {
    var flechaE = document.getElementById("setaBannerEsquerda");
    var flechaD = document.getElementById("setaBannerDireita");
    flechaE.onclick = "";
    flechaD.onclick = "";
}

function boxSistema_Click() {
    if ($("#boxLogin").css("top") == "0px") {
        $("#boxLogin").animate({ top: -74 }, "slow");
        $("#boxLoginConteudo").animate({ top: -74 }, "slow");
    } else {
        $("#boxLogin").animate({ top: 0 }, "slow");
        $("#boxLoginConteudo").animate({ top: 0 }, "slow");
    }
}

function boxClick(boxImg, checkBox) {
    $(boxImg).toggleClass('boxSelecionado');
    document.getElementById(checkBox).checked = !document.getElementById(checkBox).checked;
    //$(checkBox).attr('checked', !$(checkBox).attr('checked'));
} 

function pararLoading(){
    if (typeof (carregando) != 'undefined') {
        clearTimeout(carregando);
    }
}

function continuarLoading() {
    if (typeof (carregando) != 'undefined') {
        clearTimeout(carregando);
    }
   carregarProximoBanner(segundoExterno,sistemaExterno);
}

function pararLoading_pub() {
    if (typeof (loading) != 'undefined') {
        clearTimeout(loading);
    }
}

function continuarLoading_pub() {
    if (typeof (loading) != 'undefined') {
        clearTimeout(loading);
    }
    carregarProxPublicidade(segundoExterno, publicidadeExterna);
}

function carregarProximoBanner(segundo, sistema) {
    var setaD = document.getElementById('setaBannerDireita');
    var setaE = document.getElementById('setaBannerEsquerda');
    if (segundo < 22) {
        sistemaExterno = sistema;
        segundoExterno = segundo;

        carregando = window.setTimeout('carregarProximoBanner(' + (segundo + 1) + ',"' + sistema + '")', 700);
    }
    else {
        switch (sistema) {
            case 'institucional':
                selecionar("doc");
                mostrarSeta(setaE);
                break;
            case 'doc':
                selecionar("flag");
                break;
            case 'flag':
                selecionar("buy");
                break;
            case 'buy':
                selecionar("tools");
                ocultarSeta(setaD);
                break;
            case 'tools':
                selecionar("institucional");
                mostrarSeta(setaD);
                ocultarSeta(setaE);
                break;
        }
    }

}

function anteriorPasso() {
    disableClick();
    var setaD = document.getElementById('setaBannerDireita');
    var setaE = document.getElementById('setaBannerEsquerda');
    switch (sistemaExterno) {
        case 'doc':
            selecionar("institucional");
            ocultarSeta(setaE);
            break;
        case 'flag':
            selecionar("doc");
            break;
        case 'buy':
            selecionar("flag");
            break;
        case 'tools':
            selecionar("buy");
            mostrarSeta(setaD);
            break;
        case 'institucional':
            
            break;
    }
}

function proximoPasso() {
    disableClick();
    var setaD = document.getElementById('setaBannerDireita');
    var setaE = document.getElementById('setaBannerEsquerda');
    switch (sistemaExterno) {
        case 'institucional':
            selecionar("doc");
            mostrarSeta(setaE);
            break;
        case 'doc':
            selecionar("flag");
            break;
        case 'flag':
            selecionar("buy");
            break;
        case 'buy':
            selecionar("tools");
            ocultarSeta(setaD);
            break;
        case 'tools':
            
            break;
    }
}


function ocultarSeta(id) {
    id.style.display = 'none';
}
function mostrarSeta(id) {
    id.style.display = 'inline-block';
}

function selecionar(sistema) {

    if (typeof (carregando) != 'undefined') {
        clearTimeout(carregando);
    }

    switch(sistema) {
        case 'institucional':
            $('#banner_mask').scrollTo($('#banner_institucional'), 2000, { easing: 'swing', queue: false, axis: 'xy', onAfter: function () {enableClick();}});
            break;
        case 'doc':
            $('#banner_mask').scrollTo($('#banner_doc'), 2000, { easing: 'swing', queue: false, axis: 'xy', onAfter: function () {
                enableClick();
            } 
            });
            break;
        case 'flag':
            $('#banner_mask').scrollTo($('#banner_flag'), 2000, { easing: 'swing', queue: false, axis: 'xy', onAfter: function () {
                enableClick();
            } 
            });
        break;
        case 'buy':
            $('#banner_mask').scrollTo($('#banner_buy'), 2000, { easing: 'swing', queue: false, axis: 'xy', onAfter: function () {
                enableClick();
            } 
            });
        break;
        case 'tools':
            $('#banner_mask').scrollTo($('#banner_tools'), 2000, { easing: 'swing', queue: false, axis: 'xy', onAfter: function () {
                enableClick();
            } 
            });
            break;
    }
    carregarProximoBanner(0,sistema);
}

function ocultarPanel(panelId) {
    $("#" + panelId).fadeOut("normal", function () {
        $("#boxTransparent_" + panelId).slideUp("normal", function () {
        });
    });
}

function mostrarPanel(panelId) {
    $("#" + panelId).fadeIn("normal");
    $("#boxTransparent_" + panelId).slideDown("normal");
    document.getElementById('ctl00_TxtEmail').focus();
}

function slideToTop() {
    $.scrollTo('#topo', 800, { easing: 'swing' });
}

function verificaLoginEmBranco(email, senha) {

    email = document.getElementById(email);
    senha = document.getElementById(senha);

    $("#inputLoginErroNome").removeClass("inputLoginHover");
    $("#inputLoginErroSenha").removeClass("inputLoginHover");

    if (email.value.length <= 0) {
        $("#inputLoginErroNome").toggleClass("inputLoginHover");
        return false;
    } else if (senha.value.length <= 0) {
        $("#inputLoginErroSenha").toggleClass("inputLoginHover");
        return false;
    }
    return true;
}

function carregaPropostaByURL(checkID, checkbox) {
    window.onload = function () { changeCheck(checkID, checkbox); };
}

function verificaInputs() {
    var doc = $("#ctl00_contentCorpo_txtDocCheck");
    var docButton = document.getElementById("docCheck");

    var flag = $("#ctl00_contentCorpo_txtFlagCheck");
    var flagButton = document.getElementById("flagCheck");

    var buy = $("#ctl00_contentCorpo_txtBuyCheck");
    var buyButton = document.getElementById("buyCheck");

    var tools = $("#ctl00_contentCorpo_txtToolsCheck");
    var toolsButton = document.getElementById("toolsCheck");

    if (docButton && flagButton && buyButton && toolsButton != null) {
        doc.val() == "1" ? docButton.className = "checked" : docButton.className = "unchecked";
        flag.val() == "1" ? flagButton.className = "checked" : flagButton.className = "unchecked";
        buy.val() == "1" ? buyButton.className = "checked" : buyButton.className = "unchecked";
        tools.val() == "1" ? toolsButton.className = "checked" : toolsButton.className = "unchecked";
    }
}

function changeCheck(checkID,checkbox) {
    var objeto = document.getElementById(checkID);
    var objCheckBox = document.getElementById(checkbox);
    if (objeto.className == "unchecked") {
        objCheckBox.value = 1;
    } else {
        objCheckBox.value = 0;
    }
    verificaInputs();
}

function carregaFlipImagens() {
    jQuery('#flip').jcoverflip({
        current: 2,
        beforeCss: function (el, container, offset) {
            el.children().removeClass("lightBox");

            switch (offset) {
                case 0:
                    return [
                                $.jcoverflip.animationElement(el, { left: (container.width() / 2 - 150) - 250 + 'px', bottom: '20px' }, {}),
                                $.jcoverflip.animationElement(el.find('img'), { width: '180px' }, {})
                            ];
                    break;
                case 1:
                    return [
                                $.jcoverflip.animationElement(el, { left: (container.width() / 2 - 150) - 800 + 'px', bottom: '40px' }, {}),
                                $.jcoverflip.animationElement(el.find('img'), { width: '120px' }, {})
                            ];
                    break;
                case 2:
                    return [
                                $.jcoverflip.animationElement(el, { left: (container.width() / 2 - 150) - 800 + 'px', bottom: '60px' }, {}),
                                $.jcoverflip.animationElement(el.find('img'), { width: '60px' }, {})
                            ];
                    break;
                case 3:
                    return [
                                $.jcoverflip.animationElement(el, { left: (container.width() / 2 - 150) - 800 + 'px', bottom: '80px' }, {}),
                                $.jcoverflip.animationElement(el.find('img'), { width: '0px' }, {})
                            ];
                    break;
                case 4:
                    return [
                                $.jcoverflip.animationElement(el, { left: (container.width() / 2 - 150) - 1000 + 'px', bottom: '100px' }, {}),
                                $.jcoverflip.animationElement(el.find('img'), { width: tamanhoInicial + 'px' }, {})
                            ];
                    break;
                default:
                    return [
                                $.jcoverflip.animationElement(el, { left: (container.width() / 2 - 150) - 200 + 'px', bottom: '100px' }, {}),
                                $.jcoverflip.animationElement(el.find('img'), { width: tamanhoInicial + 'px' }, {})
                            ];
                    break;
            }



        },
        afterCss: function (el, container, offset) {
            el.children().removeClass("lightBox");

            switch (offset) {
                case 0:
                    return [
                                $.jcoverflip.animationElement(el, { left: (container.width() / 2 - 150) + 370 + 'px', bottom: '20px' }, {}),
                                $.jcoverflip.animationElement(el.find('img'), { width: '180px' }, {})
                            ];
                    break;
                case 1:
                    return [
                                $.jcoverflip.animationElement(el, { left: (container.width() / 2 - 150) + 800 + 'px', bottom: '40px' }, {}),
                                $.jcoverflip.animationElement(el.find('img'), { width: '120 px' }, {})
                            ];
                    break;
                case 2:
                    return [
                                $.jcoverflip.animationElement(el, { left: (container.width() / 2 - 150) + 946 + 'px', bottom: '60px' }, {}),
                                $.jcoverflip.animationElement(el.find('img'), { width: '120 px' }, {})
                            ];
                    break;
                case 3:
                    return [
                                $.jcoverflip.animationElement(el, { left: (container.width() / 2 - 150) + 946 + 'px', bottom: '80px' }, {}),
                                $.jcoverflip.animationElement(el.find('img'), { width: '120 px' }, {})
                            ];
                    break;
                case 4:
                    return [
                                $.jcoverflip.animationElement(el, { left: (container.width() / 2 - 150) + 946 + 'px', bottom: '100px' }, {}),
                                $.jcoverflip.animationElement(el.find('img'), { width: '120 px' }, {})
                            ];
                    break;
                default:
                    return [
                                $.jcoverflip.animationElement(el, { left: (container.width() / 2 - 150) + 946 + 'px', bottom: '120px' }, {}),
                                $.jcoverflip.animationElement(el.find('img'), { width: tamanhoInicial + 'px' }, {})
                            ];
                    break;
            }
        },
        currentCss: function (el, container) {

            el.children().addClass("lightBox");

            return [
              $.jcoverflip.animationElement(el, { left: (container.width() / 2 - 150) + 'px', bottom: 0 }, {}),
              $.jcoverflip.animationElement(el.find('img'), { width: '300px' }, {})
            ];
        },
        change: function (event, ui) {
            jQuery('#scrollbar').slider('value', ui.to * 25);
            $('.lightBox').lightBox();
        }
    });


    jQuery('#scrollbar').slider({
        value: 50,
        stop: function (event, ui) {
            if (event.originalEvent) {
                var newVal = Math.round(ui.value / 25);
                jQuery('#flip').jcoverflip('current', newVal);
                jQuery('#scrollbar').slider('value', newVal * 25);
            }
        }
    });
}


function idioma(x) {
    document.getElementById("idioma" + x).style.display = 'block';
    document.getElementById("btIdioma" + x).style.display = 'none';
}

function mostraEsconde(x) {
    if (document.getElementById(x).style.display == 'none') {
        document.getElementById(x).style.display = 'block';
        document.getElementById("bt" + x).className = 'botaoSimplesOff';
    } else {
        document.getElementById(x).style.display = 'none';
        document.getElementById("bt" + x).className = 'botaoSimples';
    }
}
