﻿var pathUrl = null;
var newPath = 'cartao-interna.aspx?valor=&cobertura=&empresa=&bandeira=';
var sPath = newPath.split('&');
var v = 0;
var checkInput;
sUrl = new Array();
sUrl[0] = '';
function loading(){
    $('div#comparar-cartoes').hide();
    $('.obs').hide();
    $('#conteudo-cartoes').append('<div class="load-cartoes"><img src="../../../img/ajax-loader.gif" /><br /><br />Aguarde, carregando dados</div>');
    $('.btn-comparar').hide();
    setTimeout("$('.load-cartoes').remove()",3000);
    setTimeout("$('.obs').show()",3000);
    setTimeout("$('div#comparar-cartoes').show()",3000);
    setTimeout("$('.btn-comparar').show()",3000);
};
function filtraCartoes() {
    cc = new Array();
    ce = new Array();
    cb = new Array();
    $('.caracteristicas input').each(function() {
        if ( $(this).attr('check') == '1' ) {
            if ( $(this).hasClass('chkCobertura') ) {
                t = $(this).attr('value');
                if ( cc.length != 0 ) {
                    i = cc.length;
                    cc[i] = t;
                } else {
                    cc[0] = t;
                }
            } else if ( $(this).hasClass('chkEmpresa') ) {
                t = $(this).attr('value');
                if ( ce.length != 0 ) {
                    i = ce.length;
                    ce[i] = t;
                } else {
                    ce[0] = t;
                }
            } else if ( $(this).hasClass('chkBandeira') ) {
                t = $(this).attr('value');
                if ( cb.length != 0 ) {
                    i = cb.length;
                    cb[i] = t;
                } else {
                    cb[0] = t;
                }
            }
        }
    });
    rPath = sPath[0] +'' + sUrl[0] +'&'+ sPath[1] +''+ cc +'&'+ sPath[2] +''+ ce +'&'+ sPath[3] + ''+ cb;
    $('div#comparar-cartoes').load(rPath +' .external-content');
    loading();
    setTimeout('lightbox();', 3000);
    setTimeout('alertaCartoes();', 3000);
};
function alertaCartoes() {
    checkInput = 0;
    $('.tipo-cartoes label input').attr('check', '1');
    $('.tipo-cartoes label input').click(function() {
        if ($(this).attr('check') == '1') {
            $(this).attr('check', '0');
            checkInput++;
            if (checkInput > 4) {
                lightbox('263.132', '/img/lightbox/comparar-mais-4.png');
            }
        } else {
            $(this).attr('check', '1');
            checkInput--;
        }
    });
    $('.btn-comparar').click(function() {
        if (checkInput == 0 || checkInput == 1) {
            lightbox('263.132', '/img/lightbox/comparar-0.png');
            return false;
        }
    });
};
$(function() {
    alertaCartoes();
    $("#slider").slider({
        orientation: "vertical",
        value: 10,
        min: 1,
        max: 10,
        step: 1,
        slide: function(event, ui) {
            $("#amount").val(ui.value);
        }
    });
    $("#amount").val($("#slider").slider("value"));
    var count = 10;
    $('ul.valores li a').each(function() {
        $(this).attr('rel', count);
        count = count - 1;
    });
    $('.ui-slider-handle').mouseup(function() {
        $('ul.valores li a').each(function() {
            loading();
            var valor = $("#slider").slider("value");
            if ($(this).attr('rel') == valor) {
                pathUrl = $(this).attr('href');
                p = pathUrl.split('=');
                sUrl = p[1].split('&');
                faixa = $(this).text();
                v = 1;
            }
        });
        filtraCartoes();
    });
    $('ul.valores li a').click(function() {
        loading();
        var valor = $(this).attr('rel');
        $('#slider').slider('option', 'value', valor);
        pathUrl = $(this).attr('href');
        p = pathUrl.split('=');
        sUrl = p[1].split('&');
        faixa = $(this).text();
        v = 1;
        filtraCartoes();
        return false;
    });
    $('.chkCobertura, .chkEmpresa, .chkBandeira').attr('check', '0');
    $('.chkEmpresa.ativo').attr('check', '1');
    $('.chkCobertura, .chkEmpresa, .chkBandeira').click(function() {
        if ($(this).attr('check') == '1') {
            $(this).attr('check', '0');
        } else {
            $(this).attr('check', '1');
        }
        filtraCartoes();
    });
});


function alimentarHidden(obj) {
    var cartoes = '';
    $('.chkSelecionar').each(function() {
        if ( $(this).attr('checked')) {
            cartoes = cartoes + '' + $(this).attr('value') + ';';
        }
    });
    $('.hidden').attr('value',cartoes);
};
function DesabilitarCheckBoxBandeiras() {
    if(document.getElementById('ctl00_ContentPlaceHolder1_chkCobertura').disabled) {
        document.getElementById('ctl00_ContentPlaceHolder1_chkCobertura').disabled = false;
        document.getElementById('ctl00_ContentPlaceHolder1_chkCobertura2').disabled = false;    
    } else {
        document.getElementById('ctl00_ContentPlaceHolder1_chkCobertura').disabled = true;
        document.getElementById('ctl00_ContentPlaceHolder1_chkCobertura2').disabled = true;        
        document.getElementById('ctl00_ContentPlaceHolder1_chkCobertura').checked = false;
        document.getElementById('ctl00_ContentPlaceHolder1_chkCobertura2').checked = false;
    }
};