if (typeof dominioMelia === 'undefined' || dominioMelia === null) {
dominioMelia = "";
}
if (typeof dominioPortal === 'undefined' || dominioPortal === null) {
dominioPortal = "www1.melia.com";
}
var sTipoBusquedaHotels = "hotels";
var sTipoBusquedaDestinations = "destinations";
var sTipoBusquedaGeolocation = "geolocation";
var filtroMarca = "";
var nombreDestinoWCM = "";
var isMobile = (/android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(navigator.userAgent.toLowerCase()));
var urlDestinations = "/booking/zone/C_Zone.jsp";
var urlHotels = "/booking/rates/C_Rates.jsp";
var urlFlexDates = "/booking/flexdates/C_FlexDates.jsp";
var monedaConsulta = 'EUR';
var numberOfAdults = 8;
var numberOfChildren = 4;
var ageChildren = 17;
var maxPax = 4;
var sNombreCookie1 = "lastSearchJSON1";
var sNombreCookie2 = "lastSearchJSON2";
var sNombreCookie3 = "lastSearchJSON3";
var search1, search2, search3 = "";
var cookieDesencriptada1, cookieDesencriptada2, cookieDesencriptada3 = "";
var IDHotel = "";
var parentDestination;
var finalDestination;
var destinoId;
var latitud, longitud;
var unavailableDays = [];
var unavailableCheckIn = [];
var unavailableCheckOut = [];
var formatoDateCookie = "dd-mm-yy";
var categorySearch = "";
var keyName = "";
var mbe = new MBE("es");
$("document").ready(function(){
checkCookie();
translationDestinations();
addGeolocationOption();
//Calendario
mbe.calendar.draw();
//Ocupacion
mbe.rooms.setMaxRooms(5);
mbe.rooms.setMaxAdults(numberOfAdults);
mbe.rooms.setMaxChildren(numberOfChildren);
mbe.rooms.setMaxChildAge(ageChildren);
mbe.rooms.draw();
});
/***************************************************** BUSCADOR *************************************************/
function checkCookie() {
// vacio si no la encuentra
search1 = getCookie(sNombreCookie1);
// vacio si no la encuentra
search2 = getCookie(sNombreCookie2);
// vacio si no la encuentra
search3 = getCookie(sNombreCookie3);
if (search1 == "") {
setCookie(sNombreCookie1, '', 365);
} else {
cookieDesencriptada1 = decript(search1);
}
if (search2 == "") {
setCookie(sNombreCookie2, '', 365);
} else {
cookieDesencriptada2 = decript(search2);
}
if (search3 == "") {
setCookie(sNombreCookie3, '', 365);
} else {
cookieDesencriptada3 = decript(search3);
}
}
function translationDestinations() {
// Añadimos las últimas búsquedas encontradas
if (search1 !== "") {
addLastSearch(search1, cookieDesencriptada1, 'cookieAux1');
}
if (search2 !== "") {
addLastSearch(search2, cookieDesencriptada2, 'cookieAux2');
}
if (search3 !== "") {
addLastSearch(search3, cookieDesencriptada3, 'cookieAux3');
}
if ($('#lastSearchesMBE ul li').length > 0) $("#lastSearchesMBE ul").prepend('
'+mbe.txt.lastSearches+'');
}
function addLastSearch(cookie, cookieDesencriptada, idCookie) {
try {
var todayDate = new Date();
todayDate.setHours(0,0,0,0);
var objBusqueda = null;
objBusqueda = JSON.parse(cookieDesencriptada);
var fechaHoy = new Date();
var checkinDate = (objBusqueda.flexDates) ? new Date(objBusqueda.anio, objBusqueda.mes, fechaHoy.getDate()) : new Date(objBusqueda.anio, objBusqueda.mes, objBusqueda.dia);
if (objBusqueda !== null && checkinDate >= todayDate) {
var tipo = objBusqueda.categorySearch;
var descCabecera = objBusqueda.tituloDestino;
var descBuscador = objBusqueda.tituloDestino;
$("#lastSearchesMBE ul").append('');
if (tipo === sTipoBusquedaHotels) {
var objAutoCompletado = document.getElementById(idCookie);
if (typeof objAutoCompletado !== 'undefined' && objAutoCompletado != null) {
objAutoCompletado.innerHTML = '' + descCabecera;
objAutoCompletado.setAttribute('data-value', descBuscador);
$("#"+idCookie).on('click touchend', function(e) {
e.preventDefault();e.stopPropagation();
loadSearchData(tipo, objBusqueda);
});
}
} else if (tipo === sTipoBusquedaDestinations) {
var objAutoCompletado = document.getElementById(idCookie);
if (typeof objAutoCompletado !== 'undefined' && objAutoCompletado != null) {
objAutoCompletado.innerHTML = '' + descCabecera;
objAutoCompletado.setAttribute('data-value', descBuscador);
$("#"+idCookie).on('click touchend', function(e) {
e.preventDefault();e.stopPropagation();
loadSearchData(tipo, objBusqueda);
});
destinoId = objBusqueda.destinoId;
}
} else if (tipo === sTipoBusquedaGeolocation) {
var objAutoCompletado = document.getElementById(idCookie);
if (typeof objAutoCompletado !== 'undefined' && objAutoCompletado != null) {
objAutoCompletado.innerHTML = '' + descCabecera;
objAutoCompletado.setAttribute('data-value', descBuscador);
objAutoCompletado.setAttribute('latitud', objBusqueda.latitud);
objAutoCompletado.setAttribute('longitud', objBusqueda.longitud);
objAutoCompletado.setAttribute('destinoGeolocalizado',objBusqueda.tituloDestino);
$("#"+idCookie).on('click touchend', function(e) {
e.preventDefault();e.stopPropagation();
loadSearchData(tipo, objBusqueda);
});
}
}
}
} catch(err) {
console.log(err);
}
}
function addGeolocationOption() {
if (isMobile) {
$("#lastSearchesMBE ul").append(''+mbe.txt.geoLoc+'');
$("#geolocOption").on('click touchend', function(event) {
event.preventDefault();event.stopPropagation();
getGeolocation();
$("#autocompleteResults").hide();
});
}
}
function getGeolocation() {
var options = {
enableHighAccuracy : true,
timeout : 5000,
maximumAge : 0
};
// Try W3C Geolocation (Preferred)
if (navigator.geolocation) {
loading("on");
navigator.geolocation.getCurrentPosition(handleGeolocation, handleGeolocationError, options);
} else {
mostrarMensaje(mbe.txt.error['geolocNotAv'], 'error');
}
}
function handleGeolocation(pos) {
var crd = pos.coords;
coordinates = crd;
try {
lat = crd.latitude;
lng = crd.longitude;
bUbicado = true;
var objGeocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(lat, lng);
objGeocoder.geocode(
{'latLng' : latlng},
function(results, status) {
if (status === google.maps.GeocoderStatus.OK) {
var result = results[0];
if (result) {
// look for locality tag and country
var city = "";
var country = "";
var ac = "";
var iNumPartesResultado = result.address_components.length;
for ( var i = 0; i < iNumPartesResultado; i++) {
ac = result.address_components[i];
if (ac.types.indexOf("locality") >= 0) {
city = ac.long_name;
}
if (ac.types.indexOf("country") >= 0) {
country = ac.long_name;
}
}
updatePosition(city, country);
actualizaLiteralDestinoGeoLoc();
} else {
mostrarMensaje(mbe.txt.error['geolocNotRes'], 'error');
}
} else {
mostrarMensaje(mbe.txt.error['geolocGen'] + ' ' + status, 'error');
}
loading("off");
});
} catch (e) {
loading("off");
mostrarMensaje(mbe.txt.error['geolocGen'] + ' ' + e.message, 'error');
}
}
function handleGeolocationError(e) {
mostrarMensaje(mbe.txt.error['geolocGen'] + ' ' + e.message, 'error');
loading("off");
}
function updatePosition(city, country) {
if (city !== '' || country !== '') {
var objLocation = $('#geolocOption');
if (objLocation !== null && objLocation !== undefined) {
if (city !== '') {
objLocation.attr('data-value', city);
objLocation.attr("destinoGeolocalizado", city);
destinoGeolocalizado = city;
} else if (country !== '') {
objLocation.attr('data-value', country);
objLocation.attr("destinoGeolocalizado", country);
}else {
objLocation.attr('data-value', "Ubicación");
objLocation.attr("destinoGeolocalizado", "Ubicación");
}
objLocation.attr("latitud", lat);
objLocation.attr("longitud", lng);
}
}
}
function actualizaLiteralDestinoGeoLoc() {
var latitud = $('#geolocOption').attr("latitud");
var longitud = $('#geolocOption').attr("longitud");
var destino = $('#geolocOption').attr("destinoGeolocalizado");
if (destino != undefined) {
var objCoordenadas = new Object();
objCoordenadas.latitud = latitud;
objCoordenadas.longitud = longitud;
updateSearchConditions('geolocation', objCoordenadas, destino,'');
$("#destination").val(destino);
} else {
getGeolocation();
}
}
function buscarDisponibilidad() {
loading('on');
if (!validarFormulario()) {
loading('off');
return false;
}
sendAvailabilityForm(categorySearch);
}
function sendAvailabilityForm(categorySearch) {
var fechaRegistroCookie = new Date().toISOString();
if (typeof (parentDestination) === 'undefined' || parentDestination === "") {
parentDestination = getDestinationParent(citiesAndHotels, finalDestination);
}
var destino = $('#destination').val();
var sIdHoteles = destinationsHotelsID.toString();
var listaHoteles = '';
var formStr = '';
var urlStr = '';
var tipoBusqueda = '';
switch (categorySearch) {
case "destinations":
formStr += '';
cookieJSON.codigoPromocion = '';
var form = $(formStr);
cookieJSON.url = urlStr;
if (!busquedaRepetida(cookieJSON)) {
var sCookieJSON = JSON.stringify(cookieJSON);
var cookieEncriptada = encript(sCookieJSON);
insertCookieJSON(cookieEncriptada);
}
$('body').append(form);
form.submit();
}
function busquedaRepetida(cookieSearch) {
return checkBusquedaRepetida(cookieSearch, cookieDesencriptada1) || checkBusquedaRepetida(cookieSearch, cookieDesencriptada2) || checkBusquedaRepetida(cookieSearch, cookieDesencriptada3);
}
function checkBusquedaRepetida(cookieSearch, cookie) {
if (cookie != undefined && cookie != "") {
try {
var sCookie = JSON.parse(cookie);
return cookieSearch.url == sCookie.url;
} catch (e) {
return false;
}
} else return false;
}
function updateSearchConditions(type, id, destName, destParent) {
switch (type) {
case "hotels":
unavailableDays = [];
unavailableCheckIn = [];
unavailableCheckOut = [];
IDHotel = id;
destinationsHotelsID = "";
categorySearch = type;
latitud = "";
longitud = "";
updateHotelConditions(IDHotel);
break;
case "destinations":
categorySearch = type;
unavailableDays = [];
unavailableCheckIn = [];
unavailableCheckOut = [];
IDHotel = "";
latitud = "";
longitud = "";
updateAdultsChildrens(undefined, undefined, undefined, undefined);
if (id != undefined && id != null) {
updateDestinationHotelsIDByDestination(id);
}
finalDestination = destName;
parentDestination = destParent;
break;
case "geolocation":
categorySearch = type;
unavailableDays = [];
unavailableCheckIn = [];
unavailableCheckOut = [];
IDHotel = "";
updateAdultsChildrens(undefined, undefined, undefined, undefined);
if (typeof (id) === 'object') {
latitud = id.latitud;
longitud = id.longitud;
}
updateDestinationHotelsIDByGeolocation(id);
destinoGeolocalizacion = destName;
finalDestination = destName;
parentDestination = destParent;
break;
default:
break;
}
mbe.calendar.setClosed(unavailableDays);
mbe.calendar.setCTA(unavailableCheckIn);
mbe.calendar.setCTD(unavailableCheckOut);
mbe.calendar.draw();
}
function updateHotelConditions(idSolRes) {
if (idSolRes != "") {
loading('on');
$.ajax({
url : dominioMelia + '/booking/services/E_HotelCalendar.jsp',
datatype : 'json',
async : false,
data : {
idHotel : idSolRes
},
success : function(data) {
if (typeof data !== 'undefined' && typeof data.dates !== 'undefined') {
for (var i=0; i 0) {
var children = parseInt($('.mbeChildrenRoom'+i).val(), 10);
for (var j=0; j 0) {
var children = parseInt($('.mbeChildrenRoom'+i).val(), 10);
if (adults + children > maxPax) {
mostrarMensaje(mbe.txt.error['maxOcupation'].replace('%1', (i+1)), 'error');
return false;
}
}
}
// Comprobamos la ocupacion si ha elegido mas de una habitacion con ocupacion distinta
var comprobarOcupacion = false;
if (totalHabitaciones > 1) {
var adultsHab1 = parseInt($('.mbeAdultsRoom0').val(), 10);
for (var i=1; i 0) {
var childrenHab1 = parseInt($('.mbeChildrenRoom0').val(), 10);
for (var i=1; i 0) {
for (var j=0; j> 2;
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
enc4 = chr3 & 63;
if (isNaN(chr2)) {
enc3 = enc4 = 64;
} else if (isNaN(chr3)) {
enc4 = 64;
}
output = output +
Base64._keyStr.charAt(enc1) + Base64._keyStr.charAt(enc2) +
Base64._keyStr.charAt(enc3) + Base64._keyStr.charAt(enc4);
}
return output;
},
// public method for decoding
decode : function (input) {
var output = "";
var chr1, chr2, chr3;
var enc1, enc2, enc3, enc4;
var i = 0;
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
while (i < input.length) {
enc1 = Base64._keyStr.indexOf(input.charAt(i++));
enc2 = Base64._keyStr.indexOf(input.charAt(i++));
enc3 = Base64._keyStr.indexOf(input.charAt(i++));
enc4 = Base64._keyStr.indexOf(input.charAt(i++));
chr1 = (enc1 << 2) | (enc2 >> 4);
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
chr3 = ((enc3 & 3) << 6) | enc4;
output = output + String.fromCharCode(chr1);
if (enc3 != 64) {
output = output + String.fromCharCode(chr2);
}
if (enc4 != 64) {
output = output + String.fromCharCode(chr3);
}
}
output = Base64._utf8_decode(output);
return output;
},
// private method for UTF-8 encoding
_utf8_encode : function (string) {
string = string.replace(/\r\n/g,"\n");
var utftext = "";
for (var n = 0; n < string.length; n++) {
var c = string.charCodeAt(n);
if (c < 128) {
utftext += String.fromCharCode(c);
}
else if((c > 127) && (c < 2048)) {
utftext += String.fromCharCode((c >> 6) | 192);
utftext += String.fromCharCode((c & 63) | 128);
}
else {
utftext += String.fromCharCode((c >> 12) | 224);
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
utftext += String.fromCharCode((c & 63) | 128);
}
}
return utftext;
},
// private method for UTF-8 decoding
_utf8_decode : function (utftext) {
var string = "";
var i = 0;
var c = c1 = c2 = 0;
while ( i < utftext.length ) {
c = utftext.charCodeAt(i);
if (c < 128) {
string += String.fromCharCode(c);
i++;
}
else if((c > 191) && (c < 224)) {
c2 = utftext.charCodeAt(i+1);
string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
i += 2;
}
else {
c2 = utftext.charCodeAt(i+1);
c3 = utftext.charCodeAt(i+2);
string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
i += 3;
}
}
return string;
}
}