﻿// Paginação das listagens
$(document).ready(function() {
    $(".listagem").each(function() { $(this).children(".linha-ofertas:not(:first)").hide(); });
    $(".listagem").each(function() { $(this).children(".linha-ofertas:first").show(); });


    $('.listagem a.leftarrow, .listagem a.rightarrow').click(function(ev) {
        //prevent browser jumping to top
        ev.preventDefault();

        //parent
        var $parent = $(this).parent().parent();
        //get current visible item
        var $visibleItem = $parent.children('.linha-ofertas:visible');

        //get total item count
        var total = $parent.children('.linha-ofertas').length;

        //get index of current visible item
        var index = $visibleItem.prevAll('.linha-ofertas').length;

        //if we click next increment current index, else decrease index
        $(this).attr('href') === '#Next' ? index++ : index--;
        var direcao = $(this).attr('href') === '#Next' ? 'left' : 'right';
        //if we are now past the beginning or end show the last or first item
        if (index === -1) {
            index = total - 1;
        }
        if (index === total) {
            index = 0
        }

        //hide current show item
        $visibleItem.hide('slide', { direction: direcao }, 500, function() { $parent.children('.linha-ofertas:eq(' + index + ')').show('slide', { direction: direcao }, 500); });


        //fade in the relevant item


    });
    $.superbox.settings = {
        boxId: "superbox", // Id attribute of the "superbox" element
        boxClasses: "", // Class of the "superbox" element
        overlayOpacity: .6, // Background opaqueness
        boxWidth: "600", // Default width of the box
        boxHeight: "400", // Default height of the box
        loadTxt: "Carregando...", // Loading text
        closeTxt: "<img alt='Fechar' src='images/estrutura/indique/fechar.gif'/>", // "Close" button text
        prevTxt: "Anterior", // "Previous" button text
        nextTxt: "Próximo" // "Next" button text
    };
    $.superbox();
});
// FIM - Paginação das listagens
// Validações
function validarCPF(cpf) {
    var filtro = /^\d{3}.\d{3}.\d{3}-\d{2}$/i;
    if (!filtro.test(cpf)) {
        //window.alert("CPF inválido. Tente novamente.");
        return false;
    }

    cpf = remove(cpf, ".");
    cpf = remove(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") {
        //window.alert("CPF inválido. Tente novamente.");
        return false;
    }

    soma = 0;
    for (i = 0; i < 9; i++)
        soma += parseInt(cpf.charAt(i)) * (10 - i);
    resto = 11 - (soma % 11);
    if (resto == 10 || resto == 11)
        resto = 0;
    if (resto != parseInt(cpf.charAt(9))) {
        //window.alert("CPF inválido. Tente novamente.");
        return false;
    }
    soma = 0;
    for (i = 0; i < 10; i++)
        soma += parseInt(cpf.charAt(i)) * (11 - i);
    resto = 11 - (soma % 11);
    if (resto == 10 || resto == 11)
        resto = 0;
    if (resto != parseInt(cpf.charAt(10))) {
        //window.alert("CPF inválido. Tente novamente.");
        return false;
    }
    return true;
}
function remove(str, sub) {
    i = str.indexOf(sub);
    r = "";
    if (i == -1) return str;
    r += str.substring(0, i) + remove(str.substring(i + sub.length), sub);
    return r;
}
function vc_txtCadCPF(sender, args) {
    args.IsValid = validarCPF(args.Value);
}
// FIM - Validações
//Foco e Blur
function noFoco(o) {
    o.value = '';
}
function noBlur(o) {
    if (jQuery.trim(o.value) == '') {
        o.value = o.title;
    }
}
// FIM - Foco e Blur