document.addEventListener('DOMContentLoaded', init) function init() { window._gEscapadas = { desde: 'Desde...', currency: '€', checking: 'Consultando...', checkWithHotel: 'Consultar', reserve: 'RESERVAR', requestReseravtion: 'SOLICITAR RESERVA', pricesTitle: 'Precios para el día:' } window.addEventListener('message', messageCb, false) if (window.gEscapadas) { loadTable() loadFrame() // initReservationButton() } } function initReservationButton () { document.getElementById('reservar-button').addEventListener('click', function() { var buttonTxt = document.getElementById('reservar-button-text').innerHTML if (buttonTxt === 'SOLICITAR RESERVAR') { var url = 'https://creator.zohopublic.com/direccion3/cursostablet/form-perma/Formulario_Reserva_Estatico/RwPPgpCEPz9quxKSKnyv7QPAjTXHEjHR0KeZU0945taGHSevKO9CBeZb9EOkXrtOu3fd3tvah3pMEt1mABRag8C3pajEyAY3Pmn6'; url += '?nombre_hotel=' + window.gEscapadas.nombreHotel + '&email_reservas=' + window.gEscapadas.emailReservas url += '&nombre_escapada=' + window.gEscapadas.nombreEscapada + '&direccion=' + window.gEscapadas.direccion url += '&telefono_hotel=' + window.gEscapadas.telefono url += '®imen=' url += '&incluidos=' url += '&otros=' window.open(url); } else { jQuery('html, body').animate({ scrollTop: jQuery("#Reservar").offset().top }, 400); } }) } function messageCb (event) { if (event.data && event.data.type === 'resize') { var frame = document.getElementById('reservation-table') if (frame) { frame.style.height = event.data.height + 'px' } } if (event.data && event.data.type == 'price') { var price_doble = parseInt(event.data.price.split(' ')[0], 10) var price_individual = parseInt(price_doble * 0.8, 10) var price_triple = parseInt(price_doble * 1.1, 10) if (document.getElementById('precio_ind').innerHTML === window._gEscapadas.checking) { document.getElementById('precio_ind').innerHTML = addDesde(price_individual) } if (document.getElementById('precio_doble').innerHTML === window._gEscapadas.checking) { document.getElementById('precio_doble').innerHTML = addDesde(price_doble) } if (document.getElementById('precio_triple').innerHTML === window._gEscapadas.checking) { document.getElementById('precio_triple').innerHTML = addDesde(price_triple) } document.getElementById('reservation_info_date').innerHTML = window._gEscapadas.pricesTitle + ' ' + event.data.date } } function addIncluidosBasePrice(price, adults = 2) { var global = window.gEscapadas.incluidos.global || 0 var adulto = window.gEscapadas.incluidos.adulto || 0 return price + global + adults * adulto } function loadTable () { // VALOR INICIAL document.getElementById('reservation_info_date').innerHTML = '1ª Noche' document.getElementById('precio_ind').innerHTML = window._gEscapadas.checking document.getElementById('precio_doble').innerHTML = window._gEscapadas.checking document.getElementById('precio_triple').innerHTML = window._gEscapadas.checking // PARAMETROS DEL HOTEL document.getElementById('hotel_name').innerHTML = window.gEscapadas.nombreHotel // INCLUIDOS document.getElementById('incluidos1').innerHTML = window.gEscapadas.incluidos.texto1 document.getElementById('incluidos2').innerHTML = window.gEscapadas.incluidos.texto2 document.getElementById('validez_desde').innerHTML = checkDate(window.gEscapadas.incluidos.desde) document.getElementById('validez_hasta').innerHTML = checkDate(window.gEscapadas.incluidos.hasta) var incluidos2 = window.gEscapadas.incluidos.texto2 if (!incluidos2 || incluidos2.length === 0) { document.getElementById('fila_incluidos2').style.display = 'none' } else { document.getElementById('fila_incluidos2').style.display = 'block' } // CARNET_VIP var carnetVipDescuento = window.gEscapadas.carnetVip.descuento var carnetVipTexto = window.gEscapadas.carnetVip.texto var cvTexts = []; if (carnetVipTexto.length > 0) { cvTexts.push(carnetVipTexto); } if (!isNaN(carnetVipDescuento) && carnetVipDescuento > 0) { cvTexts.push(carnetVipDescuento + '% Descuento'); } if (cvTexts.length === 2) { document.getElementById('fila_cv2').style.display = 'block' document.getElementById('cv1').innerHTML = cvTexts[0] document.getElementById('cv2').innerHTML = cvTexts[1] } else if (cvTexts.length === 1) { document.getElementById('fila_cv2').style.display = 'none' document.getElementById('cv1').innerHTML = cvTexts[0] } else { document.getElementById('fila_cv2').style.display = 'none' document.getElementById('cv1').innerHTML = 'Pendiente de definir' } // TIPS var tipsDescription = window.gEscapadas.tips.descripcion var tipsUrl = window.gEscapadas.tips.url if (!tipsDescription || tipsDescription.length === 0) { document.getElementById('tips_row').style.display = 'none' } else { if (!tipsUrl || tipsUrl.length === 0) { document.getElementById('tips_no_link').style.display = 'block' document.getElementById('tips_anchor').style.display = 'none' document.getElementById('tips_no_link').innerHTML = tipsDescription } else { document.getElementById('tips_no_link').style.display = 'none' document.getElementById('tips_anchor').style.display = 'block' document.getElementById('tips_anchor').innerHTML = tipsDescription document.getElementById('tips_anchor').setAttribute('href', tipsUrl) } } // TIMEOUT PARA ESPERAR DATOS DE EXPEDIA / BOOKING setTimeout(function() { if (document.getElementById('precio_ind').innerHTML === window._gEscapadas.checking) { document.getElementById('precio_ind').innerHTML = addDesde(addIncluidosBasePrice(window.gEscapadas.preciosReferencia.precioIndividual, 1)) } if (document.getElementById('precio_doble').innerHTML === window._gEscapadas.checking) { document.getElementById('precio_doble').innerHTML = addDesde(addIncluidosBasePrice(window.gEscapadas.preciosReferencia.precioDoble, 2)) } if (document.getElementById('precio_triple').innerHTML === window._gEscapadas.checking) { document.getElementById('precio_triple').innerHTML = addDesde(addIncluidosBasePrice(window.gEscapadas.preciosReferencia.precioTriple, 3)) } }, 10000); } function loadFrame() { var reservationTable = document.getElementById('reservation-table'); var incluidos = document.getElementById('incluidos1').innerHTML; var incluidos2El = document.getElementById('incluidos2'); var incluidos2; if (incluidos2El) { incluidos2 = incluidos2El.innerHTML; } if (incluidos2 && incluidos2.length > 0) { incluidos += '::' + incluidos2; } var incl_e = window.gEscapadas.incluidos; var incluidos_price = incl_e.global + '::' + incl_e.adulto + '::' + incl_e.ninio + '::' + incl_e.diario + '::' + incl_e.desde + '::' + incl_e.hasta; var referer = window.location.host + window.location.pathname; var carnetVipDto = window.gEscapadas.carnetVip.descuento / 100.0; var salt = Math.random(); setTimeout(function() { reservationTable.src = 'https://app.galiciaescapadas.com/?hotel_expedia=' + window.gEscapadas.expedia + '&hotel_booking=' + window.gEscapadas.booking + '&adults=2' + '&incluidos=' + incluidos + '&carnet_vip=' + window.gEscapadas.carnetVip.texto + '&nombre_hotel=' + window.gEscapadas.nombreHotel + '&email_reservas=' + window.gEscapadas.emailReservas + '&nombre_escapada=' + window.gEscapadas.nombreEscapada + '&direccion=' + window.gEscapadas.direccion + '&telefono_hotel=' + window.gEscapadas.telefono + '&weekday=' + window.gEscapadas.diaSemana + '&carnet_vip_value=' + carnetVipDto + '&referer=' + referer + '&incluidos_price=' + incluidos_price + '&salt=' + salt; }); } function addDesde (price) { if (!isNaN(price)) { return window._gEscapadas.desde + ' ' + price + ' ' + window._gEscapadas.currency } return window._gEscapadas.checkWithHotel } function checkDate (date) { if (date) { var arrDate = date.split('-') var year = parseInt(arrDate[2], 10) var month = parseInt(arrDate[1], 10) - 1 var day = parseInt(arrDate[0], 10) if (!isNaN(year) && !isNaN(year) && !isNaN(year)) { return date } return 'permanente' } else { return 'permanente' } }