function alertZ(message, type = 'info'){
Swal.fire({
icon: type,
title: message
});
}
function popZ(message, type = 'info', url = null, focusZ = null){
const toast = createToastZ(message, type);
const timeout = getToastTimeoutZ(type);
let closed = false;
$("#toast-container").append(toast);
requestAnimationFrame(function() {
toast.addClass("show");
});
const closeToast = function() {
if (closed) return;
closed = true;
toast.removeClass("show").addClass("hide");
setTimeout(function() {
toast.remove();
if (url) {
window.location.href = url;
} else if (focusZ) {
$(focusZ).focus();
}
}, 220);
};
toast.find(".toastz-close").on("click", closeToast);
setTimeout(closeToast, timeout);
}
function createToastZ(message, type = 'info') {
const normalizedType = normalizeToastTypeZ(type);
const icon = getToastIconZ(normalizedType);
const title = getToastTitleZ(normalizedType);
return $(`
${icon}
${escapeHtmlZ(title)}
${escapeHtmlZ(message)}
×
`);
}
function normalizeToastTypeZ(type) {
const aliases = {
danger: "error",
primary: "info",
secondary: "info",
dark: "info",
light: "info"
};
const normalized = aliases[type] || type;
const allowed = ["success", "warning", "error", "info"];
return allowed.includes(normalized) ? normalized : "info";
}
function getToastIconZ(type) {
const icons = {
success: "✓",
warning: "!",
error: "×",
info: "i"
};
return icons[type] || icons.info;
}
function getToastTitleZ(type) {
const titles = {
success: "Tudo certo",
warning: "Atenção",
error: "Ops",
info: "Aviso"
};
return titles[type] || titles.info;
}
function getToastTimeoutZ(type) {
const normalizedType = normalizeToastTypeZ(type);
const timeouts = {
success: 2600,
info: 3200,
warning: 4200,
error: 5200
};
return timeouts[normalizedType] || 3200;
}
function escapeHtmlZ(value) {
return String(value ?? "")
.replace(/&/g, "&")
.replace(//g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
}
$('.money').mask('#.##0,00', { reverse: true });
$('.cpf').mask('000.000.000-00', { reverse: true });
$('.cnpj').mask('00.000.000/0000-00', {reverse: true});
var SPMaskBehavior = function (val) { return val.replace(/\D/g, '').length === 11 ? '(00) 00000-0000' : '(00) 0000-00009'; },
spOptions = { onKeyPress: function(val, e, field, options) { field.mask(SPMaskBehavior.apply({}, arguments), options); } };
var SPMaskBehaviorZ = function (val){ return val.replace(/\D/g, '').length <= 11 ? '000.000.000-009' : '00.000.000/0000-00'; },
optionsCNPJF = { onKeyPress: function (cpf, ev, el, op) { el.mask(SPMaskBehaviorZ.apply({}, arguments), op); } }
$(document).on("focus", ".phone", function() {
$(this).mask(SPMaskBehavior, spOptions);
});
$(document).on("focus", ".date", function() {
$(this).mask('00/00/0000');
});
$(document).on("focus", ".cnpj", function() {
$(this).mask('00.000.000/0000-00', {reverse: true});
});
$(document).on("focus", ".cpf", function() {
$(this).mask('000.000.000-00', {reverse: true});
});
$(document).on("focus", ".cpfCnpj", function() {
$(this).mask(SPMaskBehaviorZ, optionsCNPJF);
});
$(document).on("focus", ".money", function() {
$(this).mask('#.##0,00', {reverse: true});
});
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 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 );
}
$(document).on("blur", ".cpfCnpj", function() {
var validoZ = false;
var campo = $(this).val().replace(/\D/g, '');
if (($(this).val().trim() != "" )){
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(campo.length == 11){
if ( ( campo_filtrado.substring(9,11) == checkCPF( campo_filtrado.substring(0,9) ) ) && ( campo_filtrado.substring(11,12)=="") ){ validoZ = true;}
}
if(campo.length == 14){
if (campo_filtrado.length >= 14){
if ( campo_filtrado.substring(12,14) == checkCNPJ( campo_filtrado.substring(0,12) ) ){ validoZ = true; }
}
}
if (!validoZ) popZ("CPF / CNPJ inválido, ajuste para prosseguir.", type = 'error', url = null, $(this));
}
});
function showToast(msg, tipo = 'success', tempo = 3000) {
popZ(msg, tipo);
}
function initCookieConsentZ() {
const storageKey = "garagem164CookieConsent:v1";
try {
if (localStorage.getItem(storageKey) === "accepted") {
return;
}
} catch (error) {
return;
}
if ($("#cookie-consent-z").length) {
return;
}
const banner = $(`
🍪
Usamos cookies
Utilizamos cookies essenciais e recursos de navegação para melhorar sua experiência na Garagem 1:64.
Saiba mais na nossa Política de Privacidade .
`);
$("body").append(banner);
requestAnimationFrame(function() {
banner.addClass("is-visible");
});
banner.find("[data-cookie-consent-accept]").on("click", function() {
try {
localStorage.setItem(storageKey, "accepted");
} catch (error) {}
banner.removeClass("is-visible").addClass("is-hidden");
setTimeout(function() {
banner.remove();
}, 240);
});
}
function initMobileNavZ() {
const body = $("body");
const toggle = $(".mobile-nav-toggle");
const nav = $("#main-navlinks");
if (!toggle.length || !nav.length) {
return;
}
const closeMenu = function() {
body.removeClass("mobile-nav-open");
toggle.attr("aria-expanded", "false");
};
const openMenu = function() {
body.addClass("mobile-nav-open");
toggle.attr("aria-expanded", "true");
};
toggle.on("click", function(event) {
event.preventDefault();
event.stopPropagation();
if (body.hasClass("mobile-nav-open")) {
closeMenu();
} else {
openMenu();
}
});
nav.on("click", "a", closeMenu);
$(document).on("click", function(event) {
if (!body.hasClass("mobile-nav-open")) {
return;
}
if ($(event.target).closest(".navbar").length) {
return;
}
closeMenu();
});
$(document).on("keydown", function(event) {
if (event.key === "Escape") {
closeMenu();
}
});
$(window).on("resize", function() {
if (window.innerWidth > 760) {
closeMenu();
}
});
}
$(document).on("click", "[data-footer-ad-filter]", function() {
const filterType = String($(this).data("footer-ad-filter") || "");
const filterValue = String($(this).data("filter-value") || "");
if (!filterType || !filterValue) {
return;
}
const filters = {
search: "",
manufacturers: "",
scales: "",
conditions: "",
price: "",
state: "",
city: "",
chips: "",
sort: "recent"
};
if (filterType === "manufacturer") {
filters.manufacturers = filterValue;
} else if (filterType === "condition") {
filters.conditions = filterValue;
filters.chips = filterValue;
}
sessionStorage.setItem("garagem164AdFilters", JSON.stringify(filters));
});
$(function() {
initMobileNavZ();
initCookieConsentZ();
});