/*############################################################################# FILE: ataGlanceSearchVisualJQ.js ASMWS - 2007/06 DESCRIPTION: Contains javascript jQuery code of the ataGlanceSearch page for the OFFER_VISUAL_EFFECTS. #############################################################################*/ var searchText = new Object(); captureSearchText(searchText); var searchPrefs = new Object(); captureSearchPrefs(searchPrefs); var cityInfo = new Object(); getCityInfo(cityInfo); var SORIGEN = "div#popupSelect1"; var SDESTINO = "div#popupSelect2"; $(document).ready(function(){ datePicker2meses("1"); datePicker2meses("2"); //Añadimos inicialmente todas las ciudades a origen y destino putCities(cityInfo, SORIGEN); putCities(cityInfo, SDESTINO); //Activamos el evento click para los botones de origen y destino, así como sus campos respectivos $("#butSel1, input#city1View").click(function(){ abrir_selector(SORIGEN); }); $("#butSel2, input#city2View").click(function(){ abrir_selector(SDESTINO); }); //Nos aseguramos que si los campos hidden que contienen la información de origen y destino están vacíos, también los estén los campos que muestran el nombre completo de la ciudad. Lo mismo para las fechas. if ($("input#city1").val() == '') ponerCiudad('', 1); if ($("input#city2").val() == '') ponerCiudad('', 2); if ($("input#date1").val() == '') ponerFecha('', 1); if ($("input#date2").val() == '') ponerFecha('', 2); //Si hemos pasado los parámetros de segmento y fechas por url, los ponemos /* var sector1_o = $.getURLParam('sector1_o'); var sector1_d = $.getURLParam('sector1_d'); var departDay1 = $.getURLParam('departDay1'); var departDay2 = $.getURLParam('departDay2'); var departMonth1 = $.getURLParam('departMonth1'); var departMonth2 = $.getURLParam('departMonth2'); var travel = $.getURLParam('travel'); */ //Pongo las guardadas inicialmente en los campos var sector1_o = $("input#city1").val(); var sector1_d = $("input#city2").val(); var departDay1 =$("input#date1").val() var departDay2 = $("input#date2").val() var travel = radioValue("travel"); if (sector1_o != null && sector1_d != null && sector1_o != "" && sector1_d != "") { putOriginCity(cityInfo.cities[sector1_o]); putDestinationCity(cityInfo.cities[sector1_d]); } /* if (departDay1 != null && departMonth1 != null) { var any = departMonth1.substr(0, 4); var mes = departMonth1.substr(4, 2); ponerFecha(new Date(mes + '/' + departDay1 + '/' + any), 1); } if (departDay2 != null && departMonth2 != null) { var any = departMonth2.substr(0, 4); var mes = departMonth2.substr(4, 2); ponerFecha(new Date(mes + '/' + departDay2 + '/' + any), 2); } */ if (departDay1 != null && departDay1 != "") { ponerFecha(new Date(departDay1), 1); } if (departDay2 != null && departDay2 != "") { ponerFecha(new Date(departDay2), 2); } if (travel != null) { if (travel == 1) $('input#oneWayRadio').attr('checked', true); else if (travel == 2) $('input#roundTripRadio').attr('checked', true); } //Preparamos los calendarios para cada market //datePicker(1); //datePicker(2); //Deshabilitamos el calendario de vuelta al seleccionar "solo ida" $('div#travelOptions input.inputRadio').click(function() { if (this.id == 'oneWayRadio') { $('div#dateSel2').slideUp('normal'); } else { $('div#dateSel2').slideDown('normal'); } }); //Activamos el botón de submit $('input#searchButton').click(function() { submitSearch(); }); }); //Pone una ciudad en el input de origen y rehace el combo de destino function putOriginCity(ciudad) { ponerCiudad(ciudad, 1); //Recuperamos las rutas de la ciudad origen y le ponemos el nombre $.each(ciudad.rutas.cities, function(code, city) { if((code!="IST") && (code!="TLV") && (code!="TUN")) city.name = cityInfo.cities[code].name; }); putCities(ciudad.rutas, SDESTINO); //Si el destino actual no es una ruta válida del origen lo borramos de la selección if (ciudad.rutas.cities[$("input#city2").val()] == undefined) ponerCiudad('', 2); comprobarFechas(); document.getElementById("testigo1city").click(); document.getElementById("testigo2city").click(); } //Pone una ciudad en el input de destino y rehace el combo de origen function putDestinationCity(ciudad) { ponerCiudad(ciudad, 2); //Si el destino actual no es una ruta válida del origen, como hemos seleccionado un destino borramos el origen var s_origen = $("input#city1").val(); if (s_origen != '') { var origen = cityInfo.cities[s_origen]; if (origen.rutas.cities[$("input#city2").val()] == undefined) { //Como poner en origen solamente las ciudades que tengan como ruta el destino que hemos seleccionado es muy rebuscado, ponemos todas las ciudades. Si se selecciona en origen una ciudad no válida respecto al destino, ya se borrará el destino. putCities(cityInfo, SORIGEN); ponerCiudad('', 1); } } comprobarFechas(); document.getElementById("testigo1city").click(); document.getElementById("testigo2city").click(); } //Inicializa los calendarios function datePicker(market) { //Ponemos los nombres de los meses y días de la semana en el idioma actual Date.monthNames = searchText.months; Date.abbrDayNames = searchText.weekdays_short; //Creamos el calendario $('input#date' + market + 'View').datePicker({showYearNavigation: false, createButton: false, horizontalOffset: 100}); //Ponemos la fecha que nos proporciona skylights como fecha máxima para seleccionar var f = new Date($('input#cal_final-date').val()); $('input#date' + market + 'View').dpSetEndDate(_asString(f)); //Acción al hacer click en la imagen del calendario $('img#calendari' + market + ', input#date' + market + 'View').bind('click', function() { $('input#date' + market + 'View').dpDisplay(); //Añadimos los bordes superiores redondeados $('div#dp-popup').bordesRedondos(false); }); //Acción al seleccionar una fecha del calendario $('input#date' + market + 'View').bind('dateSelected', function(e, selectedDate, $td) { ponerFecha(selectedDate, market); //Si cambiamos la ida y es más alta que la vuelta, igualamos la vuelta if (this.id == 'date1View') { var tmp_fecha = $("input#date2").val(); if (tmp_fecha == '') { ponerFecha(selectedDate, 2); //document.getElementsByName("date2")[0].fireEvent("onclick") //$('input#date2').fireEvent("onclick"); // $('input#date2').click; document.getElementById("testigo2").click(); } else { var fecha_vuelta = new Date(tmp_fecha); if (selectedDate > fecha_vuelta) { ponerFecha(selectedDate, 2); //document.getElementsByName("date2")[0].fireEvent("onclick") //$('input#date2').fireEvent("onclick"); //$('input#date2').click; document.getElementById("testigo2").click(); } } } //Si cambiamos la vuelta y es más baja que la ida, igualamos la ida else { var tmp_fecha = $("input#date1").val(); if (tmp_fecha == '') { ponerFecha(selectedDate, 1); //document.getElementsByName("date1")[0].fireEvent("onclick") //$('input#date1').fireEvent("onclick"); // $('input#date1').click; document.getElementById("testigo2").click(); } else { var fecha_ida = new Date($("input#date1").val()); if (selectedDate < fecha_ida) { ponerFecha(selectedDate, 1); //document.getElementsByName("date1")[0].fireEvent("onclick") //$('input#date1').fireEvent("onclick"); //$('input#date1').click; document.getElementById("testigo1").click(); } } } //document.getElementsByName("date" + market)[0].fireEvent("onclick") //$('input#date' + market).click(); $('input#date' + market).click; document.getElementById("testigo" + market).click(); }); }; //Pone una fecha en los diversos campos de fechas function ponerFecha(selectedDate, market) { var lafecha = selectedDate == '' ? new Date : selectedDate; if (selectedDate == '') { //Fecha oculta $('input#date' + market).val(''); //Fecha visible $('input#date' + market + 'View').val(''); } else { //Fecha oculta $('input#date' + market).val(_asString(lafecha, 'mm/dd/yyyy')); //Fecha visible var fecha_view = searchText.weekdays[lafecha.getDay()] + ' ' + lafecha.getDate() + ' ' + searchText.months[lafecha.getMonth()] + ', ' + lafecha.getFullYear(); $('input#date' + market + 'View').val(fecha_view); } //Fecha interna del plugin de calendario, para que se quede marcada $('input#date' + market + 'View').dpSetSelected(_asString(lafecha)); } //Comprueba que las fechas de los calendarios sean coherentes con las rutas seleccionadas function comprobarFechas() { var hoy = new Date(); //Si la ruta no se ha iniciado todavía, ponemos su fecha de inicio como fecha mínima para seleccionar if ($("input#city1").val() != '' && $("input#city2").val() != '') { var origen = cityInfo.cities[$("input#city1").val()]; var destino = origen.rutas.cities[$("input#city2").val()]; var fecha_inicio = new Date(destino.date_init); if (fecha_inicio > hoy) { $('input.calendari').dpSetStartDate(_asString(fecha_inicio)); return; } } //Ponemos la fecha actual como fecha mínima de selección $('input.calendari').dpSetStartDate(_asString(hoy)); } //Función de utilidad. Devuelve una fecha como string en el formato indicado function _asString(fecha, formato) { if (formato != undefined) { Date.format = formato; } var f = fecha.asString(); Date.format = 'dd/mm/yyyy'; return f; } //Función de submit al pulsar el botón de búsqueda. function submitSearch() { //Temporalmente deshabilitamos las rutas baleares para menos del 23 de julio var origen = $('input#city1').val(); var destino = $('input#city2').val(); if (origen == 'IBZ' || origen == 'MAH' || destino == 'IBZ' || destino == 'MAH') { var hoy = new Date(); var fecha = new Date('07/23/2007'); if (hoy < fecha) { alert(searchText.tarifa_no_disponible_hasta); return; } } if (validCities() && validDates() && validPax()) { //Ponemos los valores donde espera encontrarlos skylights document.skylightsForm.page.value = 'SEARCH'; document.skylightsForm.module.value = 'SB'; document.skylightsForm.event.value = 'search'; //Ciudades document.skylightsForm.from1.value = $('input#city1').val(); document.skylightsForm.to1.value = $('input#city2').val(); //Fechas var fecha_ida = _asString(new Date($('input#date1').val())).split('/'); var fecha_vuelta = _asString(new Date($('input#date2').val())).split('/'); document.skylightsForm.departDay1.value = fecha_ida[0]; document.skylightsForm.departMonth1.value = '' + fecha_ida[2] + fecha_ida[1]; document.skylightsForm.departDay2.value = fecha_vuelta[0]; document.skylightsForm.departMonth2.value = '' + fecha_vuelta[2] + fecha_vuelta[1]; //Días de búsqueda var antes_despues = $('#depart_all_FlexBySelect').val(); document.skylightsForm.depart1FlexBy.value = antes_despues; document.skylightsForm.depart2FlexBy.value = antes_despues; document.skylightsForm.depart_all_FlexBy.value = antes_despues; //Número de mercados document.skylightsForm.numberMarkets.value = $('input#roundTripRadio').attr('checked') ? 2 : 1; document.skylightsForm.submit(); } } //Valida que el par de ciudades esté seleccionado function validCities() { var is_valid = true; if ($('input#city1').val() == '') { alert( searchText.missingDepartCity ); is_valid = false; } else if ($('input#city2').val() == '') { alert( searchText.missingArriveCity ); is_valid = false; } return is_valid; } //Valida que las fechas estén seleccionadas function validDates() { var is_valid = true; if ($('input#date1').val() == '') { alert( searchText.popup_sector_1_invalid_date ); is_valid = false; } else if ($('input#roundTripRadio').attr('checked') && $('input#date2').val() == '') { alert( searchText.popup_sector_2_invalid_date ); is_valid = false; } return is_valid; } //Valida que los pasajeros estén correctos function validPax() { var adults = document.skylightsForm.ADULT.value; var infants = document.skylightsForm.INFANT.value; var paxTotal = 0; for (i = 0; i < searchPrefs.paxTypes.length; i++) { var paxType = searchPrefs.paxTypes[i]; var paxSelect = document.getElementById(paxType +"Select"); paxTotal = eval(paxTotal) + eval(paxSelect.options[paxSelect.selectedIndex].value); } if ((paxTotal > searchPrefs.MAX_PASSENGERS_ALLOWED) && ( searchPrefs.MAX_PASSENGERS_ALLOWED > 0 )) { alert("\n" + searchText.popup_max_passenger_amount_1 + searchPrefs.MAX_PASSENGERS_ALLOWED + searchText.popup_max_passenger_amount_2 + "\n"); return false; } if ( paxTotal < 1) { alert(searchText.popup_missing_passenger_amount); return false; } if ( (adults / infants) < 1 ) { alert(searchText.popup_too_many_infants); document.skylightsForm.INFANT.focus(); return false; } return true; } var c2StartDate = new Date(); c2StartDate.setDate( c2StartDate.getDate()-1 ); var c2FinalDate = new Date($('input#cal_final-date').val()); function datePicker2meses(market) { $('#calOne'+market).jCal({ day: new Date(), days: 1, showMonths: 2, dayOffset: 1, monthSelect: false, //dow: searchText.weekdays_short, //ml: searchText.months, dCheck: function (day) { var activa = true; if( day=c2FinalDate ){ activa = false; } return activa; }, callback: function (day, days) { var selectedDate = day; ponerFecha(selectedDate, market); //Si cambiamos la ida y es más alta que la vuelta, igualamos la vuelta if (market == '1') { var tmp_fecha = $("input#date2").val(); if (tmp_fecha == '') { ponerFecha(selectedDate, 2); } else { var fecha_vuelta = new Date(tmp_fecha); if (selectedDate > fecha_vuelta) ponerFecha(selectedDate, 2); } } //Si cambiamos la vuelta y es más baja que la ida, igualamos la ida else { var tmp_fecha = $("input#date1").val(); if (tmp_fecha == '') { ponerFecha(selectedDate, 1); } else { var fecha_ida = new Date($("input#date1").val()); if (selectedDate < fecha_ida) ponerFecha(selectedDate, 1); } } document.getElementById("testigo"+market).click(); $('#jCalD'+market).hide(); if(market=="1"){ $(document).unbind('mousedown'); }else{ $(document).unbind('mousedown'); } return true; } }); $('button#date'+market+'Button, input#date'+market+'View').unbind("click"); $('button#date'+market+'Button, input#date'+market+'View').click(function(){ var jId = "#date"+market+"Button"; var os = $(jId).offset(); $('#jCalD'+market).css("top", os.top); $('#jCalD'+market).css("left", 193); $('#jCalD1').hide(); $('#jCalD2').hide(); $('#jCalD'+market).show(); if(market=="1"){ $(document).bind('mousedown', function(e){ var el = e.target; var cal = $('#jCalD1')[0]; while (true){ if (el == cal) { return true; } else if (el == document) { $('#jCalD1').hide(); $(document).unbind('mousedown'); return false; } else { el = $(el).parent()[0]; } } }); }else{ $(document).bind('mousedown', function(e){ var el = e.target; var cal = $('#jCalD2')[0]; while (true){ if (el == cal) { return true; } else if (el == document) { $('#jCalD2').hide(); $(document).unbind('mousedown'); return false; } else { el = $(el).parent()[0]; } } }); } }); //Pone la fecha inicial seleccionada if( $('input#date' + market).val()!='' ){ var fecha_ini = new Date( $('input#date' + market).val() ); $('#calOne'+market).data('day', fecha_ini); //$('input#date' + market + 'View').dpSetSelected( fecha_ini ); } }