eynhtest

Untitled

Sep 20th, 2018
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function updateAll(nombre, text) {
  2.     var siblingSelect = $("[name=" + nombre + "]").next();
  3.     $(siblingSelect).children().find(".filter-option").html(text);
  4. }
  5.  
  6. function validateAmount(obj) {
  7.     var isAdultSelect;
  8.     var selectAObj;
  9.     var selectNObj;
  10.     if (obj.name.indexOf("nadults") > -1) {
  11.         isAdultSelect = true;
  12.         selectAObj = $('*[name="' + obj.name + '"]');
  13.         selectNObj = $('*[name="nchilds' + obj.name.split("nadults")[1] + '"]');
  14.     } else {
  15.         isAdultSelect = false;
  16.         selectNObj = $('*[name="' + obj.name + '"]');
  17.         selectAObj = $('*[name="nadults' + obj.name.split("nchilds")[1] + '"]');
  18.     }
  19.     if (isAdultSelect) {
  20.         if (parseInt(selectAObj.val()) + parseInt(selectNObj.val()) > 4) {
  21.             var maxAdultos = 4 - parseInt(selectNObj.val());
  22.             selectAObj.val(maxAdultos).change();
  23.         }
  24.     } else {
  25.         if (parseInt(selectAObj.val()) + parseInt(selectNObj.val()) > 4) {
  26.             var maxNinos = 4 - parseInt(selectAObj.val());
  27.             selectNObj.val(maxNinos).change();
  28.         }
  29.     }
  30.     deleteOptions(obj);
  31. }
  32.  
  33. function deleteOptions(obj) {
  34.     var isAdultSelect;
  35.     var selectAObj;
  36.     var selectNObj;
  37.     if (obj.name.indexOf("nadults") > -1) {
  38.         isAdultSelect = true;
  39.         selectAObj = $('*[name="' + obj.name + '"]');
  40.         selectNObj = $('*[name="nchilds' + obj.name.split("nadults")[1] + '"]');
  41.     } else {
  42.         isAdultSelect = false;
  43.         selectNObj = $('*[name="' + obj.name + '"]');
  44.         selectAObj = $('*[name="nadults' + obj.name.split("nchilds")[1] + '"]');
  45.     }
  46.     if (isAdultSelect) {
  47.         var maxNinos = 4 - parseInt(selectAObj.val());
  48.         if (preAdultos < selectAObj.val()) {
  49.             selectNObj.next().find("li").each(function() {
  50.                 if (parseInt($(this).attr("rel")) > maxNinos) $(this).attr("style", "display:none !important");
  51.             });
  52.             selectNObj.children().each(function() {
  53.                 if (parseInt($(this).attr("value")) > maxNinos) $(this).attr("style", "display:none !important");
  54.             });
  55.         } else {
  56.             for (var i = 0; i < preAdultos - selectAObj.val(); i++) {
  57.                 selectNObj.children("[style = 'display:none !important']:first").attr("style", "");
  58.                 selectNObj.next().find("[style = 'display:none !important']:first").attr("style", "");
  59.             }
  60.         }
  61.         preAdultos = selectAObj.val();
  62.     } else {
  63.         var maxAdultos = 4 - parseInt(selectNObj.val());
  64.         if (preNinos < selectNObj.val()) {
  65.             selectAObj.next().find("li").each(function() {
  66.                 if (parseInt($(this).attr("rel")) >= maxAdultos) $(this).attr("style", "display:none !important");
  67.             });
  68.             selectAObj.children().each(function() {
  69.                 if (parseInt($(this).attr("value")) > maxAdultos) $(this).attr("style", "display:none !important");
  70.             });
  71.         } else {
  72.             for (var i = 0; i < preNinos - selectNObj.val(); i++) {
  73.                 selectAObj.children("[style = 'display:none !important']:first").attr("style", "");
  74.                 selectAObj.next().find("[style = 'display:none !important']:first").attr("style", "");
  75.             }
  76.         }
  77.         preNinos = selectNObj.val();
  78.     }
  79. }
  80.  
  81. function generateOcupations(valor, room, rooms, adult, adults, child, children, subdomain) {
  82.     valor = parseInt(valor);
  83.     if (valor > 5) {
  84.         multiHab(subdomain);
  85.         $("#habs").val("1");
  86.         $("#habs").change();
  87.         return false;
  88.     }
  89.     var html = "";
  90.     if (valor == 1) {
  91.         $(".ocupaciones").children().first().remove();
  92.         $(".ocupaciones").css("margin-top", "0px");
  93.     }
  94.     if (valor > 1) {
  95.         $(".ocupaciones").css("margin-top", "-9px");
  96.     }
  97.     var sHabitacion = room;
  98.     if (valor > 1) sHabitacion = rooms;
  99.     if (valor > 0) {
  100.         var roomCap = room.charAt(0).toUpperCase() + room.slice(1);
  101.         for (var i = 0; i < valor; i++) {
  102.             var idx = i + 1;
  103.             if (valor >= 1) html += "<label>" + roomCap + " " + idx + "</label>";
  104.             html += '<select name="nadults' + idx + '" class="selectpicker" data-style="btn-info" onchange="updateAll(this.name,this.options[this.selectedIndex].innerHTML); validateAmount(this)">';
  105.             html += '<option class="adulto" value="1">1 ' + adult + "</option>";
  106.             html += '<option class="adulto" value="2" selected>2 ' + adults + "</option>";
  107.             html += '<option class="adulto" value="3">3 ' + adults + "</option>";
  108.             html += '<option class="adulto" value="4">4 ' + adults + "</option>";
  109.             html += "</select> ";
  110.             html += '<select name="nchilds' + idx + '" class="selectpicker" data-style="btn-info" onchange="updateAll(this.name,this.options[this.selectedIndex].innerHTML); validateAmount(this)">';
  111.             html += '<option class="nino" value="0">0 ' + children + "</option>";
  112.             html += '<option class="nino" value="1">1 ' + child + " </option>";
  113.             html += '<option class="nino" value="2">2 ' + children + "</option>";
  114.             html += '<option class="nino" value="3">3 ' + children + "</option>";
  115.             html += "</select>";
  116.             html += '<div class="clearfix"></div>';
  117.         }
  118.         $(".ocupaciones").html(html);
  119.         $(".selectpicker").selectpicker();
  120.         $(".mainSelectRom button .pull-left").html(valor + " " + sHabitacion);
  121.     }
  122. }
  123.  
  124. function generateOcupationsAdvancedSearch(valor, room, rooms, adult, adults, child, children, subdomain) {
  125.     valor = parseInt(valor);
  126.     if (valor > 5) {
  127.         multiHab(subdomain);
  128.         $("#habs").val("1");
  129.         $("#habs").change();
  130.         return false;
  131.     }
  132.     var html = "";
  133.     var cantAgregar;
  134.     if (preValor == 1) {
  135.         sHabitacion = rooms;
  136.         $(".ocupaciones").prepend("<label>" + room + " " + preValor + "</label>");
  137.     }
  138.     if (valor == 1) {
  139.         $(".ocupaciones").children().first().remove();
  140.     }
  141.     if (preValor < valor) {
  142.         cantAgregar = valor - preValor;
  143.         for (var i = 0; i < cantAgregar; i++) {
  144.             var idx = i + 1 + preValor;
  145.             html += '<div id="hab' + idx + '">';
  146.             if (valor > 1) html += "<label>" + room + " " + idx + "</label>";
  147.             html += '<select name="nadults' + idx + '" class="selectpicker" data-style="btn-info" onchange="updateAll(this.name,this.options[this.selectedIndex].innerHTML); validateAmount(this)">';
  148.             html += '<option class="adulto" value="1">1 ' + adult + "</option>";
  149.             html += '<option class="adulto" value="2" selected>2 ' + adults + "</option>";
  150.             html += '<option class="adulto" value="3">3 ' + adults + "</option>";
  151.             html += '<option class="adulto" value="4">4 ' + adults + "</option>";
  152.             html += "</select> ";
  153.             html += '<select name="nchilds' + idx + '" class="selectpicker" data-style="btn-info" onchange="updateAll(this.name,this.options[this.selectedIndex].innerHTML); validateAmount(this)">';
  154.             html += '<option class="nino" value="0">0 ' + children + "</option>";
  155.             html += '<option class="nino" value="1">1 ' + child + " </option>";
  156.             html += '<option class="nino" value="2">2 ' + children + "</option>";
  157.             html += '<option class="nino" value="3">3 ' + children + "</option>";
  158.             html += "</select>";
  159.             html += '<div class="clearfix"></div>';
  160.             html += "</div>";
  161.         }
  162.         var sHabitacion = room;
  163.         if (valor > 1) sHabitacion = rooms;
  164.         $(".ocupaciones").append(html);
  165.         $(".selectpicker").selectpicker();
  166.         $(".mainSelectRom button .pull-left").html(valor + " " + sHabitacion);
  167.     } else {
  168.         for (var i = preValor; i > valor; i--) {
  169.             $("#hab" + i).remove();
  170.         }
  171.     }
  172.     preValor = valor;
  173. }
  174.  
  175. function setMaxRangeDate(iniID, finID, add) {
  176.     var iniElement = $(iniID).length >= 1 ? iniID : "#" + iniID;
  177.     var finElement = $(finID).length >= 1 ? finID : "#" + finID;
  178.     var dateFin = $.datepicker.parseDate(Dates.currentPattern, $(finElement).val());
  179.     var dateIni = $.datepicker.parseDate(Dates.currentPattern, $(iniElement).val());
  180.     if (add) {
  181.         dateFin = dateIni;
  182.         dateFin.setDate(dateFin.getDate() + 15);
  183.         $(finElement).val($.datepicker.formatDate(Dates.currentPattern, dateFin));
  184.     } else {
  185.         dateIni = dateFin;
  186.         dateIni.setDate(dateIni.getDate() - 15);
  187.         $(iniElement).val($.datepicker.formatDate(Dates.currentPattern, dateFin));
  188.     }
  189. }
  190.  
  191. function multiHab(subdomain) {
  192.     showMultiHabAlert(subdomain);
  193. }
  194.  
  195. function showMultiHabAlert(subdomain) {
  196.     var multiHabSubdomain = "";
  197.     if (subdomain != undefined) {
  198.         multiHabSubdomain = subdomain;
  199.     }
  200.     $.fancybox({
  201.         href: multiHabSubdomain + "/booking/lightbox/toContact",
  202.         type: "iframe",
  203.         closeBtn: 1,
  204.         closeClick: !1,
  205.         helpers: {
  206.             overlay: {
  207.                 closeClick: !1
  208.             }
  209.         }
  210.     });
  211. }
  212.  
  213. $(document).ready(function() {
  214.     preValor = 1;
  215.     preAdultos = 2;
  216.     preNinos = 0;
  217.     $(".roomsContainer").hide();
  218.     if ($("#calendarIda") == null || $("#calendarIda").size() == 0) {
  219.         $(function() {
  220.             $("#ida").datepicker({
  221.                 minDate: 0,
  222.                 dateFormat: Dates.currentPattern,
  223.                 altField: "#idaAlt",
  224.                 altFormat: Dates.pattern,
  225.                 onSelect: function(dateText, inst) {
  226.                     $("#idaAlt").change();
  227.                     var dDay = get2DigitsDateNumber(inst.selectedDay);
  228.                     var dMonth = get2DigitsDateNumber(inst.selectedMonth + 1);
  229.                     var dYear = get2DigitsDateNumber(inst.selectedYear);
  230.                     var dateIniString = dYear + "/" + dMonth + "/" + dDay;
  231.                     var dateIni = new Date(dateIniString);
  232.                     var dateOut = new Date(dateIni);
  233.                     dateOut.setDate(dateIni.getDate() + 1);
  234.                     var dateIniFormated = $.datepicker.formatDate(Dates.currentPattern, dateIni);
  235.                     var dateOutFormated = $.datepicker.formatDate(Dates.currentPattern, dateOut);
  236.                     $("#ida").parent().attr("data-date", dateIniFormated);
  237.                     $("#fin").val(dateOutFormated);
  238.                     $("#fin").parent().attr("data-date", dateOutFormated);
  239.                     $("#fin").datepicker("option", "minDate", dateOutFormated);
  240.                 }
  241.             });
  242.         });
  243.         $(function() {
  244.             var minDateFin = 0;
  245.             if ($("#ida").length > 0 && $("#ida").val() != "") {
  246.                 minDateFin = $.datepicker.parseDate(Dates.currentPattern, $("#ida").val());
  247.                 minDateFin.setDate(minDateFin.getDate() + 1);
  248.                 minDateFin = $.datepicker.formatDate(Dates.currentPattern, minDateFin);
  249.             }
  250.             $("#fin").datepicker({
  251.                 minDate: 0,
  252.                 dateFormat: Dates.currentPattern,
  253.                 altField: "#finAlt",
  254.                 altFormat: Dates.pattern,
  255.                 onSelect: function(dateText, inst) {
  256.                     $("#finAlt").change();
  257.                     var dDay = get2DigitsDateNumber(inst.selectedDay);
  258.                     var dMonth = get2DigitsDateNumber(inst.selectedMonth + 1);
  259.                     var dYear = get2DigitsDateNumber(inst.selectedYear);
  260.                     var dateIniString = dYear + "/" + dMonth + "/" + dDay;
  261.                     var dateIni = new Date(dateIniString);
  262.                     var dateFormated = $.datepicker.formatDate(Dates.currentPattern, dateIni);
  263.                     var dateFin = $.datepicker.parseDate(Dates.currentPattern, $("#fin").val());
  264.                     var dateIni = $.datepicker.parseDate(Dates.currentPattern, $("#ida").val());
  265.                     var diffDays = Math.floor((dateFin - dateIni) / 1e3 / 60 / 60 / 24);
  266.                     if (diffDays > 15) {
  267.                         setMaxRangeDate("ida", "fin", true);
  268.                         showCalendarAlert();
  269.                     }
  270.                     $("#fin").parent().attr("data-date", dateFormated);
  271.                 }
  272.             });
  273.         });
  274.     }
  275.     $("#ida").datepicker("option", $.datepicker.regional[Dates.datepickerLang]);
  276.     $("#fin").datepicker("option", $.datepicker.regional[Dates.datepickerLang]);
  277.     $(window).on("orientationchange", function(event) {
  278.         $("#ida").datepicker("hide");
  279.         $("#fin").datepicker("hide");
  280.         $("#ida").blur();
  281.         $("#fin").blur();
  282.     });
  283.     $(window).resize(function() {
  284.         $("#ida").datepicker("hide");
  285.         $("#fin").datepicker("hide");
  286.         $("#ida").blur();
  287.         $("#fin").blur();
  288.     });
  289. });
  290.  
  291. $(document).ready(function() {
  292.     type1 = $("#type").val();
  293.     locality1 = $("#locality").val();
  294.     name1 = $("#name").val();
  295.     $("#location").keyup(function() {
  296.         var params = $("#location").val();
  297.         var lang = $("#lang").val();
  298.         var autocompleteNumber = typeof autocompleteParam != "undefined" ? autocompleteParam : 3;
  299.         if (params.length >= autocompleteNumber) {
  300.             filter(HtmlSpecialChars(params), function(data) {
  301.                 var datos = $.parseJSON(data);
  302.                 var hoteles = datos[0].results[0];
  303.                 var termBuscado = datos[0].results[1];
  304.                 var currentParams = $("#location").val();
  305.                 if (currentParams.toUpperCase() === termBuscado.term.toUpperCase()) {
  306.                     var htmlDestino = "";
  307.                     var htmlHotel = "";
  308.                     var htmlPoi = "";
  309.                     var html = "";
  310.                     if (hoteles.length > 0) {
  311.                         html += "<ul>";
  312.                         for (var i = 0; i < hoteles.length; i++) {
  313.                             if (hoteles[i].icon == "hotelHome") htmlHotel += llenarListaLanding(hoteles, i); else if (hoteles[i].icon == "destinationHome") htmlDestino += llenarListaLanding(hoteles, i); else htmlPoi += llenarListaLanding(hoteles, i);
  314.                         }
  315.                         html += htmlDestino + htmlHotel + htmlPoi;
  316.                         html += "</ul>";
  317.                     } else {
  318.                         html += "<li>";
  319.                         html += "<div>";
  320.                         html += labelCoincidencias;
  321.                         html += "</div>";
  322.                         html += "</li>";
  323.                     }
  324.                     $("#results").html(html);
  325.                     $("#results").show();
  326.                 }
  327.             });
  328.         } else $("#location").attr("name", "");
  329.     });
  330.     $("#fieldSearch").keyup(function() {
  331.         var params = $("#fieldSearch").val();
  332.         var lang = $("#lang").val();
  333.         var autocompleteNumber = typeof autocompleteParam != "undefined" ? autocompleteParam : 3;
  334.         if (params.length >= autocompleteNumber) {
  335.             filter(HtmlSpecialChars(params), function(data) {
  336.                 var datos = $.parseJSON(data);
  337.                 var hoteles = datos[0].results[0];
  338.                 var termBuscado = datos[0].results[1];
  339.                 var currentParams = $("#fieldSearch").val();
  340.                 if (currentParams.toUpperCase() === termBuscado.term.toUpperCase()) {
  341.                     var htmlDestino = "";
  342.                     var htmlHotel = "";
  343.                     var htmlPoi = "";
  344.                     var html = "";
  345.                     if (hoteles.length > 0) {
  346.                         html += "<ul>";
  347.                         for (var i = 0; i < hoteles.length; i++) {
  348.                             if (hoteles[i].icon == "hotelHome") htmlHotel += llenarListaFieldSearch(hoteles, i); else if (hoteles[i].icon == "destinationHome") htmlDestino += llenarListaFieldSearch(hoteles, i); else htmlPoi += llenarListaFieldSearch(hoteles, i);
  349.                         }
  350.                         html += htmlDestino + htmlHotel + htmlPoi;
  351.                         html += "</ul>";
  352.                     } else {
  353.                         html += "<li>";
  354.                         html += "<div>";
  355.                         html += labelCoincidencias;
  356.                         html += "</div>";
  357.                         html += "</li>";
  358.                     }
  359.                     $("#results").html(html);
  360.                     $(".autoComplete").show();
  361.                 }
  362.             });
  363.         } else $("#locationCode").attr("name", "");
  364.     });
  365. });
  366.  
  367. function setParametersLocation(name, locality, type, code, tcm) {
  368.     name1 = decodeHtmlSpecialChars(name);
  369.     locality1 = decodeHtmlSpecialChars(locality);
  370.     type1 = type;
  371.     if (type != "destination") $("#location").val(name1 + ", " + locality1); else $("#location").val(name1 + locality1.replace(name1, ""));
  372.     if (type == "hotel") $("#locationCode").attr("name", "hotelId"); else if (type == "destination") {
  373.         $("#locationCode").attr("name", "destinationId");
  374.         $("#destinationTcm").val(tcm);
  375.     } else if (type == "poi") {
  376.         $("#locationCode").attr("name", "poiId");
  377.         $("#destinationTcm").val(tcm);
  378.     }
  379.     $("#locationCode").val(code);
  380.     $("#locationTCM").val(tcm);
  381. }
  382.  
  383. function setParametersLocation(name, locality, type, code, tcm, url, vh) {
  384.     name1 = decodeHtmlSpecialChars(name);
  385.     locality1 = decodeHtmlSpecialChars(locality);
  386.     type1 = type;
  387.     if (type != "destination") $("#location").val(name1 + ", " + locality1); else $("#location").val(name1 + locality1.replace(name1, ""));
  388.     if (type == "hotel") {
  389.         $("#locationCode").attr("name", "hotelId");
  390.     } else if (type == "destination") {
  391.         $("#locationCode").attr("name", "destinationId");
  392.         $("#destinationTcm").val(tcm);
  393.     } else if (type == "poi") {
  394.         $("#locationCode").attr("name", "poiId");
  395.         $("#destinationTcm").val(tcm);
  396.     }
  397.     $("#locationCode").val(code);
  398.     $("#locationTCM").val(tcm);
  399.     $("#url").val(url);
  400.     $("#virtualHotel").val(vh);
  401. }
  402.  
  403. function setParametersFieldSearch(name, locality, type, code, tcm) {
  404.     name1 = decodeHtmlSpecialChars(name);
  405.     locality1 = decodeHtmlSpecialChars(locality);
  406.     type1 = type;
  407.     if (type != "destination") $("#fieldSearch").val(name1 + ", " + locality1); else $("#fieldSearch").val(name1 + locality1.replace(name1, ""));
  408.     if (type == "hotel") $("#locationCode").attr("name", "hotelId"); else if (type == "destination") {
  409.         $("#locationCode").attr("name", "destinationId");
  410.         $("#destinationTcm").val(tcm);
  411.     } else if (type == "poi") {
  412.         $("#locationCode").attr("name", "poiId");
  413.         $("#destinationTcm").val(tcm);
  414.     }
  415.     $("#locationCode").val(code);
  416.     $("#locationTCM").val(tcm);
  417. }
  418.  
  419. function setParametersFieldSearch(name, locality, type, code, tcm, url, vh) {
  420.     name1 = decodeHtmlSpecialChars(name);
  421.     locality1 = decodeHtmlSpecialChars(locality);
  422.     type1 = type;
  423.     if (type != "destination") $("#fieldSearch").val(name1 + ", " + locality1); else $("#fieldSearch").val(name1 + locality1.replace(name1, ""));
  424.     if (type == "hotel") $("#locationCode").attr("name", "hotelId"); else if (type == "destination") {
  425.         $("#locationCode").attr("name", "destinationId");
  426.         $("#destinationTcm").val(tcm);
  427.     } else if (type == "poi") {
  428.         $("#locationCode").attr("name", "poiId");
  429.         $("#destinationTcm").val(tcm);
  430.     }
  431.     $("#locationCode").val(code);
  432.     $("#locationTCM").val(tcm);
  433.     $("#url").val(url);
  434.     $("#virtualHotel").val(vh);
  435. }
  436.  
  437. $(document).click(function(evt) {
  438.     if (evt.target.id == "location" || evt.target.id == "fieldSearch") return;
  439.     if ($(".autoComplete").is(":visible")) {
  440.         $(".autoComplete").hide();
  441.         $("#results").html("");
  442.     }
  443. });
  444.  
  445. function validarlocationSubmit() {
  446.     if (type1 != "destination") {
  447.         if (name1 + " " + locality1 + " " + type1 != $("#location").val() && $("#location").val().toLowerCase() != $("#locationCode").val().toLowerCase()) {
  448.             $("#locationCode").attr("name", "");
  449.             $("#locationCode").val("");
  450.         }
  451.     } else {
  452.         if (name1 + locality1.replace(name1, "") + " " + type1 != $("#location").val() && $("#location").val().toLowerCase() != $("#locationCode").val().toLowerCase()) {
  453.             $("#locationCode").attr("name", "");
  454.             $("#locationCode").val("");
  455.         }
  456.     }
  457.     if ($("#location").attr("name") !== undefined && $("#location").attr("name") === "searchStringID") {
  458.         $("#locationTCM").attr("name", "locationTCM");
  459.     } else {
  460.         $("#locationTCM").attr("name", "searchStringID");
  461.     }
  462.     $("#locationTCM").val($("#location").val());
  463.     callSeguimientoForms("success", "locationForm", "success");
  464.     if ($("#url").val() != "" && $("input[name*='hotelId']").length > 0 && ($("input[name*='fini']").length == 0 || $("input[name*='fini']").val() == "") && ($("input[name*='fout']").length == 0 || $("input[name*='fout']").val() == "")) window.location.href = $("#url").val(); else $("#locationForm").submit();
  465. }
  466.  
  467. function validarLandingSubmit(landing) {
  468.     if ($("#locationCode").val() == "") {
  469.         $("#locationCode").attr("name", "");
  470.     }
  471.     if ($("#location").attr("name") !== undefined && $("#location").attr("name") === "searchStringID") {
  472.         $("#locationTCM").attr("name", "locationTCM");
  473.     } else {
  474.         $("#locationTCM").attr("name", "searchStringID");
  475.     }
  476.     $("#eida").hide();
  477.     $("#efin").hide();
  478.     noerror = true;
  479.     var errorField = "";
  480.     if (typeof isB2E != "undefined" && isB2E != "") {
  481.         var fechaIda = $("#ida").val();
  482.         var fechaFin = $("#fin").val();
  483.         if (!validateLength(fechaIda)) {
  484.             $("#eida").show();
  485.             $("#fechaIda").addClass("error");
  486.             noerror = false;
  487.             if (errorField == "") errorField = "fechaIda";
  488.         } else {
  489.             $("#fechaIda").removeClass("error");
  490.         }
  491.         if (!validateLength(fechaFin)) {
  492.             $("#efin").show();
  493.             $("#fechaFin").addClass("error");
  494.             noerror = false;
  495.             if (errorField == "") errorField = "fechaFin";
  496.         } else {
  497.             $("#fechaFin").removeClass("error");
  498.         }
  499.     }
  500.     $("#locationTCM").val($("#location").val());
  501.     var habis = $("#habs").val();
  502.     var adult = 0;
  503.     var ninos = 0;
  504.     for (var i = 1; i <= habis; i++) {
  505.         adult += parseInt($("[name=nadults" + i + "]").val());
  506.         ninos += parseInt($("[name=nchilds" + i + "]").val());
  507.     }
  508.     if (noerror) {
  509.         $("#loadingModal").modal({
  510.             show: !0,
  511.             backdrop: "static",
  512.             keyboard: !1
  513.         });
  514.         callSeguimientoForms("success", "resultPageForm", "success");
  515.         if (landing == undefined) trackHotelSearch(page_section, $("#locationCode").val(), $("#ida").val(), $("#fin").val());
  516.         if (landing) trackNewGeneralSearch(page_section, $("#locationCode").val(), $("#ida").val(), $("#fin").val(), habis, adult, ninos); else trackModifySearch(page_section, $("#locationCode").val(), $("#ida").val(), $("#fin").val(), habis, adult, ninos);
  517.         if ($("#virtualHotel").val() != "" && $("#url").val() != "" && $("input[name*='hotelId']").length > 0) {
  518.             $("#urlHotel").val($("#url").val());
  519.             $("#locationForm").submit();
  520.         } else {
  521.             if ($("#url").val() != "" && $("input[name*='hotelId']").length > 0 && ($('[data-input-target="fini"]').length == 0 || $('[data-input-target="fini"]').val() == "") && ($('[data-input-target="fout"]').length == 0 || $('[data-input-target="fout"]').val() == "")) window.location.href = $("#url").val(); else $("#locationForm").submit();
  522.         }
  523.     } else {
  524.         callSeguimientoForms("error", "resultPageForm", errorField);
  525.     }
  526. }
  527.  
  528. $(document).ready(function() {
  529.     $("#location").click(function() {
  530.         if (!$(this).hasClass("selected")) {
  531.             $(this).select();
  532.             $(this).addClass("selected");
  533.         }
  534.     });
  535.     $("#location").blur(function() {
  536.         if ($(this).hasClass("selected")) {
  537.             $(this).removeClass("selected");
  538.         }
  539.     });
  540.     $("#inputSearch").click(function() {
  541.         if (!$(this).hasClass("selected")) {
  542.             $(this).select();
  543.             $(this).addClass("selected");
  544.         }
  545.     });
  546.     $("#inputSearch").blur(function() {
  547.         if ($(this).hasClass("selected")) {
  548.             $(this).removeClass("selected");
  549.         }
  550.     });
  551.     $("#fieldSearch").click(function() {
  552.         if (!$(this).hasClass("selected")) {
  553.             $(this).select();
  554.             $(this).addClass("selected");
  555.         }
  556.     });
  557.     $("#fieldSearch").blur(function() {
  558.         if ($(this).hasClass("selected")) {
  559.             $(this).removeClass("selected");
  560.         }
  561.     });
  562. });
  563.  
  564. function clearCalendar() {
  565.     $("#diaSalida").val("");
  566.     $("#mesSalida").val("");
  567.     $("#mesSalidav").val("");
  568.     $("#anioSalida").val("");
  569.     $("#diaLlegada").val("");
  570.     $("#mesLlegada").val("");
  571.     $("#mesLlegadav").val("");
  572.     $("#anioLlegada").val("");
  573.     $("#calendar").hide();
  574. }
  575.  
  576. function llenarListaLanding(hoteles, i) {
  577.     var html = "";
  578.     if (hoteles[i].url != null && hoteles[i].url != undefined) html += '<li onclick="setParametersLocation(' + "'" + HtmlSpecialChars(hoteles[i].name) + "'" + ", " + "'" + HtmlSpecialChars(hoteles[i].locality) + "'" + ", " + "'" + hoteles[i].type + "'" + ", " + "'" + hoteles[i].code + "'" + ", " + "'" + hoteles[i].tcm + "'" + ", " + "'" + hoteles[i].url + "'" + ", " + "'" + hoteles[i].vh + "'" + ");showOptions('#calendar');$('.autoComplete').hide()\">"; else html += '<li onclick="setParametersLocation(' + "'" + HtmlSpecialChars(hoteles[i].name) + "'" + ", " + "'" + HtmlSpecialChars(hoteles[i].locality) + "'" + ", " + "'" + hoteles[i].type + "'" + ", " + "'" + hoteles[i].code + "'" + ", " + "'" + hoteles[i].tcm + "'" + ");showOptions('#calendar');$('.autoComplete').hide()\">";
  579.     html += '<a href="#">';
  580.     if (hoteles[i].icon == "airtport") html += '<span class="icon airports"></span>'; else if (hoteles[i].icon == "hotelHome") html += '<span class="icon hotels"></span>'; else if (hoteles[i].icon == "destinationHome") html += '<span class="icon cities"></span>'; else html += '<span class="icon noplace"></span>';
  581.     html += hoteles[i].name + (hoteles[i].icon != "destinationHome" ? " " + hoteles[i].locality : hoteles[i].locality.replace(hoteles[i].name, ""));
  582.     html += "<small>";
  583.     if (hoteles[i].icon != "hotelHome") html += hoteles[i].num_hotels + " " + (hoteles[i].num_hotels == 1 ? labelHotel : labelHotels);
  584.     html += "</small>";
  585.     html += "</a>";
  586.     html += "</li>";
  587.     return html;
  588. }
  589.  
  590. function llenarListaFieldSearch(hoteles, i) {
  591.     var html = "";
  592.     if (hoteles[i].url != null && hoteles[i].url != undefined) {
  593.         html += '<li onclick="setParametersFieldSearch(' + "'" + HtmlSpecialChars(hoteles[i].name) + "'" + ", " + "'" + HtmlSpecialChars(hoteles[i].locality) + "'" + ", " + "'" + hoteles[i].type + "'" + ", " + "'" + hoteles[i].code + "'" + ", " + "'" + hoteles[i].tcm + "'" + ", " + "'" + hoteles[i].url + "'" + ", " + "'" + hoteles[i].vh + "'" + ");showOptions('#calendar');$('.autoComplete').hide()\">";
  594.     } else {
  595.         html += '<li onclick="setParametersFieldSearch(' + "'" + HtmlSpecialChars(hoteles[i].name) + "'" + ", " + "'" + HtmlSpecialChars(hoteles[i].locality) + "'" + ", " + "'" + hoteles[i].type + "'" + ", " + "'" + hoteles[i].code + "'" + ", " + "'" + hoteles[i].tcm + "'" + ");showOptions('#calendar');$('.autoComplete').hide()\">";
  596.     }
  597.     html += '<a href="#">';
  598.     if (hoteles[i].icon == "airtport") html += '<span class="icon airports"></span>'; else if (hoteles[i].icon == "hotelHome") html += '<span class="icon hotels"></span>'; else if (hoteles[i].icon == "destinationHome") html += '<span class="icon cities"></span>'; else html += '<span class="icon noplace"></span>';
  599.     html += hoteles[i].name + (hoteles[i].icon != "destinationHome" ? " " + hoteles[i].locality : hoteles[i].locality.replace(hoteles[i].name, ""));
  600.     html += "<small>";
  601.     if (hoteles[i].icon != "hotelHome") html += hoteles[i].num_hotels + " " + (hoteles[i].num_hotels == 1 ? labelHotel : labelHotels);
  602.     html += "</small>";
  603.     html += "</a>";
  604.     html += "</li>";
  605.     return html;
  606. }
  607.  
  608. function filterHome(textToFind, callback) {
  609.     var autocompleteSubdomain = "";
  610.     if (typeof subdomainLang != "undefined") {
  611.         autocompleteSubdomain = subdomainLang;
  612.     }
  613.     $.ajax({
  614.         type: "GET",
  615.         url: autocompleteSubdomain + "/rest/auto/autocompleteHome/" + textToFind,
  616.         dataType: "json",
  617.         cache: true,
  618.         error: function() {},
  619.         success: function(data) {
  620.             var resultsArrayFinal = [];
  621.             resultsArrayFinal.push({
  622.                 results: data
  623.             });
  624.             callback(JSON.stringify(resultsArrayFinal));
  625.         },
  626.         error: function(xhr, status, error) {
  627.             var err = eval("(" + xhr.responseText + ")");
  628.             alert(err.Message + " " + status + " " + error);
  629.         }
  630.     });
  631. }
  632.  
  633. function filter(textToFind, callback) {
  634.     var autocompleteSubdomain = "";
  635.     if (typeof subdomainLang != "undefined") {
  636.         autocompleteSubdomain = subdomainLang;
  637.     }
  638.     $.ajax({
  639.         type: "GET",
  640.         url: autocompleteSubdomain + "/rest/auto/autocomplete/" + textToFind,
  641.         dataType: "json",
  642.         cache: true,
  643.         error: function() {},
  644.         success: function(data) {
  645.             var resultsArrayFinal = [];
  646.             resultsArrayFinal.push({
  647.                 results: data
  648.             });
  649.             callback(JSON.stringify(resultsArrayFinal));
  650.         },
  651.         error: function(xhr, status, error) {
  652.             var err = eval("(" + xhr.responseText + ")");
  653.             alert(err.Message + " " + status + " " + error);
  654.         }
  655.     });
  656. }
  657.  
  658. var Hashtable = function() {
  659.     var FUNCTION = "function";
  660.     var arrayRemoveAt = typeof Array.prototype.splice == FUNCTION ? function(arr, idx) {
  661.         arr.splice(idx, 1);
  662.     } : function(arr, idx) {
  663.         var itemsAfterDeleted, i, len;
  664.         if (idx === arr.length - 1) {
  665.             arr.length = idx;
  666.         } else {
  667.             itemsAfterDeleted = arr.slice(idx + 1);
  668.             arr.length = idx;
  669.             for (i = 0, len = itemsAfterDeleted.length; i < len; ++i) {
  670.                 arr[idx + i] = itemsAfterDeleted[i];
  671.             }
  672.         }
  673.     };
  674.     function hashObject(obj) {
  675.         var hashCode;
  676.         if (typeof obj == "string") {
  677.             return obj;
  678.         } else if (typeof obj.hashCode == FUNCTION) {
  679.             hashCode = obj.hashCode();
  680.             return typeof hashCode == "string" ? hashCode : hashObject(hashCode);
  681.         } else if (typeof obj.toString == FUNCTION) {
  682.             return obj.toString();
  683.         } else {
  684.             try {
  685.                 return String(obj);
  686.             } catch (ex) {
  687.                 return Object.prototype.toString.call(obj);
  688.             }
  689.         }
  690.     }
  691.     function equals_fixedValueHasEquals(fixedValue, variableValue) {
  692.         return fixedValue.equals(variableValue);
  693.     }
  694.     function equals_fixedValueNoEquals(fixedValue, variableValue) {
  695.         return typeof variableValue.equals == FUNCTION ? variableValue.equals(fixedValue) : fixedValue === variableValue;
  696.     }
  697.     function createKeyValCheck(kvStr) {
  698.         return function(kv) {
  699.             if (kv === null) {
  700.                 throw new Error("null is not a valid " + kvStr);
  701.             } else if (typeof kv == "undefined") {
  702.                 throw new Error(kvStr + " must not be undefined");
  703.             }
  704.         };
  705.     }
  706.     var checkKey = createKeyValCheck("key"), checkValue = createKeyValCheck("value");
  707.     function Bucket(hash, firstKey, firstValue, equalityFunction) {
  708.         this[0] = hash;
  709.         this.entries = [];
  710.         this.addEntry(firstKey, firstValue);
  711.         if (equalityFunction !== null) {
  712.             this.getEqualityFunction = function() {
  713.                 return equalityFunction;
  714.             };
  715.         }
  716.     }
  717.     var EXISTENCE = 0, ENTRY = 1, ENTRY_INDEX_AND_VALUE = 2;
  718.     function createBucketSearcher(mode) {
  719.         return function(key) {
  720.             var i = this.entries.length, entry, equals = this.getEqualityFunction(key);
  721.             while (i--) {
  722.                 entry = this.entries[i];
  723.                 if (equals(key, entry[0])) {
  724.                     switch (mode) {
  725.                       case EXISTENCE:
  726.                         return true;
  727.  
  728.                       case ENTRY:
  729.                         return entry;
  730.  
  731.                       case ENTRY_INDEX_AND_VALUE:
  732.                         return [ i, entry[1] ];
  733.                     }
  734.                 }
  735.             }
  736.             return false;
  737.         };
  738.     }
  739.     function createBucketLister(entryProperty) {
  740.         return function(aggregatedArr) {
  741.             var startIndex = aggregatedArr.length;
  742.             for (var i = 0, len = this.entries.length; i < len; ++i) {
  743.                 aggregatedArr[startIndex + i] = this.entries[i][entryProperty];
  744.             }
  745.         };
  746.     }
  747.     Bucket.prototype = {
  748.         getEqualityFunction: function(searchValue) {
  749.             return typeof searchValue.equals == FUNCTION ? equals_fixedValueHasEquals : equals_fixedValueNoEquals;
  750.         },
  751.         getEntryForKey: createBucketSearcher(ENTRY),
  752.         getEntryAndIndexForKey: createBucketSearcher(ENTRY_INDEX_AND_VALUE),
  753.         removeEntryForKey: function(key) {
  754.             var result = this.getEntryAndIndexForKey(key);
  755.             if (result) {
  756.                 arrayRemoveAt(this.entries, result[0]);
  757.                 return result[1];
  758.             }
  759.             return null;
  760.         },
  761.         addEntry: function(key, value) {
  762.             this.entries[this.entries.length] = [ key, value ];
  763.         },
  764.         keys: createBucketLister(0),
  765.         values: createBucketLister(1),
  766.         getEntries: function(entries) {
  767.             var startIndex = entries.length;
  768.             for (var i = 0, len = this.entries.length; i < len; ++i) {
  769.                 entries[startIndex + i] = this.entries[i].slice(0);
  770.             }
  771.         },
  772.         containsKey: createBucketSearcher(EXISTENCE),
  773.         containsValue: function(value) {
  774.             var i = this.entries.length;
  775.             while (i--) {
  776.                 if (value === this.entries[i][1]) {
  777.                     return true;
  778.                 }
  779.             }
  780.             return false;
  781.         }
  782.     };
  783.     function searchBuckets(buckets, hash) {
  784.         var i = buckets.length, bucket;
  785.         while (i--) {
  786.             bucket = buckets[i];
  787.             if (hash === bucket[0]) {
  788.                 return i;
  789.             }
  790.         }
  791.         return null;
  792.     }
  793.     function getBucketForHash(bucketsByHash, hash) {
  794.         var bucket = bucketsByHash[hash];
  795.         return bucket && bucket instanceof Bucket ? bucket : null;
  796.     }
  797.     function Hashtable(hashingFunctionParam, equalityFunctionParam) {
  798.         var that = this;
  799.         var buckets = [];
  800.         var bucketsByHash = {};
  801.         var hashingFunction = typeof hashingFunctionParam == FUNCTION ? hashingFunctionParam : hashObject;
  802.         var equalityFunction = typeof equalityFunctionParam == FUNCTION ? equalityFunctionParam : null;
  803.         this.put = function(key, value) {
  804.             checkKey(key);
  805.             checkValue(value);
  806.             var hash = hashingFunction(key), bucket, bucketEntry, oldValue = null;
  807.             bucket = getBucketForHash(bucketsByHash, hash);
  808.             if (bucket) {
  809.                 bucketEntry = bucket.getEntryForKey(key);
  810.                 if (bucketEntry) {
  811.                     oldValue = bucketEntry[1];
  812.                     bucketEntry[1] = value;
  813.                 } else {
  814.                     bucket.addEntry(key, value);
  815.                 }
  816.             } else {
  817.                 bucket = new Bucket(hash, key, value, equalityFunction);
  818.                 buckets[buckets.length] = bucket;
  819.                 bucketsByHash[hash] = bucket;
  820.             }
  821.             return oldValue;
  822.         };
  823.         this.get = function(key) {
  824.             checkKey(key);
  825.             var hash = hashingFunction(key);
  826.             var bucket = getBucketForHash(bucketsByHash, hash);
  827.             if (bucket) {
  828.                 var bucketEntry = bucket.getEntryForKey(key);
  829.                 if (bucketEntry) {
  830.                     return bucketEntry[1];
  831.                 }
  832.             }
  833.             return null;
  834.         };
  835.         this.containsKey = function(key) {
  836.             checkKey(key);
  837.             var bucketKey = hashingFunction(key);
  838.             var bucket = getBucketForHash(bucketsByHash, bucketKey);
  839.             return bucket ? bucket.containsKey(key) : false;
  840.         };
  841.         this.containsValue = function(value) {
  842.             checkValue(value);
  843.             var i = buckets.length;
  844.             while (i--) {
  845.                 if (buckets[i].containsValue(value)) {
  846.                     return true;
  847.                 }
  848.             }
  849.             return false;
  850.         };
  851.         this.clear = function() {
  852.             buckets.length = 0;
  853.             bucketsByHash = {};
  854.         };
  855.         this.isEmpty = function() {
  856.             return !buckets.length;
  857.         };
  858.         var createBucketAggregator = function(bucketFuncName) {
  859.             return function() {
  860.                 var aggregated = [], i = buckets.length;
  861.                 while (i--) {
  862.                     buckets[i][bucketFuncName](aggregated);
  863.                 }
  864.                 return aggregated;
  865.             };
  866.         };
  867.         this.keys = createBucketAggregator("keys");
  868.         this.values = createBucketAggregator("values");
  869.         this.entries = createBucketAggregator("getEntries");
  870.         this.remove = function(key) {
  871.             checkKey(key);
  872.             var hash = hashingFunction(key), bucketIndex, oldValue = null;
  873.             var bucket = getBucketForHash(bucketsByHash, hash);
  874.             if (bucket) {
  875.                 oldValue = bucket.removeEntryForKey(key);
  876.                 if (oldValue !== null) {
  877.                     if (!bucket.entries.length) {
  878.                         bucketIndex = searchBuckets(buckets, hash);
  879.                         arrayRemoveAt(buckets, bucketIndex);
  880.                         delete bucketsByHash[hash];
  881.                     }
  882.                 }
  883.             }
  884.             return oldValue;
  885.         };
  886.         this.size = function() {
  887.             var total = 0, i = buckets.length;
  888.             while (i--) {
  889.                 total += buckets[i].entries.length;
  890.             }
  891.             return total;
  892.         };
  893.         this.each = function(callback) {
  894.             var entries = that.entries(), i = entries.length, entry;
  895.             while (i--) {
  896.                 entry = entries[i];
  897.                 callback(entry[0], entry[1]);
  898.             }
  899.         };
  900.         this.putAll = function(hashtable, conflictCallback) {
  901.             var entries = hashtable.entries();
  902.             var entry, key, value, thisValue, i = entries.length;
  903.             var hasConflictCallback = typeof conflictCallback == FUNCTION;
  904.             while (i--) {
  905.                 entry = entries[i];
  906.                 key = entry[0];
  907.                 value = entry[1];
  908.                 if (hasConflictCallback && (thisValue = that.get(key))) {
  909.                     value = conflictCallback(key, thisValue, value);
  910.                 }
  911.                 that.put(key, value);
  912.             }
  913.         };
  914.         this.clone = function() {
  915.             var clone = new Hashtable(hashingFunctionParam, equalityFunctionParam);
  916.             clone.putAll(that);
  917.             return clone;
  918.         };
  919.     }
  920.     return Hashtable;
  921. }();
  922.  
  923. (function(jQuery) {
  924.     var nfLocales = new Hashtable();
  925.     var nfLocalesLikeUS = [ "ae", "au", "ca", "cn", "eg", "gb", "hk", "il", "in", "jp", "sk", "th", "tw", "us" ];
  926.     var nfLocalesLikeDE = [ "at", "br", "de", "dk", "es", "gr", "it", "nl", "pt", "tr", "vn" ];
  927.     var nfLocalesLikeFR = [ "cz", "fi", "fr", "ru", "se", "pl" ];
  928.     var nfLocalesLikeCH = [ "ch" ];
  929.     var nfLocaleFormatting = [ [ ".", "," ], [ ",", "." ], [ ",", " " ], [ ".", "'" ] ];
  930.     var nfAllLocales = [ nfLocalesLikeUS, nfLocalesLikeDE, nfLocalesLikeFR, nfLocalesLikeCH ];
  931.     function FormatData(dec, group, neg) {
  932.         this.dec = dec;
  933.         this.group = group;
  934.         this.neg = neg;
  935.     }
  936.     function init() {
  937.         for (var localeGroupIdx = 0; localeGroupIdx < nfAllLocales.length; localeGroupIdx++) {
  938.             localeGroup = nfAllLocales[localeGroupIdx];
  939.             for (var i = 0; i < localeGroup.length; i++) {
  940.                 nfLocales.put(localeGroup[i], localeGroupIdx);
  941.             }
  942.         }
  943.     }
  944.     function formatCodes(locale, isFullLocale) {
  945.         if (nfLocales.size() == 0) init();
  946.         var dec = ".";
  947.         var group = ",";
  948.         var neg = "-";
  949.         if (isFullLocale == false) {
  950.             if (locale.indexOf("_") != -1) locale = locale.split("_")[1].toLowerCase(); else if (locale.indexOf("-") != -1) locale = locale.split("-")[1].toLowerCase();
  951.         }
  952.         var codesIndex = nfLocales.get(locale);
  953.         if (codesIndex) {
  954.             var codes = nfLocaleFormatting[codesIndex];
  955.             if (codes) {
  956.                 dec = codes[0];
  957.                 group = codes[1];
  958.             }
  959.         }
  960.         return new FormatData(dec, group, neg);
  961.     }
  962.     jQuery.fn.formatNumber = function(options, writeBack, giveReturnValue) {
  963.         return this.each(function() {
  964.             if (writeBack == null) writeBack = true;
  965.             if (giveReturnValue == null) giveReturnValue = true;
  966.             var text;
  967.             if (jQuery(this).is(":input")) text = new String(jQuery(this).val()); else text = new String(jQuery(this).text());
  968.             var returnString = jQuery.formatNumber(text, options);
  969.             if (writeBack) {
  970.                 if (jQuery(this).is(":input")) jQuery(this).val(returnString); else jQuery(this).text(returnString);
  971.             }
  972.             if (giveReturnValue) return returnString;
  973.         });
  974.     };
  975.     jQuery.formatNumber = function(numberString, options) {
  976.         var options = jQuery.extend({}, jQuery.fn.formatNumber.defaults, options);
  977.         var formatData = formatCodes(options.locale.toLowerCase(), options.isFullLocale);
  978.         var dec = formatData.dec;
  979.         var group = formatData.group;
  980.         var neg = formatData.neg;
  981.         var validFormat = "0#-,.";
  982.         var prefix = "";
  983.         var negativeInFront = false;
  984.         for (var i = 0; i < options.format.length; i++) {
  985.             if (validFormat.indexOf(options.format.charAt(i)) == -1) prefix = prefix + options.format.charAt(i); else if (i == 0 && options.format.charAt(i) == "-") {
  986.                 negativeInFront = true;
  987.                 continue;
  988.             } else break;
  989.         }
  990.         var suffix = "";
  991.         for (var i = options.format.length - 1; i >= 0; i--) {
  992.             if (validFormat.indexOf(options.format.charAt(i)) == -1) suffix = options.format.charAt(i) + suffix; else break;
  993.         }
  994.         options.format = options.format.substring(prefix.length);
  995.         options.format = options.format.substring(0, options.format.length - suffix.length);
  996.         var number = new Number(numberString);
  997.         return jQuery._formatNumber(number, options, suffix, prefix, negativeInFront);
  998.     };
  999.     jQuery._formatNumber = function(number, options, suffix, prefix, negativeInFront) {
  1000.         var options = jQuery.extend({}, jQuery.fn.formatNumber.defaults, options);
  1001.         var formatData = formatCodes(options.locale.toLowerCase(), options.isFullLocale);
  1002.         var dec = formatData.dec;
  1003.         var group = formatData.group;
  1004.         var neg = formatData.neg;
  1005.         var forcedToZero = false;
  1006.         if (isNaN(number)) {
  1007.             if (options.nanForceZero == true) {
  1008.                 number = 0;
  1009.                 forcedToZero = true;
  1010.             } else return null;
  1011.         }
  1012.         if (suffix == "%") number = number * 100;
  1013.         var returnString = "";
  1014.         if (options.format.indexOf(".") > -1) {
  1015.             var decimalPortion = dec;
  1016.             var decimalFormat = options.format.substring(options.format.lastIndexOf(".") + 1);
  1017.             if (options.round == true) number = new Number(number.toFixed(decimalFormat.length)); else {
  1018.                 var numStr = number.toString();
  1019.                 numStr = numStr.substring(0, numStr.lastIndexOf(".") + decimalFormat.length + 1);
  1020.                 number = new Number(numStr);
  1021.             }
  1022.             var decimalValue = number % 1;
  1023.             var decimalString = new String(decimalValue.toFixed(decimalFormat.length));
  1024.             decimalString = decimalString.substring(decimalString.lastIndexOf(".") + 1);
  1025.             for (var i = 0; i < decimalFormat.length; i++) {
  1026.                 if (decimalFormat.charAt(i) == "#" && decimalString.charAt(i) != "0") {
  1027.                     decimalPortion += decimalString.charAt(i);
  1028.                     continue;
  1029.                 } else if (decimalFormat.charAt(i) == "#" && decimalString.charAt(i) == "0") {
  1030.                     var notParsed = decimalString.substring(i);
  1031.                     if (notParsed.match("[1-9]")) {
  1032.                         decimalPortion += decimalString.charAt(i);
  1033.                         continue;
  1034.                     } else break;
  1035.                 } else if (decimalFormat.charAt(i) == "0") decimalPortion += decimalString.charAt(i);
  1036.             }
  1037.             returnString += decimalPortion;
  1038.         } else number = Math.round(number);
  1039.         var ones = Math.floor(number);
  1040.         if (number < 0) ones = Math.ceil(number);
  1041.         var onesFormat = "";
  1042.         if (options.format.indexOf(".") == -1) onesFormat = options.format; else onesFormat = options.format.substring(0, options.format.indexOf("."));
  1043.         var onePortion = "";
  1044.         if (!(ones == 0 && onesFormat.substr(onesFormat.length - 1) == "#") || forcedToZero) {
  1045.             var oneText = new String(Math.abs(ones));
  1046.             var groupLength = 9999;
  1047.             if (onesFormat.lastIndexOf(",") != -1) groupLength = onesFormat.length - onesFormat.lastIndexOf(",") - 1;
  1048.             var groupCount = 0;
  1049.             for (var i = oneText.length - 1; i > -1; i--) {
  1050.                 onePortion = oneText.charAt(i) + onePortion;
  1051.                 groupCount++;
  1052.                 if (groupCount == groupLength && i != 0) {
  1053.                     onePortion = group + onePortion;
  1054.                     groupCount = 0;
  1055.                 }
  1056.             }
  1057.             if (onesFormat.length > onePortion.length) {
  1058.                 var padStart = onesFormat.indexOf("0");
  1059.                 if (padStart != -1) {
  1060.                     var padLen = onesFormat.length - padStart;
  1061.                     var pos = onesFormat.length - onePortion.length - 1;
  1062.                     while (onePortion.length < padLen) {
  1063.                         var padChar = onesFormat.charAt(pos);
  1064.                         if (padChar == ",") padChar = group;
  1065.                         onePortion = padChar + onePortion;
  1066.                         pos--;
  1067.                     }
  1068.                 }
  1069.             }
  1070.         }
  1071.         if (!onePortion && onesFormat.indexOf("0", onesFormat.length - 1) !== -1) onePortion = "0";
  1072.         returnString = onePortion + returnString;
  1073.         if (number < 0 && negativeInFront && prefix.length > 0) prefix = neg + prefix; else if (number < 0) returnString = neg + returnString;
  1074.         if (!options.decimalSeparatorAlwaysShown) {
  1075.             if (returnString.lastIndexOf(dec) == returnString.length - 1) {
  1076.                 returnString = returnString.substring(0, returnString.length - 1);
  1077.             }
  1078.         }
  1079.         returnString = prefix + returnString + suffix;
  1080.         return returnString;
  1081.     };
  1082.     jQuery.fn.parseNumber = function(options, writeBack, giveReturnValue) {
  1083.         if (writeBack == null) writeBack = true;
  1084.         if (giveReturnValue == null) giveReturnValue = true;
  1085.         var text;
  1086.         if (jQuery(this).is(":input")) text = new String(jQuery(this).val()); else text = new String(jQuery(this).text());
  1087.         var number = jQuery.parseNumber(text, options);
  1088.         if (number) {
  1089.             if (writeBack) {
  1090.                 if (jQuery(this).is(":input")) jQuery(this).val(number.toString()); else jQuery(this).text(number.toString());
  1091.             }
  1092.             if (giveReturnValue) return number;
  1093.         }
  1094.     };
  1095.     jQuery.parseNumber = function(numberString, options) {
  1096.         var options = jQuery.extend({}, jQuery.fn.parseNumber.defaults, options);
  1097.         var formatData = formatCodes(options.locale.toLowerCase(), options.isFullLocale);
  1098.         var dec = formatData.dec;
  1099.         var group = formatData.group;
  1100.         var neg = formatData.neg;
  1101.         var valid = "1234567890.-";
  1102.         while (numberString.indexOf(group) > -1) numberString = numberString.replace(group, "");
  1103.         numberString = numberString.replace(dec, ".").replace(neg, "-");
  1104.         var validText = "";
  1105.         var hasPercent = false;
  1106.         if (numberString.charAt(numberString.length - 1) == "%" || options.isPercentage == true) hasPercent = true;
  1107.         for (var i = 0; i < numberString.length; i++) {
  1108.             if (valid.indexOf(numberString.charAt(i)) > -1) validText = validText + numberString.charAt(i);
  1109.         }
  1110.         var number = new Number(validText);
  1111.         if (hasPercent) {
  1112.             number = number / 100;
  1113.             var decimalPos = validText.indexOf(".");
  1114.             if (decimalPos != -1) {
  1115.                 var decimalPoints = validText.length - decimalPos - 1;
  1116.                 number = number.toFixed(decimalPoints + 2);
  1117.             } else {
  1118.                 number = number.toFixed(validText.length - 1);
  1119.             }
  1120.         }
  1121.         return number;
  1122.     };
  1123.     jQuery.fn.parseNumber.defaults = {
  1124.         locale: "us",
  1125.         decimalSeparatorAlwaysShown: false,
  1126.         isPercentage: false,
  1127.         isFullLocale: false
  1128.     };
  1129.     jQuery.fn.formatNumber.defaults = {
  1130.         format: "#,###.00",
  1131.         locale: "us",
  1132.         decimalSeparatorAlwaysShown: false,
  1133.         nanForceZero: true,
  1134.         round: true,
  1135.         isFullLocale: false
  1136.     };
  1137.     Number.prototype.toFixed = function(precision) {
  1138.         return jQuery._roundNumber(this, precision);
  1139.     };
  1140.     jQuery._roundNumber = function(number, decimalPlaces) {
  1141.         var power = Math.pow(10, decimalPlaces || 0);
  1142.         var value = String(Math.round(number * power) / power);
  1143.         if (decimalPlaces > 0) {
  1144.             var dp = value.indexOf(".");
  1145.             if (dp == -1) {
  1146.                 value += ".";
  1147.                 dp = 0;
  1148.             } else {
  1149.                 dp = value.length - (dp + 1);
  1150.             }
  1151.             while (dp < decimalPlaces) {
  1152.                 value += "0";
  1153.                 dp++;
  1154.             }
  1155.         }
  1156.         return value;
  1157.     };
  1158. })(jQuery);
  1159.  
  1160. (function() {
  1161.     var cache = {};
  1162.     this.tmpl = function tmpl(str, data) {
  1163.         var fn = !/\W/.test(str) ? cache[str] = cache[str] || tmpl(document.getElementById(str).innerHTML) : new Function("obj", "var p=[],print=function(){p.push.apply(p,arguments);};" + "with(obj){p.push('" + str.replace(/[\r\t\n]/g, " ").split("<%").join(" ").replace(/((^|%>)[^\t]*)'/g, "$1\r").replace(/\t=(.*?)%>/g, "',$1,'").split(" ").join("');").split("%>").join("p.push('").split("\r").join("\\'") + "');}return p.join('');");
  1164.         return data ? fn(data) : fn;
  1165.     };
  1166. })();
  1167.  
  1168. (function($) {
  1169.     $.baseClass = function(obj) {
  1170.         obj = $(obj);
  1171.         return obj.get(0).className.match(/([^ ]+)/)[1];
  1172.     };
  1173.     $.fn.addDependClass = function(className, delimiter) {
  1174.         var options = {
  1175.             delimiter: delimiter ? delimiter : "-"
  1176.         };
  1177.         return this.each(function() {
  1178.             var baseClass = $.baseClass(this);
  1179.             if (baseClass) $(this).addClass(baseClass + options.delimiter + className);
  1180.         });
  1181.     };
  1182.     $.fn.removeDependClass = function(className, delimiter) {
  1183.         var options = {
  1184.             delimiter: delimiter ? delimiter : "-"
  1185.         };
  1186.         return this.each(function() {
  1187.             var baseClass = $.baseClass(this);
  1188.             if (baseClass) $(this).removeClass(baseClass + options.delimiter + className);
  1189.         });
  1190.     };
  1191.     $.fn.toggleDependClass = function(className, delimiter) {
  1192.         var options = {
  1193.             delimiter: delimiter ? delimiter : "-"
  1194.         };
  1195.         return this.each(function() {
  1196.             var baseClass = $.baseClass(this);
  1197.             if (baseClass) if ($(this).is("." + baseClass + options.delimiter + className)) $(this).removeClass(baseClass + options.delimiter + className); else $(this).addClass(baseClass + options.delimiter + className);
  1198.         });
  1199.     };
  1200. })(jQuery);
  1201.  
  1202. (function($) {
  1203.     function Draggable() {
  1204.         this._init.apply(this, arguments);
  1205.     }
  1206.     Draggable.prototype.oninit = function() {};
  1207.     Draggable.prototype.events = function() {};
  1208.     Draggable.prototype.onmousedown = function() {
  1209.         this.ptr.css({
  1210.             position: "absolute"
  1211.         });
  1212.     };
  1213.     Draggable.prototype.onmousemove = function(evt, x, y) {
  1214.         this.ptr.css({
  1215.             left: x,
  1216.             top: y
  1217.         });
  1218.     };
  1219.     Draggable.prototype.onmouseup = function() {};
  1220.     Draggable.prototype.isDefault = {
  1221.         drag: false,
  1222.         clicked: false,
  1223.         toclick: true,
  1224.         mouseup: false
  1225.     };
  1226.     Draggable.prototype._init = function() {
  1227.         if (arguments.length > 0) {
  1228.             this.ptr = $(arguments[0]);
  1229.             this.outer = $(".draggable-outer");
  1230.             this.is = {};
  1231.             $.extend(this.is, this.isDefault);
  1232.             var _offset = this.ptr.offset();
  1233.             this.d = {
  1234.                 left: _offset.left,
  1235.                 top: _offset.top,
  1236.                 width: this.ptr.width(),
  1237.                 height: this.ptr.height()
  1238.             };
  1239.             this.oninit.apply(this, arguments);
  1240.             this._events();
  1241.         }
  1242.     };
  1243.     Draggable.prototype._getPageCoords = function(event) {
  1244.         if (event.targetTouches && event.targetTouches[0]) {
  1245.             return {
  1246.                 x: event.targetTouches[0].pageX,
  1247.                 y: event.targetTouches[0].pageY
  1248.             };
  1249.         } else return {
  1250.             x: event.pageX,
  1251.             y: event.pageY
  1252.         };
  1253.     };
  1254.     Draggable.prototype._bindEvent = function(ptr, eventType, handler) {
  1255.         var self = this;
  1256.         if (this.supportTouches_) ptr.get(0).addEventListener(this.events_[eventType], handler, false); else ptr.bind(this.events_[eventType], handler);
  1257.     };
  1258.     Draggable.prototype._events = function() {
  1259.         var self = this;
  1260.         this.supportTouches_ = "ontouchend" in document;
  1261.         this.events_ = {
  1262.             click: this.supportTouches_ ? "touchstart" : "click",
  1263.             down: this.supportTouches_ ? "touchstart" : "mousedown",
  1264.             move: this.supportTouches_ ? "touchmove" : "mousemove",
  1265.             up: this.supportTouches_ ? "touchend" : "mouseup"
  1266.         };
  1267.         this._bindEvent($(document), "move", function(event) {
  1268.             if (self.is.drag) {
  1269.                 event.stopPropagation();
  1270.                 event.preventDefault();
  1271.                 self._mousemove(event);
  1272.             }
  1273.         });
  1274.         this._bindEvent($(document), "down", function(event) {
  1275.             if (self.is.drag) {
  1276.                 event.stopPropagation();
  1277.                 event.preventDefault();
  1278.             }
  1279.         });
  1280.         this._bindEvent($(document), "up", function(event) {
  1281.             self._mouseup(event);
  1282.         });
  1283.         this._bindEvent(this.ptr, "down", function(event) {
  1284.             self._mousedown(event);
  1285.             return false;
  1286.         });
  1287.         this._bindEvent(this.ptr, "up", function(event) {
  1288.             self._mouseup(event);
  1289.         });
  1290.         this.ptr.find("a").click(function() {
  1291.             self.is.clicked = true;
  1292.             if (!self.is.toclick) {
  1293.                 self.is.toclick = true;
  1294.                 return false;
  1295.             }
  1296.         }).mousedown(function(event) {
  1297.             self._mousedown(event);
  1298.             return false;
  1299.         });
  1300.         this.events();
  1301.     };
  1302.     Draggable.prototype._mousedown = function(evt) {
  1303.         this.is.drag = true;
  1304.         this.is.clicked = false;
  1305.         this.is.mouseup = false;
  1306.         var _offset = this.ptr.offset();
  1307.         var coords = this._getPageCoords(evt);
  1308.         this.cx = coords.x - _offset.left;
  1309.         this.cy = coords.y - _offset.top;
  1310.         $.extend(this.d, {
  1311.             left: _offset.left,
  1312.             top: _offset.top,
  1313.             width: this.ptr.width(),
  1314.             height: this.ptr.height()
  1315.         });
  1316.         if (this.outer && this.outer.get(0)) {
  1317.             this.outer.css({
  1318.                 height: Math.max(this.outer.height(), $(document.body).height()),
  1319.                 overflow: "hidden"
  1320.             });
  1321.         }
  1322.         this.onmousedown(evt);
  1323.     };
  1324.     Draggable.prototype._mousemove = function(evt) {
  1325.         this.is.toclick = false;
  1326.         var coords = this._getPageCoords(evt);
  1327.         this.onmousemove(evt, coords.x - this.cx, coords.y - this.cy);
  1328.     };
  1329.     Draggable.prototype._mouseup = function(evt) {
  1330.         var oThis = this;
  1331.         if (this.is.drag) {
  1332.             this.is.drag = false;
  1333.             if (this.outer && this.outer.get(0)) {
  1334.                 if ($.browser.mozilla) {
  1335.                     this.outer.css({
  1336.                         overflow: "hidden"
  1337.                     });
  1338.                 } else {
  1339.                     this.outer.css({
  1340.                         overflow: "visible"
  1341.                     });
  1342.                 }
  1343.                 if ($.browser.msie && $.browser.version == "6.0") {
  1344.                     this.outer.css({
  1345.                         height: "100%"
  1346.                     });
  1347.                 } else {
  1348.                     this.outer.css({
  1349.                         height: "auto"
  1350.                     });
  1351.                 }
  1352.             }
  1353.             this.onmouseup(evt);
  1354.         }
  1355.     };
  1356.     window.Draggable = Draggable;
  1357. })(jQuery);
  1358.  
  1359. (function($) {
  1360.     function isArray(value) {
  1361.         if (typeof value == "undefined") return false;
  1362.         if (value instanceof Array || !(value instanceof Object) && Object.prototype.toString.call(value) == "[object Array]" || typeof value.length == "number" && typeof value.splice != "undefined" && typeof value.propertyIsEnumerable != "undefined" && !value.propertyIsEnumerable("splice")) {
  1363.             return true;
  1364.         }
  1365.         return false;
  1366.     }
  1367.     $.slider = function(node, settings) {
  1368.         var jNode = $(node);
  1369.         if (!jNode.data("jslider")) jNode.data("jslider", new jSlider(node, settings));
  1370.         return jNode.data("jslider");
  1371.     };
  1372.     $.fn.slider = function(action, opt_value) {
  1373.         var returnValue, args = arguments;
  1374.         function isDef(val) {
  1375.             return val !== undefined;
  1376.         }
  1377.         function isDefAndNotNull(val) {
  1378.             return val != null;
  1379.         }
  1380.         this.each(function() {
  1381.             var self = $.slider(this, action);
  1382.             if (typeof action == "string") {
  1383.                 switch (action) {
  1384.                   case "value":
  1385.                     if (isDef(args[1]) && isDef(args[2])) {
  1386.                         var pointers = self.getPointers();
  1387.                         if (isDefAndNotNull(pointers[0]) && isDefAndNotNull(args[1])) {
  1388.                             pointers[0].set(args[1]);
  1389.                             pointers[0].setIndexOver();
  1390.                         }
  1391.                         if (isDefAndNotNull(pointers[1]) && isDefAndNotNull(args[2])) {
  1392.                             pointers[1].set(args[2]);
  1393.                             pointers[1].setIndexOver();
  1394.                         }
  1395.                     } else if (isDef(args[1])) {
  1396.                         var pointers = self.getPointers();
  1397.                         if (isDefAndNotNull(pointers[0]) && isDefAndNotNull(args[1])) {
  1398.                             pointers[0].set(args[1]);
  1399.                             pointers[0].setIndexOver();
  1400.                         }
  1401.                     } else returnValue = self.getValue();
  1402.                     break;
  1403.  
  1404.                   case "prc":
  1405.                     if (isDef(args[1]) && isDef(args[2])) {
  1406.                         var pointers = self.getPointers();
  1407.                         if (isDefAndNotNull(pointers[0]) && isDefAndNotNull(args[1])) {
  1408.                             pointers[0]._set(args[1]);
  1409.                             pointers[0].setIndexOver();
  1410.                         }
  1411.                         if (isDefAndNotNull(pointers[1]) && isDefAndNotNull(args[2])) {
  1412.                             pointers[1]._set(args[2]);
  1413.                             pointers[1].setIndexOver();
  1414.                         }
  1415.                     } else if (isDef(args[1])) {
  1416.                         var pointers = self.getPointers();
  1417.                         if (isDefAndNotNull(pointers[0]) && isDefAndNotNull(args[1])) {
  1418.                             pointers[0]._set(args[1]);
  1419.                             pointers[0].setIndexOver();
  1420.                         }
  1421.                     } else returnValue = self.getPrcValue();
  1422.                     break;
  1423.  
  1424.                   case "calculatedValue":
  1425.                     var value = self.getValue().split(";");
  1426.                     returnValue = "";
  1427.                     for (var i = 0; i < value.length; i++) {
  1428.                         returnValue += (i > 0 ? ";" : "") + self.nice(value[i]);
  1429.                     }
  1430.                     ;
  1431.                     break;
  1432.  
  1433.                   case "skin":
  1434.                     self.setSkin(args[1]);
  1435.                     break;
  1436.                 }
  1437.             } else if (!action && !opt_value) {
  1438.                 if (!isArray(returnValue)) returnValue = [];
  1439.                 returnValue.push(self);
  1440.             }
  1441.         });
  1442.         if (isArray(returnValue) && returnValue.length == 1) returnValue = returnValue[0];
  1443.         return returnValue || this;
  1444.     };
  1445.     var OPTIONS = {
  1446.         settings: {
  1447.             from: 1,
  1448.             to: 10,
  1449.             step: 1,
  1450.             smooth: true,
  1451.             limits: true,
  1452.             round: 0,
  1453.             format: {
  1454.                 format: "#,##0.##"
  1455.             },
  1456.             value: "5;7",
  1457.             dimension: ""
  1458.         },
  1459.         className: "jslider",
  1460.         selector: ".jslider-",
  1461.         template: tmpl('<span class="<%=className%>">' + "<table><tr><td>" + '<div class="<%=className%>-bg">' + '<i class="l"></i><i class="f"></i><i class="r"></i>' + '<i class="v"></i>' + "</div>" + '<div class="<%=className%>-pointer"></div>' + '<div class="<%=className%>-pointer <%=className%>-pointer-to"></div>' + '<div class="<%=className%>-label"><span><%=settings.from%></span></div>' + '<div class="<%=className%>-label <%=className%>-label-to"><span><%=settings.to%></span><%=settings.dimension%></div>' + '<div class="<%=className%>-value"><span></span><%=settings.dimension%></div>' + '<div class="<%=className%>-value <%=className%>-value-to"><span></span><%=settings.dimension%></div>' + '<div class="<%=className%>-scale"><%=scale%></div>' + "</td></tr></table>" + "</span>")
  1462.     };
  1463.     function jSlider() {
  1464.         return this.init.apply(this, arguments);
  1465.     }
  1466.     jSlider.prototype.init = function(node, settings) {
  1467.         this.settings = $.extend(true, {}, OPTIONS.settings, settings ? settings : {});
  1468.         this.inputNode = $(node).hide();
  1469.         this.settings.interval = this.settings.to - this.settings.from;
  1470.         this.settings.value = this.inputNode.attr("value");
  1471.         if (this.settings.calculate && $.isFunction(this.settings.calculate)) this.nice = this.settings.calculate;
  1472.         if (this.settings.onstatechange && $.isFunction(this.settings.onstatechange)) this.onstatechange = this.settings.onstatechange;
  1473.         this.is = {
  1474.             init: false
  1475.         };
  1476.         this.o = {};
  1477.         this.create();
  1478.     };
  1479.     jSlider.prototype.onstatechange = function() {};
  1480.     jSlider.prototype.create = function() {
  1481.         var $this = this;
  1482.         this.domNode = $(OPTIONS.template({
  1483.             className: OPTIONS.className,
  1484.             settings: {
  1485.                 from: this.nice(this.settings.from),
  1486.                 to: this.nice(this.settings.to),
  1487.                 dimension: this.settings.dimension
  1488.             },
  1489.             scale: this.generateScale()
  1490.         }));
  1491.         this.inputNode.after(this.domNode);
  1492.         this.drawScale();
  1493.         if (this.settings.skin && this.settings.skin.length > 0) this.setSkin(this.settings.skin);
  1494.         this.sizes = {
  1495.             domWidth: this.domNode.width(),
  1496.             domOffset: this.domNode.offset()
  1497.         };
  1498.         $.extend(this.o, {
  1499.             pointers: {},
  1500.             labels: {
  1501.                 0: {
  1502.                     o: this.domNode.find(OPTIONS.selector + "value").not(OPTIONS.selector + "value-to")
  1503.                 },
  1504.                 1: {
  1505.                     o: this.domNode.find(OPTIONS.selector + "value").filter(OPTIONS.selector + "value-to")
  1506.                 }
  1507.             },
  1508.             limits: {
  1509.                 0: this.domNode.find(OPTIONS.selector + "label").not(OPTIONS.selector + "label-to"),
  1510.                 1: this.domNode.find(OPTIONS.selector + "label").filter(OPTIONS.selector + "label-to")
  1511.             }
  1512.         });
  1513.         $.extend(this.o.labels[0], {
  1514.             value: this.o.labels[0].o.find("span")
  1515.         });
  1516.         $.extend(this.o.labels[1], {
  1517.             value: this.o.labels[1].o.find("span")
  1518.         });
  1519.         if (!$this.settings.value.split(";")[1]) {
  1520.             this.settings.single = true;
  1521.             this.domNode.addDependClass("single");
  1522.         }
  1523.         if (!$this.settings.limits) this.domNode.addDependClass("limitless");
  1524.         this.domNode.find(OPTIONS.selector + "pointer").each(function(i) {
  1525.             var value = $this.settings.value.split(";")[i];
  1526.             if (value) {
  1527.                 $this.o.pointers[i] = new jSliderPointer(this, i, $this);
  1528.                 var prev = $this.settings.value.split(";")[i - 1];
  1529.                 if (prev && new Number(value) < new Number(prev)) value = prev;
  1530.                 value = value < $this.settings.from ? $this.settings.from : value;
  1531.                 value = value > $this.settings.to ? $this.settings.to : value;
  1532.                 $this.o.pointers[i].set(value, true);
  1533.             }
  1534.         });
  1535.         this.o.value = this.domNode.find(".v");
  1536.         this.is.init = true;
  1537.         $.each(this.o.pointers, function(i) {
  1538.             $this.redraw(this);
  1539.         });
  1540.         (function(self) {
  1541.             $(window).resize(function() {
  1542.                 self.onresize();
  1543.             });
  1544.         })(this);
  1545.     };
  1546.     jSlider.prototype.setSkin = function(skin) {
  1547.         if (this.skin_) this.domNode.removeDependClass(this.skin_, "_");
  1548.         this.domNode.addDependClass(this.skin_ = skin, "_");
  1549.     };
  1550.     jSlider.prototype.setPointersIndex = function(i) {
  1551.         $.each(this.getPointers(), function(i) {
  1552.             this.index(i);
  1553.         });
  1554.     };
  1555.     jSlider.prototype.getPointers = function() {
  1556.         return this.o.pointers;
  1557.     };
  1558.     jSlider.prototype.generateScale = function() {
  1559.         if (this.settings.scale && this.settings.scale.length > 0) {
  1560.             var str = "";
  1561.             var s = this.settings.scale;
  1562.             var prc = Math.round(100 / (s.length - 1) * 10) / 10;
  1563.             for (var i = 0; i < s.length; i++) {
  1564.                 str += '<span style="left: ' + i * prc + '%">' + (s[i] != "|" ? "<ins>" + s[i] + "</ins>" : "") + "</span>";
  1565.             }
  1566.             return str;
  1567.         } else return "";
  1568.         return "";
  1569.     };
  1570.     jSlider.prototype.drawScale = function() {
  1571.         this.domNode.find(OPTIONS.selector + "scale span ins").each(function() {
  1572.             $(this).css({
  1573.                 marginLeft: -$(this).outerWidth() / 2
  1574.             });
  1575.         });
  1576.     };
  1577.     jSlider.prototype.onresize = function() {
  1578.         var self = this;
  1579.         this.sizes = {
  1580.             domWidth: this.domNode.width(),
  1581.             domOffset: this.domNode.offset()
  1582.         };
  1583.         $.each(this.o.pointers, function(i) {
  1584.             self.redraw(this);
  1585.         });
  1586.     };
  1587.     jSlider.prototype.update = function() {
  1588.         this.onresize();
  1589.         this.drawScale();
  1590.     };
  1591.     jSlider.prototype.limits = function(x, pointer) {
  1592.         if (!this.settings.smooth) {
  1593.             var step = this.settings.step * 100 / this.settings.interval;
  1594.             x = Math.round(x / step) * step;
  1595.         }
  1596.         var another = this.o.pointers[1 - pointer.uid];
  1597.         if (another && pointer.uid && x < another.value.prc) x = another.value.prc;
  1598.         if (another && !pointer.uid && x > another.value.prc) x = another.value.prc;
  1599.         if (x < 0) x = 0;
  1600.         if (x > 100) x = 100;
  1601.         return Math.round(x * 10) / 10;
  1602.     };
  1603.     jSlider.prototype.redraw = function(pointer) {
  1604.         if (!this.is.init) return false;
  1605.         this.setValue();
  1606.         if (this.o.pointers[0] && this.o.pointers[1]) this.o.value.css({
  1607.             left: this.o.pointers[0].value.prc + "%",
  1608.             width: this.o.pointers[1].value.prc - this.o.pointers[0].value.prc + "%"
  1609.         });
  1610.         this.o.labels[pointer.uid].value.html(this.nice(pointer.value.origin));
  1611.         this.redrawLabels(pointer);
  1612.     };
  1613.     jSlider.prototype.redrawLabels = function(pointer) {
  1614.         function setPosition(label, sizes, prc) {
  1615.             sizes.margin = -sizes.label / 2;
  1616.             label_left = sizes.border + sizes.margin;
  1617.             if (label_left < 0) sizes.margin -= label_left;
  1618.             if (sizes.border + sizes.label / 2 > self.sizes.domWidth) {
  1619.                 sizes.margin = 0;
  1620.                 sizes.right = true;
  1621.             } else sizes.right = false;
  1622.             label.o.css({
  1623.                 left: prc + "%",
  1624.                 marginLeft: sizes.margin,
  1625.                 right: "auto"
  1626.             });
  1627.             if (sizes.right) label.o.css({
  1628.                 left: "auto",
  1629.                 right: 0
  1630.             });
  1631.             return sizes;
  1632.         }
  1633.         var self = this;
  1634.         var label = this.o.labels[pointer.uid];
  1635.         var prc = pointer.value.prc;
  1636.         var sizes = {
  1637.             label: label.o.outerWidth(),
  1638.             right: false,
  1639.             border: prc * this.sizes.domWidth / 100
  1640.         };
  1641.         if (!this.settings.single) {
  1642.             var another = this.o.pointers[1 - pointer.uid];
  1643.             var another_label = this.o.labels[another.uid];
  1644.             switch (pointer.uid) {
  1645.               case 0:
  1646.                 if (sizes.border + sizes.label / 2 > another_label.o.offset().left - this.sizes.domOffset.left) {
  1647.                     another_label.o.css({
  1648.                         visibility: "hidden"
  1649.                     });
  1650.                     another_label.value.html(this.nice(another.value.origin));
  1651.                     label.o.css({
  1652.                         visibility: "visible"
  1653.                     });
  1654.                     prc = (another.value.prc - prc) / 2 + prc;
  1655.                     if (another.value.prc != pointer.value.prc) {
  1656.                         label.value.html(this.nice(pointer.value.origin) + "&nbsp;&ndash;&nbsp;" + this.nice(another.value.origin));
  1657.                         sizes.label = label.o.outerWidth();
  1658.                         sizes.border = prc * this.sizes.domWidth / 100;
  1659.                     }
  1660.                 } else {
  1661.                     another_label.o.css({
  1662.                         visibility: "visible"
  1663.                     });
  1664.                 }
  1665.                 break;
  1666.  
  1667.               case 1:
  1668.                 if (sizes.border - sizes.label / 2 < another_label.o.offset().left - this.sizes.domOffset.left + another_label.o.outerWidth()) {
  1669.                     another_label.o.css({
  1670.                         visibility: "hidden"
  1671.                     });
  1672.                     another_label.value.html(this.nice(another.value.origin));
  1673.                     label.o.css({
  1674.                         visibility: "visible"
  1675.                     });
  1676.                     prc = (prc - another.value.prc) / 2 + another.value.prc;
  1677.                     if (another.value.prc != pointer.value.prc) {
  1678.                         label.value.html(this.nice(another.value.origin) + "&nbsp;&ndash;&nbsp;" + this.nice(pointer.value.origin));
  1679.                         sizes.label = label.o.outerWidth();
  1680.                         sizes.border = prc * this.sizes.domWidth / 100;
  1681.                     }
  1682.                 } else {
  1683.                     another_label.o.css({
  1684.                         visibility: "visible"
  1685.                     });
  1686.                 }
  1687.                 break;
  1688.             }
  1689.         }
  1690.         sizes = setPosition(label, sizes, prc);
  1691.         if (another_label) {
  1692.             var sizes = {
  1693.                 label: another_label.o.outerWidth(),
  1694.                 right: false,
  1695.                 border: another.value.prc * this.sizes.domWidth / 100
  1696.             };
  1697.             sizes = setPosition(another_label, sizes, another.value.prc);
  1698.         }
  1699.         this.redrawLimits();
  1700.     };
  1701.     jSlider.prototype.redrawLimits = function() {
  1702.         if (this.settings.limits) {
  1703.             var limits = [ true, true ];
  1704.             for (key in this.o.pointers) {
  1705.                 if (!this.settings.single || key == 0) {
  1706.                     var pointer = this.o.pointers[key];
  1707.                     var label = this.o.labels[pointer.uid];
  1708.                     var label_left = label.o.offset().left - this.sizes.domOffset.left;
  1709.                     var limit = this.o.limits[0];
  1710.                     if (label_left < limit.outerWidth()) limits[0] = false;
  1711.                     var limit = this.o.limits[1];
  1712.                     if (label_left + label.o.outerWidth() > this.sizes.domWidth - limit.outerWidth()) limits[1] = false;
  1713.                 }
  1714.             }
  1715.             for (var i = 0; i < limits.length; i++) {
  1716.                 if (limits[i]) this.o.limits[i].fadeIn("fast"); else this.o.limits[i].fadeOut("fast");
  1717.             }
  1718.         }
  1719.     };
  1720.     jSlider.prototype.setValue = function() {
  1721.         var value = this.getValue();
  1722.         this.inputNode.attr("value", value);
  1723.         this.onstatechange.call(this, value);
  1724.     };
  1725.     jSlider.prototype.getValue = function() {
  1726.         if (!this.is.init) return false;
  1727.         var $this = this;
  1728.         var value = "";
  1729.         $.each(this.o.pointers, function(i) {
  1730.             if (this.value.prc != undefined && !isNaN(this.value.prc)) value += (i > 0 ? ";" : "") + $this.prcToValue(this.value.prc);
  1731.         });
  1732.         return value;
  1733.     };
  1734.     jSlider.prototype.getPrcValue = function() {
  1735.         if (!this.is.init) return false;
  1736.         var $this = this;
  1737.         var value = "";
  1738.         $.each(this.o.pointers, function(i) {
  1739.             if (this.value.prc != undefined && !isNaN(this.value.prc)) value += (i > 0 ? ";" : "") + this.value.prc;
  1740.         });
  1741.         return value;
  1742.     };
  1743.     jSlider.prototype.prcToValue = function(prc) {
  1744.         if (this.settings.heterogeneity && this.settings.heterogeneity.length > 0) {
  1745.             var h = this.settings.heterogeneity;
  1746.             var _start = 0;
  1747.             var _from = this.settings.from;
  1748.             for (var i = 0; i <= h.length; i++) {
  1749.                 if (h[i]) var v = h[i].split("/"); else var v = [ 100, this.settings.to ];
  1750.                 v[0] = new Number(v[0]);
  1751.                 v[1] = new Number(v[1]);
  1752.                 if (prc >= _start && prc <= v[0]) {
  1753.                     var value = _from + (prc - _start) * (v[1] - _from) / (v[0] - _start);
  1754.                 }
  1755.                 _start = v[0];
  1756.                 _from = v[1];
  1757.             }
  1758.         } else {
  1759.             var value = this.settings.from + prc * this.settings.interval / 100;
  1760.         }
  1761.         return this.round(value);
  1762.     };
  1763.     jSlider.prototype.valueToPrc = function(value, pointer) {
  1764.         if (this.settings.heterogeneity && this.settings.heterogeneity.length > 0) {
  1765.             var h = this.settings.heterogeneity;
  1766.             var _start = 0;
  1767.             var _from = this.settings.from;
  1768.             for (var i = 0; i <= h.length; i++) {
  1769.                 if (h[i]) var v = h[i].split("/"); else var v = [ 100, this.settings.to ];
  1770.                 v[0] = new Number(v[0]);
  1771.                 v[1] = new Number(v[1]);
  1772.                 if (value >= _from && value <= v[1]) {
  1773.                     var prc = pointer.limits(_start + (value - _from) * (v[0] - _start) / (v[1] - _from));
  1774.                 }
  1775.                 _start = v[0];
  1776.                 _from = v[1];
  1777.             }
  1778.         } else {
  1779.             var prc = pointer.limits((value - this.settings.from) * 100 / this.settings.interval);
  1780.         }
  1781.         return prc;
  1782.     };
  1783.     jSlider.prototype.round = function(value) {
  1784.         value = Math.round(value / this.settings.step) * this.settings.step;
  1785.         if (this.settings.round) value = Math.round(value * Math.pow(10, this.settings.round)) / Math.pow(10, this.settings.round); else value = Math.round(value);
  1786.         return value;
  1787.     };
  1788.     jSlider.prototype.nice = function(value) {
  1789.         value = value.toString().replace(/,/gi, ".").replace(/ /gi, "");
  1790.         if ($.formatNumber) {
  1791.             return $.formatNumber(new Number(value), this.settings.format || {}).replace(/-/gi, "&minus;");
  1792.         } else {
  1793.             return new Number(value);
  1794.         }
  1795.     };
  1796.     function jSliderPointer() {
  1797.         Draggable.apply(this, arguments);
  1798.     }
  1799.     jSliderPointer.prototype = new Draggable();
  1800.     jSliderPointer.prototype.oninit = function(ptr, id, _constructor) {
  1801.         this.uid = id;
  1802.         this.parent = _constructor;
  1803.         this.value = {};
  1804.         this.settings = this.parent.settings;
  1805.     };
  1806.     jSliderPointer.prototype.onmousedown = function(evt) {
  1807.         this._parent = {
  1808.             offset: this.parent.domNode.offset(),
  1809.             width: this.parent.domNode.width()
  1810.         };
  1811.         this.ptr.addDependClass("hover");
  1812.         this.setIndexOver();
  1813.     };
  1814.     jSliderPointer.prototype.onmousemove = function(evt, x) {
  1815.         var coords = this._getPageCoords(evt);
  1816.         this._set(this.calc(coords.x));
  1817.     };
  1818.     jSliderPointer.prototype.onmouseup = function(evt) {
  1819.         if (this.parent.settings.callback && $.isFunction(this.parent.settings.callback)) this.parent.settings.callback.call(this.parent, this.parent.getValue());
  1820.         this.ptr.removeDependClass("hover");
  1821.     };
  1822.     jSliderPointer.prototype.setIndexOver = function() {
  1823.         this.parent.setPointersIndex(1);
  1824.         this.index(2);
  1825.     };
  1826.     jSliderPointer.prototype.index = function(i) {
  1827.         this.ptr.css({
  1828.             zIndex: i
  1829.         });
  1830.     };
  1831.     jSliderPointer.prototype.limits = function(x) {
  1832.         return this.parent.limits(x, this);
  1833.     };
  1834.     jSliderPointer.prototype.calc = function(coords) {
  1835.         var x = this.limits((coords - this._parent.offset.left) * 100 / this._parent.width);
  1836.         return x;
  1837.     };
  1838.     jSliderPointer.prototype.set = function(value, opt_origin) {
  1839.         this.value.origin = this.parent.round(value);
  1840.         this._set(this.parent.valueToPrc(value, this), opt_origin);
  1841.     };
  1842.     jSliderPointer.prototype._set = function(prc, opt_origin) {
  1843.         if (!opt_origin) this.value.origin = this.parent.prcToValue(prc);
  1844.         this.value.prc = prc;
  1845.         this.ptr.css({
  1846.             left: prc + "%"
  1847.         });
  1848.         this.parent.redraw(this);
  1849.     };
  1850. })(jQuery);
  1851.  
  1852. function validateHomeNHRewards() {
  1853.     var noerror = true;
  1854.     var errorField = "";
  1855.     $("#einputEmail").hide();
  1856.     $("#einputPassword").hide();
  1857.     var usuario = $("#inputEmail").val();
  1858.     if (!validateLength(usuario) || usuario == $("#inputEmail").attr("placeholder")) {
  1859.         $("#einputEmail").show();
  1860.         $("#inputEmail").addClass("error");
  1861.         noerror = false;
  1862.         if (errorField == "") errorField = "user";
  1863.     } else {
  1864.         $("#inputEmail").removeClass("error");
  1865.     }
  1866.     var password = $("#inputPassword").val();
  1867.     if (!validateLength(password) || password == $("#inputPassword").attr("placeholder")) {
  1868.         $("#einputPassword").show();
  1869.         $("#inputPassword").addClass("error");
  1870.         noerror = false;
  1871.         if (errorField == "") errorField = "password";
  1872.     } else {
  1873.         $("#inputPassword").removeClass("error");
  1874.     }
  1875.     if (!noerror) callSeguimientoForms("error", "loginRewardsForm", errorField);
  1876.     return noerror;
  1877. }
  1878.  
  1879. function validateHomeNHRewardsMob() {
  1880.     var noerror = true;
  1881.     var errorField = "";
  1882.     $("#einputEmailMob").hide();
  1883.     $("#einputPasswordMob").hide();
  1884.     var usuario = $("#inputEmailMob").val();
  1885.     if (!validateLength(usuario) || usuario == $("#inputEmailMob").attr("placeholder")) {
  1886.         $("#einputEmailMob").show();
  1887.         $("#inputEmailMob").addClass("error");
  1888.         noerror = false;
  1889.         if (errorField == "") errorField = "user";
  1890.     } else {
  1891.         $("#inputEmailMob").removeClass("error");
  1892.     }
  1893.     var password = $("#inputPasswordMob").val();
  1894.     if (!validateLength(password) || password == $("#inputPasswordMob").attr("placeholder")) {
  1895.         $("#einputPasswordMob").show();
  1896.         $("#inputPasswordMob").addClass("error");
  1897.         noerror = false;
  1898.         if (errorField == "") errorField = "password";
  1899.     } else {
  1900.         $("#inputPasswordMob").removeClass("error");
  1901.     }
  1902.     if (!noerror) callSeguimientoForms("error", "loginRewardsFormMob", errorField);
  1903.     return noerror;
  1904. }
  1905.  
  1906. $(function() {
  1907.     $("img.lazy").lazyload({
  1908.         effect: "fadeIn",
  1909.         failure_limit: 1
  1910.     });
  1911.     setTimeout(function() {
  1912.         $(window).trigger("scroll");
  1913.     }, 100);
  1914.     setUserDataGEOIP();
  1915.     $(".fancybox").fancybox();
  1916.     $("#allreviews").fancybox({
  1917.         height: 500
  1918.     });
  1919.     $(".qty-opiniones").fancybox({
  1920.         height: 500
  1921.     });
  1922.     $("a#modificar").fancybox({
  1923.         hideOnContentClick: true
  1924.     });
  1925.     $(".selectpicker").selectpicker();
  1926.     $("#lnkForgotPassword").attr("onclick", "forgotPassword();");
  1927.     $("#lnkForgotPasswordMob").attr("onclick", "forgotPasswordMob();");
  1928.     $("#userLoggedMenu").hide();
  1929.     $(".btnLogout").click(function() {
  1930.         logout();
  1931.     });
  1932.     $("#loginForm").submit(function(event) {
  1933.         var nomb = $("#inputEmail").val();
  1934.         var psw = $("#inputPassword").val();
  1935.         doLogin(ssoUrl, nomb, psw, ssoService, ssoAuth);
  1936.         event.preventDefault();
  1937.     });
  1938.     $("#loginFormMob").submit(function(event) {
  1939.         var nombMob = $("#inputEmailMob").val();
  1940.         var pswMob = $("#inputPasswordMob").val();
  1941.         doLogin(ssoUrl, nombMob, pswMob, ssoService, ssoAuth);
  1942.         event.preventDefault();
  1943.     });
  1944.     if (readAcceptCookie() == "true" || decoratorData.pageID.indexOf("83289") > -1) {
  1945.         $(".politicaRewards").hide();
  1946.     } else {
  1947.         $(".politicaRewards").show();
  1948.     }
  1949.     createAcceptCookie(false);
  1950. });
  1951.  
  1952. function resetPass(email) {
  1953.     if (email.attr("placeholder") == email.val()) {
  1954.         email.addClass("error");
  1955.     } else {
  1956.         email.removeClass("error");
  1957.         var request = $.ajax({
  1958.             type: "GET",
  1959.             url: "/auth/ResetPwd.do",
  1960.             data: "user=" + email.val() + "&lang=" + globalLang,
  1961.             success: function(result) {
  1962.                 var json = JSON.parse(result);
  1963.                 if (json["errors"]["ERROR_002"] != null) {
  1964.                     alert(json["errors"]["ERROR_002"]);
  1965.                 }
  1966.             }
  1967.         });
  1968.         email.val("");
  1969.     }
  1970. }
  1971.  
  1972. function forgotPasswordMob() {
  1973.     var email = $("#inputEmailMob");
  1974.     resetPass(email);
  1975. }
  1976.  
  1977. function forgotPassword() {
  1978.     var email = $("#inputEmail");
  1979.     resetPass(email);
  1980. }
  1981.  
  1982. function logout() {
  1983.     var accion = "/j_spring_security_logout";
  1984.     $.ajaxSetup({
  1985.         cache: false
  1986.     });
  1987.     $.getJSON(accion, null, function(data) {
  1988.         var urlLogin = globalHttpProtocol + location.href;
  1989.         window.location = urlLogin;
  1990.         var cookieName = "userLoggedData";
  1991.         sessionStorage.removeItem(cookieName);
  1992.         var cookieRememberMe = "rememberme";
  1993.         $.cookie(cookieRememberMe, null, {
  1994.             path: "/"
  1995.         });
  1996.     });
  1997. }
  1998.  
  1999. var dynamicTelephones = function() {
  2000.     var _campId = typeof campId != "undefined" ? campId : "";
  2001.     var _country = typeof country != "undefined" ? country : "";
  2002.     var _countryName = typeof countryName != "undefined" ? countryName : "";
  2003.     var _continent = typeof continent != "undefined" ? continent : "";
  2004.     var _webSection = typeof page_section != "undefined" ? page_section : "";
  2005.     var channelIndex = "-1";
  2006.     var telephone = "";
  2007.     var telephoneWebSection = "";
  2008.     var global = "";
  2009.     var countryName = "";
  2010.     var countryText = "";
  2011.     var countryFound = false;
  2012.     var telephoneJSON = "/resources/telephoneJSON.txt";
  2013.     var telephoneCountry = "";
  2014.     var countryUser = "";
  2015.     var init = function() {
  2016.         if (typeof Agent != "undefined") {
  2017.             _country = Agent.country;
  2018.             _campId = Agent.campId;
  2019.             _countryName = Agent.countryName;
  2020.             _continent = Agent.continent;
  2021.             if (Agent.country != getCookieValue("USER_CT_COUNTRYCODE")) {
  2022.                 console.log("Agentcountry, ", Agent.country, "USER_CT_COUNTRYCODE: ", getCookieValue("USER_CT_COUNTRYCODE"));
  2023.             }
  2024.         }
  2025.         _continent = getCookieValue("USER_CT_CONTINENT") != "" && getCookieValue("USER_CT_CONTINENT") != "null" ? getCookieValue("USER_CT_CONTINENT") : _continent;
  2026.         _country = getCookieValue("USER_CT_COUNTRYCODE") != "" && getCookieValue("USER_CT_COUNTRYCODE") != "null" ? getCookieValue("USER_CT_COUNTRYCODE") : _country;
  2027.         _countryName = getCookieValue("USER_CT_COUNTRYCODE") != "" && getCookieValue("USER_CT_COUNTRYCODE") != "null" ? getCookieValue("USER_CT_COUNTRYCODE") : _countryName;
  2028.         countryText = _country;
  2029.         countryUser = _country;
  2030.         if (_campId == "8431996") {
  2031.             $(".labelMeta").removeClass("hidden");
  2032.             $(".imageMetaSearch").html('<img src="/system/img/trivago.png" alt="" class="triplogo">');
  2033.         }
  2034.         if (_campId == "8565112") {
  2035.             $(".labelMeta").removeClass("hidden");
  2036.             $(".imageMetaSearch").html('<img src="/system/img/logos/logo-google.svg" alt="" class="triplogo">');
  2037.         }
  2038.         if (_campId == "8435709") {
  2039.             $(".labelMeta").removeClass("hidden");
  2040.             $(".imageMetaSearch").html('<img src="/system/img/tripadvisor.png" alt="" class="triplogo">');
  2041.         }
  2042.         $.ajax({
  2043.             cache: true,
  2044.             url: telephoneJSON,
  2045.             dataType: "json",
  2046.             success: function(data) {
  2047.                 if (_campId != null) {
  2048.                     for (var i = 0; i < data.channels.length; i++) {
  2049.                         for (var j = 0; j < data.channels[i].agent.length; j++) {
  2050.                             if (data.channels[i].agent[j].campId == _campId) {
  2051.                                 channelIndex = i;
  2052.                             }
  2053.                         }
  2054.                     }
  2055.                     if (channelIndex != "-1") {
  2056.                         for (var k = 0; k < data.channels[channelIndex].telephones.length; k++) {
  2057.                             if (data.channels[channelIndex].telephones[k].country == countryUser) {
  2058.                                 telephoneCountry = data.channels[channelIndex].telephones[k].telephone;
  2059.                                 telephone = data.channels[channelIndex].telephones[k].telephone;
  2060.                                 countryName = data.channels[channelIndex].telephones[k].countryName;
  2061.                                 countryFound = true;
  2062.                             } else {
  2063.                                 $(".telephoneList").append('<li><a href="tel:' + data.channels[channelIndex].telephones[k].telephone + '">' + data.channels[channelIndex].telephones[k].telephone + " (" + data.channels[channelIndex].telephones[k].country + ")" + "</a></li>");
  2064.                             }
  2065.                         }
  2066.                         if (data.channels[channelIndex].globalChannel != "") {
  2067.                             if (countryFound) {
  2068.                                 $(".telephoneList").html($(".telephoneList").html() + '<li><a href="tel:' + data.channels[channelIndex].globalChannel + '">' + data.channels[channelIndex].globalChannel + " (" + labelGlobalAccess + ")" + "</a></li>");
  2069.                                 global = data.channels[channelIndex].globalChannel;
  2070.                             } else {
  2071.                                 telephone = data.channels[channelIndex].globalChannel;
  2072.                                 global = data.channels[channelIndex].globalChannel;
  2073.                                 countryText = labelGlobalAccess;
  2074.                             }
  2075.                         }
  2076.                     }
  2077.                 }
  2078.                 if (channelIndex == "-1") {
  2079.                     for (var i = 0; i < data.channels.length; i++) {
  2080.                         if (data.channels[i].defaultChannel == "Yes") {
  2081.                             for (var k = 0; k < data.channels[i].telephones.length; k++) {
  2082.                                 if (data.channels[i].telephones[k].country == _country) {
  2083.                                     telephone = data.channels[i].telephones[k].telephone;
  2084.                                     countryName = data.channels[i].telephones[k].countryName;
  2085.                                     countryFound = true;
  2086.                                 } else {
  2087.                                     $(".telephoneList").html($(".telephoneList").html() + '<li><a href="tel:' + data.channels[i].telephones[k].telephone + '">' + data.channels[i].telephones[k].telephone + " (" + data.channels[i].telephones[k].country + ")" + "</a></li>");
  2088.                                 }
  2089.                             }
  2090.                             if (data.channels[i].globalChannel != "") {
  2091.                                 if (countryFound) {
  2092.                                     $(".telephoneList").html($(".telephoneList").html() + '<li><a href="tel:' + data.channels[i].globalChannel + '">' + data.channels[i].globalChannel + " (" + labelGlobalAccess + ")" + "</a></li>");
  2093.                                     global = data.channels[i].globalChannel;
  2094.                                 } else {
  2095.                                     telephone = data.channels[i].globalChannel;
  2096.                                     global = data.channels[i].globalChannel;
  2097.                                     countryText = labelGlobalAccess;
  2098.                                 }
  2099.                             }
  2100.                         }
  2101.                         if (data.channels[i].webSection != null && data.channels[i].webSection == _webSection) {
  2102.                             for (var k = 0; k < data.channels[i].telephones.length; k++) {
  2103.                                 if (data.channels[i].telephones[k].country == _country) {
  2104.                                     telephoneWebSection = data.channels[i].telephones[k].telephone;
  2105.                                     break;
  2106.                                 } else {
  2107.                                     telephoneWebSection = data.channels[i].globalChannel;
  2108.                                 }
  2109.                             }
  2110.                         }
  2111.                     }
  2112.                 }
  2113.                 $(".phoneHeader").html(telephone + " (" + countryText + ")" + $(".phoneHeader").html());
  2114.                 $(".phoneHeaderMob").html(telephone + " (" + countryText + ")" + $(".phoneHeaderMob").html());
  2115.                 $(".dynamicTelephone").each(function(indice, elemento) {
  2116.                     $(elemento).text($(elemento).text() + telephone);
  2117.                 });
  2118.                 $(".phoneGlobal").html(global);
  2119.                 $(".phoneCountry").html(countryName);
  2120.                 if (telephone != global) {
  2121.                     $(".phoneContact").html(telephone);
  2122.                 } else {
  2123.                     $("#telephoneContact").hide();
  2124.                 }
  2125.                 if (telephoneWebSection) {
  2126.                     $(".dynamicTelephoneWidget").html(telephoneWebSection);
  2127.                 } else {
  2128.                     $(".dynamicTelephoneWidget").html(telephone);
  2129.                 }
  2130.                 var dinamicTel = $(".dynamicTelephone").html();
  2131.                 var globalTel = $(".phoneGlobal").html();
  2132.                 var sectionTel = $(".dynamicTelephoneWidget").html();
  2133.                 $(".dynamicTelephone").attr("href", "tel:" + telephone);
  2134.                 $(".phoneGlobal").attr("href", "tel:" + global);
  2135.                 $("#contactTel .dynamicTelephone").html("(" + countryText + ")" + "</br> " + dinamicTel);
  2136.                 $(".dynamicTelephoneWidget").attr("href", "tel:" + $(".dynamicTelephoneWidget").text());
  2137.                 changeHTMLMobile();
  2138.             },
  2139.             error: function() {
  2140.                 console.log("Error al recuperar los telefonos dynamicos");
  2141.                 var globalTelephone = "+34 91 398 46 61";
  2142.                 $(".phoneHeader").html(globalTelephone + " (" + labelGlobalAccess + ") <b class='caret'></b>");
  2143.                 $(".phoneHeaderMob").html(globalTelephone + " (" + labelGlobalAccess + ") <b class='caret'></b>");
  2144.                 $().html("<li><a href='tel:+43 0820 40 11 56 08'>+43 0820 40 11 56 08 (AT)</a></li><li><a href='tel:+32 070 35 47 72'>+32 070 35 47 72 (BE)</a></li><li><a href='tel:+33 (0)821 77 42 96'>+33 (0)821 77 42 96 (FR)</a></li><li><a href='tel:+49 30 22388599'>+49 30 22388599 (DE)</a></li><li><a href='tel:(+39) 848 390 227'>(+39) 848 390 227 (IT)</a></li><li><a href='tel:+351 707 500 302'>+351 707 500 302 (PT)</a></li><li><a href='tel:902 570 368'>902 570 368 (ES)</a></li><li><a href='tel:+41 (0)848 20 74 16'>+41 (0)848 20 74 16 (CH)</a></li><li><a href='tel:+31 (0)20 79 56 088'>+31 (0)20 79 56 088 (NL)</a></li><li><a href='tel:+44 (0)870 80 71 359'>+44 (0)870 80 71 359 (GB)</a></li><li><a href='tel:+1 646 568 4725'>+1 646 568 4725 (US)</a></li><li><a href='tel:+54 (0)11 5776 6464'>+54 (0)11 5776 6464 (AR)</a></li><li><a href='tel:+56 (0)2 341 7575'>+56 (0)2 341 7575 (CL)</a></li><li><a href='tel:+57 1 589 7744'>+57 1 589 7744 (CO)</a></li><li><a href='tel:+52 (0)55 52291500'>+52 (0)55 52291500 (MX)</a></li><li><a href='tel:+598 (0)2 9160001'>+598 (0)2 9160001 (UY)</a></li><li><a href='tel:+58 295 400 7111'>+58 295 400 7111 (VE)</a></li>");
  2145.                 $(".dynamicTelephone").each(function(indice, elemento) {
  2146.                     $(elemento).text(globalTelephone + "");
  2147.                 });
  2148.                 $(".phoneGlobal").html(globalTelephone + "");
  2149.                 $(".phoneCountry").html("Spain");
  2150.                 $("#telephoneContact").hide();
  2151.                 telephoneCountry = "+34 91 398 46 61";
  2152.                 global = "+34 91 398 46 61";
  2153.                 changeHTMLMobile();
  2154.             }
  2155.         });
  2156.     };
  2157.     var changeHTMLMobile = function() {
  2158.         countryName = countryName != "" ? countryName : countryText;
  2159.         telephoneCountry = telephoneCountry != "" ? telephoneCountry : telephone;
  2160.         $("a.mobileDynamicTelephone").attr("href", "tel:" + telephoneCountry.replace(/ /g, "")).html(telephoneCountry);
  2161.         $(".mobileDynamicTelephoneTxt").html(telephoneCountry);
  2162.         $("a.mobileDynamicTelephoneHref").attr("href", "tel:" + telephoneCountry.replace(/ /g, ""));
  2163.         $("a.mobileDynamicPhoneGlobal").attr("href", "tel:" + global.replace(/ /g, "")).html(global);
  2164.         $("a.mobileDynamicPhoneGlobalHref").attr("href", "tel:" + global.replace(/ /g, ""));
  2165.         $(".mobileDynamicPhoneGlobalTxt").html(global);
  2166.         $("#mobileContactTel .mobileDynamicTelephone").html(countryName + "</br> " + telephoneCountry);
  2167.     };
  2168.     return {
  2169.         init: init
  2170.     };
  2171. }();
  2172.  
  2173. function getCookieValue(cookieName) {
  2174.     cookieMatch = document.cookie.match("(^|;)\\s*" + cookieName + "\\s*=\\s*([^;]+)");
  2175.     return cookieMatch ? cookieMatch.pop() : "";
  2176. }
  2177.  
  2178. function getCookieValue(cookieName) {
  2179.     cookieMatch = document.cookie.match("(^|;)\\s*" + cookieName + "\\s*=\\s*([^;]+)");
  2180.     return cookieMatch ? cookieMatch.pop() : "";
  2181. }
  2182.  
  2183. $(document).ready(function() {
  2184.     dynamicTelephones.init();
  2185. });
  2186.  
  2187. function trackClickDetectIPOrigin(page) {
  2188.     try {
  2189.         utag.link({
  2190.             eventCategory: page,
  2191.             eventAction: "click availability pop up",
  2192.             event: "availability | click"
  2193.         });
  2194.     } catch (err) {
  2195.         utagError = err;
  2196.     }
  2197. }
  2198.  
  2199. function trackShowDetectIPOrigin(page) {
  2200.     try {
  2201.         utag.link({
  2202.             eventCategory: page,
  2203.             eventAction: "impression availability pop up",
  2204.             event: "availability | impression"
  2205.         });
  2206.     } catch (err) {
  2207.         utagError = err;
  2208.     }
  2209. }
  2210.  
  2211. function trackChangeLanguage(page, language) {
  2212.     try {
  2213.         utag.link({
  2214.             eventCategory: page,
  2215.             eventAction: "change language",
  2216.             eventLabel: language,
  2217.             event: "header | language"
  2218.         });
  2219.     } catch (err) {
  2220.         utagError = err;
  2221.     }
  2222. }
  2223.  
  2224. function trackGeneralSearch(page, name, startDate, endDate, nrooms, nadults, nchild) {
  2225.     try {
  2226.         var nights = calculateNumNights(startDate, endDate);
  2227.         utag.link({
  2228.             eventCategory: page,
  2229.             eventAction: "search",
  2230.             eventLabel: createLabelSearchData(name, startDate, endDate, nrooms, nadults, nchild),
  2231.             eventValue: nights,
  2232.             event: "home | searchbox"
  2233.         });
  2234.     } catch (err) {
  2235.         utagError = err;
  2236.     }
  2237. }
  2238.  
  2239. function trackSignupNewsletter(page) {
  2240.     try {
  2241.         utag.link({
  2242.             eventCategory: page,
  2243.             eventAction: "sign up newsletter",
  2244.             eventLabel: "",
  2245.             event: "home | newsletter"
  2246.         });
  2247.     } catch (err) {
  2248.         utagError = err;
  2249.     }
  2250. }
  2251.  
  2252. function trackSignupRewardsHome(page) {
  2253.     try {
  2254.         utag.link({
  2255.             eventCategory: page,
  2256.             eventAction: "sign up nh rewards",
  2257.             eventLabel: "",
  2258.             event: "home | nh rewards"
  2259.         });
  2260.     } catch (err) {
  2261.         utagError = err;
  2262.     }
  2263. }
  2264.  
  2265. function trackNewGeneralSearch(page, name, startDate, endDate, nrooms, nadults, nchild) {
  2266.     try {
  2267.         utag.link({
  2268.             eventCategory: page,
  2269.             eventAction: "new search",
  2270.             eventLabel: createLabelSearchData(name, startDate, endDate, nrooms, nadults, nchild),
  2271.             eventValue: calculateNumNights(startDate, endDate),
  2272.             event: "SRP | newSearch"
  2273.         });
  2274.     } catch (err) {
  2275.         utagError = err;
  2276.     }
  2277. }
  2278.  
  2279. function trackSelectHotel(page, hotelsearch, checkin, checkout, price, position, numHabis) {
  2280.     try {
  2281.         var numNights = calculateNumNights(checkin, checkout);
  2282.         var quantity = parseInt(numNights) * parseInt(numHabis);
  2283.         utag.link({
  2284.             eventCategory: page,
  2285.             eventAction: "select hotel",
  2286.             eventLabel: createLabelHotelSearchData(hotelsearch, checkin, checkout),
  2287.             eventValue: numNights,
  2288.             event: "SRP | select hotel",
  2289.             ecommerce_action: "add",
  2290.             ecommerce_actionField_list: "search results",
  2291.             products_id: [ hotelsearch ],
  2292.             products_price: [ price ],
  2293.             products_position: [ position ],
  2294.             products_quantity: [ quantity ]
  2295.         });
  2296.     } catch (err) {
  2297.         utagError = err;
  2298.     }
  2299. }
  2300.  
  2301. function trackBookHotelPage(page, hotelsearch, checkin, checkout, price, numHabis) {
  2302.     try {
  2303.         var numNights = calculateNumNights(checkin, checkout);
  2304.         var quantity = parseInt(numNights) * parseInt(numHabis);
  2305.         utag.link({
  2306.             eventCategory: page,
  2307.             eventAction: "book now",
  2308.             eventLabel: hotelsearch,
  2309.             event: "PDP | book",
  2310.             ecommerce_action: "add",
  2311.             ecommerce_actionField_list: "Hotel Page",
  2312.             products_id: [ hotelsearch ],
  2313.             products_price: [ price ],
  2314.             products_quantity: [ quantity ]
  2315.         });
  2316.     } catch (err) {
  2317.         utagError = err;
  2318.     }
  2319. }
  2320.  
  2321. function trackViewHotelPage(page, name, price, position) {
  2322.     try {
  2323.         utag.link({
  2324.             eventCategory: page,
  2325.             eventAction: "view hotel page",
  2326.             eventLabel: name,
  2327.             event: "SRP | view hotel",
  2328.             ecommerce_action: "product_click",
  2329.             ecommerce_actionField_list: "Search Results",
  2330.             products_id: [ name ],
  2331.             products_position: [ position ],
  2332.             products_price: [ price ]
  2333.         });
  2334.     } catch (err) {
  2335.         utagError = err;
  2336.     }
  2337. }
  2338.  
  2339. function trackHotelSearch(page, hotelsearch, checkin, checkout) {
  2340.     try {
  2341.         utag.link({
  2342.             eventCategory: page,
  2343.             eventAction: "search",
  2344.             eventLabel: createLabelHotelSearchData(hotelsearch, checkin, checkout),
  2345.             eventValue: calculateNumNights(checkin, checkout),
  2346.             event: "PDP | search"
  2347.         });
  2348.     } catch (err) {
  2349.         utagError = err;
  2350.     }
  2351. }
  2352.  
  2353. function trackSignupRewards(page) {
  2354.     try {
  2355.         utag.link({
  2356.             eventCategory: page,
  2357.             eventAction: "sign up nh rewards",
  2358.             eventLabel: "",
  2359.             event: "PDP | nh rewards"
  2360.         });
  2361.     } catch (err) {
  2362.         utagError = err;
  2363.     }
  2364. }
  2365.  
  2366. function trackMiceSearch(page, name, nrooms, nasistentes, nsalones, eventType) {
  2367.     try {
  2368.         utag.link({
  2369.             eventCategory: page,
  2370.             eventAction: "search a meeting",
  2371.             eventLabel: createLabelMiceSearchData(name, nrooms, nasistentes, nsalones, eventType),
  2372.             event: "mice | search"
  2373.         });
  2374.     } catch (err) {
  2375.         utagError = err;
  2376.     }
  2377. }
  2378.  
  2379. function trackMiceSearchInResult(page, name, nrooms, nasistentes, nsalones, eventType) {
  2380.     try {
  2381.         utag.link({
  2382.             eventCategory: page,
  2383.             eventAction: "search  a meeting",
  2384.             eventLabel: createLabelMiceSearchData(name, nrooms, nasistentes, nsalones, eventType),
  2385.             event: "mice | search results"
  2386.         });
  2387.     } catch (err) {
  2388.         utagError = err;
  2389.     }
  2390. }
  2391.  
  2392. function trackMiceSearchInDestiny(page, name, nrooms, nasistentes, nsalones, eventType) {
  2393.     try {
  2394.         utag.link({
  2395.             eventCategory: page,
  2396.             eventAction: "search a meeting",
  2397.             eventLabel: createLabelMiceSearchData(name, nrooms, nasistentes, nsalones, eventType),
  2398.             event: "mice | search"
  2399.         });
  2400.     } catch (err) {
  2401.         utagError = err;
  2402.     }
  2403. }
  2404.  
  2405. function trackMiceRequestQuote(page, where, name, nrooms) {
  2406.     try {
  2407.         var eventTrack = "request a quote | " + where;
  2408.         utag.link({
  2409.             eventCategory: page,
  2410.             eventAction: eventTrack,
  2411.             eventLabel: createLabelMiceSearchDataQuote(name, nrooms),
  2412.             event: "mice | search results"
  2413.         });
  2414.     } catch (err) {
  2415.         utagError = err;
  2416.     }
  2417. }
  2418.  
  2419. function trackMiceRequestQuotePopup(page, hotel, nrooms) {
  2420.     try {
  2421.         utag.link({
  2422.             eventCategory: page,
  2423.             eventAction: "request a quote | pop up",
  2424.             eventLabel: createLabelMiceSearchDataHeader(hotel, nrooms),
  2425.             event: "micesearch | quote"
  2426.         });
  2427.     } catch (err) {
  2428.         utagError = err;
  2429.     }
  2430. }
  2431.  
  2432. function trackMicePersonalize(page, hotels) {
  2433.     try {
  2434.         utag.link({
  2435.             eventCategory: page,
  2436.             eventAction: "personalize event",
  2437.             eventLabel: hotels,
  2438.             event: "Micefunnel | step1"
  2439.         });
  2440.     } catch (err) {
  2441.         utagError = err;
  2442.     }
  2443. }
  2444.  
  2445. function trackMiceSendEnquiry(page, hotels) {
  2446.     try {
  2447.         utag.link({
  2448.             eventCategory: page,
  2449.             eventAction: "send enquiry",
  2450.             eventLabel: hotels,
  2451.             event: "Micefunnel | step1"
  2452.         });
  2453.     } catch (err) {
  2454.         utagError = err;
  2455.     }
  2456. }
  2457.  
  2458. function trackDealsSearch(page, country, city, startDate, endDate) {
  2459.     try {
  2460.         var eventLabelTrack = country + "|" + city + "|" + startDate + "-" + endDate;
  2461.         utag.link({
  2462.             eventCategory: page,
  2463.             eventAction: "search an offer",
  2464.             eventLabel: eventLabelTrack,
  2465.             eventValue: calculateNumNights(startDate, endDate),
  2466.             event: "offers | search"
  2467.         });
  2468.     } catch (err) {
  2469.         utagError = err;
  2470.     }
  2471. }
  2472.  
  2473. function trackDealsBook(page, tabName, offerName, id, position) {
  2474.     try {
  2475.         var eventLabelTrack = tabName + "|" + offerName;
  2476.         utag.link({
  2477.             eventCategory: page,
  2478.             eventAction: "book an offer",
  2479.             eventLabel: eventLabelTrack,
  2480.             event: "offers | book",
  2481.             ecommerce_action: "promo_click",
  2482.             promotions_id: [ id ],
  2483.             promotions_name: [ offerName ],
  2484.             promotions_position: [ position ],
  2485.             promotions_creative: [ tabName ]
  2486.         });
  2487.     } catch (err) {
  2488.         utagError = err;
  2489.     }
  2490. }
  2491.  
  2492. function trackShowRewardsRate(page) {
  2493.     try {
  2494.         utag.link({
  2495.             eventCategory: page,
  2496.             eventAction: "select nh rewards rates tab",
  2497.             eventLabel: "",
  2498.             event: "funnel | step1 | nhrewtab"
  2499.         });
  2500.     } catch (err) {
  2501.         utagError = err;
  2502.     }
  2503. }
  2504.  
  2505. function trackShowPackageRate(page) {
  2506.     try {
  2507.         utag.link({
  2508.             eventCategory: page,
  2509.             eventAction: "select packages tab",
  2510.             event: "funnel1 | step1 | packagestab"
  2511.         });
  2512.     } catch (err) {
  2513.         utagError = err;
  2514.     }
  2515. }
  2516.  
  2517. function trackBookRoom(page, name, roomType, startDate, endDate, nrooms, nadults, nchild) {
  2518.     try {
  2519.         utag.link({
  2520.             eventCategory: page,
  2521.             eventAction: "book",
  2522.             eventLabel: createLabelRoomData(name, roomType, startDate, endDate, nrooms, nadults, nchild),
  2523.             eventValue: calculateNumNights(startDate, endDate),
  2524.             event: "funnel | step1 | book now"
  2525.         });
  2526.     } catch (err) {
  2527.         utagError = err;
  2528.     }
  2529. }
  2530.  
  2531. function trackSelectRoom(page, name, roomType, startDate, endDate, nrooms, nadults, nchild) {
  2532.     try {
  2533.         utag.link({
  2534.             eventCategory: page,
  2535.             eventAction: "room display",
  2536.             eventLabel: createLabelRoomData(name, roomType, startDate, endDate, nrooms, nadults, nchild),
  2537.             eventValue: calculateNumNights(startDate, endDate),
  2538.             event: "funnel | step1 | book"
  2539.         });
  2540.     } catch (err) {
  2541.         utagError = err;
  2542.     }
  2543. }
  2544.  
  2545. function trackSelectRoomRewards(page, name, roomType, startDate, endDate, nrooms, nadults, nchild) {
  2546.     try {
  2547.         utag.link({
  2548.             eventCategory: page,
  2549.             eventAction: "room display | NH Rewards",
  2550.             eventLabel: createLabelRoomData(name, roomType, startDate, endDate, nrooms, nadults, nchild),
  2551.             eventValue: calculateNumNights(startDate, endDate),
  2552.             event: "funnel | step1 | booknhrew"
  2553.         });
  2554.     } catch (err) {
  2555.         utagError = err;
  2556.     }
  2557. }
  2558.  
  2559. function trackModifySearch(page, name, startDate, endDate, nrooms, nadults, nchild) {
  2560.     try {
  2561.         utag.link({
  2562.             eventCategory: page,
  2563.             eventAction: "modify search",
  2564.             eventLabel: createLabelSearchData(name, startDate, endDate, nrooms, nadults, nchild),
  2565.             eventValue: calculateNumNights(startDate, endDate),
  2566.             event: "funnel | step1 | modify"
  2567.         });
  2568.     } catch (err) {
  2569.         utagError = err;
  2570.     }
  2571. }
  2572.  
  2573. function trackProceedToBook(page, name, startDate, endDate, nrooms, nadults, nchild, rate) {
  2574.     try {
  2575.         utag.link({
  2576.             eventCategory: page,
  2577.             eventAction: "proceed to book",
  2578.             eventLabel: createLabelBook(name, startDate, endDate, nrooms, nadults, nchild, rate),
  2579.             eventValue: calculateNumNights(startDate, endDate),
  2580.             event: "funnel | step2"
  2581.         });
  2582.     } catch (err) {
  2583.         utagError = err;
  2584.     }
  2585. }
  2586.  
  2587. function trackFilterAvail(page) {
  2588.     try {
  2589.         utag.link({
  2590.             eventCategory: page,
  2591.             eventAction: "filters use | select only available hotels",
  2592.             event: "SRP | filtersAvailability"
  2593.         });
  2594.     } catch (err) {
  2595.         utagError = err;
  2596.     }
  2597. }
  2598.  
  2599. function trackFilterStars(page, stars) {
  2600.     try {
  2601.         utag.link({
  2602.             eventCategory: page,
  2603.             eventAction: "filters use | select stars",
  2604.             eventLabel: stars,
  2605.             event: "SRP | filtersStars"
  2606.         });
  2607.     } catch (err) {
  2608.         utagError = err;
  2609.     }
  2610. }
  2611.  
  2612. function trackFilterPrice(page, minPrice, maxPrice) {
  2613.     try {
  2614.         var priceRange = minPrice + "-" + maxPrice;
  2615.         utag.link({
  2616.             eventCategory: page,
  2617.             eventAction: "filters use | select price range",
  2618.             eventLabel: priceRange,
  2619.             event: "SRP | filtersPrice"
  2620.         });
  2621.     } catch (err) {
  2622.         utagError = err;
  2623.     }
  2624. }
  2625.  
  2626. function trackFilterServices(page, service) {
  2627.     try {
  2628.         utag.link({
  2629.             eventCategory: page,
  2630.             eventAction: "filters use | select services",
  2631.             eventLabel: service,
  2632.             event: "SRP | filterServices"
  2633.         });
  2634.     } catch (err) {
  2635.         utagError = err;
  2636.     }
  2637. }
  2638.  
  2639. function trackFilterBrand(page, brand) {
  2640.     try {
  2641.         utag.link({
  2642.             eventCategory: page,
  2643.             eventAction: "filters use | select brand",
  2644.             eventLabel: brand,
  2645.             event: "SRP | filterBrand"
  2646.         });
  2647.     } catch (err) {
  2648.         utagError = err;
  2649.     }
  2650. }
  2651.  
  2652. function trackFilterNearTo(page, nearTo) {
  2653.     try {
  2654.         utag.link({
  2655.             eventCategory: page,
  2656.             eventAction: "filters use | select near to",
  2657.             eventLabel: nearTo,
  2658.             event: "SRP | filterNext"
  2659.         });
  2660.     } catch (err) {
  2661.         utagError = err;
  2662.     }
  2663. }
  2664.  
  2665. function trackChangeOrder(page, orderBy) {
  2666.     try {
  2667.         utag.link({
  2668.             eventCategory: page,
  2669.             eventAction: "order by",
  2670.             eventLabel: orderBy,
  2671.             event: "SRP | order"
  2672.         });
  2673.     } catch (err) {
  2674.         utagError = err;
  2675.     }
  2676. }
  2677.  
  2678. function trackHotelPageCheckAvail(page, name, startDate, endDate, nrooms, nadults, nchild) {
  2679.     try {
  2680.         var nights = calculateNumNights(startDate, endDate);
  2681.         utag.link({
  2682.             eventCategory: page,
  2683.             eventAction: "search",
  2684.             eventLabel: createLabelSearchData(name, startDate, endDate, nrooms, nadults, nchild),
  2685.             eventValue: nights,
  2686.             event: "PDP | search"
  2687.         });
  2688.     } catch (err) {
  2689.         utagError = err;
  2690.     }
  2691. }
  2692.  
  2693. function trackHotelPageWeather(page) {
  2694.     try {
  2695.         utag.link({
  2696.             eventCategory: page,
  2697.             eventAction: "see weather prediction",
  2698.             event: "PDP | weather"
  2699.         });
  2700.     } catch (err) {
  2701.         utagError = err;
  2702.     }
  2703. }
  2704.  
  2705. function trackHotelPageAll(page) {
  2706.     try {
  2707.         utag.link({
  2708.             eventCategory: page,
  2709.             eventAction: "see all hotels in destination",
  2710.             event: "PDP | all"
  2711.         });
  2712.     } catch (err) {
  2713.         utagError = err;
  2714.     }
  2715. }
  2716.  
  2717. function trackMiceComercial(page) {
  2718.     try {
  2719.         utag.link({
  2720.             eventCategory: page,
  2721.             eventAction: "contact comercial team",
  2722.             event: "mice | comercial"
  2723.         });
  2724.     } catch (err) {
  2725.         utagError = err;
  2726.     }
  2727. }
  2728.  
  2729. function trackMiceNewsletter(page) {
  2730.     try {
  2731.         utag.link({
  2732.             eventCategory: page,
  2733.             eventAction: "sign up newsletter",
  2734.             event: "mice | newsletter"
  2735.         });
  2736.     } catch (err) {
  2737.         utagError = err;
  2738.     }
  2739. }
  2740.  
  2741. function trackMiceRequestQuoteBuscador(page, name, nrooms) {
  2742.     try {
  2743.         utag.link({
  2744.             eventCategory: page,
  2745.             eventAction: "request a quote | header",
  2746.             eventLabel: createLabelMiceSearchDataHeader(name, nrooms),
  2747.             event: "mice | search results"
  2748.         });
  2749.     } catch (err) {
  2750.         utagError = err;
  2751.     }
  2752. }
  2753.  
  2754. function trackMiceFilterStars(page, stars) {
  2755.     try {
  2756.         utag.link({
  2757.             eventCategory: page,
  2758.             eventAction: "filters use | select stars",
  2759.             eventLabel: stars,
  2760.             event: "mice | search | filtersStars"
  2761.         });
  2762.     } catch (err) {
  2763.         utagError = err;
  2764.     }
  2765. }
  2766.  
  2767. function trackMiceFilterServices(page, service) {
  2768.     try {
  2769.         utag.link({
  2770.             eventCategory: page,
  2771.             eventAction: "filters use | select services",
  2772.             eventLabel: service,
  2773.             event: "mice | search | filterServices"
  2774.         });
  2775.     } catch (err) {
  2776.         utagError = err;
  2777.     }
  2778. }
  2779.  
  2780. function trackMiceFilterBrand(page, brand) {
  2781.     try {
  2782.         utag.link({
  2783.             eventCategory: page,
  2784.             eventAction: "filters use | select brand",
  2785.             eventLabel: brand,
  2786.             event: "mice | search | filterBrand"
  2787.         });
  2788.     } catch (err) {
  2789.         utagError = err;
  2790.     }
  2791. }
  2792.  
  2793. function trackMiceFilterNearTo(page, nearTo) {
  2794.     try {
  2795.         utag.link({
  2796.             eventCategory: page,
  2797.             eventAction: "filters use | select near to",
  2798.             eventLabel: nearTo,
  2799.             event: "mice | search | filterNext"
  2800.         });
  2801.     } catch (err) {
  2802.         utagError = err;
  2803.     }
  2804. }
  2805.  
  2806. function trackMiceSalones(page, minSalones, maxSalones) {
  2807.     try {
  2808.         var salones = minSalones + "-" + maxSalones;
  2809.         utag.link({
  2810.             eventCategory: page,
  2811.             eventAction: "filters use | select meeting rooms",
  2812.             eventLabel: salones,
  2813.             event: "mice | search | filterMeetingRooms"
  2814.         });
  2815.     } catch (err) {
  2816.         utagError = err;
  2817.     }
  2818. }
  2819.  
  2820. function trackMiceRooms(page, minRooms, maxRooms) {
  2821.     try {
  2822.         var rooms = minRooms + "-" + maxRooms;
  2823.         utag.link({
  2824.             eventCategory: page,
  2825.             eventAction: "filters use | select rooms",
  2826.             eventLabel: rooms,
  2827.             event: "mice | search | filterRooms"
  2828.         });
  2829.     } catch (err) {
  2830.         utagError = err;
  2831.     }
  2832. }
  2833.  
  2834. function trackMiceCapacidad(page, minCap, maxCap) {
  2835.     try {
  2836.         var cap = minCap + "-" + maxCap;
  2837.         utag.link({
  2838.             eventCategory: page,
  2839.             eventAction: "filters use | select max capacity",
  2840.             eventLabel: cap,
  2841.             event: "mice | search | filterCapacity"
  2842.         });
  2843.     } catch (err) {
  2844.         utagError = err;
  2845.     }
  2846. }
  2847.  
  2848. function trackMiceChangeOrder(page, orderBy) {
  2849.     try {
  2850.         utag.link({
  2851.             eventCategory: page,
  2852.             eventAction: "order by",
  2853.             eventLabel: orderBy,
  2854.             event: "mice | search | order"
  2855.         });
  2856.     } catch (err) {
  2857.         utagError = err;
  2858.     }
  2859. }
  2860.  
  2861. function trackSelectHotelMice(page, name) {
  2862.     try {
  2863.         utag.link({
  2864.             eventCategory: page,
  2865.             eventAction: "select hotel",
  2866.             eventLabel: name,
  2867.             event: "mice | search | selecthotel"
  2868.         });
  2869.     } catch (err) {
  2870.         utagError = err;
  2871.     }
  2872. }
  2873.  
  2874. function trackViewHotelMice(page, name) {
  2875.     try {
  2876.         utag.link({
  2877.             eventCategory: page,
  2878.             eventAction: "view hotel page",
  2879.             eventLabel: name,
  2880.             event: "mice | search | view hotel"
  2881.         });
  2882.     } catch (err) {
  2883.         utagError = err;
  2884.     }
  2885. }
  2886.  
  2887. function trackAdvanceSearch(page, name, startDate, endDate, nrooms, nadults, nchild) {
  2888.     try {
  2889.         var nights = "";
  2890.         if (startDate != undefined && endDate != undefined) {
  2891.             nights = calculateNumNights(startDate, endDate);
  2892.         }
  2893.         utag.link({
  2894.             eventCategory: page,
  2895.             eventAction: "advanced search",
  2896.             eventLabel: createLabelSearchData(name, startDate, endDate, nrooms, nadults, nchild),
  2897.             eventValue: nights,
  2898.             event: "advsearch"
  2899.         });
  2900.     } catch (err) {
  2901.         utagError = err;
  2902.     }
  2903. }
  2904.  
  2905. function trackCallBook(page) {
  2906.     try {
  2907.         utag.link({
  2908.             eventCategory: page,
  2909.             eventAction: "call to book",
  2910.             event: "call | book"
  2911.         });
  2912.     } catch (err) {
  2913.         utagError = err;
  2914.     }
  2915. }
  2916.  
  2917. function trackCancel(page) {
  2918.     try {
  2919.         utag.link({
  2920.             eventCategory: page,
  2921.             eventAction: "cancel booking",
  2922.             event: "mybookings"
  2923.         });
  2924.     } catch (err) {
  2925.         utagError = err;
  2926.     }
  2927. }
  2928.  
  2929. function trackModify(page) {
  2930.     try {
  2931.         utag.link({
  2932.             eventCategory: page,
  2933.             eventAction: "modify booking",
  2934.             event: "mybookings"
  2935.         });
  2936.     } catch (err) {
  2937.         utagError = err;
  2938.     }
  2939. }
  2940.  
  2941. function trackConfirm(page) {
  2942.     try {
  2943.         utag.link({
  2944.             eventCategory: page,
  2945.             eventAction: "confirm booking",
  2946.             event: "mybookings"
  2947.         });
  2948.     } catch (err) {
  2949.         utagError = err;
  2950.     }
  2951. }
  2952.  
  2953. function trackChat(page) {
  2954.     try {
  2955.         utag.link({
  2956.             eventCategory: page,
  2957.             eventAction: "chat online",
  2958.             event: "chat"
  2959.         });
  2960.     } catch (err) {
  2961.         utagError = err;
  2962.     }
  2963. }
  2964.  
  2965. function trackCalendarSearch(page, name, startDate, endDate) {
  2966.     try {
  2967.         utag.link({
  2968.             eventCategory: page,
  2969.             eventAction: "book",
  2970.             eventLabel: createLabelCalendar(name, startDate, endDate),
  2971.             event: "calendar | check availability"
  2972.         });
  2973.     } catch (err) {
  2974.         utagError = err;
  2975.     }
  2976. }
  2977.  
  2978. function trackTripAdvisor(page, hotel) {
  2979.     try {
  2980.         utag.link({
  2981.             eventCategory: page,
  2982.             eventAction: "read Tripadvisor reviews",
  2983.             eventLabel: hotel,
  2984.             event: "PDP | ta"
  2985.         });
  2986.     } catch (err) {
  2987.         utagError = err;
  2988.     }
  2989. }
  2990.  
  2991. function trackConfirmationOtraReserva(page) {
  2992.     try {
  2993.         utag.link({
  2994.             eventCategory: page,
  2995.             eventAction: "book another stay",
  2996.             event: "mybookings"
  2997.         });
  2998.     } catch (err) {
  2999.         utagError = err;
  3000.     }
  3001. }
  3002.  
  3003. function formAbandon(form, campo) {
  3004.     try {
  3005.         utag.link({
  3006.             eventCategory: form,
  3007.             eventAction: "form analysys abandon",
  3008.             eventLabel: campo,
  3009.             event: "form"
  3010.         });
  3011.     } catch (err) {
  3012.         utagError = err;
  3013.     }
  3014. }
  3015.  
  3016. function formSuccess(form) {
  3017.     try {
  3018.         utag.link({
  3019.             eventCategory: form,
  3020.             eventAction: "form analysys success",
  3021.             event: "form"
  3022.         });
  3023.     } catch (err) {
  3024.         utagError = err;
  3025.     }
  3026. }
  3027.  
  3028. function formError(form, campo) {
  3029.     try {
  3030.         utag.link({
  3031.             eventCategory: form,
  3032.             eventAction: "form analysys error",
  3033.             eventLabel: campo,
  3034.             event: "form"
  3035.         });
  3036.     } catch (err) {
  3037.         utagError = err;
  3038.     }
  3039. }
  3040.  
  3041. function createLabelSearchData(name, startDate, endDate, nrooms, nadults, nchild) {
  3042.     var eventLabelTrack = name + "|" + startDate + "-" + endDate + "|" + nrooms + "|" + nadults + "|" + nchild;
  3043.     return eventLabelTrack;
  3044. }
  3045.  
  3046. function createLabelHotelSearchData(hotelsearch, checkin, checkout) {
  3047.     var eventLabelTrack = hotelsearch + "|" + checkin + "|" + checkout;
  3048.     return eventLabelTrack;
  3049. }
  3050.  
  3051. function createLabelMiceSearchDataHeader(name, nrooms) {
  3052.     var eventLabelTrack = "";
  3053.     name.each(function(hotel) {
  3054.         eventLabelTrack += $(this).attr("id") + "|" + nrooms + ",";
  3055.     });
  3056.     eventLabelTrack = eventLabelTrack.substring(0, eventLabelTrack.length - 1);
  3057.     return eventLabelTrack;
  3058. }
  3059.  
  3060. function createLabelMiceSearchData(name, nrooms, nasistentes, nsalones, eventType) {
  3061.     var eventLabelTrack = name + "|" + nrooms + "|" + nasistentes + "|" + nsalones + "|" + eventType;
  3062.     return eventLabelTrack;
  3063. }
  3064.  
  3065. function createLabelMiceSearchDataQuote(name, nrooms) {
  3066.     var eventLabelTrack = name + "|" + nrooms;
  3067.     return eventLabelTrack;
  3068. }
  3069.  
  3070. function createLabelRoomData(name, roomType, startDate, endDate, nrooms, nadults, nchild) {
  3071.     var eventLabelTrack = name + "|" + roomType + "|" + startDate + "-" + endDate + "|" + nrooms + "|" + nadults + "|" + nchild;
  3072.     return eventLabelTrack;
  3073. }
  3074.  
  3075. function createLabelBook(name, startDate, endDate, nrooms, nadults, nchild, rate) {
  3076.     var eventLabelTrack = name + "|" + startDate + "-" + endDate + "|" + nrooms + "|" + nadults + "|" + nchild + "|" + rate;
  3077.     return eventLabelTrack;
  3078. }
  3079.  
  3080. function createLabelCalendar(name, startDate, endDate) {
  3081.     var eventLabelTrack = name + "|" + startDate + "-" + endDate;
  3082.     return eventLabelTrack;
  3083. }
  3084.  
  3085. function calculateNumNights(start, end) {
  3086.     var dateIni = $.datepicker.parseDate("dd/mm/yy", start);
  3087.     var dateFin = $.datepicker.parseDate("dd/mm/yy", end);
  3088.     var diffDays = Math.floor((dateFin - dateIni) / 1e3 / 60 / 60 / 24);
  3089.     return diffDays;
  3090. }
  3091.  
  3092. var formsAnalysys = [ "flexiblePaymentForm", "flexiblePaymentPersonalForm", "flexiblePaymentRoomForm", "flexiblePaymentGarantizaForm", "prepaymentPersonalForm", "prepaymentRoomForm", "prepaymentPagoForm", "prepaymentFacturaForm", "prepaymentForm", "loginRewardsForm", "rewardsForm", "newsletterSubscribeForm", "loginb2tForm", "loginb2bForm", "b2bForm", "b2tForm", "miceOrganizeForm", "micePersonalizeForm", "signupRewardsForm", "homeForm" ];
  3093.  
  3094. function trackPromoClick(page, promoId, promoName, promoCreative, promoPosition) {
  3095.     try {
  3096.         utag.link({
  3097.             eventCategory: page,
  3098.             eventAction: "promotion click",
  3099.             ecommerce_action: "promo_click",
  3100.             promotions_id: [ promoId ],
  3101.             promotions_name: [ promoName ],
  3102.             promotions_creative: [ promoCreative ],
  3103.             promotions_position: [ promoPosition ]
  3104.         });
  3105.     } catch (err) {
  3106.         console.log(err);
  3107.         utagError = err;
  3108.     }
  3109. }
  3110.  
  3111. function trackVirtualTourClick(page, hotel) {
  3112.     try {
  3113.         utag.link({
  3114.             eventCategory: page,
  3115.             eventAction: "virtual tour",
  3116.             eventLabel: hotel
  3117.         });
  3118.     } catch (err) {
  3119.         utagError = err;
  3120.     }
  3121. }
  3122.  
  3123. function trackTravelGuideAccede(page, guideName) {
  3124.     try {
  3125.         utag.link({
  3126.             eventCategory: page,
  3127.             eventAction: "accede to guides",
  3128.             eventLabel: guideName
  3129.         });
  3130.     } catch (err) {
  3131.         utagError = err;
  3132.     }
  3133. }
  3134.  
  3135. function trackTravelGuideAccedeFooter(page, guideName) {
  3136.     try {
  3137.         utag.link({
  3138.             eventCategory: page,
  3139.             eventAction: "accede to guides footer",
  3140.             eventLabel: guideName
  3141.         });
  3142.     } catch (err) {
  3143.         utagError = err;
  3144.     }
  3145. }
  3146.  
  3147. function trackTravelGuideBookNow(hotel) {
  3148.     try {
  3149.         utag.link({
  3150.             eventCategory: "travel guides",
  3151.             eventAction: "click in book now",
  3152.             eventLabel: hotel
  3153.         });
  3154.     } catch (err) {
  3155.         utagError = err;
  3156.     }
  3157. }
  3158.  
  3159. function trackTravelGuideSearch(page, name, startDate, endDate, nrooms, nadults, nchild) {
  3160.     try {
  3161.         var nights = calculateNumNights(startDate, endDate);
  3162.         utag.link({
  3163.             eventCategory: page,
  3164.             eventAction: "Search from guides",
  3165.             eventLabel: createLabelSearchData(name, startDate, endDate, nrooms, nadults, nchild),
  3166.             eventValue: nights,
  3167.             event: "Guides | search"
  3168.         });
  3169.     } catch (err) {
  3170.         utagError = err;
  3171.     }
  3172. }
  3173.  
  3174. function trackTripAdvisorLanding(page, hotel) {
  3175.     try {
  3176.         utag.link({
  3177.             eventCategory: page,
  3178.             eventAction: "read Tripadvisor reviews",
  3179.             eventLabel: hotel,
  3180.             event: "SRP | ta"
  3181.         });
  3182.     } catch (err) {
  3183.         utagError = err;
  3184.     }
  3185. }
  3186.  
  3187. function viewHotelGallery(page, hotel) {
  3188.     try {
  3189.         utag.link({
  3190.             eventCategory: page,
  3191.             eventAction: "view hotel gallery",
  3192.             eventLabel: hotel,
  3193.             event: "SRP | gallery"
  3194.         });
  3195.     } catch (err) {
  3196.         utagError = err;
  3197.     }
  3198. }
  3199.  
  3200. function viewHotelsInMap(page, destination) {
  3201.     try {
  3202.         utag.link({
  3203.             eventCategory: page,
  3204.             eventAction: "view hotels in map",
  3205.             eventLabel: destination,
  3206.             event: "SRP | map"
  3207.         });
  3208.     } catch (err) {
  3209.         utagError = err;
  3210.     }
  3211. }
  3212.  
  3213. function createLabelClickShare(name, socialName) {
  3214.     var eventLabelTrack = name + "|" + socialName;
  3215.     return eventLabelTrack;
  3216. }
  3217.  
  3218. function trackClickShare(page, name, socialName) {
  3219.     try {
  3220.         utag.link({
  3221.             eventCategory: page,
  3222.             eventAction: "share social",
  3223.             eventLabel: createLabelClickShare(name, socialName),
  3224.             event: "clickShare"
  3225.         });
  3226.     } catch (err) {
  3227.         utagError = err;
  3228.     }
  3229. }
  3230.  
  3231. function trackCloseFollowUs(page) {
  3232.     try {
  3233.         utag.link({
  3234.             eventCategory: page,
  3235.             eventAction: "close follow us",
  3236.             event: "closeFollowUs"
  3237.         });
  3238.     } catch (err) {
  3239.         utagError = err;
  3240.     }
  3241. }
  3242.  
  3243. function trackFollowUs(page, destination) {
  3244.     try {
  3245.         utag.link({
  3246.             eventCategory: page,
  3247.             eventAction: "follow us",
  3248.             eventLabel: destination,
  3249.             event: "followUs"
  3250.         });
  3251.     } catch (err) {
  3252.         utagError = err;
  3253.     }
  3254. }
  3255.  
  3256. function trackSuscribirseFooter(page) {
  3257.     try {
  3258.         utag.link({
  3259.             eventCategory: page,
  3260.             eventAction: "subs Footer",
  3261.             event: "suscribirseFooter"
  3262.         });
  3263.     } catch (err) {
  3264.         utagError = err;
  3265.     }
  3266. }
  3267.  
  3268. function trackSuscribirseModal(page) {
  3269.     try {
  3270.         utag.link({
  3271.             eventCategory: page,
  3272.             eventAction: "subs Modal",
  3273.             event: "suscribirseModal"
  3274.         });
  3275.     } catch (err) {
  3276.         utagError = err;
  3277.     }
  3278. }
  3279.  
  3280. function trackClickDownload(page, name) {
  3281.     try {
  3282.         utag.link({
  3283.             eventCategory: page,
  3284.             eventAction: "click download",
  3285.             eventLabel: name,
  3286.             event: "clickDownload"
  3287.         });
  3288.     } catch (err) {
  3289.         utagError = err;
  3290.     }
  3291. }
  3292.  
  3293. function trackRWClickHomePrintCard(page) {
  3294.     try {
  3295.         utag.link({
  3296.             eventCategory: page,
  3297.             eventAction: "NHR printcard",
  3298.             eventLabel: "n/a",
  3299.             event: "home | printcard"
  3300.         });
  3301.     } catch (err) {
  3302.         utagError = err;
  3303.     }
  3304. }
  3305.  
  3306. function trackRWClickHomePassBook(page) {
  3307.     try {
  3308.         utag.link({
  3309.             eventCategory: page,
  3310.             eventAction: "NHR passbook",
  3311.             eventLabel: "n/a",
  3312.             event: "home | passbook"
  3313.         });
  3314.     } catch (err) {
  3315.         utagError = err;
  3316.     }
  3317. }
  3318.  
  3319. function trackRWClickAppUp(page) {
  3320.     try {
  3321.         utag.link({
  3322.             eventCategory: page,
  3323.             eventAction: "NHR app up",
  3324.             eventLabel: "n/a",
  3325.             event: "app"
  3326.         });
  3327.     } catch (err) {
  3328.         utagError = err;
  3329.     }
  3330. }
  3331.  
  3332. function trackRWClickAppLeft(page) {
  3333.     try {
  3334.         utag.link({
  3335.             eventCategory: page,
  3336.             eventAction: "NHR app left",
  3337.             eventLabel: "n/a",
  3338.             event: "app"
  3339.         });
  3340.     } catch (err) {
  3341.         utagError = err;
  3342.     }
  3343. }
  3344.  
  3345. function trackRWClickAddCoholder(page) {
  3346.     try {
  3347.         utag.link({
  3348.             eventCategory: page,
  3349.             eventAction: "NHR add a co holder",
  3350.             eventLabel: "n/a",
  3351.             event: "co holder"
  3352.         });
  3353.     } catch (err) {
  3354.         utagError = err;
  3355.     }
  3356. }
  3357.  
  3358. function trackRWClickGoTransfer(page) {
  3359.     try {
  3360.         utag.link({
  3361.             eventCategory: page,
  3362.             eventAction: "NHR go to transfer points",
  3363.             eventLabel: "n/a",
  3364.             event: "points | transfer"
  3365.         });
  3366.     } catch (err) {
  3367.         utagError = err;
  3368.     }
  3369. }
  3370.  
  3371. function trackRWClickGoDonate(page) {
  3372.     try {
  3373.         utag.link({
  3374.             eventCategory: page,
  3375.             eventAction: "NHR go to donate points",
  3376.             eventLabel: "n/a",
  3377.             event: "points | donate"
  3378.         });
  3379.     } catch (err) {
  3380.         utagError = err;
  3381.     }
  3382. }
  3383.  
  3384. function trackRWClickTransferPoints(page, party, mail, points) {
  3385.     try {
  3386.         utag.link({
  3387.             eventCategory: page,
  3388.             eventAction: "NHR transfer points",
  3389.             eventLabel: party + "|" + mail,
  3390.             eventValue: points,
  3391.             event: "points | transfer"
  3392.         });
  3393.     } catch (err) {
  3394.         utagError = err;
  3395.     }
  3396. }
  3397.  
  3398. function trackRWClickDonatePoints(page, organization, points) {
  3399.     try {
  3400.         utag.link({
  3401.             eventCategory: page,
  3402.             eventAction: "NHR donate points",
  3403.             eventLabel: organization,
  3404.             eventValue: points,
  3405.             event: "points | donate"
  3406.         });
  3407.     } catch (err) {
  3408.         utagError = err;
  3409.     }
  3410. }
  3411.  
  3412. function trackRWClickSocial(page, social) {
  3413.     try {
  3414.         utag.link({
  3415.             eventCategory: page,
  3416.             eventAction: "NHR social media",
  3417.             eventLabel: social,
  3418.             eventValue: "n/a",
  3419.             event: "profile | social media"
  3420.         });
  3421.     } catch (err) {
  3422.         utagError = err;
  3423.     }
  3424. }
  3425.  
  3426. function trackRWClickModify(page, hotelId, localizer) {
  3427.     try {
  3428.         utag.link({
  3429.             eventCategory: page,
  3430.             eventAction: "NHR modify",
  3431.             eventLabel: hotelId + "|" + localizer,
  3432.             eventValue: "n/a",
  3433.             event: "modify"
  3434.         });
  3435.     } catch (err) {
  3436.         utagError = err;
  3437.     }
  3438. }
  3439.  
  3440. function trackRWClickReadTripAdvisor(page, hotelId) {
  3441.     try {
  3442.         utag.link({
  3443.             eventCategory: page,
  3444.             eventAction: "NHR read Tripadvisor reviews",
  3445.             eventLabel: hotelId,
  3446.             eventValue: "n/a",
  3447.             event: "bookigns | TripAdvisor"
  3448.         });
  3449.     } catch (err) {
  3450.         utagError = err;
  3451.     }
  3452. }
  3453.  
  3454. function trackRWClickRepeatStay(page, hotelId, localizer) {
  3455.     try {
  3456.         utag.link({
  3457.             eventCategory: page,
  3458.             eventAction: "NHR repeat stay",
  3459.             eventLabel: hotelId + "|" + localizer,
  3460.             eventValue: "n/a",
  3461.             event: "bookigns | repeat stay"
  3462.         });
  3463.     } catch (err) {
  3464.         utagError = err;
  3465.     }
  3466. }
  3467.  
  3468. function trackRWClickFilterFaq(page, filterUsed) {
  3469.     try {
  3470.         utag.link({
  3471.             eventCategory: page,
  3472.             eventAction: "NHR filter FAQs",
  3473.             eventLabel: filterUsed,
  3474.             eventValue: "n/a",
  3475.             event: "customer care"
  3476.         });
  3477.     } catch (err) {
  3478.         utagError = err;
  3479.     }
  3480. }
  3481.  
  3482. function trackRWClickContactUsLeft(page) {
  3483.     try {
  3484.         utag.link({
  3485.             eventCategory: page,
  3486.             eventAction: "NHR contact us left",
  3487.             eventLabel: "n/a",
  3488.             eventValue: "n/a",
  3489.             event: "contact"
  3490.         });
  3491.     } catch (err) {
  3492.         utagError = err;
  3493.     }
  3494. }
  3495.  
  3496. function trackRWClickMissinPoints(page) {
  3497.     try {
  3498.         utag.link({
  3499.             eventCategory: page,
  3500.             eventAction: "NHR missing points",
  3501.             eventLabel: "n/a",
  3502.             eventValue: "n/a",
  3503.             event: "points | missing"
  3504.         });
  3505.     } catch (err) {
  3506.         utagError = err;
  3507.     }
  3508. }
  3509.  
  3510. function trackLandingLazyload(data) {
  3511.     try {
  3512.         if (data) {
  3513.             utag.view({
  3514.                 busqHSinDispo: data.busqHSinDispo,
  3515.                 busqListado: data.busqListado,
  3516.                 busqNumResult: data.busqNumResult,
  3517.                 busqSinDispo: data.busqSinDispo,
  3518.                 products_id: data.products_id,
  3519.                 products_list: data.products_list,
  3520.                 products_position: data.products_position,
  3521.                 products_price: data.products_price,
  3522.                 products_quantity: data.products_quantity,
  3523.                 search: data.search
  3524.             });
  3525.         }
  3526.     } catch (err) {
  3527.         utagError = err;
  3528.     }
  3529. }
  3530.  
  3531. function trackLogin(eventCategory, eventLabel, eventAction) {
  3532.     try {
  3533.         utag.link({
  3534.             eventCategory: eventCategory,
  3535.             eventAction: eventAction,
  3536.             eventLabel: eventLabel,
  3537.             event: "event"
  3538.         });
  3539.     } catch (err) {
  3540.         utagError = err;
  3541.     }
  3542. }
  3543.  
  3544. function sendUtagData() {
  3545.     (function(a, b, c, d) {
  3546.         a = "//tags.tiqcdn.com/utag/nh-hoteles/es-main-2014/prod/utag.js";
  3547.         b = document;
  3548.         c = "script";
  3549.         d = b.createElement(c);
  3550.         d.src = a;
  3551.         d.type = "text/java" + c;
  3552.         d.async = true;
  3553.         a = b.getElementsByTagName(c)[0];
  3554.         a.parentNode.insertBefore(d, a);
  3555.     })();
  3556. }
  3557.  
  3558. $(document).ready(function() {
  3559.     TrackForms.init();
  3560.     $("#languageLinks >.dropdown-menu >li").click(function() {
  3561.         trackChangeLanguage(page_section, $(this).text().trim());
  3562.     });
  3563.     $(".listHotelsDisplay >>.hotelItem >>> .title > a").click(function() {
  3564.         var price;
  3565.         if ($(this).parents(".hotelItem").find(".price-night").length != 0) price = $(this).parents(".hotelItem").find(".price-night >> .priceChange").text(); else price = $(this).parents(".hotelItem").find(".total-price >> .priceChange").text();
  3566.         var hotelName = $(this).parents(".hotelItem").find('[name="hotelId"]').val();
  3567.         var hotelPosition = $(this).parents(".hotelItem").find(".labels.nhrec").text();
  3568.         trackViewHotelPage(page_section, hotelName, price, hotelPosition);
  3569.     });
  3570.     $(".suscribe").click(function() {
  3571.         trackSignupNewsletter(page_section);
  3572.     });
  3573.     $(".nh-rewards >.btn-xs").click(function() {
  3574.         trackSignupRewards(page_section);
  3575.     });
  3576.     $("#normalRate").find(".btn-xs").click(function() {
  3577.         var info = $(this).parents("tr");
  3578.         var adults = parseInt(info.find('[name = "nadults1"]').val());
  3579.         var child = parseInt(info.find('[name = "nchilds1"]').val());
  3580.         var rooms = 2;
  3581.         while (info.find('[name = "nadults' + rooms + '"]').val() != "") {
  3582.             adults += parseInt(info.find('[name = "nadults' + rooms + '"]').val());
  3583.             child += parseInt(info.find('[name = "nchilds' + rooms + '"]').val());
  3584.             if (rooms > 5) break;
  3585.             rooms += 1;
  3586.         }
  3587.         trackSelectRoom(page_section, info.find('[name = "hotelId"]').val(), info.find('[name = "roomCategoryCode"]').val(), info.find('[name = "fini"]').val(), info.find('[name = "fout"]').val(), rooms - 1, adults, child, info.find('[name = "ratePriceCode"]').val());
  3588.     });
  3589.     $("#rewardsRate").find(".btn-xs").click(function() {
  3590.         var info = $(this).parents("tr");
  3591.         var adults = parseInt(info.find('[name = "nadults1"]').val());
  3592.         var child = parseInt(info.find('[name = "nchilds1"]').val());
  3593.         var rooms = 2;
  3594.         while (info.find('[name = "nadults' + rooms + '"]').val() != "") {
  3595.             adults += parseInt(info.find('[name = "nadults' + rooms + '"]').val());
  3596.             child += parseInt(info.find('[name = "nchilds' + rooms + '"]').val());
  3597.             if (rooms > 5) break;
  3598.             rooms += 1;
  3599.         }
  3600.         trackSelectRoomRewards(page_section, info.find('[name = "hotelId"]').val(), info.find('[name = "roomCategoryCode"]').val(), info.find('[name = "fini"]').val(), info.find('[name = "fout"]').val(), rooms - 1, adults, child, info.find('[name = "ratePriceCode"]').val());
  3601.     });
  3602.     $("#liRewardsRate").click(function() {
  3603.         trackShowRewardsRate(page_section);
  3604.     });
  3605.     $("#liPromotionsRate").click(function() {
  3606.         trackShowPackageRate(page_section);
  3607.     });
  3608.     $("#promotionsRate").find(".btn-xs").click(function() {
  3609.         var info = $(this).parents("tr");
  3610.         var adults = parseInt(info.find('[name = "nadults1"]').val());
  3611.         var child = parseInt(info.find('[name = "nchilds1"]').val());
  3612.         var rooms = 2;
  3613.         while (info.find('[name = "nadults' + rooms + '"]').val() != "") {
  3614.             adults += parseInt(info.find('[name = "nadults' + rooms + '"]').val());
  3615.             child += parseInt(info.find('[name = "nchilds' + rooms + '"]').val());
  3616.             if (rooms > 5) break;
  3617.             rooms += 1;
  3618.         }
  3619.         trackSelectRoomRewards(page_section, info.find('[name = "hotelId"]').val(), info.find('[name = "roomCategoryCode"]').val(), info.find('[name = "fini"]').val(), info.find('[name = "fout"]').val(), rooms - 1, adults, child, info.find('[name = "ratePriceCode"]').val());
  3620.     });
  3621.     $("form[action='/booking/meetings/hotelpagemice']").children("input[type='submit']").click(function() {
  3622.         var nasistentes = $("[name = 'nasistentes']").val();
  3623.         var fieldSearch = $('[name = "backCode"]').val();
  3624.         var where = "";
  3625.         if ($(this).parents(".buttons").length == 0) where = "top"; else where = "down";
  3626.         trackMiceRequestQuote(page_section, where, fieldSearch, nasistentes);
  3627.     });
  3628.     $("div[class='card travel']").children("form").children("div[class='intermedio']").children("div[class='pull-right']").children("a").click(function() {
  3629.         var tabName = $("#tablist").children(".activa").attr("data-type");
  3630.         var offerName = $(this).parent().parent().siblings("h3").text();
  3631.         var id = $(this).parent().children(".idpromo").val();
  3632.         var position = $(this).parents(".card").index() / 2;
  3633.         trackDealsBook(page_section, tabName, offerName, id, position);
  3634.     });
  3635.     $("div[class='card advance'] > div[class='buttons bottom'] > div[class='pull-right']").click(function() {
  3636.         var tabName = "GLOBAL";
  3637.         var offerName = $(this).parent().siblings("h3").text().trim();
  3638.         var id = $(this).parent().children(".idpromo");
  3639.         var position = $(this).parents(".card").index() + 1;
  3640.         trackDealsBook(page_section, tabName, offerName, id, position);
  3641.     });
  3642.     $("#weather >a").click(function() {
  3643.         trackHotelPageWeather(page_section);
  3644.     });
  3645.     $("#seeAll").click(function() {
  3646.         trackHotelPageAll(page_section);
  3647.     });
  3648.     $(".restaurants >>.buttons").eq(0).click(function() {
  3649.         trackMiceComercial(page_section);
  3650.     });
  3651.     $(".latestSearch > button").click(function() {
  3652.         trackMiceNewsletter(page_section);
  3653.     });
  3654.     $(".featured-result >>.row >> button").click(function() {
  3655.         var info = $(".hotelItem >>> tbody").find("tr").eq(1);
  3656.         var adults = parseInt(info.find('[name = "nadults1"]').val());
  3657.         var child = parseInt(info.find('[name = "nchilds1"]').val());
  3658.         var rooms = 2;
  3659.         while (info.find('[name = "nadults' + rooms + '"]').val() != "") {
  3660.             adults += parseInt(info.find('[name = "nadults' + rooms + '"]').val());
  3661.             child += parseInt(info.find('[name = "nchilds' + rooms + '"]').val());
  3662.             rooms += 1;
  3663.         }
  3664.         trackBookRoom(page_section, info.find('[name = "hotelId"]').val(), info.find('[name = "roomCategoryCode"]').val(), info.find('[name = "fini"]').val(), info.find('[name = "fout"]').val(), rooms - 1, adults, child, info.find('[name = "ratePriceCode"]').val());
  3665.     });
  3666.     $("#anotherBook").click(function() {
  3667.         trackConfirmationOtraReserva(page_section);
  3668.     });
  3669.     $("footer a#guides").click(function() {
  3670.         trackTravelGuideAccedeFooter(page_section, "n/a");
  3671.     });
  3672. });
  3673.  
  3674. var TrackForms = function() {
  3675.     var formulary;
  3676.     var lblFilledInput = "No data entered";
  3677.     var trackedForms = {};
  3678.     var init = function() {
  3679.         formulary = $("form:not(.no-track)");
  3680.         events();
  3681.     };
  3682.     var events = function() {
  3683.         formulary.find("input,textarea,select").on("keydown change", function() {
  3684.             var $f = $(this).parents("form");
  3685.             var name = $f.attr("name") || $f.attr("id");
  3686.             if (name) {
  3687.                 trackedForms[name] = true;
  3688.             }
  3689.         });
  3690.         formulary.on("submit", function() {
  3691.             var name = $(this).attr("name") || $(this).attr("id");
  3692.             if (name) {
  3693.                 trackedForms[name] = false;
  3694.             }
  3695.         });
  3696.         window.onbeforeunload = function() {
  3697.             console.log("eventLeave onbeforeunload:", trackedForms);
  3698.             if (!$.isEmptyObject(trackedForms)) {
  3699.                 callTrackFunctions();
  3700.             }
  3701.         };
  3702.     };
  3703.     var callTrackFunctions = function() {
  3704.         $.each(trackedForms, function(formName, eventLeave) {
  3705.             if (formName && eventLeave) {
  3706.                 var formElement = $('form[name="' + formName + '"]').length ? $('form[name="' + formName + '"]') : $("form#" + formName);
  3707.                 var formLastInput = formElement.find('input[type!="hidden"][type!="submit"][type!="checkbox"]').filter(function() {
  3708.                     return $(this).val() != "";
  3709.                 });
  3710.                 var formLastInputId = formLastInput.last().attr("id") || lblFilledInput;
  3711.                 console.log("formAbandon: ", formName, formLastInputId);
  3712.                 formAbandon(formName, formLastInputId);
  3713.             }
  3714.         });
  3715.     };
  3716.     var setTrackedForms = function(formName, value) {
  3717.         if (formName && value) {
  3718.             trackedForms[formName] = value;
  3719.         }
  3720.     };
  3721.     return {
  3722.         init: init,
  3723.         setTrackedForms: setTrackedForms,
  3724.         trackedForms: trackedForms
  3725.     };
  3726. }();
  3727.  
  3728. function eventoMiceRequestQuotePopUp() {
  3729.     var hotel = $(".hotelSeleccionadoSpan");
  3730.     var nasistentes = $("[name = 'nasistentes']").val();
  3731.     trackMiceRequestQuotePopup(page_section, hotel, nasistentes);
  3732. }
  3733.  
  3734. function buscarHotelPage(hotel) {
  3735.     var adults = 0;
  3736.     var children = 0;
  3737.     var rooms = parseInt($("#selectorControlRooms").val());
  3738.     for (var n = 1; n <= rooms; n++) {
  3739.         adults += parseInt($('[name = "nadults' + n + '"]').val());
  3740.         children += parseInt($('[name = "nchilds' + n + '"]').val());
  3741.     }
  3742.     trackHotelPageCheckAvail(page_section, hotel, $('[name = "fini"]').val(), $('[name = "fout"]').val(), rooms, adults, children);
  3743. }
  3744.  
  3745. function reservarHotelRP(hotel, price, position) {
  3746.     trackSelectHotel(page_section, hotel, $("#ida").val(), $("#fin").val(), price, position, $("#habs").val());
  3747. }
  3748.  
  3749. function filtroNearTo(orig) {
  3750.     var nearTo = $("#filtroPOI option:selected").text();
  3751.     if (orig == "landing") trackFilterNearTo(page_section, nearTo); else if (orig == "mice") trackMiceFilterNearTo(page_section, nearTo);
  3752. }
  3753.  
  3754. var actualCurrency;
  3755.  
  3756. var Currency = function() {
  3757.     var currencyJSON;
  3758.     var init = function() {
  3759.         var currencySel = $("#divisa");
  3760.         var currencySel2 = $("#divisa2");
  3761.         var currencyInputHidden = $(".divisaInput");
  3762.         selectedDivisa = selectedDivisa.split(",")[0];
  3763.         selectedDivisa = selectedDivisa != "," && selectedDivisa != null ? selectedDivisa : "";
  3764.         getCurrencyData(function() {
  3765.             if (selectedDivisa != "") {
  3766.                 updateDivisaForForm(selectedDivisa);
  3767.                 divisaAnterior2 = selectedDivisa;
  3768.             } else {
  3769.                 updateDivisaForForm(actualDivisa);
  3770.                 divisaAnterior2 = actualDivisa;
  3771.                 currencyInputHidden.val(selectedDivisa || "");
  3772.             }
  3773.         });
  3774.     };
  3775.     var getCurrencyData = function(fn) {
  3776.         $.ajax({
  3777.             url: "/rest/jsonCurrency",
  3778.             dataType: "json",
  3779.             async: false,
  3780.             cache: true,
  3781.             success: function(data) {
  3782.                 currencyJSON = data;
  3783.             },
  3784.             error: function(data) {}
  3785.         });
  3786.         if (typeof fn == "function") {
  3787.             fn();
  3788.         }
  3789.     };
  3790.     var changeCurrency = function(precio, currencyIn, currencyOut) {
  3791.         var cambio = importeCambioFromJson(currencyIn, currencyOut);
  3792.         precio = precio * cambio;
  3793.         return precio;
  3794.     };
  3795.     var importeCambioFromJson = function(currencyIn, currencyOut) {
  3796.         var cambio;
  3797.         if (currencyJSON) {
  3798.             $.each(currencyJSON.currencies, function(key, val) {
  3799.                 if (currencyJSON.currencies[key].cur_origin == currencyIn) {
  3800.                     $.each(currencyJSON.currencies[key].conversions, function(key2, val2) {
  3801.                         if (currencyJSON.currencies[key].conversions[key2].cur_dest == currencyOut) {
  3802.                             cambio = currencyJSON.currencies[key].conversions[key2].rate;
  3803.                         }
  3804.                     });
  3805.                 }
  3806.             });
  3807.         }
  3808.         return cambio;
  3809.     };
  3810.     var cambiarDivisa = function(id) {
  3811.         var to = $("#" + id).val();
  3812.         if (id == "divisa" || id == "divisa2") {
  3813.             var tasa = 0;
  3814.             $(".divisaInput").val(to);
  3815.             if (to != actualCurrency) {
  3816.                 tasa = parseFloat(importeCambioFromJson(actualCurrency, to));
  3817.                 $(".currencyChange").text(to);
  3818.                 $(".priceChange").each(function() {
  3819.                     var precio = parseFloat($(this).siblings(".originalPrice").text());
  3820.                     precio = precio * tasa;
  3821.                     precio = (Math.round(precio * 100) / 100).toFixed(2);
  3822.                     $(this).text(precio);
  3823.                     if ($(this).parents(".hotelItem").length > 0) {
  3824.                         if (precio.length >= 7) {
  3825.                             $(this).parents(".dataHotel").removeClass("col-md-2").addClass("col-md-3");
  3826.                             $(this).parents(".hotelItem").find(".carousel.slide.hotel").removeClass("col-md-10").addClass("col-md-9");
  3827.                         } else if (precio.length < 7) {
  3828.                             $(this).parents(".dataHotel").removeClass("col-md-3").addClass("col-md-2");
  3829.                             $(this).parents(".hotelItem").find(".carousel.slide.hotel").removeClass("col-md-9").addClass("col-md-10");
  3830.                         }
  3831.                     }
  3832.                 });
  3833.                 treatMoreData(tasa, tasa);
  3834.             } else {
  3835.                 URL = buildQuery("1", divisaAnterior, actualCurrency);
  3836.                 tasa = parseFloat(importeCambioFromJson(divisaAnterior, actualCurrency));
  3837.                 $(".currencyChange").text(actualCurrency);
  3838.                 $(".priceChange").each(function() {
  3839.                     var precio = $(this).siblings(".originalPrice").text();
  3840.                     $(this).text(precio);
  3841.                     if ($(this).parents(".hotelItem").length > 0) {
  3842.                         if (precio.length >= 7) {
  3843.                             $(this).parents(".dataHotel").removeClass("col-md-2").addClass("col-md-3");
  3844.                             $(this).parents(".hotelItem").find(".carousel.slide.hotel").removeClass("col-md-10").addClass("col-md-9");
  3845.                         } else if (precio.length < 7) {
  3846.                             $(this).parents(".dataHotel").removeClass("col-md-3").addClass("col-md-2");
  3847.                             $(this).parents(".hotelItem").find(".carousel.slide.hotel").removeClass("col-md-9").addClass("col-md-10");
  3848.                         }
  3849.                     }
  3850.                 });
  3851.                 treatMoreData(1, tasa);
  3852.             }
  3853.             divisaAnterior = to;
  3854.         } else {
  3855.             return;
  3856.         }
  3857.         if ($("body").hasClass("page-landing") || $("#mapGoogleMob").length != 0 && markersMob.length > 0) {
  3858.             setDivisaOnMap();
  3859.         }
  3860.     };
  3861.     var setDivisaOnMap = function() {
  3862.         if (mapMob) {
  3863.             to = $(".divisaInput:first").val();
  3864.             $(".info-result-room").each(function() {
  3865.                 var $this = $(this);
  3866.                 var price_change = $this.find(".priceChange");
  3867.                 var price_total = $this.find(".total-price .priceChange");
  3868.                 var price_night = $this.find(".price-night .priceChange");
  3869.                 var num = $this.find(".nhrec").text();
  3870.                 if (price_total.length != 0) {
  3871.                     var content_window = markersMob[parseInt(num)].infoWindows.content_;
  3872.                     re1 = $(content_window).find(".total-price .pull-right").html();
  3873.                     re2 = price_total.html();
  3874.                     var output = content_window.replace(re1, re2 + "<sup>" + to + "</sup>");
  3875.                     if (price_night.length != 0) {
  3876.                         re1 = $(output).find(".night-price .pull-right").html();
  3877.                         re2 = price_night.html();
  3878.                         var output = output.replace(re1, re2 + "<sup>" + to + "</sup>");
  3879.                     }
  3880.                     markersMob[parseInt(num)].infoWindows.setContent(output);
  3881.                 }
  3882.             });
  3883.         }
  3884.     };
  3885.     var treatMoreData = function(tasa, tasaControlPoint) {
  3886.         var rangoPrecio = new Array(2);
  3887.         var controlPoints = new Array(2);
  3888.         controlPoints[0] = 0;
  3889.         controlPoints[1] = 0;
  3890.         rangoPrecio[0] = 99999;
  3891.         rangoPrecio[1] = -1;
  3892.         if ($("#range2").length > 0 || $("#rangeMob").length > 0) {
  3893.             var hoteles = $("div.hotelItem.hotelDispo, div.hotelItem.hotelNearby");
  3894.             hoteles.each(function() {
  3895.                 var precio = parseFloat($(this).find(".hotel-total-price").text());
  3896.                 if (!isNaN(precio) && rangoPrecio[0] >= precio) rangoPrecio[0] = precio;
  3897.                 if (!isNaN(precio) && rangoPrecio[1] <= precio) rangoPrecio[1] = precio;
  3898.             });
  3899.             if (rangoPrecio[0] == 99999 && rangoPrecio[1] == -1) {
  3900.                 rangoPrecio[0] = 0;
  3901.                 rangoPrecio[1] = 1;
  3902.             }
  3903.         }
  3904.         if ($("#range2").length > 0) {
  3905.             var porcentage = $("#range2").slider("prc").split(";");
  3906.             controlPoints = $("#range2").slider("value").split(";");
  3907.             controlPoints[0] = tasaControlPoint * controlPoints[0];
  3908.             controlPoints[1] = tasaControlPoint * controlPoints[1];
  3909.             updateSlider("#range2", rangoPrecio[0], controlPoints[0], controlPoints[1], rangoPrecio[1]);
  3910.             $("#range2").slider("prc", porcentage[0], porcentage[1]);
  3911.         }
  3912.         if ($("#rangeMob").length > 0) {
  3913.             var porcentage = $("#rangeMob").slider("prc").split(";");
  3914.             controlPoints = $("#rangeMob").slider("value").split(";");
  3915.             controlPoints[0] = tasaControlPoint * controlPoints[0];
  3916.             controlPoints[0] = (Math.round(controlPoints[0] * 100) / 100).toFixed(2);
  3917.             controlPoints[1] = tasaControlPoint * controlPoints[1];
  3918.             controlPoints[1] = (Math.round(controlPoints[1] * 100) / 100).toFixed(2);
  3919.             updateSlider("#rangeMob", rangoPrecio[0], controlPoints[0], controlPoints[1], rangoPrecio[1]);
  3920.             $("#rangeMob").slider("prc", porcentage[0], porcentage[1]);
  3921.         }
  3922.         if ($("#rangeMob").length > 0 || $("#range2").length > 0) {
  3923.             filtroPrecioActi[0] = controlPoints[0];
  3924.             filtroPrecioActi[1] = controlPoints[1];
  3925.         }
  3926.     };
  3927.     var updateSlider = function(sliderID, ini, p1, p2, fin) {
  3928.         var slideParent = $(sliderID).parent();
  3929.         var inputRange2 = slideParent.find("h3").prop("outerHTML") + $(sliderID).prop("outerHTML") + slideParent.find("span.small").prop("outerHTML");
  3930.         slideParent.text("");
  3931.         slideParent.append(inputRange2);
  3932.         if (ini == fin) ini = 1;
  3933.         $(sliderID).val("" + Math.floor(ini) + ";" + Math.ceil(fin) + "");
  3934.         $(sliderID).attr("value", "" + Math.floor(ini) + ";" + Math.ceil(fin) + "");
  3935.         $(sliderID).after("<scr" + "ipt>" + ' $("' + sliderID + '").slider({  from:' + Math.floor(ini) + ",  to: " + Math.ceil(fin) + ', step: 1,  round: 1,  dimension: " ' + $(".currencyChange").first().text() + '",  skin: "plastic",  callback: function( value ){    var min =this.o.pointers[0].value.origin; var max =this.o.pointers[1].value.origin;     filterByPrice(min, max );       }       });      </scr' + "ipt>");
  3936.         $(sliderID).slider("value", p1, p2);
  3937.     };
  3938.     var buildQuery = function(amount, from, to) {
  3939.         var str = "https://rate-exchange.appspot.com/currency?from=" + from + "&to=" + to + "&q=" + amount;
  3940.         return str;
  3941.     };
  3942.     var cambiarInfoTags = function(selectedCurrency, actualCurrency) {
  3943.         cloneOriginalPrices();
  3944.         $(".divisaInput").val(selectedCurrency);
  3945.         var tasa = 1;
  3946.         if (actualCurrency && selectedCurrency) {
  3947.             tasa = parseFloat(importeCambioFromJson(actualCurrency, selectedCurrency));
  3948.         }
  3949.         $(".currencyChange").text(selectedCurrency);
  3950.         $(".priceChange").each(function() {
  3951.             var precio = parseFloat($(this).siblings(".originalPrice").text());
  3952.             precio = precio * tasa;
  3953.             precio = (Math.round(precio * 100) / 100).toFixed(2);
  3954.             $(this).text(precio);
  3955.         });
  3956.     };
  3957.     var updateDivisaForForm = function(divisa) {
  3958.         if (divisa == "") {
  3959.             divisa = "EUR";
  3960.             divisaAnterior = divisa;
  3961.             actualCurrency = divisa;
  3962.         } else {
  3963.             actualCurrency = "";
  3964.             if ($(".currencyChange").length > 1) actualCurrency = $(".currencyChange").first().text(); else actualCurrency = $(".currencyChange").text();
  3965.             actualCurrency = $.trim(actualCurrency);
  3966.             if (actualCurrency == "") actualCurrency = "EUR";
  3967.             divisaAnterior = actualCurrency;
  3968.         }
  3969.         divisaAnterior2 = actualCurrency;
  3970.         cloneOriginalPrices();
  3971.         $("#divisa").val(divisa).change();
  3972.         $("#divisa2").val(divisa).change();
  3973.         $(".divisaInput").val($("#divisa").val());
  3974.         cambiarDivisa("divisa");
  3975.     };
  3976.     var cloneOriginalPrices = function() {
  3977.         $(".hidden.originalPrice").remove();
  3978.         $(".priceChange").each(function() {
  3979.             var precio = $(this).text();
  3980.             $(this).after('<span class="hidden originalPrice">' + precio + "</span>");
  3981.         });
  3982.     };
  3983.     var spaSelectDivisa = function() {
  3984.         actualCurrency = "";
  3985.         if ($(".currencyChange").length > 1) actualCurrency = $(".currencyChange").first().text(); else actualCurrency = $(".currencyChange").text();
  3986.         actualCurrency = $.trim(actualCurrency);
  3987.         if (actualCurrency == "") actualCurrency = "EUR";
  3988.         divisaAnterior = actualCurrency;
  3989.         cloneOriginalPrices();
  3990.         $("#divisa").val(actualCurrency).change();
  3991.         $(".divisaInput").val($("#divisa").val());
  3992.     };
  3993.     return {
  3994.         init: init,
  3995.         updateDivisaForForm: updateDivisaForForm,
  3996.         cambiarDivisa: cambiarDivisa,
  3997.         setDivisaOnMap: setDivisaOnMap
  3998.     };
  3999. }();
  4000.  
  4001. $(function() {
  4002.     if ($("#divisa").length > 0 || $("#divisa2").length > 0) {}
  4003. });
  4004.  
  4005. function cambiarDivisa(id) {
  4006.     Currency.cambiarDivisa(id);
  4007. }
  4008.  
  4009. $(document).on("click", ".fancybox-item.fancybox-close", function(event) {
  4010.     if ($("#divisa").length > 0) {
  4011.         parent.$("#divisa").addClass("inicioPagina");
  4012.         parent.$("#divisa").val(parent.divisaAnterior2).change();
  4013.         parent.$("#divisa2").addClass("inicioPagina");
  4014.         parent.$("#divisa2").val(parent.divisaAnterior2).change();
  4015.     }
  4016. });
  4017.  
  4018. var pois = {};
  4019.  
  4020. var filterPois = {};
  4021.  
  4022. var isCountry = false;
  4023.  
  4024. var mapMob;
  4025.  
  4026. poiMarkersMob = new Array();
  4027.  
  4028. markersMob = new Array();
  4029.  
  4030. var clicado = false;
  4031.  
  4032. var filtroEstrellasActi = {};
  4033.  
  4034. var filtroServiciosActi = {};
  4035.  
  4036. var filtroMarcaActi = {};
  4037.  
  4038. var filtroTypoMarcaActi = {};
  4039.  
  4040. var filtroPrecioActi = new Array(2);
  4041.  
  4042. var filtroDistMonuActi = {
  4043.     poi: "",
  4044.     distance: 0
  4045. };
  4046.  
  4047. var ratingsDictionary = {
  4048.     stars5: 5,
  4049.     stars4: 4,
  4050.     stars3: 3,
  4051.     stars2: 2,
  4052.     stars1: 1
  4053. };
  4054.  
  4055. var numHotelByPrice;
  4056.  
  4057. var mostrarNodispo = true;
  4058.  
  4059. var isPageLanding = true;
  4060.  
  4061. var isPageLandingWithoutDates = false;
  4062.  
  4063. var isResultPage = false;
  4064.  
  4065. var tituloHotelesNodispo;
  4066.  
  4067. var tituloHotelesNearby;
  4068.  
  4069. var tituloHotelesNearbyNoDispo;
  4070.  
  4071. var servicesNotToFilter = {
  4072.     "icon-rooms": true
  4073. };
  4074.  
  4075. var searchString;
  4076.  
  4077. var value;
  4078.  
  4079. var auxStructure;
  4080.  
  4081. var contadorToShow;
  4082.  
  4083. var BuildFilters = function() {
  4084.     var listResults = $("#newResults");
  4085.     var init = function() {
  4086.         buildStars();
  4087.         if (!LandingPage.isNoAvailabilityPage) {
  4088.             buildPrice();
  4089.         }
  4090.         buildServices();
  4091.         buildPois();
  4092.         buildBrand();
  4093.         hideLoadingElements();
  4094.         filterEvents();
  4095.         initializeHelpersFilters();
  4096.         showNumHotelsSidebar();
  4097.         updateNumHotelsFiltered();
  4098.         handleTitleResults();
  4099.     };
  4100.     var buildStars = function() {
  4101.         var ratingsDictionary = {
  4102.             stars5: false,
  4103.             stars4: false,
  4104.             stars3: false,
  4105.             stars2: false,
  4106.             stars1: false
  4107.         };
  4108.         var stars = false;
  4109.         ratingsDictionary["stars5"] = $(".hotelItem .stars5").length > 0 ? true : false;
  4110.         ratingsDictionary["stars4"] = $(".hotelItem .stars4").length > 0 ? true : false;
  4111.         ratingsDictionary["stars3"] = $(".hotelItem .stars3").length > 0 ? true : false;
  4112.         ratingsDictionary["stars2"] = $(".hotelItem .stars2").length > 0 ? true : false;
  4113.         ratingsDictionary["stars1"] = $(".hotelItem .stars1").length > 0 ? true : false;
  4114.         for (var key in ratingsDictionary) {
  4115.             if (ratingsDictionary[key]) {
  4116.                 $("[class='filters']").find("div.starsHotel.firstlevelContent").find("ul").append('<li class="' + key + '"><input name="" type="checkbox" value="" onchange =" activa($(this).parent()), filterHotelsByStars(this)"><span class="totalHotels">2 Hoteles</span></li>');
  4117.                 $("[class='filters mob']").find("div.starsHotel.firstlevelContent").find("ul").append('<li class="' + key + '"><input name="" type="checkbox" value="" onchange =" activa($(this).parent()), filterHotelsByStars(this)"><span class="totalHotels">2 Hoteles</span></li>');
  4118.             }
  4119.         }
  4120.     };
  4121.     var buildServices = function() {
  4122.         var servicioIsMain = {};
  4123.         var servicioNotMain = {};
  4124.         var servicioText = {};
  4125.         var aux = $("div.hotelItem");
  4126.         aux.each(function(index) {
  4127.             var listaServicios = $(this).find(".col-md-3.servicesHotel").children("ul").children("");
  4128.             listaServicios.each(function(index) {
  4129.                 var stringArrayAux = $(this).children().attr("class").split(" ")[0];
  4130.                 if (!servicesNotToFilter[stringArrayAux]) {
  4131.                     if ($(this).hasClass("isMainService")) {
  4132.                         servicioIsMain[stringArrayAux] = true;
  4133.                     } else {
  4134.                         servicioNotMain[stringArrayAux] = true;
  4135.                     }
  4136.                     servicioText[stringArrayAux] = $(this).text();
  4137.                 }
  4138.             });
  4139.         });
  4140.         var cont = 0;
  4141.         for (var key in servicioIsMain) {
  4142.             if (cont < 6) {
  4143.                 $("[class='filters']").find("div.services.firstlevelContent").find("ul").append('<li class="text-overflow" onClick="activa(this), filterHotelsByServices(this)"><span class="' + key + ' tooltip-icon" title="' + servicioText[key] + '"></span>' + servicioText[key] + "</li>");
  4144.             } else {
  4145.                 $("[class='filters']").find("div.services.firstlevelContent").find("ul").append('<li class="notvisible oculto text-overflow" onClick="activa(this), filterHotelsByServices(this)"><span class="' + key + ' tooltip-icon" title="' + servicioText[key] + '"></span>' + servicioText[key] + "</li>");
  4146.             }
  4147.             $("[class='filters mob']").find("div.services.firstlevelContent").find("ul").append('<li class="text-overflow" onClick="activa(this), filterHotelsByServices(this)"><span class="' + key + '"></span>' + servicioText[key] + "</li>");
  4148.             cont++;
  4149.         }
  4150.         for (var key in servicioNotMain) {
  4151.             if (cont < 6) {
  4152.                 $("[class='filters']").find("div.services.firstlevelContent").find("ul").append('<li class="text-overflow" onClick="activa(this), filterHotelsByServices(this)"><span class="' + key + ' tooltip-icon" title="' + servicioText[key] + '"></span>' + servicioText[key] + "</li>");
  4153.             } else {
  4154.                 $("[class='filters']").find("div.services.firstlevelContent").find("ul").append('<li class="notvisible oculto text-overflow" onClick="activa(this), filterHotelsByServices(this)"><span class="' + key + ' tooltip-icon" title="' + servicioText[key] + '"></span>' + servicioText[key] + "</li>");
  4155.             }
  4156.             $("[class='filters mob']").find("div.services.firstlevelContent").find("ul").append('<li class="text-overflow" onClick="activa(this), filterHotelsByServices(this)"><span class="' + key + '"></span>' + servicioText[key] + "</li>");
  4157.             cont++;
  4158.         }
  4159.         if (cont <= 6) {
  4160.             $("[class='filters']").find("div.services.firstlevelContent").find("a").remove();
  4161.         }
  4162.     };
  4163.     var buildPois = function() {
  4164.         var rangoKm = new Array(2);
  4165.         rangoKm[0] = 999999;
  4166.         rangoKm[1] = -1;
  4167.         filterPois = getPoisToFilter();
  4168.         var numPois = 0;
  4169.         if (Object.keys) {
  4170.             numPois = Object.keys(filterPois).length;
  4171.         } else {
  4172.             for (var prop in filterPois) {
  4173.                 if (filterPois.hasOwnProperty(prop)) numPois++;
  4174.             }
  4175.         }
  4176.         if (!lastSearch.isPOI) {
  4177.             if (numPois > 0) {
  4178.                 $("#filtroPOI").append('<option class="empty">' + labelChooseOption + "</option>");
  4179.                 $("#filtroPOIMob").append('<option class="empty">' + labelChooseOption + "</option>");
  4180.                 $.map(filterPois, function(element, key) {
  4181.                     $("#filtroPOI").append('<option class="' + key + '">' + element[0].description + "</option>");
  4182.                     $("#filtroPOIMob").append('<option class="' + key + '">' + element[0].description + "</option>");
  4183.                 });
  4184.             } else {
  4185.                 $("#filtroPOI").append('<option class="empty">' + labelEmpty + "</option>");
  4186.                 $("#filtroPOIMob").append('<option class="empty">' + labelEmpty + "</option>");
  4187.                 $("#filtroPOI").prop("disabled", true);
  4188.                 $("#filtroPOIMob").prop("disabled", true);
  4189.             }
  4190.         } else {
  4191.             $("#filtroPOI").append('<option class="' + pageData.keySearch + '">' + pageData.destinationName + "</option>");
  4192.             $("#filtroPOIMob").append('<option class="' + pageData.keySearch + '">' + pageData.destinationName + "</option>");
  4193.             $("#filtroPOI").prop("disabled", true);
  4194.             $("#filtroPOIMob").prop("disabled", true);
  4195.         }
  4196.         var aux = $("div.hotelItem");
  4197.         aux.each(function(index) {
  4198.             $(".hotelNearby, .hotelNearbyNoDispo").find("ul.POIS").empty();
  4199.             var hotelesNearby = $(".hotelNearby, .hotelNearbyNoDispo").find("ul.POIS");
  4200.             hotelesNearby.each(function() {
  4201.                 var $hotel = $(this);
  4202.                 var hotelClass = $.trim($(this).parents(".hotelItem").find(".hotelName").text().replace(/\ /g, "").toLowerCase());
  4203.                 var hotelLat = $hotel.parents(".hotelItem").find(".coordenate .latitude").text();
  4204.                 var hotelLong = $hotel.parents(".hotelItem").find(".coordenate .longitude").text();
  4205.                 var distancia = 0;
  4206.                 $.each(filterPois, function(poi, poi_values) {
  4207.                     distancia = getDistanceBetweenCoords(hotelLat, hotelLong, poi_values[0].latitude, poi_values[0].longitude);
  4208.                     var output_pois = "";
  4209.                     $.each(poi_values[0], function(name, value) {
  4210.                         output_pois += '<li class="' + name + '">' + value + "</li>";
  4211.                     });
  4212.                     var output = '<li class="' + poi + '">' + "<ul>" + '<li data-poiid="' + hotelClass + "-" + poi + '">' + distancia + " Km</li>" + output_pois + "</ul>" + "</li>";
  4213.                     $hotel.append(output);
  4214.                 });
  4215.             });
  4216.             var pois = $(this).find("ul.POIS").children("");
  4217.             if (lastSearch.isPOI) {
  4218.                 pois = $("div.hotelItem").find("ul.POIS").find("li." + pageData.keySearch + "");
  4219.                 pois.each(function() {
  4220.                     var km = $(this).find("li").first().text().replace(",", ".");
  4221.                     km = km.split(" ");
  4222.                     km = parseFloat(km[0]);
  4223.                     if (!isNaN(km) && rangoKm[0] >= km) rangoKm[0] = km;
  4224.                     if (!isNaN(km) && rangoKm[1] <= km) rangoKm[1] = km;
  4225.                 });
  4226.             } else {
  4227.                 pois.each(function() {
  4228.                     if ($(this).find("li").siblings(".toFilter").text().toLowerCase() == "yes") {
  4229.                         var km = $(this).find("li").first().text().replace(",", ".");
  4230.                         km = km.split(" ");
  4231.                         km = parseFloat(km[0]);
  4232.                         if (!isNaN(km) && rangoKm[0] >= km) rangoKm[0] = km;
  4233.                         if (!isNaN(km) && rangoKm[1] <= km) rangoKm[1] = km;
  4234.                     }
  4235.                 });
  4236.             }
  4237.         });
  4238.         if (rangoKm[0] == 999999 && rangoKm[1] == -1) {
  4239.             rangoKm[0] = 0;
  4240.             rangoKm[1] = 1;
  4241.         }
  4242.         $("#range1").val("" + Math.ceil(parseFloat(rangoKm[1])) + "");
  4243.         $("#range1").attr("value", "" + Math.ceil(parseFloat(rangoKm[1])) + "");
  4244.         $("#range1").after("<scr" + 'ipt> jQuery("#range1").slider({ from: 0, to: ' + Math.ceil(parseFloat(rangoKm[1])) + ', step: 0.1, round: 1,  dimension: "KM", skin: "plastic",      callback: function( value ){      filterByPoi(this.o.pointers[0].value.origin);  }   }); </scr' + "ipt>");
  4245.         $("#rangeMob1").val("" + Math.ceil(parseFloat(rangoKm[1])) + "");
  4246.         $("#rangeMob1").attr("value", "" + Math.ceil(parseFloat(rangoKm[1])) + "");
  4247.         $("#rangeMob1").after("<scr" + 'ipt> jQuery("#rangeMob1").slider({ from: 0, to: ' + Math.ceil(parseFloat(rangoKm[1])) + ', step: 0.1, round: 1,  dimension: "KM", skin: "plastic",      callback: function( value ){    filterByPoi(this.o.pointers[0].value.origin);  }   }); </scr' + "ipt>");
  4248.     };
  4249.     var buildBrand = function() {
  4250.         var marcas = {};
  4251.         var aux = $("div.hotelItem");
  4252.         var listHotels = $(listResults).find(".hotelItem");
  4253.         $.each(listHotels, function(i, ele) {
  4254.             marcas[$(ele).attr("data-hotelmarca")] = true;
  4255.         });
  4256.         cont = 0;
  4257.         for (var key in marcas) {
  4258.             if (cont < 6) {
  4259.                 $("[class='filters']").find("div.hotelGroup.firstlevelContent").find("ul").append('<li><input name="" type="checkbox" value="" onchange="activa($(this).parent()), filterBrand(this)">' + key + ' <span class="result">4 hoteles</span></li>');
  4260.             } else {
  4261.                 $("[class='filters']").find("div.hotelGroup.firstlevelContent").find("ul").append('<li class="notvisible oculto"><input name="" type="checkbox" value="" onchange="filterBrand(this)">' + key + '<span class="result">4 hoteles</span></li>');
  4262.             }
  4263.             $("[class='filters mob']").find("div.hotelGroup.firstlevelContent").find("ul").append('<li class="col-sm-6 col-xs-6"><input name="" type="checkbox" value="" onchange="activa($(this).parent()), filterBrand(this)">' + key + ' <span class="result">4 hoteles</span></li>');
  4264.             cont++;
  4265.         }
  4266.         if (cont < 5) {
  4267.             $("[class='filters']").find("div.hotelGroup.firstlevelContent").find("a").remove();
  4268.         }
  4269.         cont = 0;
  4270.     };
  4271.     var buildPrice = function() {
  4272.         var rangoPrecio = new Array(2);
  4273.         rangoPrecio[0] = 99999;
  4274.         rangoPrecio[1] = -1;
  4275.         var listHotels = $(listResults).find(".hotelItem");
  4276.         $.each(listHotels, function(i, ele) {
  4277.             var precio = parseFloat($(ele).find(".hotel-total-price").text());
  4278.             if (!isNaN(precio) && rangoPrecio[0] >= precio && precio != -1) {
  4279.                 rangoPrecio[0] = precio;
  4280.             }
  4281.             if (!isNaN(precio) && rangoPrecio[1] <= precio && precio != -1) {
  4282.                 rangoPrecio[1] = precio;
  4283.             }
  4284.             if (rangoPrecio[0] == 99999 && rangoPrecio[1] == -1) {
  4285.                 rangoPrecio[0] = 0;
  4286.                 rangoPrecio[1] = 1;
  4287.             }
  4288.         });
  4289.         if (rangoPrecio[0] == rangoPrecio[1]) {
  4290.             rangoPrecio[0] = 1;
  4291.         }
  4292.         $("#range2").val("" + Math.floor(rangoPrecio[0]) + ";" + Math.ceil(rangoPrecio[1]) + "");
  4293.         $("#range2").attr("value", "" + Math.floor(rangoPrecio[0]) + ";" + Math.ceil(rangoPrecio[1]) + "");
  4294.         $("#range2").after("<scr" + "ipt>" + ' $("#range2").slider({  from:' + Math.floor(rangoPrecio[0]) + ",  to: " + Math.ceil(rangoPrecio[1]) + ', step: 1,  round: 1,  dimension: " ' + $.trim($(".currencyChange").first().text()) + '",  skin: "plastic",  callback: function( value ){  var min =this.o.pointers[0].value.origin; var max =this.o.pointers[1].value.origin;     filterByPrice(min, max );       }       });      </scr' + "ipt>");
  4295.         $("#rangeMob").val("" + Math.floor(rangoPrecio[0]) + ";" + Math.ceil(rangoPrecio[1]) + "");
  4296.         $("#rangeMob").attr("value", "" + Math.floor(rangoPrecio[0]) + ";" + Math.ceil(rangoPrecio[1]) + "");
  4297.         $("#rangeMob").after("<scr" + "ipt>" + ' $("#rangeMob").slider({  from:' + Math.floor(rangoPrecio[0]) + ",  to: " + Math.ceil(rangoPrecio[1]) + ', step: 1,  round: 1,  dimension: " ' + $.trim($(".currencyChange").first().text()) + '",  skin: "plastic",  callback: function( value ){  var min =this.o.pointers[0].value.origin; var max =this.o.pointers[1].value.origin;     filterByPrice(min, max );       }       });      </scr' + "ipt>");
  4298.         $(".prices.firstlevelContent").fadeIn();
  4299.     };
  4300.     var filterEvents = function() {
  4301.         $(".showFilters a.filtersGlobalAux").on("click", function(e) {
  4302.             showFiltersAux(".filtersMob");
  4303.         });
  4304.         $("a.hideFiltersAux").on("click", function(e) {
  4305.             $(this).parent().parent().parent().hide();
  4306.             hideFiltersAux();
  4307.         });
  4308.         $("a.hideFilters").on("click", function(e) {
  4309.             $("body").css("overflow", "auto");
  4310.         });
  4311.         $(window).resize(function() {
  4312.             if ($("div.shortBy.mob").is(":visible") || $("div.filters.mob").is(":visible")) {
  4313.                 $("body").css("overflow", "hidden");
  4314.             } else {
  4315.                 $("body").css("overflow", "auto");
  4316.             }
  4317.         });
  4318.         $('.filtersMob [name="disponibilidadMob"], .filters [name="disponibilidad"]').on("click", function() {
  4319.             filterHotelsByDisponibilidad($(this).data("filter"));
  4320.         });
  4321.         $("#filtroPOIMob, #filtroPOI").on("change", function() {
  4322.             filterByPoi(-1, this);
  4323.             actualizarCampoPOIdeHotelItem();
  4324.             cambiarCampo();
  4325.         });
  4326.         if (lastSearch.isPOI) {
  4327.             $("#selectSort").val("distPoiAsc");
  4328.             $("#selectSortMob").val("distPoiAsc");
  4329.             $("#selectSort").change();
  4330.             $("#selectSortMob").change();
  4331.             cambiarCampo();
  4332.             if ($("div.hotelItem").length > 1) {
  4333.                 $(".js-total-hotels").text($("div.hotelItem").length);
  4334.                 $(".destinoBusqueda").html(" " + pageLabels.lblHotelsInPoi + " " + pageData.destino + ", " + pageData.pais);
  4335.             } else {
  4336.                 $(".js-total-hotels").text($("div.hotelItem").length);
  4337.                 $(".destinoBusqueda").html(" " + pageLabels.lblHotelInPoi + " " + pageData.destino + ", " + pageData.pais);
  4338.             }
  4339.         } else {
  4340.             $("#selectSort").selectpicker("refresh");
  4341.             $("#selectSortMob").selectpicker("refresh");
  4342.             var toHidePoiasc = $("#selectSort").find('option[value="distPoiAsc"]').text();
  4343.             var toHidePoides = $("#selectSort").find('option[value="distPoiDes"]').text();
  4344.             $('ul.inner li:contains("' + toHidePoiasc + '")').attr("style", "display:none!important");
  4345.             $('ul.inner li:contains("' + toHidePoides + '")').attr("style", "display:none!important");
  4346.             if ($("div.hotelItem").length > 1) {
  4347.                 $(".js-total-hotels").text($("div.hotelItem").length);
  4348.                 $(".destinoBusqueda").html(" " + pageLabels.lblHotelsInDestination + " " + pageData.destino + ", " + pageData.pais);
  4349.             } else {
  4350.                 $(".js-total-hotels").text($("div.hotelItem").length);
  4351.                 $(".destinoBusqueda").html(" " + pageLabels.lblHotelInDestination + " " + pageData.destino + ", " + pageData.pais);
  4352.             }
  4353.         }
  4354.         $(window).load(function() {
  4355.             if (pageData.filterStars) {
  4356.                 var stars = pageData.filterStars.split(",");
  4357.                 buildDynamicStars(stars);
  4358.             }
  4359.             if (pageData.filterServices) {
  4360.                 var services = pageData.filterServices.split(",");
  4361.                 buildDynamicServices(services);
  4362.             }
  4363.         });
  4364.     };
  4365.     var getPoisToFilter = function() {
  4366.         var pois = {};
  4367.         var poisToFilter;
  4368.         if (isPageLanding) {
  4369.             poisToFilter = $("div.hotelItem").find("ul.POIS>li").filter("li:contains('Yes'),li:contains('yes')");
  4370.         } else {
  4371.             poisToFilter = $("#hotelesNoDispo .hotelItem").find("ul.POIS>li").filter("li:contains('Yes'),li:contains('yes')");
  4372.         }
  4373.         poisToFilter.each(function() {
  4374.             if ($(this).find("li.toFilter").text() == "Yes" || $(this).find("li.toFilter").text() == "yes") {
  4375.                 var poi = $(this).attr("class");
  4376.                 var description = $(this).find("li.description").text();
  4377.                 var latitude = $(this).find("li.latitude").text();
  4378.                 var longitude = $(this).find("li.longitude").text();
  4379.                 var typePOI = $(this).find("li.typePOI").text();
  4380.                 var isCityCenter = $(this).find("li.isCityCenter").text();
  4381.                 var toFilter = $(this).find("li.toFilter").text();
  4382.                 pois[poi] = [ {
  4383.                     description: description,
  4384.                     latitude: latitude,
  4385.                     longitude: longitude,
  4386.                     toFilter: toFilter,
  4387.                     isCityCenter: isCityCenter,
  4388.                     typePOI: typePOI
  4389.                 } ];
  4390.             }
  4391.         });
  4392.         return pois;
  4393.     };
  4394.     var initializeHelpersFilters = function() {
  4395.         tituloHotelesNodispo = $("#hotelesNoDispo").children("h3, hr");
  4396.         tituloHotelesNearby = $("#hotelesNearby").children("h3, hr");
  4397.         tituloHotelesNearbyNoDispo = $("#hotelesNearbyNoDispo").children("h3, hr");
  4398.         numHotelByPrice = $("div.hotelItem").length;
  4399.         var aux = $("[class='filters']").find("div.starsHotel.firstlevelContent").find("ul").children("");
  4400.         aux.each(function(index) {
  4401.             filtroEstrellasActi[ratingsDictionary[$(this).attr("class")]] = false;
  4402.         });
  4403.         aux = $("[class='filters']").find("div.services.firstlevelContent").find("ul").children("").children("");
  4404.         aux.each(function(index) {
  4405.             var elemento = $(this).attr("class");
  4406.             elemento = elemento.split(" ");
  4407.             filtroServiciosActi[elemento[0]] = false;
  4408.         });
  4409.         aux = $("[class='filters']").find("div.hotelGroup.firstlevelContent").find("ul").children("");
  4410.         aux.each(function(index) {
  4411.             filtroMarcaActi[$(this).clone().children().remove().end().text().replace(/ /g, " ").replace(/\s+$/, "")] = false;
  4412.         });
  4413.         if ($("#range2").length > 0) {
  4414.             aux = $("#range2").val().split(";");
  4415.             filtroPrecioActi[0] = parseFloat(aux[0]);
  4416.             filtroPrecioActi[1] = parseFloat(aux[1]);
  4417.         }
  4418.         $("#filtroPOI").selectpicker("refresh");
  4419.         $("#filtroPOIMob").selectpicker("refresh");
  4420.         filtroDistMonuActi.distance = parseFloat($("#range1").slider("value"));
  4421.         aux = $("[class='filters']").find("div.nearForm.firstlevelContent").find("div.filter-option.pull-left").text();
  4422.         var aux2 = $("[class='filters']").find("div.nearForm.firstlevelContent").find(".selectpicker").find("option:contains(" + aux + ")").attr("class");
  4423.         filtroDistMonuActi.poi = "." + aux2;
  4424.         if (lastSearch.isPOI) {
  4425.             $("#filtroPOI").prop("disabled", false);
  4426.             $("#filtroPOI").change();
  4427.             $("#filtroPOI").prop("disabled", true);
  4428.         }
  4429.         if (isCountry != null && isCountry) {
  4430.             $(".destino").next().show();
  4431.             $(".destino").show();
  4432.             var hideDistCentroDes = $("#selectSort").find('option[value="distCentroDes"]').text();
  4433.             var hideDistCentroAsc = $("#selectSort").find('option[value="distCentroAsc"]').text();
  4434.             $('ul.inner li:contains("' + hideDistCentroDes + '")').attr("style", "display:none!important");
  4435.             $('ul.inner li:contains("' + hideDistCentroAsc + '")').attr("style", "display:none!important");
  4436.         }
  4437.         if ($("#filtroPOI option:selected").attr("class") == "empty") {
  4438.             $("span.jslider.jslider_plastic.jslider-single").hide();
  4439.         }
  4440.         for (var key in filtroTypoMarcaActi) filtroTypoMarcaActi[key] = false;
  4441.         if (isPageLandingWithoutDates) {
  4442.             $(".hotelSinfecha").removeClass("hidden");
  4443.             $("div.hotelItem").each(function() {
  4444.                 $(this).find(".priceRewards").hide();
  4445.                 $(this).find(".addToolTip").hide();
  4446.             });
  4447.         }
  4448.     };
  4449.     var showNumHotelsSidebar = function() {
  4450.         var typeOfRating = {};
  4451.         var typeOfMarca = {};
  4452.         var domRating = $("[class='filters']").find("div.starsHotel.firstlevelContent").find("ul").children("");
  4453.         domRating.each(function() {
  4454.             typeOfRating[$(this).attr("class")] = 0;
  4455.         });
  4456.         var domMarca = $("[class='filters']").find("div.hotelGroup.firstlevelContent").find("ul").children("");
  4457.         domMarca.each(function(index) {
  4458.             typeOfMarca[$(this).clone().children().remove().end().text().replace(/ /g, " ").replace(/\s+$/, "")] = 0;
  4459.         });
  4460.         $("div.hotelItem").each(function() {
  4461.             if ($(this).find(".stars").length != 0) {
  4462.                 var rating = $(this).find(".stars").attr("class").replace(/[^0-9\.]+/g, "");
  4463.             }
  4464.             var marca = $(this).attr("data-hotelMarca");
  4465.             typeOfRating["stars" + rating.toString()] += 1;
  4466.             typeOfMarca[marca] += 1;
  4467.         });
  4468.         domRating.each(function() {
  4469.             var info = $(this).text();
  4470.             var infoArray = info.split(" ");
  4471.             infoArray[0] = typeOfRating[$(this).attr("class")];
  4472.             if (infoArray[0] > 1) infoArray[1] = labelHotels; else infoArray[1] = labelHotel;
  4473.             $(this).children("span").text(infoArray.join(" "));
  4474.         });
  4475.         domMarca.each(function(index) {
  4476.             var info = $(this).children("span").text();
  4477.             var infoArray = info.split(" ");
  4478.             infoArray[0] = typeOfMarca[$(this).clone().children().remove().end().text().replace(/ /g, " ").replace(/\s+$/, "")];
  4479.             if (infoArray[0] > 1) infoArray[1] = labelHotels; else infoArray[1] = labelHotel;
  4480.             $(this).children("span").text(infoArray.join(" "));
  4481.         });
  4482.         domRating = $("[class='filters mob']").find("div.starsHotel.firstlevelContent").find("ul").children("");
  4483.         domMarca = $("[class='filters mob']").find("div.hotelGroup.firstlevelContent").find("ul").children("");
  4484.         domRating.each(function() {
  4485.             var info = $(this).text();
  4486.             var infoArray = info.split(" ");
  4487.             infoArray[0] = typeOfRating[$(this).attr("class")];
  4488.             if (infoArray[0] > 1) infoArray[1] = labelHotels; else infoArray[1] = labelHotel;
  4489.             $(this).children("span").text(infoArray.join(" "));
  4490.         });
  4491.         domMarca.each(function(index) {
  4492.             var info = $(this).children("span").text();
  4493.             var infoArray = info.split(" ");
  4494.             infoArray[0] = typeOfMarca[$(this).clone().children().remove().end().text().replace(/ /g, " ").replace(/\s+$/, "")];
  4495.             if (infoArray[0] > 1) infoArray[1] = labelHotels; else infoArray[1] = labelHotel;
  4496.             $(this).children("span").text(infoArray.join(" "));
  4497.         });
  4498.         numHotelByPrice = 0;
  4499.         var hoteles = $("div.hotelItem");
  4500.         hoteles.each(function() {
  4501.             var precio = -1;
  4502.             if (!$(this).hasClass("hotelNodispo")) {
  4503.                 precio = parseFloat($(this).find(".hotel-total-price").text());
  4504.             }
  4505.             if (!isNaN(precio) && precio != -1) {
  4506.                 numHotelByPrice++;
  4507.             }
  4508.         });
  4509.     };
  4510.     var buildDynamicStars = function(stars) {
  4511.         if (stars) {
  4512.             for (var i = 0; i < stars.length; i++) {
  4513.                 if ($(".starsHotel.firstlevelContent > ul").find(".stars" + stars[i] + ">input").get(0) == null) {
  4514.                     $(".starsHotel.firstlevelContent > ul > li").each(function() {
  4515.                         if ($(this).attr("class").split("stars")[1] < stars[i]) {
  4516.                             $('<li class="stars' + stars[i] + '"><input type="checkbox" onchange=" activa($(this).parent()), filterHotelsByStars(this)" value="" name=""><span class="totalHotels">0 Hoteles</span></li>').insertBefore(".starsHotel.firstlevelContent > ul > li." + $(this).attr("class"));
  4517.                             $(".starsHotel.firstlevelContent").find(".stars" + stars[i] + ">input").prop("checked", true).change();
  4518.                             $("li.stars" + stars[i]).remove();
  4519.                             return false;
  4520.                         }
  4521.                     });
  4522.                 } else {
  4523.                     $(".starsHotel.firstlevelContent").find(".stars" + stars[i] + ">input").prop("checked", true).change();
  4524.                 }
  4525.             }
  4526.         }
  4527.     };
  4528.     var buildDynamicServices = function(services) {
  4529.         if (services) {
  4530.             $(".more").click();
  4531.             for (var j = 0; j < services.length; j++) {
  4532.                 if ($(".services > ul").find("." + services[j]).get(0) == null) {
  4533.                     $(".services > ul").prepend('<li class="text-overflow" onclick="activa(this), filterHotelsByServices(this)"><span class="' + services[j] + ' tooltip-icon" data-original-title="' + services[j] + '"></span>' + services[j] + "</li>");
  4534.                 }
  4535.                 $(".services > ul").find("." + services[j]).parent().click();
  4536.             }
  4537.         }
  4538.     };
  4539.     var hideLoadingElements = function() {
  4540.         $(".lazy-hide").fadeIn();
  4541.         $(".lazy-disabled").removeClass("lazy-disabled");
  4542.         $(".loading-lazy").hide();
  4543.     };
  4544.     return {
  4545.         init: init,
  4546.         buildPrice: buildPrice,
  4547.         buildDynamicServices: buildDynamicServices,
  4548.         buildDynamicStars: buildDynamicStars
  4549.     };
  4550. }();
  4551.  
  4552. var LandingFilters = function() {
  4553.     var totalNumHotels = 0;
  4554.     var init = function() {
  4555.         var visibleHotels = $("#view-list .hotelItem").filter(function() {
  4556.             return $(this).css("display") == "inline-block";
  4557.         });
  4558.         totalNumHotels = visibleHotels.length || 0;
  4559.         if (totalNumHotels == 0) {
  4560.             $(".js-alert-error").show();
  4561.         } else {
  4562.             pageInitActions();
  4563.         }
  4564.     };
  4565.     var pageInitActions = function() {
  4566.         BuildFilters.init();
  4567.         isPageLanding = true;
  4568.         if (!pageData.withDates) {
  4569.             $(".loading-lazy").fadeOut(500);
  4570.             $(".lazy-hide").fadeIn(500);
  4571.             isPageLandingWithoutDates = true;
  4572.         }
  4573.     };
  4574.     return {
  4575.         init: init
  4576.     };
  4577. }();
  4578.  
  4579. function updateNumHotelsFiltered(isfirstLoad) {
  4580.     var visibleHotels = $("#view-list .hotelItem").filter(function() {
  4581.         return $(this).css("display") == "inline-block";
  4582.     });
  4583.     var totalNumHotels = visibleHotels.length || 0;
  4584.     if (!isfirstLoad) {
  4585.         $(".js-total-hotels").text(totalNumHotels);
  4586.         var lblHotelFound = totalNumHotels == 1 ? labelHotelFound : labelHotelsFound;
  4587.         var lblHotelInPOI = totalNumHotels == 1 ? labelHotelInPOI : labelHotelsInPOI;
  4588.         var lblHotelInDestination = totalNumHotels == 1 ? labelHotelInDestination : labelHotelsInDestination;
  4589.         $(".hotelsFoundText").text(lblHotelFound);
  4590.         if (lastSearch.isPOI) {
  4591.             $(".destinoBusqueda").text(lblHotelInPOI + " " + pageData.destino + ", " + pageData.pais);
  4592.         } else {
  4593.             $(".destinoBusqueda").text(lblHotelInDestination + " " + pageData.destino + ", " + pageData.pais);
  4594.         }
  4595.         if (totalNumHotels == 0) {
  4596.             $(".js-alert-filter").show();
  4597.         } else {
  4598.             $(".js-alert-filter").hide();
  4599.         }
  4600.     }
  4601.     visibleHotels.each(function(index) {
  4602.         cambiarNumerodeHotel(index, $(this));
  4603.     });
  4604. }
  4605.  
  4606. function applyFilters(filter) {
  4607.     if (pageData.isIpad) updatePaginateResults();
  4608.     var numEStrellasAct = $("div.starsHotel.firstlevelContent:visible").find("ul").children("").filter(".active").length;
  4609.     var numServiciosAct = $("div.services.firstlevelContent:visible").find("ul").children("").filter(".active").length;
  4610.     var numMarcasAct = $("div.hotelGroup.firstlevelContent:visible").find("ul").children("").filter(".active").length;
  4611.     var numTypesMarcasAct = $("div.hotelType.firstlevelContent:visible").not(".destino").find("ul").children("").filter(".active").length;
  4612.     contadorToShow = 0;
  4613.     hotel = $("div.hotelItem");
  4614.     hotel.each(function(index) {
  4615.         if (filter == "filterByPrice") {
  4616.             var precio = parseFloat($(this).find(".hotel-total-price").text());
  4617.         } else if (filter == "filterSliderGenerico") {
  4618.             value = parseFloat($(this).find(searchString).text());
  4619.         }
  4620.         if (!canShow($(this), numEStrellasAct == 0 ? true : false, numServiciosAct == 0 ? true : false, numMarcasAct == 0 ? true : false, numTypesMarcasAct == 0 ? true : false)) {
  4621.             if (markersMob[parseInt($(this).find(".nhrec").text())] != null) {
  4622.                 markersMob[parseInt($(this).find(".nhrec").text())].setMap(null);
  4623.             }
  4624.             $(this).hide();
  4625.         } else {
  4626.             if (markersMob[parseInt($(this).find(".nhrec").text())] != null) {
  4627.                 markersMob[parseInt($(this).find(".nhrec").text())].setMap(mapMob);
  4628.             }
  4629.             $(this).show();
  4630.         }
  4631.         if (filter == "filterByPrice") {
  4632.             if (precio >= filtroPrecioActi[0] && precio <= filtroPrecioActi[1]) numHotelByPrice++;
  4633.         }
  4634.     });
  4635.     handleTitleResults();
  4636.     if (pageData.isIpad) {
  4637.         reorderResults();
  4638.         if ($("#selectSort").val() != "distCentroDes" && $("#selectSort").val() != "distCentroAsc" && $("#selectSort").val() != "distPoiDes" && $("#selectSort").val() != "distPoiAsc") $("#selectSort").change();
  4639.     }
  4640. }
  4641.  
  4642. function filterHotelsByCity(element) {
  4643.     var aux = $(element).parent().attr("class");
  4644.     aux = aux.replace(" active", "");
  4645.     var activo = element.checked;
  4646.     var city = $.trim($(element).parent().clone().children().remove().end().text());
  4647.     $(".starsHotel.firstlevelContent:hidden").find("." + aux).children("input");
  4648.     var registrarCambioDes = $(".destino.hotelType.firstlevelContent:hidden").filter(":contains('" + city + "')").find("input");
  4649.     registrarCambioDes.prop("checked", element.checked);
  4650.     activa(registrarCambioDes.parent());
  4651.     applyFilters("");
  4652.     updateNumHotelsFiltered();
  4653. }
  4654.  
  4655. function filterHotelsByStars(element) {
  4656.     var aux = $(element).parent().attr("class");
  4657.     aux = aux.replace(" active", "");
  4658.     var rating = ratingsDictionary[aux];
  4659.     var activo = element.checked;
  4660.     var registrarCambioDes = $(".starsHotel.firstlevelContent:hidden").find("." + aux).children("input");
  4661.     registrarCambioDes.prop("checked", element.checked);
  4662.     activa(registrarCambioDes.parent());
  4663.     if (activo) filtroEstrellasActi[rating] = true; else filtroEstrellasActi[rating] = false;
  4664.     applyFilters("");
  4665.     updateNumHotelsFiltered();
  4666.     trackFilterStars(page_section, rating);
  4667. }
  4668.  
  4669. function filterHotelsByDisponibilidad(band) {
  4670.     if (pageData.isIpad) updatePaginateResults();
  4671.     mostrarNodispo = band;
  4672.     if (band) $("div.firstlevelContent.availability:hidden").find("input").first().prop("checked", true); else $("div.firstlevelContent.availability:hidden").find("input").last().prop("checked", true);
  4673.     if (band) {
  4674.         var numEStrellasAct = $("div.starsHotel.firstlevelContent:visible").find("ul").children("").filter(".active").length;
  4675.         var numServiciosAct = $("div.services.firstlevelContent:visible").find("ul").children("").filter(".active").length;
  4676.         var numMarcasAct = $("div.hotelGroup.firstlevelContent:visible").find("ul").children("").filter(".active").length;
  4677.         var numTypesMarcasAct = $("div.hotelType.firstlevelContent:visible").not(".destino").find("ul").children("").filter(".active").length;
  4678.         $("[id = hotelesNoDispo]").show();
  4679.         $("#hotelesNoDispo .hotelItem").show();
  4680.         $("[id = hotelesNearbyNoDispo]").show();
  4681.         $("#hotelesNearbyNoDispo .hotelItem").show();
  4682.         applyFilters();
  4683.     } else {
  4684.         $("[id = hotelesNoDispo]").hide();
  4685.         $("#hotelesNoDispo .hotelItem").hide();
  4686.         $("[id = hotelesNearbyNoDispo]").hide();
  4687.         $("#hotelesNearbyNoDispo .hotelItem").hide();
  4688.         $(markersMob).each(function() {
  4689.             if (this.metadata && this.metadata.class == "nodisp") {
  4690.                 this.setMap(null);
  4691.             }
  4692.         });
  4693.         trackFilterAvail(page_section);
  4694.     }
  4695.     if (pageData.isIpad) reorderResults();
  4696.     updateNumHotelsFiltered();
  4697. }
  4698.  
  4699. function filterHotelsByServices(element) {
  4700.     var aux = $(element).children().attr("class");
  4701.     var activo = $(element).attr("class").search("active") != -1 ? true : false;
  4702.     aux = aux.split(" ");
  4703.     var servicios = "." + aux[0];
  4704.     var hotlesToFilter;
  4705.     var filtroOculto = $("div.services.firstlevelContent:hidden").find("ul").find(servicios).parent();
  4706.     activa(filtroOculto);
  4707.     if (activo) filtroServiciosActi[aux[0]] = true; else filtroServiciosActi[aux[0]] = false;
  4708.     applyFilters("");
  4709.     updateNumHotelsFiltered();
  4710.     trackFilterServices(page_section, aux[0].split("-")[1]);
  4711. }
  4712.  
  4713. function filterBrand(element) {
  4714.     var brand = $(element).parent().clone().children().remove().end().text().replace(/ /g, " ").replace(/\s+$/, "");
  4715.     var activo = element.checked;
  4716.     var registrarCambioDes = $("div.hotelGroup.firstlevelContent:hidden").find("ul").children().filter(":contains(" + brand + ")");
  4717.     activa(registrarCambioDes);
  4718.     registrarCambioDes = registrarCambioDes.children("input");
  4719.     registrarCambioDes.prop("checked", element.checked);
  4720.     if (activo) filtroMarcaActi[brand] = true; else filtroMarcaActi[brand] = false;
  4721.     applyFilters("");
  4722.     updateNumHotelsFiltered();
  4723.     trackFilterBrand(page_section, brand);
  4724. }
  4725.  
  4726. function filterTypeBrand(element) {
  4727.     var typoHotel = $(element).parent().find("span.hotelTypeName").text();
  4728.     var activo = element.checked;
  4729.     if (activo) filtroTypoMarcaActi[typoHotel] = true; else filtroTypoMarcaActi[typoHotel] = false;
  4730.     applyFilters("");
  4731.     updateNumHotelsFiltered();
  4732. }
  4733.  
  4734. function canShow(element, showRating, showServicio, showMarca, showTypeMarca) {
  4735.     if (!mostrarNodispo && element.hasClass("hotelNodispo")) {
  4736.         return;
  4737.     }
  4738.     if ($(element).find(".stars").length != 0) {
  4739.         var rating = $(element).find(".stars").attr("class").replace(/[^0-9\.]+/g, "");
  4740.     }
  4741.     var servicio = {};
  4742.     var typeHotels = {};
  4743.     var listaServicios = $(element).find(".col-md-3.servicesHotel").children("ul").children("");
  4744.     listaServicios.each(function(index) {
  4745.         var stringArrayAux = $(this).children().attr("class").split(" ")[0];
  4746.         servicio[stringArrayAux] = true;
  4747.     });
  4748.     var listaTypoHotel = $(element).find(".filterHotelType").find("li");
  4749.     listaTypoHotel.each(function() {
  4750.         var hotelTypeName = $(this).text();
  4751.         typeHotels[hotelTypeName] = true;
  4752.     });
  4753.     var precio = parseFloat($(element).find(".hotel-total-price").text());
  4754.     var marca = $(element).attr("data-hotelMarca");
  4755.     var haveServicioFiltro = true;
  4756.     if (!showServicio) {
  4757.         for (key in filtroServiciosActi) {
  4758.             if (filtroServiciosActi[key] && !(key in servicio)) {
  4759.                 haveServicioFiltro = false;
  4760.                 break;
  4761.             }
  4762.         }
  4763.     } else {
  4764.         haveServicioFiltro = true;
  4765.     }
  4766.     var haveTypeMarcaFilter = true;
  4767.     if (!showTypeMarca) {
  4768.         for (key in filtroTypoMarcaActi) {
  4769.             if (filtroTypoMarcaActi[key] && !(key in typeHotels)) {
  4770.                 haveTypeMarcaFilter = false;
  4771.                 break;
  4772.             }
  4773.         }
  4774.     } else {
  4775.         haveTypeMarcaFilter = true;
  4776.     }
  4777.     var haveFiltroRating = showRating ? true : filtroEstrellasActi[rating];
  4778.     var haveFilterMarca = showMarca ? true : filtroMarcaActi[marca];
  4779.     var filtroPrecio = isNaN(precio) ? true : filtroPrecioActi[0] <= precio && filtroPrecioActi[1] >= precio;
  4780.     var haveFiltroDisPoi;
  4781.     if ($(element).find("ul.POIS").find(filtroDistMonuActi.poi).length > 0) {
  4782.         var aux = $(element).find("ul.POIS").find(filtroDistMonuActi.poi).find("li").first().text().replace(",", ".");
  4783.         var disPoi = parseFloat(aux.split(" ")[0]);
  4784.         haveFiltroDisPoi = disPoi <= filtroDistMonuActi.distance ? true : false;
  4785.     } else if (filtroDistMonuActi.poi == ".empty") {
  4786.         haveFiltroDisPoi = true;
  4787.     } else {
  4788.         if (lastSearch.isPOI) {
  4789.             haveFiltroDisPoi = true;
  4790.         } else {
  4791.             haveFiltroDisPoi = false;
  4792.         }
  4793.     }
  4794.     var haveFilterCity = false;
  4795.     haveFilterCity = true;
  4796.     if (haveServicioFiltro && haveTypeMarcaFilter && haveFiltroRating && filtroPrecio && haveFilterMarca && haveFiltroDisPoi && haveFilterCity) {
  4797.         return true;
  4798.     } else {
  4799.         return false;
  4800.     }
  4801. }
  4802.  
  4803. function filterByPrice(min, max) {
  4804.     numHotelByPrice = 0;
  4805.     filtroPrecioActi[0] = min;
  4806.     filtroPrecioActi[1] = max;
  4807.     console.log("filterByPrice: ", filtroPrecioActi);
  4808.     $("#range2").slider("value", min, max);
  4809.     $("#rangeMob").slider("value", min, max);
  4810.     applyFilters("filterByPrice");
  4811.     updateNumHotelsFiltered();
  4812.     trackFilterPrice(page_section, min, max);
  4813. }
  4814.  
  4815. function genericFilterSlider(min, max, sliderID, auxStructure1, searchString1) {
  4816.     searchString = searchString1;
  4817.     auxStructure = auxStructure1;
  4818.     var numEStrellasAct = $("div.starsHotel.firstlevelContent:visible").find("ul").children("").filter(".active").length;
  4819.     var numServiciosAct = $("div.services.firstlevelContent:visible").find("ul").children("").filter(".active").length;
  4820.     var numMarcasAct = $("div.hotelGroup.firstlevelContent:visible").find("ul").children("").filter(".active").length;
  4821.     var numTypesMarcasAct = $("div.hotelType.firstlevelContent:visible").not(".destino").find("ul").children("").filter(".active").length;
  4822.     auxStructure.min = min;
  4823.     auxStructure.max = max;
  4824.     $(sliderID).slider("value", min, max);
  4825.     var parentClass = "." + $("#range-rooms").parent().attr("class").split(" ")[0];
  4826.     $(parentClass).filter(":hidden").find("input").slider("value", min, max);
  4827.     applyFilters("filterSliderGenerico");
  4828.     updateNumHotelsFiltered();
  4829. }
  4830.  
  4831. function filterByPoi(distance, element) {
  4832.     if (distance == -1) {
  4833.         filtroDistMonuActi.distance = parseFloat($("#range1").slider("value"));
  4834.         var value = $(element).val();
  4835.         if ($("#filtroPOI").val() != value) $("#filtroPOI").val(value).change();
  4836.         if ($("#filtroPOIMob").val() != value) $("#filtroPOIMob").val(value).change();
  4837.     } else {
  4838.         filtroDistMonuActi.distance = distance;
  4839.         $("#range1").slider("value", distance);
  4840.         $("#rangeMob1").slider("value", distance);
  4841.     }
  4842.     if ($("#filtroPOI option:selected").attr("class") == "empty") {
  4843.         $("span.jslider.jslider_plastic.jslider-single").hide();
  4844.     } else {
  4845.         $("span.jslider.jslider_plastic.jslider-single").show();
  4846.     }
  4847.     var aux;
  4848.     var aux2;
  4849.     if ($("div.nearForm.firstlevelContent").filter(":visible").length != 0) {
  4850.         aux = $("div.nearForm.firstlevelContent").filter(":visible").find("div.filter-option.pull-left").text();
  4851.         aux2 = $("div.nearForm.firstlevelContent").filter(":visible").find(".selectpicker").find("option:contains(" + aux + ")").attr("class");
  4852.     } else {
  4853.         aux = $("div.nearForm.firstlevelContent").first().find("div.filter-option.pull-left").text();
  4854.         aux2 = $("div.nearForm.firstlevelContent").first().find(".selectpicker").find("option:contains(" + aux + ")").attr("class");
  4855.     }
  4856.     filtroDistMonuActi.poi = "." + aux2;
  4857.     applyFilters("");
  4858.     updateNumHotelsFiltered();
  4859.     if (distance != -1) {
  4860.         filtroNearTo("landing");
  4861.     }
  4862. }
  4863.  
  4864. function handleTitleResults() {
  4865.     var wrapHotels = $("#newResults .wrap-hotels");
  4866.     $.each(wrapHotels, function(i, ele) {
  4867.         var $ele = $(ele);
  4868.         if ($ele.find(".hotelItem:visible").length == 0) {
  4869.             $ele.find(".wrap-title").hide();
  4870.         } else {
  4871.             if (!lastSearch.isPromo) {
  4872.                 $ele.find('.wrap-title:not(".show-promo")').show();
  4873.             } else {
  4874.                 $ele.find('.wrap-title:not(".hide-promo")').show();
  4875.             }
  4876.         }
  4877.     });
  4878. }
  4879.  
  4880. function cambiarCampo() {
  4881.     var textInfo = $("div.nearForm.firstlevelContent").filter(":visible").find("div.filter-option.pull-left").text();
  4882.     var classInfo = $("div.nearForm.firstlevelContent").filter(":visible").find(".selectpicker").find("option:contains(" + textInfo + ")").attr("class");
  4883.     var isCenter = false;
  4884.     $(".hotelItem").each(function() {
  4885.         if ($(this).find("." + classInfo).find(".isCityCenter").text() == "Yes") {
  4886.             isCenter = true;
  4887.             return false;
  4888.         }
  4889.     });
  4890.     if (classInfo == "empty" || isCenter) {
  4891.         var toHidePoiasc = $("#selectSort").find('option[value="distPoiAsc"]').text();
  4892.         var toHidePoides = $("#selectSort").find('option[value="distPoiDes"]').text();
  4893.         $('ul.inner li:contains("' + toHidePoiasc + '")').attr("style", "display:none!important");
  4894.         $('ul.inner li:contains("' + toHidePoides + '")').attr("style", "display:none!important");
  4895.     } else {
  4896.         var toHidePoiasc = $("#selectSort").find('option[value="distPoiAsc"]').text();
  4897.         var toHidePoides = $("#selectSort").find('option[value="distPoiDes"]').text();
  4898.         $('ul.inner li:contains("' + toHidePoiasc + '")').attr("style", "");
  4899.         $('ul.inner li:contains("' + toHidePoides + '")').attr("style", "");
  4900.     }
  4901.     if (!isCenter && ($("#selectSort").val() == "distCentroAsc" || $("#selectSort").val() == "distCentroDes")) {
  4902.         if ($("#selectSort").val() == "distCentroAsc") {
  4903.             $("#selectSort").val("distPoiAsc");
  4904.         } else {
  4905.             $("#selectSort").val("distPoiDes");
  4906.         }
  4907.         $('ul.inner li:contains("distPoiAsc")').attr("style", "");
  4908.         $('ul.inner li:contains("distPoiDes")').attr("style", "");
  4909.         $("#selectSort").change();
  4910.     } else if (isCenter && ($("#selectSort").val() == "distPoiAsc" || $("#selectSort").val() == "distPoiDes")) {
  4911.         if ($("#selectSort").val() == "distPoiAsc") {
  4912.             $("#selectSort").val("distCentroAsc");
  4913.         } else {
  4914.             $("#selectSort").val("distCentroDes");
  4915.         }
  4916.         $("#selectSort").change();
  4917.     } else if (!isCenter && ($("#selectSort").val() == "distPoiAsc" || $("#selectSort").val() == "distPoiDes")) {
  4918.         $("#selectSort").change();
  4919.     }
  4920.     textAnterior = textInfo;
  4921. }
  4922.  
  4923. function actualizarCampoPOIdeHotelItem() {
  4924.     var textInfo = $("div.nearForm.firstlevelContent").filter(":visible").find("div.filter-option.pull-left").text();
  4925.     var classInfo = $("div.nearForm.firstlevelContent").filter(":visible").find(".selectpicker").find("option:contains(" + textInfo + ")").attr("class");
  4926.     if (classInfo != "empty") {
  4927.         var hoteles = $("div.hotelItem");
  4928.         hoteles.each(function() {
  4929.             var descriptionInfo = $(this).find("ul.POIS").find("li." + classInfo).find("li.description").text();
  4930.             var distanceInfo = $(this).find("ul.POIS").find("li." + classInfo).find("li").first().text();
  4931.             $(this).first().find("div.nearFrom").replaceWith('<div class = "nearFrom"><strong>' + distanceInfo + "</strong>" + " " + descriptionInfo + "<div>");
  4932.         });
  4933.     } else {
  4934.         var hoteles = $("div.hotelItem");
  4935.         hoteles.each(function() {
  4936.             var descriptionInfo = $(this).find("ul.POIS").children().first().find("li.description").text();
  4937.             var distanceInfo = $(this).find("ul.POIS").children().first().find("li").first().text();
  4938.             $(this).first().find("div.nearFrom").replaceWith('<div class = "nearFrom"><strong>' + distanceInfo + "</strong>" + " " + descriptionInfo + "<div>");
  4939.             if ($("#selectSort").val() == "distPoiAsc" || $("#selectSort").val() == "distPoiDes") cambiarOrdenar();
  4940.         });
  4941.     }
  4942. }
  4943.  
  4944. function cambiarOrdenar() {
  4945.     $("#selectSort").val("nhRec");
  4946.     $("#selectSortMob").val("nhRec");
  4947.     $("#selectSort").change();
  4948.     $("#selectSortMob").change();
  4949. }
  4950.  
  4951. function showFiltersAux(filtroMostrar) {
  4952.     $(filtroMostrar).addClass("activa");
  4953.     $(".showFilters").hide();
  4954.     $(".blackBG").show();
  4955.     $(filtroMostrar).animate({
  4956.         top: 0
  4957.     }, 500, function() {
  4958.         $("footer").hide();
  4959.     });
  4960.     $("body").css("overflow", "hidden");
  4961. }
  4962.  
  4963. function hideFiltersAux() {
  4964.     $(".filtersMob").removeClass("activa");
  4965.     $(".showFilters").show();
  4966.     $(".listHotels").show();
  4967.     $("footer").show();
  4968.     $(".blackBG").hide();
  4969.     $("html, body").animate({
  4970.         scrollTop: 0
  4971.     }, "slow");
  4972.     $("body").css("overflow", "auto");
  4973. }
  4974.  
  4975. function cambiarNumerodeHotel(index, element) {
  4976.     var indexValues = $(element).find(".hotelIndex");
  4977.     indexValues.first().text(index + 1 + ". ");
  4978.     indexValues.last().text(index + 1 + ". ");
  4979. }
  4980.  
  4981. $(function() {
  4982.     if ($("body").hasClass("page-landing")) {}
  4983. });
  4984.  
  4985. var LandingMap = function() {
  4986.     var markers = new Array();
  4987.     var init = function() {
  4988.         var secondClick2 = 0;
  4989.         var googleDomain = isChinese ? "http://maps.google.cn" : "https://maps.googleapis.com";
  4990.         var url = googleDomain + "/maps/api/js?client=gme-nhhotels&language=" + pageData.googleLang;
  4991.         var urlInfobox = "https://cdn.rawgit.com/googlemaps/v3-utility-library/master/infobox/src/infobox.js";
  4992.         $("a.view-map").off("click");
  4993.         $("a.view-map").on("click", function(e) {
  4994.             e.preventDefault();
  4995.             if (typeof google == "undefined" && secondClick2 == 0) {
  4996.                 $.when($.getScript(url), $.Deferred(function(deferred) {
  4997.                     $(deferred.resolve);
  4998.                 })).done(function() {
  4999.                     $.when($.getScript(urlInfobox), $.Deferred(function(deferred) {
  5000.                         $(deferred.resolve);
  5001.                     })).done(function() {
  5002.                         showHideMap("show");
  5003.                         secondClick2 = 1;
  5004.                     });
  5005.                 });
  5006.             } else {
  5007.                 showHideMap("show");
  5008.             }
  5009.         });
  5010.         $("a.view-list").on("click", function() {
  5011.             showHideMap("hide");
  5012.         });
  5013.     };
  5014.     var showHideMap = function(status) {
  5015.         switch (status) {
  5016.           case "show":
  5017.             pois = mapPOIs();
  5018.             filterPois = mapPOIsFilter();
  5019.             if (!mapMob) {
  5020.                 mapMob = loadGoogleMap();
  5021.                 applyFilters();
  5022.                 Currency.setDivisaOnMap();
  5023.             }
  5024.             $(".view-map").hide();
  5025.             $(".view-list").show();
  5026.             $("#view-list").hide();
  5027.             $(".wrap-sort-by").hide();
  5028.             $("#mapGoogleMob").css({
  5029.                 visibility: "visible",
  5030.                 height: "auto"
  5031.             });
  5032.             $(".google-maps").css("padding-bottom", 15);
  5033.             break;
  5034.  
  5035.           case "hide":
  5036.             $(".view-map").show();
  5037.             $(".view-list").hide();
  5038.             $("#view-list").show();
  5039.             $(".wrap-sort-by").show();
  5040.             $("#mapGoogleMob").css({
  5041.                 visibility: "hidden",
  5042.                 height: 0
  5043.             });
  5044.             $(".google-maps").css("padding-bottom", 75 + "%");
  5045.             break;
  5046.         }
  5047.     };
  5048.     var loadGoogleMap = function() {
  5049.         if (typeof google != "undefined" && typeof MapsData != "undefined") {
  5050.             $("body,html").animate({
  5051.                 scrollTop: $(".listHotels").offset().top
  5052.             }, 800);
  5053.             var latitude = 40.322038;
  5054.             var longitude = -3.865045;
  5055.             $.each(MapsData, function(i, ele) {
  5056.                 if (ele) {
  5057.                     latitude = MapsData[i].location[0];
  5058.                     longitude = MapsData[i].location[1];
  5059.                     return false;
  5060.                 }
  5061.             });
  5062.             var latlong = new google.maps.LatLng(latitude, longitude);
  5063.             var mapholder = document.getElementById("googleMapMob");
  5064.             mapholder.style.height = "650px";
  5065.             mapholder.style.width = "100%";
  5066.             var myOptions = {
  5067.                 zoom: 11,
  5068.                 center: latlong,
  5069.                 mapTypeId: google.maps.MapTypeId.ROADMAP,
  5070.                 mapTypeControl: false,
  5071.                 navigationControlOptions: {
  5072.                     style: google.maps.NavigationControlStyle.SMALL
  5073.                 },
  5074.                 streetViewControl: false,
  5075.                 scrollwheel: false,
  5076.                 styles: [ {
  5077.                     featureType: "poi",
  5078.                     stylers: [ {
  5079.                         visibility: "off"
  5080.                     } ]
  5081.                 }, {
  5082.                     featureType: "transit.station.airport",
  5083.                     elementType: "labels",
  5084.                     stylers: [ {
  5085.                         visibility: "off"
  5086.                     } ]
  5087.                 } ]
  5088.             };
  5089.             var map = new google.maps.Map(mapholder, myOptions);
  5090.             $.each(MapsData, function(i, dato) {
  5091.                 if (dato) {
  5092.                     markers[i] = new google.maps.Marker({
  5093.                         position: new google.maps.LatLng(dato.location[0], dato.location[1]),
  5094.                         animation: google.maps.Animation.DROP,
  5095.                         map: map,
  5096.                         icon: dato.icon,
  5097.                         zIndex: google.maps.Marker.MAX_ZINDEX - google.maps.Marker.MAX_ZINDEX / (Math.round(latlong.lat() * -1e5) << 5) * 1e5
  5098.                     });
  5099.                     var markerClass = dato.clase != "" ? dato.clase : "dispo";
  5100.                     markers[i].metadata = {
  5101.                         "class": markerClass
  5102.                     };
  5103.                     if (dato.info) {
  5104.                         markers[i].infoWindows = new InfoBox({
  5105.                             disableAutoPan: false,
  5106.                             maxWidth: 427,
  5107.                             pixelOffset: new google.maps.Size(-130, -248),
  5108.                             zIndex: null,
  5109.                             boxStyle: {},
  5110.                             closeBoxMargin: "8px 8px 0 0",
  5111.                             closeBoxURL: "http://www.google.com/intl/en_us/mapfiles/close.gif",
  5112.                             InfoBoxClearance: new google.maps.Size(1, 1)
  5113.                         });
  5114.                         google.maps.event.addListener(markers[i], "click", function() {
  5115.                             $.each(markers, function(index, ele) {
  5116.                                 if (typeof ele != "undefined" && typeof ele.infoWindows != "undefined") {
  5117.                                     ele.infoWindows.close(map, ele);
  5118.                                 }
  5119.                             });
  5120.                             markers[i].infoWindows.setContent(dato.info);
  5121.                             Currency.setDivisaOnMap();
  5122.                             markers[i].infoWindows.open(map, markers[i]);
  5123.                         });
  5124.                     }
  5125.                 }
  5126.             });
  5127.             markersMob = markers;
  5128.             centerMap(markers, map, latlong);
  5129.             var listener = google.maps.event.addListener(map, "idle", function() {
  5130.                 google.maps.event.removeListener(listener);
  5131.             });
  5132.             if (clicado == true) {
  5133.                 infoWindow.open(map, marker);
  5134.             }
  5135.             var clicado = false;
  5136.             $(window).resize(function() {
  5137.                 moveGoogleMap();
  5138.             });
  5139.             if (document.body.orientationchange) {
  5140.                 function doOnOrientationChange() {
  5141.                     moveGoogleMap();
  5142.                 }
  5143.                 window.addEventListener("orientationchange", doOnOrientationChange);
  5144.             }
  5145.             return map;
  5146.         }
  5147.     };
  5148.     var mapPOIsFilter = function() {
  5149.         var pois = {};
  5150.         var i = 0;
  5151.         var isFinished = false;
  5152.         while (!isFinished) {
  5153.             isFinished = true;
  5154.             $(".hotelItem").each(function() {
  5155.                 if ($(this).find("ul.POIS>li").eq(i).length) {
  5156.                     isFinished = false;
  5157.                     if ($(this).find("ul.POIS>li").eq(i).find("li.toFilter").text() == "Yes") {
  5158.                         var poi = $(this).find("ul.POIS>li").eq(i).attr("class");
  5159.                         pois[poi] = [ $(this).find("ul.POIS>li").eq(i).find("li.description").text(), $(this).find("ul.POIS>li").eq(i).find("li.latitude").text(), $(this).find("ul.POIS>li").eq(i).find("li.longitude").text(), $(this).find("ul.POIS>li").eq(i).find("li.typePOI").text(), $(this).find("ul.POIS>li").eq(i).find("li.isCityCenter").text() ];
  5160.                     }
  5161.                 }
  5162.             });
  5163.             i++;
  5164.         }
  5165.         return pois;
  5166.     };
  5167.     var clearPOIsMob = function() {
  5168.         for (var i = 1; i < poiMarkersMob.length; i++) {
  5169.             poiMarkersMob[i].setMap(null);
  5170.             poiMarkersMob[i].infoWindow.open(null);
  5171.         }
  5172.         poiMarkersMob.length = 0;
  5173.     };
  5174.     var mapPOIs = function() {
  5175.         var pois = {};
  5176.         var i = 0;
  5177.         var isFinished = false;
  5178.         while (!isFinished) {
  5179.             isFinished = true;
  5180.             $(".hotelItem").each(function() {
  5181.                 if ($(this).find("ul.POIS>li").eq(i).length) {
  5182.                     isFinished = false;
  5183.                     var poi = $(this).find("ul.POIS>li").eq(i).attr("class");
  5184.                     pois[poi] = [ $(this).find("ul.POIS>li").eq(i).find("li.description").text(), $(this).find("ul.POIS>li").eq(i).find("li.latitude").text(), $(this).find("ul.POIS>li").eq(i).find("li.longitude").text(), $(this).find("ul.POIS>li").eq(i).find("li.typePOI").text(), $(this).find("ul.POIS>li").eq(i).find("li.isCityCenter").text() ];
  5185.                 }
  5186.             });
  5187.             i++;
  5188.         }
  5189.         return pois;
  5190.     };
  5191.     var moveGoogleMap = function() {
  5192.         console.log("moveGoogleMap");
  5193.         centerMap(markersMob, mapMob);
  5194.         recalcularZoom(mapMob);
  5195.     };
  5196.     var centerMap = function(markers, map, latlong) {
  5197.         var latlongCenter = "";
  5198.         if (!lastSearch.isPOI) {
  5199.             $(".hotelItem").each(function() {
  5200.                 $(this).find("ul.POIS>li").each(function() {
  5201.                     if ($(this).find("li.isCityCenter").text() == "Yes") latlongCenter = new google.maps.LatLng($(this).find("li.latitude").text(), $(this).find("li.longitude").text());
  5202.                 });
  5203.             });
  5204.         } else {
  5205.             $(".hotelItem").each(function() {
  5206.                 $(this).find("ul.POIS>li").each(function() {
  5207.                     if ($(this).attr("class") == "${destinoCode}") latlongCenter = new google.maps.LatLng($(this).find("li.latitude").text(), $(this).find("li.longitude").text());
  5208.                 });
  5209.             });
  5210.         }
  5211.         if (latlongCenter != "") {
  5212.             map.setCenter(latlongCenter);
  5213.         } else {
  5214.             if (markers.length > 0) {
  5215.                 if (markers.length == 2) map.setCenter(latlong); else {
  5216.                     var bounds = new google.maps.LatLngBounds();
  5217.                     for (var j = 1; j < markers.length; j++) {
  5218.                         if (markers[j] != null) bounds.extend(markers[j].getPosition());
  5219.                     }
  5220.                     map.fitBounds(bounds);
  5221.                 }
  5222.             }
  5223.         }
  5224.     };
  5225.     var recalcularZoom = function(mapa) {
  5226.         mapa = mapMob;
  5227.         var listener = google.maps.event.addListener(mapa, "idle", function() {
  5228.             var markersIn = false;
  5229.             while (!markersIn) {
  5230.                 markersIn = true;
  5231.                 for (var n = 1; n < markersMob.length; n++) {
  5232.                     if (markersMob[n] != null) {
  5233.                         var zoom = mapa.getZoom();
  5234.                         var latlongAux = markersMob[n].getPosition();
  5235.                         if (mapa.getBounds() != null && !mapa.getBounds().contains(latlongAux) && !mapa.getBounds().getNorthEast().equals(mapa.getBounds().getSouthWest())) {
  5236.                             markersIn = false;
  5237.                             mapa.setZoom(zoom - 1);
  5238.                         }
  5239.                     }
  5240.                 }
  5241.             }
  5242.             google.maps.event.removeListener(listener);
  5243.         });
  5244.     };
  5245.     return {
  5246.         init: init
  5247.     };
  5248. }();
  5249.  
  5250. var LandingSort = function() {
  5251.     var re_stars = /([1-9])/;
  5252.     var parent;
  5253.     var init = function() {
  5254.         $("#selectSortMob, #selectSort").on("change", function() {
  5255.             sortHotels(this, $(this).data("destinoCRS"));
  5256.         });
  5257.         $("#selectSort").on("change", function() {
  5258.             trackChangeOrder(page_section, $(this).val());
  5259.         });
  5260.     };
  5261.     var sortHotels = function(selected) {
  5262.         var selected_sortby = selected.value;
  5263.         var groups = [ "hotelesDispo", "hotelesNearby", "hotelesNoDispo" ];
  5264.         if (selected_sortby == "precioAsc" || selected_sortby == "precioDes") {
  5265.             groups = [ "hotelesDispo", "hotelesNearby" ];
  5266.         } else if (selected_sortby == "distCentroAsc" || selected_sortby == "distCentroDes") {
  5267.             var className = "empty";
  5268.             $(".hotelItem").each(function() {
  5269.                 if ($(this).find("li.isCityCenter").filter(":contains('Yes')").text() == "Yes") {
  5270.                     className = $(this).find("li.isCityCenter").filter(":contains('Yes')").parent().parent().attr("class");
  5271.                     return false;
  5272.                 }
  5273.             });
  5274.             if ($("#filtroPOI").val() != $("." + className).val()) {
  5275.                 $("#filtroPOI").val($("." + className).val());
  5276.                 $("#filtroPOI").change();
  5277.             }
  5278.         }
  5279.         $.each(groups, function(i, group) {
  5280.             doSortby(selected_sortby, group);
  5281.         });
  5282.         if ($("#selectSort").val() != selected.value) {
  5283.             $("#selectSort").val(selected.value);
  5284.             $("#selectSort").find('option[value="' + selected.value + '"]').change();
  5285.         }
  5286.         if ($("#selectSortMob").val() != selected.value) {
  5287.             $("#selectSortMob").val(selected.value);
  5288.             $("#selectSortMob").find('option[value="' + selected.value + '"]').change();
  5289.         }
  5290.         var visibleHotels = $(" .hotelItem").filter(function() {
  5291.             return $(this).css("Display") == "inline-block";
  5292.         });
  5293.         visibleHotels.each(function(index) {
  5294.             cambiarNumerodeHotel(index, $(this));
  5295.         });
  5296.         $("img.lazy").lazyload();
  5297.     };
  5298.     var doSortby = function(sortby, group) {
  5299.         var group_id = $("#" + group);
  5300.         if (pageData.isIpad) {
  5301.             updatePaginateResults();
  5302.         }
  5303.         var hotels_to_sort = $(group_id).find(".hotelItem").detach();
  5304.         hotels_to_sort = Array.prototype.slice.call(hotels_to_sort, 0);
  5305.         hotels_to_sort.sort(function(a, b) {
  5306.             var result = null;
  5307.             switch (sortby) {
  5308.               case "nhRec":
  5309.                 var e1 = parseInt($(".nhrec", a).text());
  5310.                 var e2 = parseInt($(".nhrec", b).text());
  5311.                 result = e1 > e2 ? 1 : -1;
  5312.                 break;
  5313.  
  5314.               case "precioAsc":
  5315.               case "precioDes":
  5316.                 var e1 = parseFloat($.trim($(".info-result-room", a).find(".priceChange").text()));
  5317.                 var e2 = parseFloat($.trim($(".info-result-room", b).find(".priceChange").text()));
  5318.                 if (sortby == "precioAsc") {
  5319.                     result = e1 > e2 ? 1 : -1;
  5320.                 } else if (sortby == "precioDes") {
  5321.                     result = e1 < e2 ? 1 : -1;
  5322.                 }
  5323.                 break;
  5324.  
  5325.               case "nombreAsc":
  5326.               case "nombreDes":
  5327.                 var e1 = $.trim($(a).find(".starsHotel .title a").text()).replace(/\n/g, "").replace(/ /g, "").replace(/\s/g, "");
  5328.                 var e2 = $.trim($(b).find(".starsHotel .title a").text()).replace(/\n/g, "").replace(/ /g, "").replace(/\s/g, "");
  5329.                 if (sortby == "nombreAsc") {
  5330.                     result = e1 > e2 ? 1 : -1;
  5331.                 } else if (sortby == "nombreDes") {
  5332.                     result = e1 < e2 ? 1 : -1;
  5333.                 }
  5334.                 break;
  5335.  
  5336.               case "distCentroAsc":
  5337.               case "distCentroDes":
  5338.               case "distPoiAsc":
  5339.               case "distPoiDes":
  5340.                 var e1 = parseFloat($.trim($(".nearFrom", a).text().split("km")[0]));
  5341.                 var e2 = parseFloat($.trim($(".nearFrom", b).text().split("km")[0]));
  5342.                 if (sortby == "distCentroAsc" || sortby == "distPoiAsc") {
  5343.                     result = e1 > e2 || isNaN(e1) ? 1 : -1;
  5344.                 } else if (sortby == "distCentroDes" || sortby == "distPoiDes") {
  5345.                     result = e1 < e2 || isNaN(e1) ? 1 : -1;
  5346.                 }
  5347.                 break;
  5348.  
  5349.               case "catAsc":
  5350.               case "catDes":
  5351.                 var str1 = $(".starsHotel .stars", a).attr("class");
  5352.                 var str2 = $(".starsHotel .stars", b).attr("class");
  5353.                 var e1 = parseInt(re_stars.exec(str1)[0]);
  5354.                 var e2 = parseInt(re_stars.exec(str2)[0]);
  5355.                 if (sortby == "catAsc") {
  5356.                     result = e1 > e2 ? 1 : -1;
  5357.                 } else if (sortby == "catDes") {
  5358.                     result = e1 < e2 ? 1 : -1;
  5359.                 }
  5360.                 break;
  5361.             }
  5362.             return result;
  5363.         });
  5364.         for (var i = 0, l = hotels_to_sort.length; i < l; i++) {
  5365.             group_id.append(hotels_to_sort[i]);
  5366.         }
  5367.         if (pageData.isIpad) {
  5368.             reorderResults();
  5369.         }
  5370.     };
  5371.     return {
  5372.         init: init,
  5373.         sortHotels: sortHotels
  5374.     };
  5375. }();
  5376.  
  5377. $(function() {
  5378.     if ($("body").hasClass("page-landing")) {}
  5379. });
  5380.  
  5381. var LandingPage = function() {
  5382.     var lazyHotels;
  5383.     var isNoAvailabilityPage = false;
  5384.     var isNoDatesPage = false;
  5385.     var groupResults = [];
  5386.     var analyticsLazyData = {};
  5387.     var urlNoPromo;
  5388.     var $sv;
  5389.     var init = function() {
  5390.         $sv = LandingServices;
  5391.         if (pageData.javaError == "true") {
  5392.             $("#error").fancybox().click();
  5393.         } else {
  5394.             groupResults["#hotelesDispo"] = 0;
  5395.             groupResults["#hotelesNoDispo"] = 0;
  5396.             groupResults["#hotelesNearby"] = 0;
  5397.             groupResults["#hotelesNearbyNoDispo"] = 0;
  5398.             groupResults["#hotelesDispoPromo"] = 0;
  5399.             groupResults["#hotelesNearbyPromo"] = 0;
  5400.             if (invalidDates()) {
  5401.                 noAvailabilityPageActions();
  5402.                 $sv.showErrorLighbox(pageData.tcmDatesError);
  5403.             } else {
  5404.                 $sv.getLastSearch(function(search) {
  5405.                     console.log("lastSearch:", search);
  5406.                     fillLastSearch();
  5407.                     callLazyAjax();
  5408.                     $sv.callTripAdvisorReviews();
  5409.                     $sv.callTrustYouReviews();
  5410.                     $sv.callLoading();
  5411.                 });
  5412.             }
  5413.         }
  5414.     };
  5415.     var fillLastSearch = function() {
  5416.         if (!$.isEmptyObject(lastSearch)) {
  5417.             if (lastSearch.fini && lastSearch.fout) {
  5418.                 var finiOutput = lastSearch.fini;
  5419.                 var foutOutput = lastSearch.fout;
  5420.                 if (typeof Dates != "undefined" && Dates.isChinese) {
  5421.                     var finiParsed = $.datepicker.parseDate(Dates.pattern, finiOutput);
  5422.                     var foutParsed = $.datepicker.parseDate(Dates.pattern, foutOutput);
  5423.                     finiOutput = $.datepicker.formatDate(Dates.patternCn, finiParsed);
  5424.                     foutOutput = $.datepicker.formatDate(Dates.patternCn, foutParsed);
  5425.                 }
  5426.                 $("#fechaIda").data("date", finiOutput);
  5427.                 $("#ida").val(finiOutput);
  5428.                 $("#idaAlt").val(lastSearch.fini);
  5429.                 $("#fechaFin").data("date", foutOutput);
  5430.                 $("#fin").val(foutOutput);
  5431.                 $("#finAlt").val(lastSearch.fout);
  5432.             } else {}
  5433.             var totalLblAdults = lastSearch.numTotalAdults == 1 ? pageLabels.lblAdult : pageLabels.lblAdults;
  5434.             var totalLblChildren = lastSearch.numTotalChildren == 1 ? pageLabels.lblChild : pageLabels.lblChildren;
  5435.             var totalLblBabies = lastSearch.numTotalBabies == 1 ? pageLabels.lblBaby : pageLabels.lblBabies;
  5436.             var roomsLblData = $(".js-info-nights [data-rooms]").data("rooms");
  5437.             if (roomsLblData) {
  5438.                 var totalLblRooms = roomsLblData.singular;
  5439.                 if (lastSearch.numRooms > 1) {
  5440.                     totalLblRooms = roomsLblData.plural.replace("{0}", lastSearch.numRooms);
  5441.                 }
  5442.                 $(".js-info-nights [data-rooms]").html(totalLblRooms);
  5443.             }
  5444.             if (lastSearch.numTotalAdults > 0) {
  5445.                 $(".js-occupancy-wrap").find("[data-id='optionRooms'] .filter-option").text(lastSearch.numTotalAdults + " " + totalLblAdults + ", " + lastSearch.numTotalChildren + " " + totalLblChildren + ", " + lastSearch.numTotalBabies + " " + totalLblBabies);
  5446.             }
  5447.             var $modal = $("#occupancy-modal");
  5448.             if (lastSearch.numRooms == 1) {
  5449.                 $modal.find('select.occupancy-select[name="nadults1"]').selectpicker("val", lastSearch.occupancy[0].adults);
  5450.                 $modal.find('select.occupancy-select[name="nchilds1"]').selectpicker("val", lastSearch.occupancy[0].children);
  5451.                 $modal.find('select.occupancy-select[name="nbabies1"]').selectpicker("val", lastSearch.occupancy[0].babies);
  5452.             } else {
  5453.                 $modal.find("#habs").selectpicker("val", lastSearch.numRooms);
  5454.                 $.each(lastSearch.occupancy, function(i, room) {
  5455.                     var n = i + 1;
  5456.                     $modal.find('select.occupancy-select[name="nadults' + n + '"]').selectpicker("val", room.adults);
  5457.                     $modal.find('select.occupancy-select[name="nchilds' + n + '"]').selectpicker("val", room.children);
  5458.                     $modal.find('select.occupancy-select[name="nbabies' + n + '"]').selectpicker("val", room.babies);
  5459.                 });
  5460.             }
  5461.             if (lastSearch.numNights == 1) {
  5462.                 $(".js-info-nights").hide();
  5463.             }
  5464.             $(".btn-search").removeClass("btn-primary").addClass("btn-default");
  5465.             if (lastSearch.voucherCode) {
  5466.                 var urlVoucher = $(".js-voucher-param").attr("href");
  5467.                 var newUrl = urlVoucher.replace(getURLParameter("voucherCode", urlVoucher), lastSearch.voucherCode);
  5468.                 $(".js-voucher-param").attr("href", newUrl);
  5469.                 $('input[name="voucherCode"]').val(lastSearch.voucherCode);
  5470.             }
  5471.             if (lastSearch.groupon) {
  5472.                 $(".js-groupon-hide").hide();
  5473.                 $(".js-groupon-show").show();
  5474.             } else {
  5475.                 $(".js-notgroupon-hide").hide();
  5476.                 $(".js-notgroupon-show").show();
  5477.             }
  5478.             pageData.filterStars = lastSearch.filterStars;
  5479.             pageData.filterServices = lastSearch.filterServices;
  5480.             loadResumeData();
  5481.             $("#locationCode").val(pageData.keySearch);
  5482.             $("#habs").on("change", function() {
  5483.                 loadResumeData();
  5484.             });
  5485.             $("#locationForm input").on("click", function() {
  5486.                 loadResumeData();
  5487.             });
  5488.         } else {
  5489.             console.log("lastSearch is empty!");
  5490.         }
  5491.         $(".btn-search").attr("disabled", false);
  5492.     };
  5493.     var loadResumeData = function() {
  5494.         var adultos = 0;
  5495.         var ninos = 0;
  5496.         var bebes = 0;
  5497.         var habitaciones = $("#habs").val();
  5498.         var pax = false;
  5499.         for (var i = 1; i <= habitaciones; i++) {
  5500.             var ad = $("[name=nadults" + i + "]").val();
  5501.             adultos = adultos + parseInt(ad);
  5502.             var ni = $("[name=nchilds" + i + "]").val();
  5503.             ninos = ninos + parseInt(ni);
  5504.             var be = $("[name=nbabies" + i + "]").val();
  5505.             bebes = bebes + parseInt(be);
  5506.         }
  5507.         $("#loc").html($("#location").val());
  5508.         $("#fel").html($("#ida").val());
  5509.         $("#fes").html($("#fin").val());
  5510.         $("#adu").html(adultos);
  5511.         $("#nin").html(ninos);
  5512.         $("#beb").html(bebes);
  5513.         $("#hab").html(habitaciones);
  5514.     };
  5515.     var callLazyAjax = function() {
  5516.         updateNumHotelsFiltered(true);
  5517.         if (LazyDataSend && !$.isEmptyObject(LazyDataSend.hotels) && pageData.destinoCode && JSON.stringify(LazyDataSend)) {
  5518.             $.ajax({
  5519.                 type: "POST",
  5520.                 url: "/rest/landing/avail/" + pageData.destinoCode,
  5521.                 headers: {
  5522.                     Accept: "application/json",
  5523.                     "Content-Type": "application/json"
  5524.                 },
  5525.                 data: JSON.stringify(LazyDataSend),
  5526.                 dataType: "json",
  5527.                 cache: false
  5528.             }).done(function(data) {
  5529.                 try {
  5530.                     if (!$.isEmptyObject(data)) {
  5531.                         console.log("Result Lazy Dispo:", data);
  5532.                         lazyHotels = data;
  5533.                         setLazyAjaxValues();
  5534.                     } else {
  5535.                         console.log("resturn Ajax: No Availability page");
  5536.                         noAvailabilityPageActions();
  5537.                     }
  5538.                 } catch (err) {
  5539.                     console.log("Ajax done but error: ", err);
  5540.                     $sv.showErrorLighbox(pageData.tcmInternalError);
  5541.                 }
  5542.             }).fail(function(data) {
  5543.                 try {
  5544.                     console.log("Fail call: ", data.status, data.responseText, typeof data.responseText);
  5545.                     var responseParsed = JSON.parse(data.responseText);
  5546.                     if (typeof responseParsed == "object" && responseParsed.message) {
  5547.                         $sv.showErrorLighbox(responseParsed.message);
  5548.                     } else {
  5549.                         $sv.showErrorLighbox(pageData.tcmInternalError);
  5550.                     }
  5551.                 } catch (err) {
  5552.                     console.log("Ajax fail but error on the code: ", err);
  5553.                     $sv.showErrorLighbox(pageData.tcmInternalError);
  5554.                 }
  5555.             });
  5556.         } else {
  5557.             if (!pageData.withDates) {
  5558.                 console.log("Landing without dates");
  5559.                 noDatesPageActions();
  5560.             } else {
  5561.                 console.log("Error: There is no hotels to send");
  5562.                 $sv.showErrorLighbox(pageData.tcmInternalError);
  5563.             }
  5564.         }
  5565.     };
  5566.     var setLazyAjaxValues = function() {
  5567.         if (lazyHotels) {
  5568.             var wrapView = $("#view-list");
  5569.             wrapDispo = wrapView.find("#hotelesDispo");
  5570.             wrapNearby = wrapView.find("#hotelesNearby");
  5571.             var groups = [ wrapDispo, wrapNearby ];
  5572.             if (lastSearch.isPromo) {
  5573.                 urlNoPromo = $sv.getNoPromoUrl();
  5574.             }
  5575.             $.each(groups, function(i, group) {
  5576.                 if (group.find(".hotelItem").length > 0) {
  5577.                     $.each(group.find(".hotelItem"), function(i, ele) {
  5578.                         setLazyHotelInfo(ele, group);
  5579.                     });
  5580.                 }
  5581.             });
  5582.             if (groupResults["#hotelesDispo"] == 0 && groupResults["#hotelesNearby"] == 0) {
  5583.                 isNoAvailabilityPage = true;
  5584.             }
  5585.             pageInitActions();
  5586.         }
  5587.     };
  5588.     var setLazyHotelInfo = function(ele, group) {
  5589.         var $ele = $(ele);
  5590.         var rec = $ele.find("[data-rec]").data("rec");
  5591.         var backcode = $ele.data("backcode");
  5592.         var hotelMarca = $ele.data("hotelMarca");
  5593.         var idGroup = "#" + group.attr("id");
  5594.         if (lazyHotels[backcode]) {
  5595.             var lazyHotelEle = lazyHotels[backcode];
  5596.             var mealRatePlanTitle = lazyHotelEle.mealRatePlanTitle;
  5597.             var roomCapacity = lazyHotelEle.roomCapacity;
  5598.             var roomTitle = lazyHotelEle.roomTitle;
  5599.             if (lazyHotelEle.price) {
  5600.                 var currency = lazyHotelEle.price.currency || "EUR";
  5601.                 actualDivisa = currency;
  5602.                 var totalPrice = lazyHotelEle.price.priceTotal;
  5603.                 var dayPrice = lazyHotelEle.price.pricePerDay;
  5604.             }
  5605.             $ele.find(".js-dayprice").html(dayPrice);
  5606.             $ele.find(".js-totalprice").html(totalPrice);
  5607.             $ele.find(".js-currency").html(currency);
  5608.             $ele.find(".js-meanplan-name").html(mealRatePlanTitle);
  5609.             $ele.find(".js-roomname").html(roomTitle);
  5610.             if (roomCapacity) {
  5611.                 var capacityData = $ele.find(".js-roomcapacity").data("capacity");
  5612.                 if (capacityData && capacityData.singular) {
  5613.                     var capacityLbl = roomCapacity == 1 ? capacityData.singular : capacityData.plural;
  5614.                     $ele.find(".js-roomcapacity").html(roomCapacity + " " + capacityLbl);
  5615.                 }
  5616.             } else {
  5617.                 $ele.find(".wrap-roomcapacity").hide();
  5618.             }
  5619.             var submitButton = $ele.find('.info-result-room form [type="submit"]');
  5620.             if (submitButton.length) {
  5621.                 submitButton.data("preciodia", dayPrice);
  5622.                 submitButton.data("preciototal", totalPrice);
  5623.                 submitButton.on("click", function() {
  5624.                     var $this = $(this);
  5625.                     reservarHotelRP($this.data("hotelcode"), $this.data("preciodia"), $this.data("num"));
  5626.                 });
  5627.                 submitButton.attr("disabled", false);
  5628.             }
  5629.             $ele.find(".btn-lazy").hide();
  5630.             $ele.find(".js-dispo-show").fadeIn();
  5631.             var linkTitle = $ele.find(".js-hotel-title");
  5632.             linkTitle.removeAttr("id").removeAttr("class");
  5633.             linkTitle.on("click", function(e) {
  5634.                 e.preventDefault();
  5635.                 $("#seeRooms" + rec).click();
  5636.             });
  5637.             if (MapsData[rec]) {
  5638.                 var mapElement = MapsData[rec];
  5639.                 var logoImage = mapElement.hotelLogo ? '<img class="logo-hotel" src="' + mapElement.hotelLogo + '" alt="' + mapElement.hotelMarca + '" />' : "";
  5640.                 var htmlRating = "";
  5641.                 var htmlStars = "";
  5642.                 if (mapElement.hotelStars) {
  5643.                     for (var i = 0; i < parseInt(mapElement.hotelStars); i++) {
  5644.                         htmlStars += '<span class="star"></span>';
  5645.                     }
  5646.                     var htmlRating = '<span class="rating">' + htmlStars + "</span>";
  5647.                 }
  5648.                 var htmlPrice = "";
  5649.                 if (dayPrice && dayPrice != totalPrice) {
  5650.                     htmlPrice += '<div class="clearfix night-price"><span class="pull-left">' + pageLabels.lblMapFrom + '</span><span class="pull-right"><span class="priceChange">' + dayPrice + '</span><sup class="currencyChange">' + currency + "</sup></span></div>";
  5651.                 }
  5652.                 if (totalPrice) {
  5653.                     htmlPrice += '<div class="total-price"><span class="pull-left">' + pageLabels.lblMapPriceTotal + '</span><span class="pull-right">' + totalPrice + "<sup>" + currency + "</sup></span></div>";
  5654.                 }
  5655.                 var htmlWindow = "";
  5656.                 if (mapElement.hotelLink && mapElement.hotelDescription && mapElement.hotelSubmitForm) {
  5657.                     htmlWindow = '<div class="infoSite new-pin clearfix"><div class="img-info-hotel pull-left">' + mapElement.hotelImage + '</div><div class="pull-left info-hotel-detail">' + logoImage + '<p class="name-hotel">' + mapElement.hotelLink + "</p>" + htmlRating + "" + htmlPrice + '<div class="">' + mapElement.hotelSubmitForm + "</div></div></div>";
  5658.                 }
  5659.                 mapElement.clase = "disp";
  5660.                 mapElement.info = htmlWindow;
  5661.                 mapElement.icon = typeof iconHotelPath[mapElement.iconKey] != "undefined" ? iconHotelPath[mapElement.iconKey] : mapElement.icon;
  5662.             }
  5663.             var isHotelPromo = lazyHotelEle.promo ? true : false;
  5664.             if (isHotelPromo) {
  5665.                 var eleDetached = $ele.detach();
  5666.                 $(idGroup + "Promo").find(".js-ajax-results").append(eleDetached);
  5667.                 if (typeof groupResults[idGroup + "Promo"] != "undefined") {
  5668.                     groupResults[idGroup + "Promo"] = groupResults[idGroup + "Promo"] + 1;
  5669.                 }
  5670.                 if ($(idGroup + "Promo").is(":hidden")) {
  5671.                     $(idGroup + "Promo").show();
  5672.                 }
  5673.             } else {
  5674.                 if (typeof groupResults[idGroup] != "undefined") {
  5675.                     groupResults[idGroup] = groupResults[idGroup] + 1;
  5676.                     if (lastSearch.isPromo && urlNoPromo) {
  5677.                         $ele.find("[data-preciototal]").parents("form").attr("action", urlNoPromo);
  5678.                     }
  5679.                 }
  5680.             }
  5681.         } else {
  5682.             setNoAvailabilityHotel(ele, group);
  5683.         }
  5684.     };
  5685.     var noDatesPageActions = function() {
  5686.         isNoDatesPage = true;
  5687.         pageInitActions();
  5688.     };
  5689.     var noAvailabilityPageActions = function() {
  5690.         LandingPage.isNoAvailabilityPage = true;
  5691.         var wrapView = $("#view-list");
  5692.         wrapDispo = wrapView.find("#hotelesDispo");
  5693.         wrapNearby = wrapView.find("#hotelesNearby");
  5694.         var lazyGroups = [ wrapDispo, wrapNearby ];
  5695.         $.each(lazyGroups, function(i, group) {
  5696.             if ($(group).find(".hotelItem").length > 0) {
  5697.                 $.each($(group).find(".hotelItem"), function(i, ele) {
  5698.                     setNoAvailabilityHotel(ele, group);
  5699.                 });
  5700.             }
  5701.         });
  5702.         $('#selectSort option[value="precioAsc"]').remove();
  5703.         $('#selectSort option[value="precioDes"]').remove();
  5704.         $("#selectSort").selectpicker("refresh");
  5705.         $(".filters .prices").hide();
  5706.         pageInitActions();
  5707.     };
  5708.     var setNoAvailabilityHotel = function(hotel, group) {
  5709.         var $hotel = $(hotel);
  5710.         $hotel.find(".btn-lazy").hide();
  5711.         $hotel.find(".js-nodispo-show").fadeIn();
  5712.         if (!$hotel.data("virtual")) {
  5713.             var eleDetached = $hotel.detach();
  5714.             var noDispoContent = $(group).data("nodispo");
  5715.             $(noDispoContent).find(".js-ajax-results").append(eleDetached);
  5716.             if (typeof groupResults[noDispoContent] != "undefined") {
  5717.                 groupResults[noDispoContent] = groupResults[noDispoContent] + 1;
  5718.             }
  5719.         }
  5720.     };
  5721.     var setLazyAnalyticsData = function() {
  5722.         if (typeof utag_data != "undefined") {
  5723.             $.each($("#view-list .hotelItem"), function(i, hotel) {
  5724.                 var $hotel = $(hotel);
  5725.                 var availInfo = $hotel.parents('.wrap-hotels[id$="NoDispo"]').length ? "-no available" : "-available";
  5726.                 utag_data.products_id.push($hotel.data("backcode"));
  5727.                 utag_data.products_list.push("search results");
  5728.                 utag_data.products_position.push(i + 1);
  5729.                 var firstBusqListado = utag_data.busqListado ? "," : "";
  5730.                 utag_data.busqListado += firstBusqListado + "" + ($hotel.data("backcode") + "" + availInfo);
  5731.                 utag_data.busqNumResult = pageData.totalHotels;
  5732.                 utag_data.busqHSinDispo = parseInt(groupResults["#hotelesNoDispo"]) == 0 ? "" : groupResults["#hotelesNoDispo"].toString();
  5733.                 utag_data.busqSinDispo = LandingPage.isNoAvailabilityPage ? "No availability" : "";
  5734.                 var firstHotelsList = utag_data.search.hotelsList ? "," : "";
  5735.                 utag_data.search.hotelsList += firstHotelsList + "" + ($hotel.data("backcode") + "" + availInfo);
  5736.                 utag_data.search.results = pageData.totalHotels;
  5737.                 utag_data.search.hWithoutAvailability = parseInt(groupResults["#hotelesNoDispo"]) == 0 ? "" : groupResults["#hotelesNoDispo"].toString();
  5738.                 utag_data.search.withoutAvailability = LandingPage.isNoAvailabilityPage ? "No availability" : "";
  5739.                 if ($hotel.find("[data-preciodia]").length > 0) {
  5740.                     var precioDia = $hotel.find("[data-preciodia]").data("preciodia");
  5741.                     if (parseFloat(precioDia)) {
  5742.                         utag_data.products_price.push(parseFloat(precioDia).toFixed(2));
  5743.                     } else {
  5744.                         utag_data.products_price.push("no-avail");
  5745.                     }
  5746.                 }
  5747.             });
  5748.             sendUtagData();
  5749.             return true;
  5750.         } else {
  5751.             return false;
  5752.         }
  5753.     };
  5754.     var pageInitActions = function() {
  5755.         $("a#modificar").fancybox({
  5756.             hideOnContentClick: true
  5757.         });
  5758.         if (lastSearch.isPromo) {
  5759.             $(".show-promo").show();
  5760.             $(".hide-promo").hide();
  5761.             $(".wrap-hotels.hide-promo").remove();
  5762.         }
  5763.         if (pageData.isIpad) {
  5764.             reorderResults();
  5765.         }
  5766.         if (lastSearch.voucherCode && lastSearch.voucherCode != "null") {
  5767.             $("#promotional").click();
  5768.         }
  5769.         if (pageData.withDates) {
  5770.             LandingFilters.init();
  5771.             LandingSort.init();
  5772.         }
  5773.         Currency.init();
  5774.         LandingMap.init();
  5775.         setLazyAnalyticsData();
  5776.     };
  5777.     var userLoggedActions = function() {
  5778.         var userData = getUserLoggedData();
  5779.         if (userData) {
  5780.             if (userData.userName != "anonymous") {
  5781.                 $(".NHSign").text("");
  5782.                 $(".NHSign").attr("class", "");
  5783.                 if (userData["username"] != "anonymous" && userData["authorities"].length > 0 && userData["authorities"][0]["authority"] != "anonymous" && userData["authorities"][0]["authority"] != "DISAMBIGUATION") {
  5784.                     showLoggedMenu(userData);
  5785.                 }
  5786.             }
  5787.         }
  5788.     };
  5789.     var invalidDates = function() {
  5790.         var invalid = false;
  5791.         if ($sv.getURLParameter("fini") && $sv.getURLParameter("fout")) {
  5792.             var currentDate = new Date();
  5793.             var currentDateFormat = $.datepicker.formatDate("dd/mm/yy", currentDate);
  5794.             try {
  5795.                 var dateFin = $.datepicker.parseDate(Dates.currentPattern, $sv.getURLParameter("fout"));
  5796.                 var dateIni = $.datepicker.parseDate(Dates.currentPattern, $sv.getURLParameter("fini"));
  5797.                 var diffDays = Math.floor((dateFin - dateIni) / 1e3 / 60 / 60 / 24);
  5798.                 invalid = diffDays == 0 || diffDays < 0 || diffDays > 15 || dateFin < dateIni || currentDateFormat != $sv.getURLParameter("fini") && currentDate > dateIni;
  5799.             } catch (errorDate) {
  5800.                 console.log(errorDate);
  5801.                 invalid = true;
  5802.             }
  5803.         }
  5804.         return invalid;
  5805.     };
  5806.     return {
  5807.         init: init,
  5808.         isNoAvailabilityPage: isNoAvailabilityPage
  5809.     };
  5810. }();
  5811.  
  5812. var LandingServices = function() {
  5813.     var getNoPromoUrl = function() {
  5814.         var pcodeParam = window.location.search.match(/pcode\=([0-9]+)/i);
  5815.         var current = window.location.href;
  5816.         return pcodeParam ? current.replace(pcodeParam[0], "") : null;
  5817.     };
  5818.     var callLoading = function() {
  5819.         $(".js-call-loading").click(function() {
  5820.             $("#loadingModal").modal({
  5821.                 show: true,
  5822.                 backdrop: "static",
  5823.                 keyboard: false
  5824.             });
  5825.         });
  5826.     };
  5827.     var getLastSearch = function(fn) {
  5828.         var extendLastSearch = {
  5829.             voucherCode: getURLParameter("voucherCode"),
  5830.             selectedDivisa: getURLParameter("divisa"),
  5831.             groupon: getURLParameter("gvoucher") == "false" ? false : true,
  5832.             isPOI: getURLParameter("poiId"),
  5833.             pcode: getURLParameter("pcode"),
  5834.             b2b: getURLParameter("b2b"),
  5835.             b2bData: null,
  5836.             contracts: [ "NHWEB" ],
  5837.             rates: null,
  5838.             searchLandingExpress: null,
  5839.             isB2EEmployee: null,
  5840.             isB2EFamily: null,
  5841.             filterStars: null,
  5842.             filterServices: null,
  5843.             isPromo: false
  5844.         };
  5845.         $.extend(lastSearch, extendLastSearch);
  5846.         selectedDivisa = lastSearch.selectedDivisa ? lastSearch.selectedDivisa : "";
  5847.         if (lastSearch.b2b) {
  5848.             var b2bObj = {
  5849.                 branch: getURLParameter("b2bData.branch"),
  5850.                 branchId: getURLParameter("b2bData.branchId"),
  5851.                 company: getURLParameter("b2bData.company"),
  5852.                 customer: getURLParameter("b2bData.customer"),
  5853.                 partyIdCompany: getURLParameter("b2bData.partyIdCompany"),
  5854.                 partyIdCustomer: getURLParameter("b2bData.partyIdCustomer"),
  5855.                 bpc: getURLParameter("b2bData.bpc"),
  5856.                 favouriteHotels: getURLParameter("b2bData.favouriteHotels"),
  5857.                 frequentHotels: getURLParameter("b2bData.frequentHotels"),
  5858.                 username: getURLParameter("b2bData.username"),
  5859.                 ccgType: getURLParameter("b2bData.ccgType"),
  5860.                 type: getURLParameter("b2bData.type")
  5861.             };
  5862.             lastSearch.b2BData = b2bObj || null;
  5863.         }
  5864.         var backingBeanUrl = "/booking/ajax/landing/getFlowInformation.html";
  5865.         $.ajax({
  5866.             type: "GET",
  5867.             url: backingBeanUrl,
  5868.             headers: {
  5869.                 Accept: "application/json",
  5870.                 "Content-Type": "application/json"
  5871.             },
  5872.             dataType: "json",
  5873.             cache: false,
  5874.             async: false
  5875.         }).done(function(data) {
  5876.             if (typeof data != "undefined" && data) {
  5877.                 if (data.displayBean) {
  5878.                     var displayBean = data.displayBean;
  5879.                     if (!$.isEmptyObject(displayBean.contracts)) {
  5880.                         lastSearch.contracts = [];
  5881.                         $.each(displayBean.contracts, function(i, contract) {
  5882.                             lastSearch.contracts.push(contract);
  5883.                         });
  5884.                     }
  5885.                     if (displayBean.isSearchLandingExpress != "") {
  5886.                         lastSearch.searchLandingExpress = displayBean.isSearchLandingExpress;
  5887.                     }
  5888.                     if (displayBean.isB2EEmployee != "") {
  5889.                         lastSearch.isB2EEmployee = $.parseJSON(displayBean.isB2EEmployee);
  5890.                     }
  5891.                     if (displayBean.isB2EFamily != "") {
  5892.                         lastSearch.isB2EFamily = $.parseJSON(displayBean.isB2EFamily);
  5893.                     }
  5894.                 }
  5895.                 if (data.backingBean) {
  5896.                     var backingBean = data.backingBean;
  5897.                     if (!$.isEmptyObject(backingBean.ratePlansPromo)) {
  5898.                         lastSearch.rates = [];
  5899.                         $.each(backingBean.ratePlansPromo, function(i, rate) {
  5900.                             lastSearch.rates.push(rate);
  5901.                         });
  5902.                     }
  5903.                 }
  5904.             }
  5905.         }).fail(function(data) {
  5906.             console.log("Fail call getFlowInformation: ", data.status, data.responseText);
  5907.         });
  5908.         LazyDataSend.fini = lastSearch.fini || null;
  5909.         LazyDataSend.fout = lastSearch.fout || null;
  5910.         LazyDataSend.voucherCode = lastSearch.voucherCode || null;
  5911.         LazyDataSend.pCode = lastSearch.pcode || null;
  5912.         LazyDataSend.b2b = lastSearch.b2b || null;
  5913.         LazyDataSend.roomRequest = [];
  5914.         LazyDataSend.b2BData = lastSearch.b2BData || null;
  5915.         LazyDataSend.destinationtype = "destination";
  5916.         LazyDataSend.contracts = lastSearch.contracts;
  5917.         LazyDataSend.rates = lastSearch.rates;
  5918.         LazyDataSend.searchLandingExpress = lastSearch.searchLandingExpress;
  5919.         LazyDataSend.b2eEmployee = lastSearch.isB2EEmployee || null;
  5920.         LazyDataSend.b2eFriends = lastSearch.isB2EFamily || null;
  5921.         lastSearch.isPromo = lastSearch.pcode ? true : false;
  5922.         if (!$.isEmptyObject(lastSearch.occupancy)) {
  5923.             lastSearch.numTotalAdults = 0;
  5924.             lastSearch.numTotalChildren = 0;
  5925.             lastSearch.numTotalBabies = 0;
  5926.             $.each(lastSearch.occupancy, function(i, room) {
  5927.                 var lazyRoomItem = {
  5928.                     numberOfAdults: room.adults,
  5929.                     numberOfChildren: room.children,
  5930.                     numberOfBabies: room.babies
  5931.                 };
  5932.                 LazyDataSend.roomRequest.push(lazyRoomItem);
  5933.                 lastSearch.numTotalAdults += parseInt(room.adults);
  5934.                 lastSearch.numTotalChildren += parseInt(room.children);
  5935.                 lastSearch.numTotalBabies += parseInt(room.babies);
  5936.             });
  5937.         }
  5938.         if (typeof fn != "undefined") {
  5939.             fn(lastSearch);
  5940.         }
  5941.     };
  5942.     var showErrorLighbox = function(tcmError) {
  5943.         var lightboxError = "#error";
  5944.         if (tcmError) {
  5945.             utag_data.page.errorType = tcmError;
  5946.             var url = $(lightboxError).attr("href");
  5947.             if (getURLParameter("tcmError", url)) {
  5948.                 var newUrl = url.replace(getURLParameter("tcmError", url), tcmError);
  5949.                 $(lightboxError).attr("href", newUrl);
  5950.             } else {
  5951.                 $(lightboxError).attr("href", url + "&tcmError=" + tcmError);
  5952.             }
  5953.         }
  5954.         $(".wrap-hotels").hide();
  5955.         $(lightboxError).fancybox({
  5956.             closeClick: false,
  5957.             hideOnOverlayClick: false,
  5958.             hideOnContentClick: false,
  5959.             helpers: {
  5960.                 overlay: {
  5961.                     closeClick: false
  5962.                 }
  5963.             }
  5964.         }).trigger("click");
  5965.         $(document).on("click", ".fancybox-item.fancybox-close", function(event) {
  5966.             event.preventDefault();
  5967.             parent.window.location.href = "/";
  5968.         });
  5969.     };
  5970.     var getURLParameter = function(name, url) {
  5971.         var urlT = url ? url : window.location.href;
  5972.         name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
  5973.         var regexS = "[\\?&]" + name + "=([^&#]*)";
  5974.         var regex = new RegExp(regexS);
  5975.         var results = regex.exec(urlT);
  5976.         if (results == null) {
  5977.             return null;
  5978.         } else {
  5979.             return decodeURIComponent(results[1].replace(/\+/g, " "));
  5980.         }
  5981.     };
  5982.     var getDiffDays = function(date1, date2) {
  5983.         date1 = new Date(date1.split("/")[2], date1.split("/")[1] - 1, date1.split("/")[0]);
  5984.         date2 = new Date(date2.split("/")[2], date2.split("/")[1] - 1, date2.split("/")[0]);
  5985.         var timeDiff = Math.abs(date1.getTime() - date2.getTime());
  5986.         var diffDays = Math.ceil(timeDiff / (1e3 * 3600 * 24));
  5987.         return diffDays;
  5988.     };
  5989.     var callTripAdvisorReviews = function() {
  5990.         var widget = $(".js-widget-reviews.js-type-tripadvisor");
  5991.         $.each(widget, function(i, widget) {
  5992.             var $widget = $(widget);
  5993.             var idTrip = $widget.data("id");
  5994.             var idHotel = $widget.data("hotel");
  5995.             var certificate = $widget.data("certificate");
  5996.             var device = $widget.data("device");
  5997.             var html;
  5998.             var idioma = typeof widgetReviewsData.idioma != "undefined" ? widgetReviewsData.idioma : langTrip;
  5999.             var lblOpinions = typeof widgetReviewsData.lblOpinions != "undefined" ? widgetReviewsData.lblOpinions : "";
  6000.             var lblCertificateExcellence = typeof widgetReviewsData.lblCertificateExcellence != "undefined" ? widgetReviewsData.lblCertificateExcellence : "";
  6001.             if (typeof idTrip != "undefined" && idTrip != "") {
  6002.                 var url = "/rest/trip/tripadvisorhotelrate/" + idTrip;
  6003.                 $.ajax({
  6004.                     cache: true,
  6005.                     async: true,
  6006.                     url: url,
  6007.                     dataType: "json",
  6008.                     success: function(data) {
  6009.                         if (data != "null") {
  6010.                             var htmlCertificate = '<span class="certificate pull-right">' + lblCertificateExcellence + "</span>";
  6011.                             if (device == "mobile") {
  6012.                                 html = '<div class="hidden-lg hidden-md"><div class="clearfix2"></div><div class="tripadvisor-rating"><div class=""><span class=""></span><span class="qty-rating">' + data.rate + '</span><span><img src="' + data.ratingImageLink + '" /></span></div><a href="https://www.tripadvisor.com/WidgetEmbed-cdspropertydetail?locationId=' + idTrip + "&amp;lang=" + idioma + '&amp;partnerId=674E62BCD5A549E3AA92015CAB228207&amp;isTA=&amp;format=html&amp;display=true" class="qty-opiniones pull-left">' + data.numComents + " " + lblOpinions + "</a>" + (certificate ? htmlCertificate : "") + "</div></div>";
  6013.                             } else {
  6014.                                 html = '<div class="col-sm-4 visible-lg visible-md addMarginTop15"><div class="tripadvisor-rating pull-right"><div class="text-right"><span class=""></span><span class="qty-rating">' + data.rate + '</span><span><img src="' + data.ratingImageLink + '" /></span></div><a href="https://www.tripadvisor.com/WidgetEmbed-cdspropertydetail?locationId=' + idTrip + "&amp;lang=" + idioma + '&amp;partnerId=674E62BCD5A549E3AA92015CAB228207&amp;isTA=&amp;format=html&amp;display=true" class="fancybox fancybox.iframe qty-opiniones text-right">' + data.numComents + " " + lblOpinions + "</a>" + (certificate ? htmlCertificate : "") + "</div></div>";
  6015.                             }
  6016.                             $widget.html(html);
  6017.                         } else {
  6018.                             $widget.hide();
  6019.                         }
  6020.                     }
  6021.                 });
  6022.             } else {
  6023.                 $widget.hide();
  6024.             }
  6025.         });
  6026.     };
  6027.     var callTrustYouReviews = function(hotelBackCode, device) {
  6028.         var widget = $(".js-widget-reviews.js-type-trustyou");
  6029.         $.each(widget, function(i, widget) {
  6030.             var $widget = $(widget);
  6031.             var idTrust = $widget.data("id");
  6032.             var device = $widget.data("device");
  6033.             var html;
  6034.             var idioma = typeof widgetReviewsData.idioma != "undefined" ? widgetReviewsData.idioma : langTrip;
  6035.             var lblReviews = typeof widgetReviewsData.lblReviews != "undefined" ? widgetReviewsData.lblReviews : "";
  6036.             if (typeof idTrust != "undefined" && idTrust != "") {
  6037.                 var url = "/trustYou/seal";
  6038.                 $.ajax({
  6039.                     cache: true,
  6040.                     async: true,
  6041.                     url: url,
  6042.                     dataType: "json",
  6043.                     success: function(data) {
  6044.                         if (data != "null") {
  6045.                             var score = data.score;
  6046.                             var scoreDes = data.scoreDes;
  6047.                             var numReviews = data.numReviews;
  6048.                             if (device == "mobile") {
  6049.                                 html = '<div class="hidden-lg hidden-md"><div class="summary-header relative"><div class="trustscore2"><div class="value">' + score + '</div><div class="badges-opi"></div><div class="score-opi">' + scoreDes + '</div><div class="trust-opi">' + numReviews + " " + lblReviews + "</div></div></div></div>";
  6050.                             } else {
  6051.                                 html = '<div class="col-sm-4 visible-lg visible-md addMarginTop15"><div class="summary-header relative"><div class="trustscore2"><div class="value">' + score + '</div><div class="badges-opi"></div><div class="score-opi">' + scoreDes + '</div><div class="trust-opi">' + numReviews + " " + lblReviews + "</div></div></div></div>";
  6052.                             }
  6053.                             $widget.html(html);
  6054.                         } else {
  6055.                             $widget.hide();
  6056.                         }
  6057.                     }
  6058.                 });
  6059.             } else {
  6060.                 $widget.hide();
  6061.             }
  6062.         });
  6063.         return false;
  6064.     };
  6065.     return {
  6066.         getDiffDays: getDiffDays,
  6067.         showErrorLighbox: showErrorLighbox,
  6068.         getURLParameter: getURLParameter,
  6069.         callTrustYouReviews: callTrustYouReviews,
  6070.         callTripAdvisorReviews: callTripAdvisorReviews,
  6071.         getLastSearch: getLastSearch,
  6072.         callLoading: callLoading,
  6073.         getNoPromoUrl: getNoPromoUrl
  6074.     };
  6075. }();
  6076.  
  6077. $(function() {
  6078.     if ($("body").hasClass("page-landing")) {
  6079.         LandingPage.init();
  6080.     }
  6081.     if (!pageData.withDates) {
  6082.         LandingFilters.init();
  6083.         LandingSort.init();
  6084.     }
  6085. });
Add Comment
Please, Sign In to add comment