jQuery.fn.forceNumericOnly = function() { return this.each(function() { jQuery(this).keydown(function(e) { if (e.shiftKey) { return false; } var key = e.charCode || e.keyCode || 0; // allow backspace, tab, delete, arrows, numbers and keypad numbers ONLY return ( key == 8 || key == 9 || key == 46 || (key >= 37 && key <= 40) || (key >= 48 && key <= 57) || (key >= 96 && key <= 105)); }); }); }; jQuery(document).ready(function() { placeHolder(); }); function placeHolder() { var input = document.createElement("input"); if(('placeholder' in input) == false) { jQuery('[placeholder]').focus(function() { var i = jQuery(this); if(i.val() == i.attr('placeholder')) { i.val('').removeClass('placeholder'); if(i.hasClass('password')) { i.removeClass('password'); this.type='password'; } } }).blur(function() { var i = jQuery(this); if(i.val() == '' || i.val() == i.attr('placeholder')) { if(this.type == 'password') { i.addClass('password'); this.type = 'text'; } i.addClass('placeholder').val(i.attr('placeholder')); } }).blur().parents('form').submit(function() { jQuery(this).find('[placeholder]').each(function() { var i = jQuery(this); if(i.val() == i.attr('placeholder')) i.val(''); }) }); } } var Galicia = { DEFAULT_CURRENCY: 'ARS', DELAY: 1000, userPoints: 0, pointsValue: null, pointValuePerRange: null, conversion: 1, currency: null, currencies: null, currenciesName: { ARS: "pesos", USD: "dólares", EUR: "euros", BRL: "reales" }, limits: null, //defaultLimit : 100, maxLimit : 250000, section: null, maxPrice: 0, logging: true, checkout: 0, cookie: { path: "/", domain: false }, prices: null, invalidMessageTime: 250, invalidMessageTimeout: null, totalProducts: 1, logMsg: null, //verificar o borrar! //german log: function (methodName, message) { if (!Galicia.logging) { return; } msg = "[galicia.js.php] [" + methodName + "] " + message; this.writeLogMsg(msg); //loguear error solamente! //german }, writeLogMsg: function (msg) { var url = window.location.origin + "/logjs/js-logger.php" jQuery.ajax({ url : url, data : { msg : msg }, type : 'post', error: function (jqXHR, textStatus, errorThrown) { console.log('Error: ' + errorThrown); } }) }, product: function(){ if ( jQuery('.cluster-flight').length ){ return 'vuelos'; } else if ( jQuery('.cluster-hotel').length ){ return 'hoteles'; } else if ( jQuery('cotizaciones-listado').length ){ return 'cotizacion'; } return 'paquetes'; } }; (function ($, g) { g.currencies = currencyTable; g.currency = currencyDefault; g.pointsToMoney = function (points, floor) { if (typeof floor == 'undefined' ) { return Math.ceil(points * g.getConversion() * g.getPointsValue(points)); } else { return Math.floor(points * g.getConversion() * g.getPointsValue(points)); } } g.moneyToPoints = function (money) { return Math.ceil( (money / g.getConversion()) / g.getPointsValueMoney(money) ); } g.getPointsValueMoney = function (money) { if (Galicia.pointValuePerRange != null) { pricePointValue = Galicia.pointValuePerRange[0].value * g.getConversion(); enRango = false; Galicia.pointValuePerRange.each(function(rangeObject,index) { rangePrice = rangeObject.value; pricePoint = money / (rangePrice * g.getConversion()); if (pricePoint >= rangeObject.start && pricePoint <= rangeObject.end) { enRango = true; pricePointValue = rangePrice * g.getConversion(); } if ((pricePoint <= rangeObject.start) && !enRango) { pricePointValue = rangePricePrev * g.getConversion(); enRango = true; } rangePricePrev = rangeObject.value; }); return pricePointValue; } //loguear Galicia.pointValuePerRange es null this.log("getPointsValueMoney", "Galicia.pointValuePerRange es null"); return Galicia.pointValuePerRange; } g.getPointsValue = function (points, price) { if (Galicia.pointValuePerRange != null) { var pointValueRange = Galicia.pointValuePerRange[0].value; Galicia.pointValuePerRange.each(function(rangeObject,index) { if (points >= rangeObject.start && points <= rangeObject.end) { productPointsAux = price / (rangeObject.value * g.getConversion()); productPoint = g.calculatePoints(price); if(productPointsAux g.maxPrice) { g.maxPrice = amount; } $(this).data("absolute_value", amount); }); g.updatePrices('moneda'); }; g.currencyChanged = function (currency) { jQuery("#converter form").submit(); } g.getLimit = function () { var limit = g.defaultLimit; if (typeof g.limits == 'object' && g.limits !== null) { limit = g.limits[this.section]; } return limit; } g.showInvalidValue = function (message) { if (!$("#converter-value").length) { return; } clearTimeout(this.invalidMessageTimeout); this.invalidMessageTimeout = setTimeout(function () { $(".error-box").show(); $(".error-box .error-message").html(g.MESSAGES[message]); $(".btn.btn-canjear").addClass("disable"); }, this.invalidMessageTime); }; g.hideInvalidValue = function () { clearTimeout(this.invalidMessageTimeout); this.invalidMessageTimeout = setTimeout(function () { $(".error-box").hide(); $(".btn.btn-canjear").removeClass("disable"); }, this.invalidMessageTime); }; g.addThousandsSeparator = function(value) { value = value.toString().replace('.', ','); return value.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1."); } g.updatePrices = function (ActionMode) { var money = parseInt($("#converter-value").val(), 10) || 0; var type = 'puntos'; var typeIsPoints = true; // Devuelve los puntos o false var points = typeIsPoints && parseInt($("#converter-value").val(), 10); var flightDebuggerExists = $('.debuggerFlight').length != 0 ? true : false; var hotelDebuggerExists = $('.debuggerHotel').length != 0 ? true : false; if (!points) { points = 0; } var limit = g.getLimit(); var atLeastOneValueIsValid = type == 'puntos'; // Fee Breakdown (desglose de tarifas) var fee_breakdown = ( $('#fee_breakdown').length && parseInt($('#fee_breakdown').val()) == 1 ); this.hideInvalidValue(); if (typeIsPoints && points < limit) { points = limit; this.showInvalidValue("MIN"); } if(g.userPoints!=-1) { if (points && points > g.userPoints) { this.showInvalidValue("POINTS"); } } /* if (!points) { points = g.moneyToPoints(this.maxPrice) || 0; } */ totalPoints = points; //points = points / g.totalProducts; i=0; if( ActionMode == 'moneda' ){ // Metodo para actualizar los puntos g.prices.each(function (index, value) { if ($(this).hasClass("total")) { points = totalPoints; } var elAmount = $(".amount", this); var elCurrency = $(".currency", this); var elPoints = $(".points", this); var priceId = $(this).attr('id'); var isClusterFlight = $('.cluster-flight').length && typeof priceId == 'undefined'; var isClusterFlightMin = $('.cluster-flight').length && typeof priceId != 'undefined'; var price = $(this).data("absolute_value") * g.getConversion() / g.originalConversion; var newPrice = 0; var pointsShowed; var totalProducts = $(this).hasClass("total") ? 1 : g.totalProducts; if (type == 'puntos') { newPrice = price - g.calculatePrice(points, price); var productPoints = g.calculatePoints(price); var pointsShowed = (productPoints < points) ? productPoints : points; if (index == 0) { } } else { newPrice = money / totalProducts; if (price < newPrice) { newPrice = price; } var pointsShowed = g.calculatePoints(price - newPrice); if (limit && pointsShowed < limit) { pointsShowed = limit; newPrice = price - g.calculatePrice(pointsShowed, price); } if ($(this).hasClass('prices-points') && (pointsShowed <= g.userPoints)) { atLeastOneValueIsValid = true; } } /*if (g.totalProducts > 1) { pointsShowed = ""; } else { pointsShowed = Math.ceil(pointsShowed); }*/ pointsShowed = Math.ceil(pointsShowed); var pointsHtml; if (!$(this).hasClass('prices-points')) { newPrice = price; } if (!$(this).hasClass('avg-price')) { newPrice = Math.round(newPrice); } else { newPrice = newPrice.toFixed(1); if( newPrice.indexOf('.0') > -1 ){ newPrice = Math.round(newPrice); } } if (flightDebuggerExists) { $('#debuggerPointValue', '.cluster-flight').text(g.getPointsValue(pointsShowed) / g.getConversion()); } if (hotelDebuggerExists) { $('#debuggerPointValue', '.habitacion').text(g.getPointsValue(pointsShowed) / g.getConversion()+' USD'); } if (newPrice > 0) { $('.final-price-plus', this).show(); $('.final-price-plus', $('#'+$(this).attr('overlay'))).show(); //Necesito la palabra puntos con P mayuscula en el detalle... var puntosText = $('body').hasClass('page-hotel-detail') ? 'Puntos' : 'puntos'; pointsHtml = " " + pointsShowed + " " + puntosText + " +"; var amountHtml = "" + g.addThousandsSeparator(newPrice) + ""; elAmount.show().html(amountHtml); elCurrency.show(); if ( isClusterFlightMin ){ // Estoy en flight min? $("strong", '#'+priceId).show(); } // Si estoy en aereos y no hay desglose, todo eso mas que no este en el precio colapsado if (isClusterFlight && !fee_breakdown){ $("strong", this).show(); } // overlay para mapa $('.amount', $('#'+$(this).attr('overlay'))).show().html(g.addThousandsSeparator(newPrice)); $('.currency', $('#'+$(this).attr('overlay'))).show().html(currencyTable[elCurrency.attr('code')].symbol); } else { $('.final-price-plus', this).hide(); var puntosText = $('body').hasClass('page-hotel-detail') ? 'Puntos' : 'puntos'; pointsHtml = " " + pointsShowed + " " + puntosText + ""; elAmount.hide(); elCurrency.hide(); // overlay para mapa $('.amount', $('#'+$(this).attr('overlay'))).hide(); $(".currency", $('#'+$(this).attr('overlay'))).hide(); $('.final-price-plus', $('#'+$(this).attr('overlay'))).hide(); //********************** if ( isClusterFlightMin ){ // Estoy en flight min? amountHtml = "0"; $('.amount', '#'+priceId).show().html(amountHtml); $(".currency", '#'+priceId).show(); $("strong", '#'+priceId).hide(); }else if( $(this).hasClass('charge-cargos') ){ amountHtml = "0"; $('.amount', this).show().html(amountHtml); $(".currency", this).show(); } // Seteos especiales para aereos if (isClusterFlight){ // Si no hay desglose, todo eso mas que no este en el precio colapsado if (!fee_breakdown){ $("strong", this).hide(); } } //********************** } //********************** if ($('.points-value', this).length > 0){ $('.points-value', this).html(g.addThousandsSeparator(pointsShowed)); $('.points-value', '#'+$(this).attr('overlay')).html(g.addThousandsSeparator(pointsShowed)); } $(this).addClass("show"); }); } else { // Metodo para actualizar los montos en general g.pricesPoints.each(function () { if ($(this).hasClass("total")) { points = totalPoints; } var elAmount = $(".amount", this); var elCurrency = $(".currency", this); var elPoints = $(".points", this); var priceId = $(this).attr('id'); var isClusterFlight = $('.cluster-flight').length && typeof priceId == 'undefined'; var isClusterFlightMin = $('.cluster-flight').length && typeof priceId != 'undefined'; var price = $(this).data("absolute_value") * g.getConversion() / g.originalConversion; var newPrice = 0; var pointsShowed; var totalProducts = $(this).hasClass("total") ? 1 : g.totalProducts; if (type == 'puntos') { newPrice = price - g.calculatePrice(points, price); var productPoints = g.calculatePoints(price); var pointsShowed = (productPoints < points) ? productPoints : points; } else { newPrice = money / totalProducts; if (price < newPrice) { newPrice = price; } var pointsShowed = g.calculatePoints(price - newPrice); if (limit && pointsShowed < limit) { pointsShowed = limit; newPrice = price - g.calculatePrice(pointsShowed, price); } if (pointsShowed <= g.userPoints) { atLeastOneValueIsValid = true; } } /*if (g.totalProducts > 1) { pointsShowed = ""; } else { }*/ pointsShowed = Math.ceil(pointsShowed); var pointsHtml; if (flightDebuggerExists) { $('#debuggerPointValue', '.cluster-flight').text(g.getPointsValue(pointsShowed) / g.getConversion()); } if (hotelDebuggerExists) { $('#debuggerPointValue', '.habitacion').text(g.getPointsValue(pointsShowed) / g.getConversion()+' USD'); } if (newPrice > 0) { newPrice = Math.round(newPrice); $('.final-price-plus', this).show(); $('.final-price-plus', $('#'+$(this).attr('overlay'))).show(); //Necesito la palabra puntos con P mayuscula en el detalle... var puntosText = $('body').hasClass('page-hotel-detail') ? 'Puntos' : 'puntos'; pointsHtml = " " + pointsShowed + " " + puntosText + " +"; amountHtml = "" + g.addThousandsSeparator(newPrice) + ""; elAmount.show().html(amountHtml); elCurrency.show(); if ( isClusterFlightMin ){ // Estoy en flight min $("strong", '#'+priceId).show(); } // Si estoy en aereos y no hay desglose, todo eso mas que no este en el precio colapsado if (isClusterFlight && !fee_breakdown){ $("strong", this).show(); } // overlay para mapa $('.amount', $('#'+$(this).attr('overlay'))).show().html(g.addThousandsSeparator(newPrice)); $('.currency', $('#'+$(this).attr('overlay'))).show().html(currencyTable[elCurrency.attr('code')].symbol); } else { $('.final-price-plus', this).hide(); var puntosText = $('body').hasClass('page-hotel-detail') ? 'Puntos' : 'puntos'; pointsHtml = " " + pointsShowed + " " + puntosText + ""; elAmount.hide(); elCurrency.hide(); // overlay para mapa $('.amount', $('#'+$(this).attr('overlay'))).hide(); $(".currency", $('#'+$(this).attr('overlay'))).hide(); $('.final-price-plus', $('#'+$(this).attr('overlay'))).hide(); //********************** if ( isClusterFlightMin ){ // Estoy en flight min amountHtml = "0"; $('.amount', '#'+priceId).show().html(amountHtml); $(".currency", '#'+priceId).show(); $("strong", '#'+priceId).hide(); }else if( $(this).hasClass('charge-cargos') ){ amountHtml = "0"; $('.amount', this).show().html(amountHtml); $(".currency", this).show(); } // Seteos especiales para aereos if (isClusterFlight){ // Si no hay desglose, todo eso mas que no este en el precio colapsado if (!fee_breakdown){ $("strong", this).hide(); } } //********************** } //********************** if ($('.points-value', this).length > 0){ $('.points-value', this).html(g.addThousandsSeparator(pointsShowed)); $('.points-value', '#'+$(this).attr('overlay')).html(g.addThousandsSeparator(pointsShowed)); } $(this).addClass("show"); }); } if (!atLeastOneValueIsValid && g.userPoints != -1) { this.showInvalidValue("MONEY"); } }; g.parseSection = function () { this.section = null; var matches = window.location.pathname.match(/\/(.*?)\//); if (!matches) { var matches = window.location.pathname.match(/\/(.*)$/) if (!matches) { return; } } this.section = matches[1]; if (this.section == 'beneficioCerrado') { this.section = "paquetes"; } }; g.setUp = function () { CurrencyChangeFlag = ""; g.prices = $(".price"); g.pricesPoints = $(".prices-points"); this.parseSection(); this.setUpPrice(); CurrencyChangeFlag = false; $("#currency").bind("currency:change", function () { CurrencyChangeFlag = "moneda"; g.currency = currencyDefault; $("#converter form").submit(); }); }; g.Input = function (input) { $this = this; this.input = $(input); this.input.keypress(function (ev) { $this.change(ev); }); }; g.Input.prototype.change = function (ev) { }; g.Input.getValue = function () { var val = parseInt(this.input.val()); if (isNaN(val)) { return 0; } return val; }; g.setUpCheckout = function (el) { var precioTotalEl = $('.preciototal'); if (precioTotalEl.length == 0) { return; } g.checkout = precioTotalEl.html().toFloat(); g.checkoutPoints = Math.ceil(g.moneyToPoints(g.checkout)); var update = function () { var val = parseInt($(el).val()); if (isNaN(val)) { val = 0; } if (val > g.checkoutPoints) { val = g.checkoutPoints; $(el).val(val); } var money = Math.ceil((g.checkout - g.pointsToMoney(val,true))); if (money <= 0) { $("#medio-de-pago-tarjeta").hide(); } else { $("#medio-de-pago-tarjeta").show(); } $("#field-cuota-card").html(money); $('#preciototal').html(money); cambiarCuotas(); }; $(el).keyup(update); update(); }; g.setUpToggle = function (el) { $(el).click(function (ev) { var container = $(this).parent(); if (container.hasClass("maximizado")) { container.removeClass("maximizado").addClass("minimizado"); Cookie.write('hide_slider', true, Galicia.cookie); } else { container.removeClass("minimizado").addClass("maximizado"); Cookie.write('hide_slider', '', Galicia.cookie); } ev.preventDefault(); }); }; g.forceUpdate = function () { jQuery("#converter form").submit(); }; g.updateBodyClass = function () { if (!$("#converter-type").length) { return; } jQuery("body").addClass("currency-selected-" + jQuery("#converter-type").val().toLowerCase()); }; $(function () { g.setUp(); if ($("#header .aviso")) { $("#header .aviso a").click(function (ev) { Cookie.write('hide_notice', true, Galicia.cookie); $("#header .aviso").hide(); ev.preventDefault(); }); } $("#converter form").submit(function (ev) { ev.preventDefault(); var type = 'puntos', value = $("#converter-value").val(); Cookie.write('galicia_type', type, Galicia.cookie); Cookie.write('galicia_value', value, Galicia.cookie); if(CurrencyChangeFlag == 'moneda'){ g.updatePrices('moneda'); CurrencyChangeFlag = false; }else{ g.updatePrices(); } }); $("#converter-value").forceNumericOnly(); $("#converter-value").keyup(function (ev) { Cookie.write('galicia_value', $(this).val(), Galicia.cookie); if (g.lastKeyUpTimeout) { clearTimeout(g.lastKeyUpTimeout); } g.lastKeyUpTimeout = setTimeout(function () { $("#converter form").submit(); }, g.DELAY); }); $("#converter .increase").click(function (ev) { // Datalayers var ObjDataLayer = dlSingleton.getInstance(); ObjDataLayer.setEvent('trackEvent'); ObjDataLayer.setCategory( g.product() + '/resultados'); ObjDataLayer.setAction('flechas'); ObjDataLayer.setLabel('incremento'); ObjDataLayer.push(ObjDataLayer.prepare()); // *** ev.preventDefault(); var val = parseFloat($("#converter-value").val()); if (isNaN(val)) { return; } $("#converter-value").val(val + 1); $("#converter form").submit(); }); $("#converter .decrease").click(function (ev) { // Datalayers var ObjDataLayer = dlSingleton.getInstance(); ObjDataLayer.setEvent('trackEvent'); ObjDataLayer.setCategory( g.product() + '/resultados'); ObjDataLayer.setAction('flechas'); ObjDataLayer.setLabel('decremento'); ObjDataLayer.push(ObjDataLayer.prepare()); // *** ev.preventDefault(); var val = parseFloat($("#converter-value").val()); if (isNaN(val) || val <= 0) { return; } if ($("#converter-type").val() == 'puntos' && val <= g.getLimit()) { return; } $("#converter-value").val(val - 1); $("#converter form").submit(); }); $(".btn.btn-canjear.disable").live("click", function (ev) { ev.stopImmediatePropagation(); ev.preventDefault(); }); /* Agrego logica para que la barra quede en top cuando scrolleo la pagina*/ $(document).ready(function() { if (!$('#converter').length) { return; } var converterFirstPosition = $('#converter').position().top; $(window).scroll(function() { if(converterFirstPosition >= $(window).scrollTop()) { if($('#converter').hasClass('fixed')) { $('#converter').removeClass('fixed'); } } else { if(!$('#converter').hasClass('fixed')) { //$('#converter').css("left", $('#wrapper').position().left); $('#converter').addClass('fixed'); } } }); $(window).resize(function() { if($('#converter').hasClass('fixed')) { $('#converter').css("left", $('#wrapper').position().left); $('#converter').addClass('fixed'); } }); }); $(document).ready(function() { $("#cerrar-aviso").live('click', function(){ $(this).parent().parent().parent().parent().hide(); }) if (!$('#converter').length) { return; } $('#hoteles-add-to-cart tr').click(function(){ var price = $(this).find($('span.price')).html(); $('div.room-price .price').html(price); }); var converterFirstPosition = $('#converter').position().top; $(window).scroll(function() { if(converterFirstPosition >= $(window).scrollTop()) { if($('#converter').hasClass('fixed')) { $('#converter').removeClass('fixed'); } } else { if(!$('#converter').hasClass('fixed')) { $('#converter').css("left", $('#wrapper').position().left); $('#converter').addClass('fixed'); } } }); $(window).resize(function() { if($('#converter').hasClass('fixed')) { $('#converter').css("left", $('#wrapper').position().left); $('#converter').addClass('fixed'); } }); }); $(".banner_paquetes_cerrados").click(function () { $("form", this).submit(); }); g.updateBodyClass(); }) $("#notificaciones").mouseover(function(){ $("#notificaciones #sobre").addClass('hover'); }).mouseout(function(){ $("#notificaciones #sobre").removeClass('hover'); }); })(jQuery, Galicia);