/**
* Funcion que hace casting de los parámetros de un vuelo
* VARIABLES GLOBALES:
* - "_auxDatosAdicionales" campos adicionales a añadir
* - "_llegadaDistintoDia" variable donde vamos a indicar si hay vuelos que lleguen el día siguiente para pedir una nueva dispo de hoteles
*/
function castingVuelos(vuelo){
// Comprobación de las variables globales
if( typeof(_auxDatosAdicionales)=='undefined' )_auxDatosAdicionales={};
if( typeof(_llegadaDistintoDia)=='undefined' )_llegadaDistintoDia=false;
// Casting de los datos
vuelo.precio = parseFloat(vuelo.precio);
vuelo.soloIda = vuelo.soloIda=='true';
vuelo.adultos = parseInt(vuelo.adultos,10);
vuelo.ninos = parseInt(vuelo.ninos,10);
vuelo.bebes = parseInt(vuelo.bebes,10);
// Por si buscamos por varios destinos para que ponga el código IATA cogemos el IATA del trayecto que estamos haciendo
vuelo.iataSalidaOrigen = vuelo.escalas[0].IDAeropuertoSalida;
if( vuelo.tipoVuelo=='ida' || vuelo.tipoVuelo=='vuelta' ){
vuelo.iataSalidaOrigen = vuelo.escalas[0].IDAeropuertoSalida;
vuelo.iataSalidaDestino = vuelo.escalas[vuelo.escalas.length-1].IDAeropuertoLlegada;
}
$.each(vuelo.escalas, function(iEscala,escala){
// Por si buscamos por varios destinos para que ponga el código IATA cogemos el IATA del trayecto que estamos haciendo
if( vuelo.tipoVuelo=='idaVuelta' && escala.tipoVuelo=='Ida' && escala.primeraEscala=='true' )vuelo.iataSalidaOrigen = escala.IDAeropuertoSalida;
if( vuelo.tipoVuelo=='idaVuelta' && escala.tipoVuelo=='Vuelta' && escala.primeraEscala=='true' )vuelo.iataSalidaDestino = escala.IDAeropuertoSalida;
// Calculo de la estancia en la escala
if( vuelo.escalas[iEscala+1] && vuelo.escalas[iEscala+1].tipoVuelo==escala.tipoVuelo ){
var horaIni = escala.horaLlegada.split(':');
var minIni = parseFloat(horaIni[0])*60 + parseFloat(horaIni[1]);
var horaFin = vuelo.escalas[iEscala+1].horaSalida.split(':');
var minFin = parseFloat(horaFin[0])*60 + parseFloat(horaFin[1]);
numeroMaletas = escala.numeroMalesta;
var duracion = 0;
if( minFin < minIni )duracion = 1440-minIni + minFin;
else duracion = minFin-minIni;
escala.duracionEscala = duracion;
}
});
}
/**
* Función que devuelve el precio de un vuelo o grupo de vuelos (ida + vuelta)
*/
function getPrecioVuelo(vuelo){
var precioVuelo = 0;
if( !vuelo )precioVuelo = 0;
else if( vuelo.precio )precioVuelo = vuelo.precio;
else if(vuelo.length==1 && vuelo[0])precioVuelo = vuelo[0].precio;
else if(vuelo.length==2 && vuelo[0] && vuelo[1])precioVuelo = (vuelo[0].precio + vuelo[1].precio);
precioVuelo = parseFloat(precioVuelo);
precioVuelo = parseFloat( precioVuelo.toFixed(2) );
return precioVuelo;
}
/**
* Función que devuelve la fecha de ida y vuelta de un vuelo
*/
function getFechasVuelo(vuelo, tipo){
if( tipo==undefined )tipo=='idaVuelta';
var fechas = {};
if( !vuelo )return fechas;
if(vuelo.fechaSalidaIda && vuelo.horaSalidaIda){
fechas['fechaIda'] = vuelo.fechaSalidaIda;
fechas['horaIda'] = vuelo.horaSalidaIda;
fechas['fechaIdaLlegada'] = vuelo.fechaLlegadaIda;
fechas['horaIdaLlegada'] = vuelo.horaLlegadaIda;
}
if(vuelo.fechaSalidaVuelta && vuelo.horaSalidaVuelta){
fechas['fechaVuelta'] = vuelo.fechaSalidaVuelta;
fechas['horaVuelta'] = vuelo.horaSalidaVuelta;
fechas['fechaVueltaLlegada'] = vuelo.fechaLlegadaVuelta;
fechas['horaVueltaLlegada'] = vuelo.horaLlegadaVuelta;
}
if(vuelo.length==1){
fechas['fechaIda'] = vuelo[0].fechaSalidaIda;
fechas['horaIda'] = vuelo[0].horaSalidaIda;
fechas['fechaIdaLlegada'] = vuelo[0].fechaLlegadaIda;
fechas['horaIdaLlegada'] = vuelo[0].horaLlegadaIda;
if(vuelo[0].fechaSalidaVuelta && vuelo[0].horaSalidaVuelta){
fechas['fechaVuelta'] = vuelo[0].fechaSalidaVuelta;
fechas['horaVuelta'] = vuelo[0].horaSalidaVuelta;
fechas['fechaVueltaLlegada'] = vuelo[0].fechaLlegadaVuelta;
fechas['horaVueltaLlegada'] = vuelo[0].horaLlegadaVuelta;
}
}
if(vuelo.length==2){
fechas['fechaIda'] = vuelo[0].fechaSalidaIda;
fechas['horaIda'] = vuelo[0].horaSalidaIda;
fechas['fechaIdaLlegada'] = vuelo[0].fechaLlegadaIda;
fechas['horaIdaLlegada'] = vuelo[0].horaLlegadaIda;
fechas['fechaVuelta'] = vuelo[1].fechaSalidaIda;
fechas['horaVuelta'] = vuelo[1].horaSalidaIda;
fechas['fechaVueltaLlegada'] = vuelo[1].fechaLlegadaIda;
fechas['horaVueltaLlegada'] = vuelo[1].horaLlegadaIda;
}
if( tipo=='ida' ){
delete( fechas['fechaVuelta'] );
delete( fechas['horaVuelta'] );
delete( fechas['fechaVueltaLlegada'] );
delete( fechas['horaVueltaLlegada'] );
}else if( tipo=='vuelta' ){
delete( fechas['fechaIda'] );
delete( fechas['horaIda'] );
delete( fechas['fechaIdaLlegada'] );
delete( fechas['horaIdaLlegada'] );
}
return fechas;
}
function getNumeroMaletas(nMaletas){
switch( nMaletas ){
case 0: return 'Sin maletas';
case 1: return nMaletas +' bagagem';
default: return nMaletas +' bagagens';
}
}
/**
* Función que devuelve las escalas de un vuelo
*/
function getEscalasVuelo(vuelo, tipoEscala){
var tipoVueloFiltrar = null;
if( vuelo.tipoVuelo=='idaVuelta' ){
if( vuelo.escalas ){
tipoVueloFiltrar = (tipoEscala=="ida" || tipoEscala=='ida')
?'Ida'
:'Volta';
}else{
tipoVueloFiltrar = (
(tipoEscala=="ida" || tipoEscala=='ida')
|| ( (tipoEscala=="vuelta" || tipoEscala=='volta') && vuelo.length==2)
)?'Ida'
:'Volta';
}
}else{
tipoVueloFiltrar = 'Ida';
}
if( !tipoVueloFiltrar )return [];
var vueloFiltrarEscalas = null;
if( vuelo.escalas )vueloFiltrarEscalas = vuelo
else vueloFiltrarEscalas = tipoEscala=='ida'?vuelo[0]:vuelo.length==2?vuelo[1]:vuelo[0];
var escalasMostrarProximo = vueloFiltrarEscalas.escalas.filter(function(el){
return el.tipoVuelo==tipoVueloFiltrar;
});
return escalasMostrarProximo;
}
/**
* Función que devuelve la duración de un vuelo (pasa de minutos a horas y minutos)
*/
function duracionVuelo(minutos){
var horas = Math.floor(minutos/60);
var mins = (minutos%60);
return (horas>0?horas +'h':'')+(mins>0?' '+mins+'min':'');
}
/**
* Función que devuelve el html de las maletas
*/
function htmlMaletas(maletas){
return maletas +' ';
// var html = '';
// switch( maletas.toString() ){
// case '0': html += 'Sin maletas'; break;
// case '1': html += maletas +' bagagem'; break;
// default: html += maletas +' bagagens'; break;
// }
// return html;
}
/**
* Función que devuelve el html de las maletas
*/
function htmlEscalas(escalas){
var html = '';
switch( escalas ){
case 0:
html = 'direto';
// + ' ';
break;
case 1:
html = '1 escala';
// + ' ';
break;
default:
html = ''+ escalas +' escalas';
// + ' ';
break;
}
return html;
}
function htmlPlazas(plazas){
if( !plazas )return '';
var html = '';
if( plazas==1 ){
html = plazas +' plaza';
}else if( plazas<9 ){
html = plazas +' plazas';
}else{
html = 'Há lugares';
}
return html;
}
// Función que obtiene el vuelo de ida de un vuelo seleccionado
function getVueloIda(vuelo){
return vuelo[0];
}
// Función que obtiene el vuelo de vuelta de un vuelo seleccionado
function getVueloVuelta(vuelo){
if( vuelo.length==2 )return vuelo[1];
else if( vuelo[0].tipoVuelo=='idaVuelta' )return vuelo[0];
return null;
}
/***** FUNCIONES DISPO DIA SIGUIENTE *****/
/**
* Funcion que obtiene la dispo de hoteles del día siguiente a la dispo actual
*/
PIDIENDO_DISPO_DIA_SIGUIENTE = false;
DISPO_HOTEL_DIA_SIGUIENTE = [];
function obtenerDispoHotelDiaSiguiente(){
PIDIENDO_DISPO_DIA_SIGUIENTE = true;
var diaOrig = $("#D1").val();
var mesAnoOrig = $("#MA1").val();
var vMesAnoOrig = mesAnoOrig.split('_');
var f = new Date(parseInt(vMesAnoOrig[1]), parseInt(vMesAnoOrig[0])-1, parseInt(diaOrig));
f.setDate(f.getDate()+1);
// Obtenemos la dispo del dia siguiente
urlPeticion = location.href.split('#')[0];
urlPeticion = urlPeticion.replace('D1='+diaOrig,'D1='+f.getDate());
urlPeticion = urlPeticion.replace('MA1='+mesAnoOrig,'MA1='+(f.getMonth()+1)+'_'+f.getFullYear());
urlPeticion = urlPeticion +'&aj=h&t='+ (new Date()).getTime();
$.ajax({
type: 'POST',
url: urlPeticion,
async: false,
dataType: "json",
success: function(data){
// Guardamos la dispo obtenida
DISPO_HOTEL_DIA_SIGUIENTE = [];
$.each(data,function(i,el){
if( el ){
if( i=='obj' )OBJ_BUSQUEDA_DIA_SIGUIENTE=el[0];
else if( typeof(el)=="object" )DISPO_HOTEL_DIA_SIGUIENTE.push(el);
}
});
// Guardamos el obj de la dispo
$('#objBusquedaDiaSiguiente').val( OBJ_BUSQUEDA_DIA_SIGUIENTE );
// Actualizamos los datos seleccionados
if( GESTOR_VUELOS ){
GESTOR_VUELOS.mostrarVueloSeleccionado('#datosVueloSeleccionado');
// Cambiamos la dispo si es necesario
if( VUELO_SELECCIONADO[0].hotelDiaSiguiente )usarDispoDiaSiguiente();
}
PIDIENDO_DISPO_DIA_SIGUIENTE = false;
}
});
}
/* Funciones para intercambiar la dispo */
var MOSTRANDO_DISPO_DIA_SIGUIENTE = false;
// Usar la dispo original
function usarDispoOrig(){
// Cambiamos la dispo del hotel
if( Paginar ){ // Cambios sólo para resultadosBusqueda.php
arrayDatosHoteles = JSON.parse( JSON.stringify(DISPO_ORIG_HOTEL) );
objDatosBusqueda = OBJ_BUSQUEDA_ORIG;
Paginar(1,$('#versionResultados').val(),1,0);
}
MOSTRANDO_DISPO_DIA_SIGUIENTE = false;
// Actualizamos los datos del paquete seleccionado
if( Paginar ){ // Cambios sólo para resultadosBusqueda.php
actualizarHotelSeleccionadoUsarDipo();
}else{ // Cambios para detallesConDipos.php
mostrarDatosSeleccionados();
if( $('#dispoFichaHotel .table').length==2 ){
$('#dispoFichaHotelDiaSiguiente' ).hide();
$('#dispoFichaHotelOrig' ).show();
}
// Actualizamos el precio del resumen del paquete seleccionado con la opción más barata
$('#precioReservaCompleta').html( $('#dispoFichaHotelOrig .precioMonedaEuro').html() );
}
}
function usarDispoDiaSiguiente(){
// Comprobamos que tenemos hoteles con la dispo del día siguiente
if( !DISPO_HOTEL_DIA_SIGUIENTE || DISPO_HOTEL_DIA_SIGUIENTE.length==0 )return false;
// Cambiamos la dispo del hotel
if( Paginar ){ // Cambios sólo para resultadosBusqueda.php
arrayDatosHoteles = JSON.parse(JSON.stringify(DISPO_HOTEL_DIA_SIGUIENTE));
objDatosBusqueda = OBJ_BUSQUEDA_DIA_SIGUIENTE;
Paginar(1,"normal",1,0);
}
MOSTRANDO_DISPO_DIA_SIGUIENTE = true;
// Actualizamos los datos del paquete seleccionado
if( Paginar ){ // Cambios sólo para resultadosBusqueda.php
actualizarHotelSeleccionadoUsarDipo();
}else{ // Cambios para detallesConDipos.php
mostrarDatosSeleccionados();
if( $('#dispoFichaHotel .table').length==2 ){
$('#dispoFichaHotelDiaSiguiente' ).show();
$('#dispoFichaHotelOrig' ).hide();
}
// Actualizamos el precio del resumen del paquete seleccionado con la opción más barata
$('#precioReservaCompleta').html( $('#dispoFichaHotelDiaSiguiente .precioMonedaEuro').html() );
}
}
/*
* Función que busca el hotel que tenemos actualmente seleccionado en la dispo del día siguiente
*/
function getPosiblesPreciosHotelSeleccinado(){
if( !HOTEL_SELECCIONADO )return null;
var idHotel = HOTEL_SELECCIONADO.ID;
var datosAloj = HOTEL_SELECCIONADO.habitaciones[0].alojamientos[0].DATOS;
var precioOrig=0, precioAgenciaOrig=0;
var precioDiaSiguitente=0, precioAgenciaDiaSiguitente=0;
var hoteles = JSON.parse( JSON.stringify(DISPO_ORIG_HOTEL) );
for(var iH=0, nH=hoteles.length; iH1 ){
// Calculamos la distancia al hotel seleccionado
var aeropuertosDistancia = [];
$.each(filtrosDisponibles['aeropuertosLlegada'], function(iata, datos){
var datosAeropuerto = IATA_AEROPUERTO[iata];
var distancia = '-';
if( datosAeropuerto ){
var latVuelo = parseFloat( datosAeropuerto.latitud );
var longVuelo = parseFloat( datosAeropuerto.longitud );
var latHotel = parseFloat( HOTEL_SELECCIONADO.latitud );
var longHotel = parseFloat( HOTEL_SELECCIONADO.longitud );
distancia = harvestine( latVuelo, longVuelo, latHotel, longHotel );
datos.iata = iata;
datos.distancia = distancia;
datos.nombre = datosAeropuerto.name[0];
aeropuertosDistancia.push(datos);
}
});
if( aeropuertosDistancia.length>1 ){
// Ordenamos los hoteles por distancia
aeropuertosDistancia.sort(function(a,b){
return a.distanciaSeleccione um dos seguintes aeroportos de destino: '
+ '
';
var precioHotel = 0;
if( HOTEL_SELECCIONADO ){
// Obtenemos el precio del hotel
precioHotel = parseFloat(
(UserAgencia==1 && mostrarPVP=='0')
?HOTEL_SELECCIONADO.habitaciones[0].alojamientos[0].precioAgencia
:HOTEL_SELECCIONADO.habitaciones[0].alojamientos[0].precio
);
// Sumamos el precio del seguro
precioHotel += SEGURO_BASE_PRECIO_PASAJERO_AGENCIA * (ADULTOS+NINOS+BEBES);
// Redondeamos el precio a 2 decimales
precioHotel = Math.round(precioHotel/(ADULTOS+NINOS+BEBES)*100)/100;
}
$.each(aeropuertosDistancia, function(iata, datos){
html += '
'
+ '';
popUpMesaje('', html);
}
}
}
}
/*
* Función que aplica la opción seleccionada del popup de multiaeropuerto
*/
function aplicarFiltroVuelosInicial(filtro, valor){
mostrarPestana('Vuelos');
if( valor=='' ){
$('li[id^='+ filtro +']').addClass( "active" );
$('input[name^='+ filtro +']').prop( "checked",0 );
$('#chkMismoAeropuerto2').prop( "checked",0 );
}else{
$('input[name^='+ filtro +']').prop( "checked",0 );
$('li[id^='+ filtro +']').removeClass( "active" );
$('input[name^='+ filtro + valor +']').prop( "checked",1 );
$('li[id^='+ filtro + valor +']').addClass( "active" );
$('#chkMismoAeropuerto2').prop( "checked",1 );
}
GESTOR_VUELOS.aplicarFiltros();
GESTOR_VUELOS.setVueloSeleccionado( GESTOR_VUELOS.minPrecioVuelo() );
mostrarPestana('Hoteles');
$('div[id^=popupMesaje]').remove();
}
/**
* Función que muestra la cabecera de los detalles de las escalas de un vuelo
*/
function mostrarCabeceraEscalaDetallesVuelosHora(iEscala, escala,numeroEscalas){
var html = '';
html += '
';
html += '
';
html += '
';
html += '';
html += '
';
html += '
';
html += '';
if (numeroEscalas>1){
html += ' Voo '+ iEscala+' ';
}
else{
html += ' Direto ';
}
html += ''+formatFechaDDMMYYYY(escala.fechaSalida)+'';
html += '
';
html += '
Origem
';
html += '
Duração
';
html += '
Destino
';
html += '
Info
';
html += '
';
html += '';
html += '
';
html += '
';
//version movil
html += '
';
html += '
';
html += '';
html += '
';
html += '
';
html += 'Tramo '+ iEscala+' ';
html += ''+formatFechaDDMMYYYY(escala.fechaSalida)+'';
html += '
';
html += '
';
html += '';
html += '
';
html += '
';
html += '
';
return html;
}
/**
* Funcion que muestra los datos de las escalas de un vuelo
*/
function mostrarEscalaDetallesVuelosHoraTable(escala){
var html = '';
html += '
';
html += '
';
html += '
';
html += '';
html += mostrarEscalaDetallesVuelosHora(escala);
html += '';
html += '
';
html += '
';
html += '
';
html += '
';
html += '';
html += mostrarEscalaDetallesVuelosHora_movil(escala);
html += '';
html += '
';
html += '
';
html += '
';
return html;
}
function mostrarEscalaDetallesVuelosHora(escala){
html = '
';
$('#datosPaqueteSeleccionado').html(html);
/*
html += '
'
+ '
'
+ '
'
+ '
'
+ '
'
+ 'Preço final por pessoa'
+ '';
if( TIPO_CABECERA_AGENCIA=='Vuelo+Hotel' ){
html += ' (inclui taxas, custos de gestão e seguro obrigatório)'
}
html += ''
+ '
'
+ '
';
if (IDMinorista!=17 || (IDMinorista==17 && UserAgencia)){ //Si no es click o está logueada
html += '