// alert("Entra al main.js");
var arrayMonth = ["Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre"];
$('.dropdown-toggle').dropdown(); //initalize dropdown
// sticky menu fuctions when scrollbar downs shows logo and menu
var affixElement = '.sticky-m';
var affixElementFilter = '.sticky-f';
$(affixElement).affix({
offset : { // Distance of between element and top page
top : $(".header_top").outerHeight(true)
// when start #footer
// bottom: function () {
// return (this.bottom = $('#footer').outerHeight(true))
// }
}
});
$(affixElementFilter).affix({offset: {top: $(".header_top").outerHeight(true)} });
//var altura = $(affixElement).offset().top;
var altura = $('#elheader').height();
$(window).on('scroll', function() { // shows or hide logo sticky
//console.log("Filtros-top:"+alturaF)
//console.log("Menu-top:"+altura)
//console.log("Scroll:"+$(window).scrollTop())
/*var altura_del_header = $('.navigation-page').outerHeight(true);
var altura_de_filtros = $('#ControlsFilters').outerHeight(true);
//console.log("altura header = "+altura_del_header+" altura filtros = "+altura_de_filtros)
if ($(window).scrollTop() >= altura_del_header){
$('#ControlsFilters').addClass('fixedFilter');
} else {
$('#ControlsFilters').removeClass('fixedFilter');
}
*/
/*if ($(window).scrollTop() >= alturaF) {
console.log("entra")
/*if ($('.navbar-toggle').css("display") == 'none') { // if is not responsive
$('.logo-sticky').css('display', 'inline-block');
}
} else {
console.log("sale")
/*$('.logo-sticky').css('display', 'none');
}*/
var alto_menu = $("nav.navbar.bs-dark").height();
$(".menu-opener, .menu-opener-inner, .menu").removeClass('active');
$('#navbar-mobile-collapse').collapse('hide');
if ($(window).scrollTop() >= altura) {
if ($('.navbar-toggle').css("display") == 'none') { // if is not responsive
$('.logo-sticky').css('display', 'inline-block');
if($('.detail-prod-info').length){$('.detail-prod-info').css('top', alto_menu);};
}
} else {
$('.logo-sticky').css('display', 'none');
}
});
// sticky menu fuctions when scrollbar downs shows logo and mencountu
$(document).ready(function() {
if(location.pathname != "/client/login" && location.pathname != "/ambassador/login" ){
setCookie('currentview', location.pathname, 1);
}
// pixel salesforce
getTipoDispositivo();
CountDown();
WaterMark();
if(isMobile()){ // show parallax on mobile
$('.parallax-2').css('backgroundSize','cover');
$('.parallax-2').css('backgroundAttachment','scroll');
}
doLogout();
if ( $("#elheader").length ) {
//search_autocomplete();
//autocompleteMobile();
calcHeight();
}
$("#ui-id-1").addClass("ui-menu-autocomplete");
openMobileMenu();
$(".ddown").hover(function() {
if ($('.navbar-toggle').css("display") == 'none') { // if change up to 768px to know if is responsive
$('.dropdown-menu', this).fadeIn("fast");
}
}, function() {
if ($('.navbar-toggle').css("display") == 'none') { // if change up to 768px to know if is responsive
$('.dropdown-menu', this).fadeOut("fast");
}
});
if(typeof $.fn.dataTable !== 'undefined' ){
$.extend(true, $.fn.dataTable.defaults, {
"serverSide": true,
"processing": true,
"language": {
"sProcessing": "", // "Procesando...",
"sLengthMenu":"Mostrar _MENU_ registros",
"sZeroRecords": "No se encontraron resultados.",
"sEmptyTable": "Ningún dato disponible en esta tabla.",
"sInfo": "",
"sInfoEmpty": "",
"sInfoFiltered": "",
"sInfoPostFix": "",
"sSearch": "Buscar:",
"sUrl": "",
"sInfoThousands": ",",
"sLoadingRecords": "Cargando...",
"oPaginate": {
"sFirst": "Primero",
"sLast": "Último",
"sNext": "Siguiente",
"sPrevious": "Anterior"
},
"oAria": {
"sSortAscending": ": Activar para ordenar la columna de manera ascendente",
"sSortDescending": ": Activar para ordenar la columna de manera descendente"
}
},
"autoWidth" : true
});
}
$('.word-counter').each(function() {
$element = $(this);
$textarea = $('#' + $element.attr('for'));
$textarea.on('keyup change', function() {
this.value = this.value.substr(0, 254);
var charsRemaining = 254 - this.value.length;
$('.word-counter[for="' + this.id + '"]').html('' + (charsRemaining > -1 ? charsRemaining : 0) + '');
});
$textarea.val($textarea.val().substr(0, 254));
var charsRemaining = 254 - $textarea.val().length;
$('.word-counter[for="' + $('#textareareferences').prop('id') + '"]').html('' + (charsRemaining > -1 ? charsRemaining : 0) + '');
});
// funcion para girar
//ida();
function ida(){
$(".flip-box-inner").addClass("ida");
$(".flip-box-inner").removeClass("vuelta");
setTimeout(vuelta, 5000);
}
function vuelta(){
$(".flip-box-inner").addClass("vuelta");
$(".flip-box-inner").removeClass("ida");
setTimeout(ida, 5000)
}
viewCupon();
$(window).resize(function() {
if ( $("#elheader").length ) {
calcHeight();
}
});
navegador();
// margenes bottom para carga de secciones
}); // end document ready
function navegador(){
if(navigator.userAgent.match(/Android/i)){
$('#navegador').html('Android');
}
if(navigator.userAgent.match(/webOS/i)){
$('#navegador').html('webOS');
}
if(navigator.userAgent.match(/iPhone/i)){
$('#navegador').html('iPhone');
}
if(navigator.userAgent.match(/iPod/i)){
$('#navegador').html('iPod');
}
if(navigator.userAgent.match(/BlackBerry/i)){
$('#navegador').html('BlackBerry');
}
if(navigator.userAgent.match(/Windows Phone/i)){
$('#navegador').html('Windows Phone');
}
}
/*
function isMobile() {
if( navigator.userAgent.match(/Android/i)
|| navigator.userAgent.match(/webOS/i)
|| navigator.userAgent.match(/iPhone/i)
|| navigator.userAgent.match(/iPad/i)
|| navigator.userAgent.match(/iPod/i)
|| navigator.userAgent.match(/BlackBerry/i)
|| navigator.userAgent.match(/Windows Phone/i)
){
return true;
}
else {
return false;
}
}
*/
// gtag disparo de eventos
$('body').on('click', '.gtag-event', function() {
sendGtag(extractGtagData(this));
});
function openMobileMenu(){
$(".navbar-toggle").click(function() {
$(".menu-opener, .menu-opener-inner, .menu").toggleClass("active");
});
$(".close-mobile-menu").click(function() {
$(".menu-opener, .menu-opener-inner, .menu").removeClass('active');
$('#navbar-mobile-collapse').collapse('hide');
});
}
function changeLang(lang) {
$.ajax({
type : 'POST',
url : '/utils/lang',
data : {
lang : lang
},
dataType : 'json',
success : function(data) {
if(data.result == 'ok')
location.reload();
else
sendNoty('error',"Error al cambiar el idioma.");
}
});
}
function doLogout() {
$('.doLogout').on('click', function(event) {
$.ajax({
type : "POST",
url : "/client/do_logout",
dataType : "json",
success : function(data) {
deleteCouponsManual();
if (data.result == 'ok') {
if( getCookie('currentview') ){
document.location.href = getCookie('currentview');
}else{
document.location.href = "/"; // reload to homepage
}
// document.location.href = "/"; // reload to homepage
} else {
sendNoty('error',"Error al cerrar sesión.");
}
},
error : function() {
sendNoty('error',"Error al cerrar sesión.");
}
});
return false;
});
}
function sendNoty(type, msg, modal, timeout) {
if(!msg) msg = 'Empty Message';
if(!modal) modal = false;
if(!timeout) timeout = 3000;
switch (type) {
case 'alert':
noty({
type : type,
text : msg,
layout : 'topRight',
theme : 'relax',
dismissQueue : true,
modal : modal,
maxVisible : 5,
timeout : timeout,
closeWith : [ 'button' ],
progressBar: true,
animation: {
open: {
height: 'toggle'
},
close: {
height: 'toggle'
},
easing: 'swing',
speed: 500
}
});
break;
case 'success':
noty({
type : type,
text : msg,
layout : 'topRight',
theme : 'relax',
dismissQueue : true,
modal : modal,
maxVisible : 5,
timeout : timeout,
closeWith : [ 'button' ],
progressBar: true,
animation: {
open: {
height: 'toggle'
},
close: {
height: 'toggle'
},
easing: 'swing',
speed: 500
}
});
break;
case 'warning':
noty({
type : type,
text : msg,
layout : 'topRight',
theme : 'relax',
dismissQueue : true,
modal : modal,
maxVisible : 5,
timeout : timeout,
closeWith : [ 'button' ],
progressBar: true,
animation: {
open: {
height: 'toggle'
},
close: {
height: 'toggle'
},
easing: 'swing',
speed: 500
}
});
break;
case 'error':
noty({
type : type,
text : msg,
layout : 'topRight',
theme : 'relax',
dismissQueue : true,
modal : modal,
maxVisible : 5,
timeout : timeout,
closeWith : [ 'button' ],
progressBar: true,
animation: {
open: {
height: 'toggle'
},
close: {
height: 'toggle'
},
easing: 'swing',
speed: 500
}
});
break;
case 'information':
noty({
type : type,
text : msg,
layout : 'topRight',
theme : 'relax',
dismissQueue : true,
modal : modal,
maxVisible : 5,
timeout : timeout,
closeWith : [ 'button' ],
progressBar: true,
animation: {
open: {
height: 'toggle'
},
close: {
height: 'toggle'
},
easing: 'swing',
speed: 500
}
});
break;
default:
noty({
type : 'alert',
text : msg,
layout : 'topRight',
theme : 'relax',
dismissQueue : true,
modal : modal,
maxVisible : 5,
timeout : timeout,
closeWith : [ 'button' ],
progressBar: true,
animation: {
open: {
height: 'toggle'
},
close: {
height: 'toggle'
},
easing: 'swing',
speed: 500
}
});
break;
}
}
function blockUI(content) {
if(!content)
content = '
'
$.msg({
fadeIn : 0,
autoUnblock : false,
clickUnblock : false,
content : content,
bgPath:'/images/'
});
};
function unblockUI() {
$.msg('unblock');
};
function search_autocomplete(){
var basePath = 'https://';
$("#search").autocomplete({
minLength: 2,
select: function(event, ui){
$("#search").val(ui.item.name);
},
source: function(request, response){
$.ajax({
url:"/search",
data:{
term: request.term
},
dataType: "json",
success: function(data){
if(data.result == 'ok') {
response($.map(data.data, function(product, index) {
return {
id : product.Product.id,
code : product.Product.code,
name : product.Product.name,
price : product.Product.price,
category : product.Product.main_slug,
subcategory : product.Subcategory.slug,
main_photo : product.ProductImage[0].file_path
}
}));
} else {
if(data.data == 'error_extencion') {
$("#search").val('');
sendNoty('error', 'Busqueda no permitida!');
}
}
}
});
}
}).data("ui-autocomplete")._renderItem = function(ul, item){
return $("
")
.data("item.autocomplete", item)
.append(""+
""+
""+item.name+"
"+
"$"+item.price+"
")
.appendTo(ul);
}
$("#search").keydown(function(event) {
if(event.keyCode == 13) {
synonyms();
}
});
$('#buttonSearch').click(function() {
synonyms();
});
}
function synonyms() {
var valor = $.trim($("#search").val());
// _etmc.push(["setOrgId", "526003570"]);
// _etmc.push(["trackPageView", { "search" : valor }]);
window.location.href = '/'+valor;
}
function autocompleteMobile(){
var basePath = 'https://';
$("#autocompleteMobile").autocomplete({
minLength: 2,
select: function(event, ui){
$("#autocompleteMobile").val(ui.item.name);
},
source: function(request, response){
$.ajax({
url:"/search",
data:{
term: request.term
},
dataType: "json",
success: function(data){
if(data.result == 'ok') {
response($.map(data.data, function(product, index) {
return {
id : product.Product.id,
code : product.Product.code,
name : product.Product.name,
price : product.Product.price,
category : product.Category[0].slug,
subcategory : product.Subcategory.slug,
main_photo : product.ProductImage[0].file_path
}
}));
} else {
if(data.data == 'error_extencion') {
$("#autocompleteMobile").val('');
sendNoty('error', 'Busqueda no permitida!');
}
}
}
});
}
}).data("ui-autocomplete")._renderItem = function(ul, item){
return $("")
.data("item.autocomplete", item)
.append(""+
""+
""+item.name+"
"+
"$"+item.price+"
")
.appendTo(ul);
}
$("#autocompleteMobile").keydown(function(event) {
if(event.keyCode == 13) {
var valor = $.trim($("#autocompleteMobile").val());
window.location.href = '/'+valor;
}
});
}
function isMobile() {
if( navigator.userAgent.match(/Android/i)
|| navigator.userAgent.match(/webOS/i)
|| navigator.userAgent.match(/iPhone/i)
|| navigator.userAgent.match(/iPad/i)
|| navigator.userAgent.match(/iPod/i)
|| navigator.userAgent.match(/BlackBerry/i)
|| navigator.userAgent.match(/Windows Phone/i)
){
return true;
}
else {
return false;
}
}
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires="+ d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
function setCookieAmbassador(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*10800000)); //el dia actual + 3 horas
var expires = "expires="+ d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
function getCookie(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for(var i = 0; i = 22 && elDia <=23){
current_banner = buenFin_preventa_0; // PREVENTA
end_date_banner = '2025/5/24 00:00:00';
flagPromoActive = true;
}else if(elDia >= 24 && elDia <=25){ // PREVENTA SE VA
current_banner = buenFin_preventa_1;
end_date_banner = '2025/5/26 00:00:00';
flagPromoActive = true;
}
break;
case 6:
switch (elDia) {
case 3:
current_banner = buenFin_ultimasHoras;
end_date_banner = '2025/6/4 00:00:00';
flagPromoActive = true;
break;
case 4:
current_banner = bannerExtendPromo;
end_date_banner = '2025/6/5 00:00:00';
flagPromoActive = true;
break;
default:
break;
}
break;
default:
break;
}
}
// if(elMes === 5 && elAno === 2025){
// if(elDia >= 22 && elDia <=23){
// current_banner = buenFin_preventa_0; // PREVENTA
// end_date_banner = '2025/5/24 00:00:00';
// flagPromoActive = true;
// }else if(elDia >= 24 && elDia <=25){ // PREVENTA SE VA
// current_banner = buenFin_preventa_1;
// end_date_banner = '2025/5/26 00:00:00';
// flagPromoActive = true;
// }
// // else if(elDia == 3 && elMes == 6 ){ // Ultimas Horas
// // current_banner = buenFin_ultimasHoras;
// // end_date_banner = '2025/6/4 00:00:00';
// // flagPromoActive = true;
// // }
// }
// if(elMes == 6 && elDia == 3 && elAno === 2025){ // Ultimas Horas
// current_banner = buenFin_ultimasHoras;
// end_date_banner = '2025/6/4 00:00:00';
// flagPromoActive = true;
// }
// if(elMes == 6 && elDia == 4 && elAno === 2025){ // Ultimas Horas
// current_banner = bannerExtendPromo;
// end_date_banner = '2025/6/5 00:00:00';
// flagPromoActive = true;
// }
if(flagPromoActive){
if($("#header-top").length){
$('#header-top').html(current_banner);
$('#header-top').show();
if($("#clock").length){
$('#clock').countdown(end_date_banner, function(event) {
//$(this).html(event.strftime('%H %M %S'));
$('#dias').html(event.strftime('%D'));
$('#horas').html(event.strftime('%H'));
$('#minutos').html(event.strftime('%M'));
});
}
}
}else{
$('#header-top').show();
}
$('#header-top').hide();
if(elMes === 04 && elAno === 2024){
if(elDia >= 25 && elDia <=28){
if($("#header-top").length){
var lafecha = '2024/04/29 00:00:00';
$('#header-top').html(elheader);
$('#header-top').show();
if($("#clock").length){
$('#clock').countdown(lafecha, function(event) {
//$(this).html(event.strftime('%H %M %S'));
$('#dias').html(event.strftime('%D'));
$('#horas').html(event.strftime('%H'));
$('#minutos').html(event.strftime('%M'));
});
}
}
}else{ $('#header-top').show(); }
}else if(elMes === 05 && elAno === 2024){
if(elDia >= 9 && elDia <=12){
if($("#header-top").length){
var lafecha = '2024/05/13 00:00:00';
$('#header-top').html(elheader2);
$('#header-top').show();
if($("#clock").length){
$('#clock').countdown(lafecha, function(event) {
//$(this).html(event.strftime('%H %M %S'));
$('#dias').html(event.strftime('%D'));
$('#horas').html(event.strftime('%H'));
$('#minutos').html(event.strftime('%M'));
});
}
}
}else{ $('#header-top').show(); }
if(elDia >= 13 && elDia <=14){
if($("#header-top").length){
var lafecha = '2024/05/15 00:00:00';
$('#header-top').html(elheader3);
$('#header-top').show();
if($("#clock").length){
$('#clock').countdown(lafecha, function(event) {
//$(this).html(event.strftime('%H %M %S'));
$('#dias').html(event.strftime('%D'));
$('#horas').html(event.strftime('%H'));
$('#minutos').html(event.strftime('%M'));
});
}
}
}else{ $('#header-top').show(); }
if(elDia >= 20 && elDia <=23){
if($("#header-top").length){
var lafecha = '2024/05/24 00:00:00';
$('#header-top').html(elheader4);
$('#header-top').show();
if($("#clock").length){
$('#clock').countdown(lafecha, function(event) {
//$(this).html(event.strftime('%H %M %S'));
$('#dias').html(event.strftime('%D'));
$('#horas').html(event.strftime('%H'));
$('#minutos').html(event.strftime('%M'));
});
}
}
}else{ $('#header-top').show(); }
}else{
$('#header-top').show();
}
}
function WaterMark(){
var dominio = document.domain;
var DL2 = dominio.split(".", 2)
//console.log("dominio = "+DL2[0])
if(DL2[0] === "www-beta-1" || DL2[0] === "www-beta-2" || DL2[0] === "www-beta-3" || DL2[0] === "www-beta-4" || DL2[0] === "www-beta-5" || DL2[0] === "www-beta-6" || DL2[0] === "www-beta-7" || DL2[0] === "www-beta-8" || DL2[0] === "www-test" || DL2[0] === "www-staging"){
$('.watermark').show();
}else{
$('.watermark').remove();
}
}
/*FUNCIONES NUEVA VERSION */
function rollover(){
//console.log("entra")
$(".btnback img").animate({
marginLeft: "-10px",
marginRight: "20px"
}, 500, function() {
// Animation complete.
});
}
function rollout(){
//console.log("sale")
$(".btnback img").animate({
marginLeft: "0px",
marginRight: "10px"
}, 500, function() {
// Animation complete.
});
}
function setFormatMoney(monto){
if(!isNaN(monto)){
return "$"+ monto.toFixed(0).replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,")+" MXN";
}else{
if( monto === "" || monto === null || monto === undefined ){
return "$0 MXN";
}else{
return "Error - "+ monto;
}
}
}
function setFormatMoneyMens(monto){
if(!isNaN(monto)){
//return "$"+ monto.toFixed(2).replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,")+" MXN"; // con 2 decimales
return "$"+ monto.toFixed(0).replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,")+" MXN";
}else{
if( monto === "" || monto === null || monto === undefined ){
return "$0 MXN";
}else{
return "Error - "+ monto;
}
}
}
function setFormatMoneyPrice(monto){
if(!isNaN(monto)){
return "$"+ monto.toFixed(0).replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
}else{
if( monto === "" || monto === null || monto === undefined ){
return "$0";
}else{
return "Error - "+ monto;
}
}
}
function setdate(date){
// console.log("Fecha a transforma: "+ date);
if(date == null)
return "";
if(date !== undefined || date !== "" ){
var temp = date.split("-");
return temp[2]+"/"+temp[1]+"/"+temp[0];
}else{
return date;
}
}
function setDateLarge(date){
if(date === null )
return "";
if(date !== undefined || date !== ""){
//console.log("Fecha a convertir: "+ date);
var temp = date.split("-");
var mes = parseInt(temp[1])-1;
return temp[2]+" de "+ arrayMonth[mes] +" de "+temp[0];
}else{
return date;
}
}
function formatDateDB(date){
if(date== null){
return "";
} else{
var month = date.getMonth()+1;
var day = date.getDate();
var year = date.getFullYear();
// if(month.length < 2)
// month = '0'+ month;
// if(day.length < 2)
// day = '0'+ day;
return year+"-"+month+"-"+day;
}
}
function showObjetString(dataObject,text){
var mensaje = "";
mensaje = text!==null? text+": "+ JSON.stringify(dataObject): "Valor del objeto: "+JSON.stringify(dataObject);
console.log(mensaje);
}
function validJustNumbers(e){
var keynum = window.event ? window.event.keyCode : e.which;
if (keynum < 48 || keynum > 57){
e.preventDefault();
}
}
function deleteCouponsManual(){
$.ajax({
type : "POST",
url : "/shoppingcart/delete_coupons",
dataType : "json",
success : function(request) {}
});
}
function imgError(imgClass){
$("."+imgClass).each(function () {
$(this).error(function(){
$(this).attr("src","/images/products/default-image.jpg");
});
});
}
function maxLengthCP(object){
if (object.value.length > 5)
object.value = object.value.slice(0, 5)
}
function sort_Json(data, key, orden) {
return data.sort(function (a, b) {
var x = a[key],
y = b[key];
if (orden === "asc") {
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
}
if (orden === "desc") {
return ((x > y) ? -1 : ((x < y) ? 1 : 0));
}
});
}
function validDomain(mail){
// var mail = "antoniodzc@tamarindo.com";
var domain = "TAMARINDO.COM";
var temp = mail.split("@");
var maildomain = temp[1];
return maildomain.toUpperCase() != domain ;
}
function getQuantityGroup(productsGroup, idProducto){
countTemp = 0 ;
for (const i in productsGroup) {
if(productsGroup[i].id == idProducto){
countTemp++;
}
}
return countTemp;
}
//ajustar altos
function calcHeight(){
var ancho = document.documentElement.clientWidth;
var height1 = document.getElementById('headerCloseCart');
var elAltoCloseCart = height1.clientHeight;
var height2 = document.getElementById('headerCart');
var elAltoCart = height2.clientHeight;
var height3 = document.getElementById('headerCartTeflon');
var elAltoCarTeflon = height3.clientHeight;
var height4 = document.getElementById('headerCartRes');
var elAltoCartRes = height4.clientHeight;
var height5 = document.getElementById('headerCloseCart');
var elAltoCartClose = height5.clientHeight;
var HeightTot = elAltoCloseCart + elAltoCart + elAltoCarTeflon + elAltoCartRes + 20;
var HeightHeadCart = elAltoCart + elAltoCartClose;
//console.log('alto = '+HeightTot);
/*AJUSTAR EL ALTO DEL SLIDER AL INICIO*/
var elheader = document.getElementById('elheader');
var elAlto = elheader.clientHeight;
/*AJUSTAR EL ALTO DEL SLIDE 2 y 3*/
var elheaderScroll = document.getElementById('headerScroll');
var elAltoScroll = elheaderScroll.clientHeight;
//console.log("el alto = "+elAlto)
/*HEIGHT DEL SLIDER*/
//$('.carousel-inner .image').css({'height': 'calc(100vh - '+elAlto+'px )'});
/*HEIGHT DEL SLIDER_2*/
if ( $("#slide_2").length ) {
$('#slide_2').css({'height': 'calc(100vh - '+elAltoScroll+'px )'});
}
/*HEIGHT DEL SLIDER_3*/
if ( $("#slide_3").length ) {
$('#slide_3').css({'height': 'calc(100vh - '+elAltoScroll+'px )'});
}
/*HEIGHT DEL SHOOPTHELOOK*/
$('.shoplook .img').css({'height': 'calc(100vh - '+elAltoScroll+'px )'});
//$('.shoplook .img').css({'height': '100vh'});
if(ancho<=481){
/*
if($('#360').length){
$('#360').css({ 'display': 'block' });
}
*/
//$('#itemsCart').css({'height': 'auto'});
}else{
/*
if($('#360').length){
$('#360').remove();
}
*/
//$('#itemsCart').css({'height': 'calc(100% - '+HeightTot+'px )'});
//$('#contenidoCart').css({'height': 'calc(100% - '+HeightHeadCart+'px )'});
}
}
function viewCupon() {
$('#cuponesDesc').on('click', function (event) {
$(this).css({ 'display': 'none' });
$('#addcupon').css({ 'display': 'table-row' });
$("#numCupon").focus();
calcHeight();
});
$('#numCupon').blur(function () {
// console.log("entra viewCupon()")
numcup = $("#numCupon").val();
if (numcup == "") {
$('#addcupon').css({ 'display': 'none' });
$('#cuponesDesc').css({ 'display': 'revert' });
} else {
}
});
}
function offRecomendados(){
$('.recomendados.recomendados-carrito').hide();
$('.carrito .shopping-cart-menu').css({ 'width': '100%' });
}
function onRecomendados(){
$('.recomendados.recomendados-carrito').show();
var ancho = document.documentElement.clientWidth;
if(ancho<=770){
$('.carrito .shopping-cart-menu').css({ 'width': '100%' });
}else{
$('.carrito .shopping-cart-menu').css({ 'width': '70%' });
}
}
function cartDown(){
var ancho = document.documentElement.clientWidth;
if(ancho<=770){
//$('#contenidoCart').animate({scrollTop: $("#itemsCart").offset().top - 110}, 1000);
//console.log('chico');
$("#contenidoCart").animate({ scrollTop: - $('.shopping-cart-menu').height() }, 1000);
}else{
$('.shopping-cart-menu').animate({scrollTop: $(".codPosEnv").offset().top}, 1000);
}
}
//Setear Estrellas
function initBarRating() {
//console.log('señalEstrellas');
$('.reviews-slct').each(function () {
var sc = $(this).attr("score");
var id = $(this).attr("id");
setBarRating(id, sc);
//console.log("id = "+id+" score = "+sc);
});
}
function setBarRating(id, score) {
//console.log('señalEstrellasSet');
var stars = 0;
if (score != 0) {
stars = score * 5 / 100;
}
if($('#'+id).hasClass("done")){
//console.log("si lo tiene "+id);
}else{
$('#'+id).toggleClass("done")
//console.log('no lo tiene '+id);
$('#' + id).barrating({
theme: 'fontawesome-stars-o',
readonly: true,
emptyValue: 0,
initialRating: stars
});
}
//$('#'+id).addClass("done");
}
// Cargar Video Slider
function getTipoDispositivo(){
tipoDispositivo = "Desktop"; //D = Desktop; T = Tablet; M = Movil;
tipoOrientacion = "Horizontal";
if(window.orientation == 0){
tipoOrientacion = "Vertical";
}else{
tipoOrientacion = "Horizontal";
}
if( screen.width <= 480 ) {
tipoDispositivo = "Movil";
}else if(screen.width > 480 && screen.width <= 768) {
tipoDispositivo = "Tablet";
}else{
tipoDispositivo = "Desktop";
}
// console.log("Tipo de Dispositivo: "+ tipoDispositivo);
// console.log("Tipo de Orientación: "+ tipoOrientacion);
var video_url_mp4 = "";
var video_url_ogg = "";
var video_url_webm = "";
if(tipoDispositivo == "Movil" && tipoOrientacion == "Vertical"){
video_url_mp4 = $("#bgvid").data( "video_url_mp4_mob" );
video_url_ogg = $("#bgvid").data( "video_url_ogg_mob" );
video_url_webm = $("#bgvid").data( "video_url_webm_mob" );
}else{
video_url_mp4 = $("#bgvid").data( "video_url_mp4_des" );
video_url_ogg = $("#bgvid").data( "video_url_ogg_des" );
video_url_webm = $("#bgvid").data( "video_url_webm_des" );
}
$("#bgvid video").first().attr('src','');
$('#bgvid').html('');
$('#bgvid').html(`
`);
$("#bgvid").load();
}
window.onorientationchange = function(event) {
getTipoDispositivo();
};
$('#icon-search').on('click', function() {
$('#autocomplete .aa-Autocomplete button').trigger('click');
});
function validate_login_generic(element_mail, element_pwd){
var caract = new RegExp(/^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/);
element_mail.keyup(function(){
element_mail.parent().removeClass('has-error');
element_mail.parent().children("span").text("").hide();
});
element_pwd.keyup(function(){
element_pwd.parent().removeClass('has-error');
element_pwd.parent().children("span").text("").hide();
});
var email = element_mail.val();
var password = element_pwd.val();
console.log('email generic: '+email);
console.log('password generic: '+password);
if( email == null || email.length == 0 || /^\s+$/.test(email) ) {
element_mail.parent().attr("class","form-group has-error");
element_mail.parent().children("span").text("Ingresa tu correo electrónico.").show();
element_mail.parent().shake();
return false;
}
if( !caract.test(email) ) {
element_mail.parent().attr("class","form-group has-error");
element_mail.parent().children("span").text("Ingresa un correo electrónico válido.").show();
element_mail.parent().shake();
return false;
}
if( password == null || password.length == 0 || /^\s+$/.test(password) ) {
element_pwd.parent().attr("class","form-group has-error");
element_pwd.parent().children("span").text("Ingresa tu contraseña.").show();
element_pwd.parent().shake();
return false;
}
if(!validDomain(email)){
element_mail.parent().attr("class","form-group has-error");
element_mail.parent().children("span").text("Dominio restringido").show();
element_mail.parent().shake();
return false;
}
return true;
}
function validate_field_generic(field_element){
var value_field_element = field_element.val();
if( value_field_element == null || value_field_element.length == 0 || /^\s+$/.test(value_field_element) ) {
field_element.parent().shake();
field_element.focus();
return false;
}
return true;
}
if($('section.sectioned').length){
var marBot = 0;
if($("#slider").length){var marBot = '200px';}
if($("section.new.product").length){var marBot = '200px';}
const sections = document.querySelectorAll('section.sectioned');
const options = {
rootMargin: marBot,
};
const observer = new IntersectionObserver(function
(entries, observer){
entries.forEach(entry => {
if(entry.isIntersecting) {
var laURL = '/sections?sec='+entry.target.id;
if(entry.target.dataset.category){laURL+= '&category='+entry.target.dataset.category;}
if(entry.target.dataset.subcategory){laURL+= '&subcategory='+entry.target.dataset.subcategory;}
if(entry.target.dataset.sku){laURL+= '&sku='+entry.target.dataset.sku;}
$(entry.target).load(laURL, function(){
//console.log(laURL);
//Section's - Home
if(entry.target.id == 'cont_slide_2' || entry.target.id == 'cont_slide_3'){
calcHeight();
}
if(entry.target.id == 'car_prod_new' || entry.target.id == 'car_view' || entry.target.id == 'car_feat' || entry.target.id == 'car_onlystore'){
initBarRating();
}
if(entry.target.id == 'car_prod_new'){
goCarouselNewsProducts();
}
if(entry.target.id == 'car_feat'){
goCarouselFeatured();
}
if(entry.target.id == 'car_onlystore'){
goCarouselOnlyStore();
console.log("entraOnly")
}
if(entry.target.id == 'car_view'){
if($(".carousel-vistos").length){
goCarouselViewed();
}
}
if(entry.target.id == 'banner_home_1' || entry.target.id == 'banner_home_2'){
$('#'+entry.target.id)[0].style.setProperty('height', 'auto', 'important');
}
//Section's - Product
if(entry.target.id == 'cont-carprodnue-desktop' || entry.target.id == 'cont-carprodnue-mobile'){
initBarRating();
goCarouselNewsProductsProd();
}
if(entry.target.id == 'cont-reviews-desktop' || entry.target.id == 'cont-reviews-mobile'){
initRatingComms();
}
if(entry.target.id == 'cont-relacionados-desktop' || entry.target.id == 'cont-relacionados-mobile'){
initBarRating();
goCarouselRelacionadosProd();
}
if(entry.target.id == 'cont-vistos-desktop' || entry.target.id == 'cont-vistos-mobile'){
initBarRating();
goCarouselVistosProd();
}
if(entry.target.id == 'cont-seofooter-desktop' || entry.target.id == 'cont-seofooter-mobile'){
}
});
observer.unobserve(entry.target);
//console.log(entry.target.id);
}
// console.log(entry.target.id);
});
}, options);
// loop
sections.forEach( section => {
observer.observe(section);
});
};
function validate_text_field(e, option){
var tecla = (document.all) ? e.keyCode : e.which;
if (tecla == 8 || tecla== 13) { return true; }
let patron = "";
switch (option) {
case "textfree": // Campo de mensajes o texto Libre
if (tecla == 124) { return false;}
return true;
break;
case "number":
patron = /^\d+$/i; // Campo Solo Numeros
break;
case "email":
patron = /^[a-zA-Z0-9@ \._-]+$/i; // Campo para correo
break;
case "address":
patron = /^[a-zA-ZñÑ0-9@ \.#+=_-]+$/i; // Campo para direcciones
break;
case "text":
default:
patron = /^[a-zA-ZñÑ ]+$/i; // Campo Solo Letras y espacios en blanco
break;
}
return patron.test(String.fromCharCode(tecla));
}
$(document).on("keypress", "#autocomplete-0-input", function (e) {
var key = (document.all) ? e.keyCode : e.which;
if (key == 124) { return false;}
});