// Máscara de telefone: (XX) XXXX-XXXX | (XX) XXXXX-XXXX function mascaraTelefone(input) { input.addEventListener('input', function () { var v = this.value.replace(/\D/g, '').substring(0, 11); if (v.length <= 10) { v = v.replace(/^(\d{0,2})(\d{0,4})(\d{0,4})/, function (_, ddd, parte1, parte2) { if (!ddd) return ''; if (!parte1) return '(' + ddd; if (!parte2) return '(' + ddd + ') ' + parte1; return '(' + ddd + ') ' + parte1 + '-' + parte2; }); } else { v = v.replace(/^(\d{2})(\d{5})(\d{0,4})/, function (_, ddd, parte1, parte2) { if (!parte2) return '(' + ddd + ') ' + parte1; return '(' + ddd + ') ' + parte1 + '-' + parte2; }); } this.value = v; }); } // Máscara de dinheiro: 1.234.567,89 function mascaraRenda(input) { input.addEventListener('input', function () { var digits = this.value.replace(/\D/g, ''); if (!digits) { this.value = ''; return; } digits = digits.replace(/^0+/, '') || '0'; while (digits.length < 3) digits = '0' + digits; var cents = digits.slice(-2); var reais = digits.slice(0, -2).replace(/^0+/, '') || '0'; reais = reais.replace(/\B(?=(\d{3})+(?!\d))/g, '.'); this.value = reais + ',' + cents; }); } // Aplica erro + shake no campo inválido function marcarErro(campo) { campo.classList.add('error'); campo.classList.remove('shake'); void campo.offsetWidth; // força reflow para reiniciar a animação campo.classList.add('shake'); campo.addEventListener('input', function () { campo.classList.remove('error'); campo.classList.remove('shake'); }, { once: true }); campo.addEventListener('animationend', function () { campo.classList.remove('shake'); }, { once: true }); } // Validação de e-mail function emailValido(email) { return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email); } // Validação do formulário de contato function validaContato() { var nome = document.getElementById('ad-nome'); var email = document.getElementById('ad-email'); var tel = document.getElementById('ad-tel'); var primeiroErro = null; if (!nome.value.trim()) { marcarErro(nome); if (!primeiroErro) primeiroErro = nome; } if (!email.value.trim() || !emailValido(email.value.trim())) { marcarErro(email); if (!primeiroErro) primeiroErro = email; } if (!tel.value.trim() || tel.value.replace(/\D/g, '').length < 10) { marcarErro(tel); if (!primeiroErro) primeiroErro = tel; } if (primeiroErro) { primeiroErro.focus(); return false; } return true; } // Validação do formulário de whatsapp function validaWhatsapp() { var nome = document.getElementById('wa-nome'); var email = document.getElementById('wa-email'); var tel = document.getElementById('wa-tel'); var primeiroErro = null; if (!nome.value.trim()) { marcarErro(nome); if (!primeiroErro) primeiroErro = nome; } if (!email.value.trim() || !emailValido(email.value.trim())) { marcarErro(email); if (!primeiroErro) primeiroErro = email; } if (!tel.value.trim() || tel.value.replace(/\D/g, '').length < 10) { marcarErro(tel); if (!primeiroErro) primeiroErro = tel; } if (primeiroErro) { primeiroErro.focus(); return false; } return true; } // Validação do formulário de simulação function validaSimule() { var nome = document.getElementById('sim-nome'); var email = document.getElementById('sim-email'); var tel = document.getElementById('sim-tel'); var renda = document.getElementById('sim-renda'); var primeiroErro = null; if (!nome.value.trim()) { marcarErro(nome); if (!primeiroErro) primeiroErro = nome; } if (!email.value.trim() || !emailValido(email.value.trim())) { marcarErro(email); if (!primeiroErro) primeiroErro = email; } if (!tel.value.trim() || tel.value.replace(/\D/g, '').length < 10) { marcarErro(tel); if (!primeiroErro) primeiroErro = tel; } if (!renda.value.trim()) { marcarErro(renda); if (!primeiroErro) primeiroErro = renda; } if (primeiroErro) { primeiroErro.focus(); return false; } return true; } // Init document.addEventListener('DOMContentLoaded', function () { // Header: scroll var header = document.getElementById('header'); if (header) { function updateHeader() { var scrolled = window.scrollY || window.pageYOffset || document.documentElement.scrollTop; if (scrolled > 80) { header.classList.add('scrolled'); header.classList.add('visible'); } else { header.classList.remove('scrolled'); header.classList.remove('visible'); } } window.addEventListener('scroll', updateHeader, { passive: true }); updateHeader(); } // Menu hambúrguer var toggle = document.getElementById('menu-toggle'); var nav = document.getElementById('header-nav'); if (toggle && nav && header) { toggle.addEventListener('click', function () { var isOpen = nav.classList.toggle('active'); toggle.classList.toggle('active', isOpen); document.body.classList.toggle('menu-open', isOpen); if (isOpen) header.classList.add('visible'); }); nav.querySelectorAll('a').forEach(function (link) { link.addEventListener('click', function () { nav.classList.remove('active'); toggle.classList.remove('active'); document.body.classList.remove('menu-open'); var scrolled = window.scrollY || window.pageYOffset || document.documentElement.scrollTop; if (scrolled <= 80) header.classList.remove('visible'); }); }); } var telInput = document.getElementById('ad-tel'); if (telInput) mascaraTelefone(telInput); var simTelInput = document.getElementById('sim-tel'); if (simTelInput) mascaraTelefone(simTelInput); var simRendaInput = document.getElementById('sim-renda'); if (simRendaInput) mascaraRenda(simRendaInput); var waTelInput = document.getElementById('wa-tel'); if (waTelInput) mascaraTelefone(waTelInput); var galeriaEl = document.querySelector('.galeria-swiper'); if (galeriaEl) { var galeriaContainer = document.querySelector('#galeria .container'); var containerLeft = galeriaContainer ? Math.round(galeriaContainer.getBoundingClientRect().left) : 0; var slidesOffsetAfter = Math.max(0, window.innerWidth - containerLeft); var galeriaNavBar = document.querySelector('#galeria .galeria-nav-bar'); var galeriaNextBtn = document.querySelector('.galeria-next'); var galeriaPrevBtn = document.querySelector('.galeria-prev'); var galeriaSwiper = new Swiper('.galeria-swiper', { centeredSlides: false, slidesPerView: 'auto', spaceBetween: 42, resistanceRatio: 0, breakpoints: { 0: { spaceBetween: 17, }, 1024: { spaceBetween: 42, }, }, slidesOffsetBefore: containerLeft, slidesOffsetAfter: slidesOffsetAfter, initialSlide: 1, speed: 300, pagination: { el: '.galeria-paginacao', clickable: true, }, on: { afterInit: function() { var s = this; var firstSlide = s.slides[0]; if (firstSlide) { var slideW = firstSlide.offsetWidth; var correctOffset = Math.max(0, window.innerWidth - containerLeft - slideW); s.params.slidesOffsetAfter = correctOffset; s.update(); } var paginacaoEl = document.querySelector('.galeria-paginacao'); if (paginacaoEl) { var bullets = paginacaoEl.querySelectorAll('.swiper-pagination-bullet'); for (var i = s.slides.length; i < bullets.length; i++) { bullets[i].remove(); } } }, slideChange: function() { var s = this; requestAnimationFrame(function() { var activeSlide = s.slides[s.activeIndex]; if (!activeSlide) return; s.setTranslate(containerLeft - activeSlide.offsetLeft); }); }, }, }); if (galeriaNextBtn) { galeriaNextBtn.addEventListener('click', function() { var last = galeriaSwiper.slides.length - 1; if (galeriaSwiper.activeIndex < last) { galeriaSwiper.slideNext(); } else { galeriaSwiper.slideTo(0); } }); } if (galeriaPrevBtn) { galeriaPrevBtn.addEventListener('click', function() { if (galeriaSwiper.activeIndex > 0) { galeriaSwiper.slideTo(galeriaSwiper.activeIndex - 1); } else { galeriaSwiper.slideTo(galeriaSwiper.slides.length - 1); } }); } // Bloqueia arrasto além do último slide var _galStartX = 0; var _galMouseDown = false; galeriaEl.addEventListener('touchstart', function(e) { _galStartX = e.touches[0].clientX; galeriaSwiper.allowTouchMove = true; }, { passive: true }); galeriaEl.addEventListener('touchmove', function(e) { if (galeriaSwiper.activeIndex < galeriaSwiper.slides.length - 1) return; if (e.touches[0].clientX < _galStartX) galeriaSwiper.allowTouchMove = false; }, { passive: true, capture: true }); galeriaEl.addEventListener('touchend', function() { galeriaSwiper.allowTouchMove = true; }, { passive: true }); galeriaEl.addEventListener('mousedown', function(e) { _galStartX = e.clientX; _galMouseDown = true; galeriaSwiper.allowTouchMove = true; }); document.addEventListener('mousemove', function(e) { if (!_galMouseDown) return; if (galeriaSwiper.activeIndex < galeriaSwiper.slides.length - 1) return; if (e.clientX < _galStartX) galeriaSwiper.allowTouchMove = false; }, true); document.addEventListener('mouseup', function() { _galMouseDown = false; galeriaSwiper.allowTouchMove = true; }); } // Plantas - Tabs var plantasTabs = document.querySelectorAll('.plantas-tab'); var plantasInfos = document.querySelectorAll('.planta-info'); var plantaImgEl = document.getElementById('planta-img-principal'); var plantasDisclaimer = document.querySelector('.plantas-disclaimer'); if (plantasTabs.length) { plantasTabs.forEach(function(tab) { tab.addEventListener('click', function() { var planta = this.getAttribute('data-planta'); var novaImg = this.getAttribute('data-img'); var novoDisclaimer = this.getAttribute('data-disclaimer'); plantasTabs.forEach(function(t) { t.classList.remove('ativo'); }); this.classList.add('ativo'); plantasInfos.forEach(function(info) { info.classList.remove('ativo'); if (info.getAttribute('data-planta') === planta) info.classList.add('ativo'); }); // reset sub-tabs ao voltar para inferior var subtabs = document.querySelectorAll('.planta-subtab'); subtabs.forEach(function(st) { st.classList.remove('ativo'); }); var firstSubtab = document.querySelector('.planta-subtab'); if (firstSubtab) firstSubtab.classList.add('ativo'); if (plantaImgEl && novaImg) { plantaImgEl.style.opacity = '0'; setTimeout(function() { plantaImgEl.src = novaImg; plantaImgEl.style.opacity = '1'; }, 200); } if (plantasDisclaimer && novoDisclaimer) { plantasDisclaimer.textContent = novoDisclaimer; } }); }); } // Plantas - Sub-tabs (157 Duplex) var plantasSubtabs = document.querySelectorAll('.planta-subtab'); if (plantasSubtabs.length) { plantasSubtabs.forEach(function(subtab) { subtab.addEventListener('click', function() { var novaImg = this.getAttribute('data-img'); plantasSubtabs.forEach(function(st) { st.classList.remove('ativo'); }); this.classList.add('ativo'); if (plantaImgEl && novaImg) { plantaImgEl.style.opacity = '0'; setTimeout(function() { plantaImgEl.src = novaImg; plantaImgEl.style.opacity = '1'; }, 200); } }); }); } // Plantas - Modal var plantasImagem = document.querySelector('.plantas-imagem'); var plantaModal = document.getElementById('planta-modal'); var plantaModalImg = document.getElementById('planta-modal-img'); var plantaModalOverlay = document.getElementById('planta-modal-overlay'); var plantaModalFechar = document.getElementById('planta-modal-fechar'); function abrirPlantaModal() { if (plantaImgEl) plantaModalImg.src = plantaImgEl.src; plantaModal.classList.add('ativo'); document.body.style.overflow = 'hidden'; } function fecharPlantaModal() { plantaModal.classList.remove('ativo'); document.body.style.overflow = ''; } if (plantasImagem && plantaModal) { plantasImagem.addEventListener('click', abrirPlantaModal); plantaModalOverlay.addEventListener('click', fecharPlantaModal); plantaModalFechar.addEventListener('click', fecharPlantaModal); document.addEventListener('keydown', function(e) { if (e.key === 'Escape') fecharPlantaModal(); }); } // // Implantação - Tabs // var implTabs = document.querySelectorAll('.impl-tab'); // var implImgEl = document.getElementById('impl-img-principal'); // var implGrupos = document.querySelectorAll('.impl-grupo'); // if (implTabs.length) { // implTabs.forEach(function(tab) { // tab.addEventListener('click', function() { // var novaImg = this.getAttribute('data-img'); // var grupoAlvo = this.getAttribute('data-grupo'); // implTabs.forEach(function(t) { t.classList.remove('ativo'); }); // this.classList.add('ativo'); // implGrupos.forEach(function(g) { // g.style.display = g.getAttribute('data-grupo') === grupoAlvo ? '' : 'none'; // }); // if (implImgEl && novaImg) { // implImgEl.style.opacity = '0'; // setTimeout(function() { // implImgEl.src = novaImg; // implImgEl.style.opacity = '1'; // }, 200); // } // }); // }); // // Inicializa exibindo apenas o grupo da tab ativa // var tabAtiva = document.querySelector('.impl-tab.ativo'); // if (tabAtiva) { // var grupoInicial = tabAtiva.getAttribute('data-grupo'); // implGrupos.forEach(function(g) { // g.style.display = g.getAttribute('data-grupo') === grupoInicial ? '' : 'none'; // }); // } // } // // Implantação - Toggle detalhes (≤1024px) // var implToggleBtn = document.getElementById('impl-toggle-btn'); // var implConteudo = document.querySelector('.impl-conteudo'); // if (implToggleBtn && implConteudo) { // implToggleBtn.addEventListener('click', function() { // var aberto = implConteudo.classList.toggle('aberto'); // implToggleBtn.setAttribute('aria-expanded', aberto); // implToggleBtn.querySelector('.impl-toggle-label').textContent = aberto ? 'Ocultar detalhes' : 'Exibir detalhes'; // }); // } // // Implantação - Modal // var implImagem = document.querySelector('.impl-imagem'); // var implModal = document.getElementById('impl-modal'); // var implModalImg = document.getElementById('impl-modal-img'); // var implModalOverlay = document.getElementById('impl-modal-overlay'); // var implModalFechar = document.getElementById('impl-modal-fechar'); // function abrirImplModal() { // if (implImgEl) implModalImg.src = implImgEl.src; // implModal.classList.add('ativo'); // document.body.style.overflow = 'hidden'; // } // function fecharImplModal() { // implModal.classList.remove('ativo'); // document.body.style.overflow = ''; // } // if (implImagem && implModal) { // implImagem.addEventListener('click', abrirImplModal); // implModalOverlay.addEventListener('click', fecharImplModal); // implModalFechar.addEventListener('click', fecharImplModal); // document.addEventListener('keydown', function(e) { // if (e.key === 'Escape') fecharImplModal(); // }); // } // Decorado 360 - troca iframe inline var decBtns = document.querySelectorAll('.decorado-btn'); var decIframe = document.getElementById('decorado-iframe'); if (decIframe) { decBtns.forEach(function(btn) { btn.addEventListener('click', function() { decBtns.forEach(function(b) { b.classList.remove('ativo'); }); this.classList.add('ativo'); decIframe.src = this.getAttribute('data-tour'); }); }); } // Decorado 360 - bloqueia duplo clique sem interferir na navegação var decBlocker = document.getElementById('decorado-dblclick-blocker'); if (decBlocker) { decBlocker.addEventListener('mousedown', function() { decBlocker.style.pointerEvents = 'none'; }); document.addEventListener('mouseup', function() { if (decBlocker) decBlocker.style.pointerEvents = 'auto'; }); decBlocker.addEventListener('dblclick', function(e) { e.preventDefault(); e.stopPropagation(); }); } // Widget fixo + ícone WhatsApp var widget = document.getElementById('agendarWidget'); var closeBtn = document.getElementById('closeBtn'); var icoZap = document.querySelector('.ico-zap'); var widgetFechado = false; if (widget && closeBtn) { closeBtn.addEventListener('click', function(e) { e.preventDefault(); e.stopPropagation(); widget.classList.add('hidden'); widgetFechado = true; }); function atualizarFixos() { var scrollTop = window.pageYOffset || document.documentElement.scrollTop; var alturaJanela = window.innerHeight; var alturaDoc = document.documentElement.scrollHeight; var noFundo = scrollTop + alturaJanela >= alturaDoc - 200; var noTopo = scrollTop < 100; if (noFundo || noTopo) { widget.classList.add('hidden'); if (icoZap) icoZap.classList.add('hidden'); } else { if (!widgetFechado) widget.classList.remove('hidden'); if (icoZap) icoZap.classList.remove('hidden'); } } window.addEventListener('scroll', atualizarFixos, { passive: true }); atualizarFixos(); } });