var lang = 'sl';

var req = location.pathname;
if (req.length >= 4 && "/" === req.substring(3, 4)) {
    lang = req.substring(1, 3);
}

function submit(formID) {
    $('#' + formID).submit();
}

// airports now included through javascript directly, why we needed here HashMap -> PageMap -> XML -> JSON conversion is beyond my comprehension
// var airports = [];

function fetchAirports() {
    return airports;
}

function fetchAirport(airportCode) {
    var airports = fetchAirports();
    for (var i = 0; i < airports.length; i++) {
        if (airports[i].code == airportCode) {
            return airports[i];
        }
    }
    return null;
}

function fetchConnectedAirports(airportCode) {
    var airport = fetchAirport(airportCode);
    var connectedAirports = [];
    for (var i = 0; i < airport.connections.length; i++) {
        var a = fetchAirport(airport.connections[i]);
        if (a != null) {
            connectedAirports.push(a);
        }
    }
    return connectedAirports;
}

function fillAirports(selectBoxID, airportCode) {

    var aports = airportCode ? fetchConnectedAirports(airportCode) : fetchAirports();
    var selectedVal = $('#' + selectBoxID + '').val();
    $('#' + selectBoxID + ' option:not(:first)').remove();
    for (var i = 0; i < aports.length; i++) {
        $('#' + selectBoxID).append('<option value="' + aports[i].code + '" title="' + aports[i].name + '"' + (aports[i].code == selectedVal ? ' selected="selected"' : '') + '>' + aports[i].name + '</option>');
    }
}

function checkFlightAvailability() {
    var departureAirportCode = $('#booking-departure-airport').val();
    var departureDate = $('#booking-departure-date').val();
    var destinationAirportCode = $('#booking-destination-airport').val();
    var returnDate = $('#booking-return-date').val();
    var showDepartureAirportMsg = false;
    var showDestinationAirportMsg = false;

    if (departureAirportCode && departureDate) {
        var departureAirport = fetchAirport(departureAirportCode);
        var departureParsed = departureDate.split('/');
        var departureDateObj = new Date().setFullYear(departureParsed[0], departureParsed[1] - 1, departureParsed[2]);
        // console.log('DEPARTURE date: ' + departureDate + ' parsed >>> year: ' + departureParsed[0] + ' month: ' + departureParsed[1] + ' day: ' + departureParsed[2]);
    }
    if (destinationAirportCode && returnDate) {
        var destinationAirport = fetchAirport(destinationAirportCode);
        var returnParsed = returnDate.split('/');
        var returnDateObj = new Date().setFullYear(returnParsed[0], returnParsed[1] - 1, returnParsed[2]);
        // console.log('RETURN date: ' + returnDate + ' parsed >>> year: ' + returnParsed[0] + ' month: ' + returnParsed[1] + ' day: ' + returnParsed[2] + '\n');
    }


    var fromParsed, untilParsed, fromDateObj, untilDateObj;

    if (departureAirport) {
        fromParsed = departureAirport.from.split('/');
        untilParsed = departureAirport.until.split('/');

        if (null != fromParsed && 'null' != fromParsed && null != untilParsed && 'null' != untilParsed) {
            // console.log('DEPARTURE (from db) from >>> month: ' + fromParsed[0] + ' day: ' + fromParsed[1]);
            // console.log('DEPARTURE (from db) until >>> month: ' + untilParsed[0] + ' day: ' + untilParsed[1]);

            fromDateObj = new Date();
            fromDateObj.setFullYear(departureParsed[0], fromParsed[0] - 1, fromParsed[1]);
            untilDateObj = new Date();
            untilDateObj.setFullYear(departureParsed[0], untilParsed[0] - 1, untilParsed[1]);

            if (departureDateObj < fromDateObj || departureDateObj > untilDateObj) {
                showDepartureAirportMsg = true;
            }
        }
    }

    if (destinationAirport) {
        fromParsed = destinationAirport.from.split('/');
        untilParsed = destinationAirport.until.split('/');

        if (null != fromParsed && 'null' != fromParsed && null != untilParsed && 'null' != untilParsed) {
            // console.log('DESTINATION (from db) from >>> month: ' + fromParsed[0] + ' day: ' + fromParsed[1] + '\n');
            // console.log('DESTINATION (from db) until >>> month: ' + untilParsed[0] + ' day: ' + untilParsed[1] + '\n');

            fromDateObj = new Date();
            fromDateObj.setFullYear(returnParsed[0], fromParsed[0] - 1, fromParsed[1]);
            untilDateObj = new Date();
            untilDateObj.setFullYear(returnParsed[0], untilParsed[0] - 1, untilParsed[1]);

            if (returnDateObj < fromDateObj || returnDateObj > untilDateObj) {
                showDestinationAirportMsg = true;
            }
        }
    }

    if (showDepartureAirportMsg && showDestinationAirportMsg) {
        alert('1. ' + departureAirport.message + '\n' + destinationAirport.message);
    } else if (showDepartureAirportMsg) {
        alert('2. ' + departureAirport.message);
    } else if (showDestinationAirportMsg) {
        alert('3. ' + destinationAirport.message);
    }
}

function toggleCalendars() {
    if ($('.calendar.narrow').css('display') == 'none') {
        $('.calendar.narrow').show();
    } else {
        $('.calendar.narrow').hide();
    }
}

function updateDateFields(id, date) {
    var monthFieldID = id.split('-').slice(0, 2).join('-') + '-month';
    var dayFieldID = id.split('-').slice(0, 2).join('-') + '-day';
    var month = '' + date.getFullYear() + (date.getMonth() > 9 ? date.getMonth() : '0' + date.getMonth());
    var day = date.getDate();
    $('#' + monthFieldID).val(month);
    $('#' + dayFieldID).val(day);
}

function updateCalendar(id) {
    if ($('#' + id + '-month').length > 0 && $('#' + id + '-day').length > 0) {
        var month = $('#' + id + '-month').val();
        var day = $('#' + id + '-day').val();
        if (month != '' && day != '') {
            var date = month.substring(0, 4) + '/' + (parseInt(month.substring(4, 6), 10) + 1) + '/' + day;
            $('#' + id + '-date').val(date);
            $('#' + id + '-date').change();
        }
    }
}

function toggleFlightType(elm) {
    if (elm == 'R') {
        $('#booking-return-month').removeAttr('disabled');
        $('#booking-return-day').removeAttr('disabled');
        $('#booking-return-date').removeAttr('disabled');
        $('#booking-return-hour').removeAttr('disabled');
        $('#cal_booking-return-date_display').removeAttr('disabled');
        $('#cal_booking-return-date').show();
        $('#flightForm').show();
        $('#multiForm').hide();
    } else if (elm == 'M') {
        $('#flightForm').hide();
        $('#multiForm').show();
    } else {
        $('#booking-return-month').attr('disabled', 'disabled');
        $('#booking-return-day').attr('disabled', 'disabled');
        $('#booking-return-date').attr('disabled', 'disabled');
        $('#booking-return-hour').attr('disabled', 'disabled');
        $('#cal_booking-return-date').hide();
        $('#flightForm').show();
        $('#multiForm').hide();
    }
}

function updateFlightType() {
    if ($('#booking-flight-return').attr('checked')) {
        toggleFlightType('R');
    } else if ($('#booking-flight-multi').attr('checked')) {
        toggleFlightType('M');
    } else {
        toggleFlightType('O');
    }
}

function toggleFareType(elm) {
    if (elm == 'price') {
        $('#search-page').val('FP');
        $('#from-page').val('ADVS');
    } else if (elm == 'schedule') {
        $('#search-page').val('SD');
        $('#from-page').val('ADVSSD');
    }
}

function fillDestinations(selectBoxID, countryCode, lang) {
    $.getJSON(
            '/booking/fm/cp2/hotels/cities.js?hotel-location-country=' + countryCode + '&lang=' + lang,
            function(data) {
                $('#' + selectBoxID + ' option:not(:first)').remove();
                for (var i = 0; i < data.length; i++) {
                    $('#' + selectBoxID).append('<option value="' + data[i].Code + '" title="' + data[i].Title + '">' + data[i].Title + '</option>');
                }
            });
}

function showTooltips(e, position) {
    $('.tooltip').css('top', (e.clientY + 15) + 'px');
    $('.tooltip').css('left', (e.clientX + (position == 'right' ? 15 : -165)) + 'px');
    $('.tooltip').show();
}

function hideTooltips() {
    $('.tooltip').hide();
}

function initBookingForm() {
    $(document).bind('ready', function () {
        $('#booking-departure-airport').change(function () {
            //if ($('#booking-destination-airport').val() == '') {
            fillAirports('booking-destination-airport', $('#booking-departure-airport').val());
            //}
            checkFlightAvailability();
        });
        $('#booking-destination-airport').change(function () {
            //if ($('#booking-departure-airport').val() == '') {
            fillAirports('booking-departure-airport', $('#booking-destination-airport').val());
            //}
            checkFlightAvailability();
        });
        $('#booking-departure-month').change(function () {
            updateCalendar('booking-departure');
            checkFlightAvailability();
        });
        $('#booking-return-month').change(function () {
            updateCalendar('booking-return');
            checkFlightAvailability();
        });
        $('#booking-departure-day').change(function () {
            updateCalendar('booking-departure');
            checkFlightAvailability();
        });
        $('#booking-return-day').change(function () {
            updateCalendar('booking-return');
            checkFlightAvailability();
        });
        $('#booking-flight-return').click(function () {
            toggleFlightType('R');
        });
        $('#booking-flight-multi').click(function () {
            toggleFlightType('M');
        });
        $('#booking-flight-oneway').click(function () {
            toggleFlightType('O');
        });
        $('#bookinig-preference-exact').click(function () {
            toggleFareType('schedule');
        });
        $('#bookinig-preference-flexible').click(function () {
            toggleFareType('price');
        });
        $('.tooltip').appendTo('body');
        $('.info').mouseover(function (e) {
            showTooltips(e, $(this).hasClass('left') ? 'left' : 'right')
        });
        $('.info').mouseout(hideTooltips);
        fillAirports('booking-destination-airport', $('#booking-departure-airport').val());
        fillAirports('booking-departure-airport', $('#booking-destination-airport').val());
        updateCalendar('booking-departure');
        updateCalendar('booking-return');
        updateFlightType();
    });
}

function initTimetableForm() {
    $(document).bind('ready', function () {
        $('#timetable-departure-airport').change(function () {
            if ($('#timetable-destination-airport').val() == '') {
                fillAirports('timetable-destination-airport', $('#timetable-departure-airport').val());
            }
        });
        $('#timetable-destination-airport').change(function () {
            if ($('#timetable-departure-airport').val() == '') {
                fillAirports('timetable-departure-airport', $('#timetable-destination-airport').val());
            }
        });
    });
}

function initTabs() {
    $(document).bind('ready', function () {
        $('.tabbed-panel .tabs li a').click(function (el) {
            $('.tabbed-panel .error').remove();
            $('.tabbed-panel .tabs li').removeClass('selected');
            $(this).parent().addClass('selected');
            $('.tabbed-panel .container > *').hide();
            $('#' + $(this).parent().attr('id').replace('tab-', '')).show();
            return false;
        });
    });
}

function initGallery(config) {
    $(document).bind('ready', function () {
        $('.gallery a').lightBox(config);
    });
}

function highlightStars(el, cssClass, on) {
    if (on) {
        el.parent().children().removeClass(cssClass);
        el.addClass(cssClass);
        pel = el;
        while (pel.length > 0) {
            pel.addClass(cssClass);
            pel = pel.prev();
        }
    } else {
        pel = el;
        while (pel.length > 0) {
            pel.removeClass(cssClass);
            pel = pel.prev();
        }
    }
}

function clickStar(el) {
    highlightStars(el, 'selected', 1);
    el.parent().prev().val(el.html());
}

function setStars(el) {
    $(el.next().children().get(el.val() - 1)).click();
}

function initHotelsForm(lang) {
    $(document).bind('ready', function () {
        $('#hotels-countries').change(function () {
            fillDestinations('hotels-destinations', $('#hotels-countries').val(), lang);
        });
        $('#hotels-countries').change();
        $('#hotel-arrival-month').change(function () {
            updateCalendar('hotel-arrival');
        });
        $('#hotel-arrival-day').change(function () {
            updateCalendar('hotel-arrival');
        });
        updateCalendar('hotel-arrival');

        $('.stars').hide();
        $('.stars').change(function () {
            setStars($(this));
        });
        $('.stars-block').show();
        $('.stars-block a').mouseover(function () {
            highlightStars($(this), 'highlight', 1);
        });
        $('.stars-block a').mouseout(function () {
            highlightStars($(this), 'highlight', 0);
        });
        $('.stars-block a').click(function () {
            clickStar($(this));
        });
        $('.stars').change();
    });
}

var scrollPosition = 0;
var scrollWindowSize = 4;
var layerCount = 1;
var offsetLeft = 0;
var elementCount = null;
var scrollLength = 120;
var scrollWidth = null;
var totalScrollWidth = null;
var scrollInterval = 3000;
var interval = null;
var enableScroll = true;
var visibleItems = null;

function doScrollLeft() {
    if (!enableScroll) return false;

    enableScroll = false;
    if (scrollPosition == 0 && $(visibleItems).prev().length == 0) {
        totalScrollWidth += scrollWidth;
        $('.scroll-pane').css('width', totalScrollWidth + 'px');
        $('.scroll-pane').prepend($('.scroll-items:eq(0)').clone().attr('id', 'items-' + layerCount++));
        offsetLeft -= scrollWidth;
        $('.scroll-pane').css('left', offsetLeft + 'px');
        if ($('.scroll-items').length > 2) {
            $('.scroll-items:last').remove();
            totalScrollWidth -= scrollWidth;
            $('.scroll-pane').css('width', totalScrollWidth + 'px');
        }
    }

    if (scrollPosition == 0) {
        scrollPosition = elementCount - 1;
        visibleItems = $(visibleItems).prev().get(0);
    } else {
        scrollPosition--;
    }

    offsetLeft += scrollLength;
    $('.scroll-pane').animate({'left' : '+=' + scrollLength + 'px'}, scrollLength * 3, 'linear', function () {
        enableScroll = true;
    });
    return true;
}

function doScrollRight() {
    if (!enableScroll) return false;

    enableScroll = false;
    if (scrollPosition == elementCount - scrollWindowSize && $(visibleItems).next().length == 0) {
        totalScrollWidth += scrollWidth;
        $('.scroll-pane').css('width', totalScrollWidth + 'px');
        $('.scroll-pane').append($('.scroll-items:eq(0)').clone().attr('id', 'items-' + layerCount++));
        if ($('.scroll-items').length > 2) {
            $('.scroll-items:first').remove();
            totalScrollWidth -= scrollWidth;
            $('.scroll-pane').css('width', totalScrollWidth + 'px');
            offsetLeft += scrollWidth;
            $('.scroll-pane').css('left', offsetLeft + 'px');
        }
    }

    if (scrollPosition == elementCount - 1) {
        scrollPosition = 0;
        visibleItems = $(visibleItems).next().get(0);
    } else {
        scrollPosition++;
    }

    offsetLeft -= scrollLength;
    $('.scroll-pane').animate({'left' : '-=' + scrollLength + 'px'}, scrollLength * 3, 'linear', function () {
        enableScroll = true;
    });
    return true;
}

function initOffersScroller() {
    $(document).bind('ready', function () {
        elementCount = $('.scroll-pane .offer').length;
        scrollWidth = elementCount * 120;
        totalScrollWidth = scrollWidth;
        $('.scroll-pane').css('width', scrollWidth + 'px');
        $('.scroll-items').css('width', totalScrollWidth + 'px');
        visibleItems = $('.scroll-items').get(0);
        $('#offers-scroll-left').click(function () {
            clearInterval(interval);
            doScrollLeft();
        });
        $('#offers-scroll-right').click(function () {
            clearInterval(interval);
            doScrollRight();
        });
        interval = setInterval(doScrollRight, scrollInterval);
    });
}

function initLet48Form() {
    $(document).bind('ready', function () {
        $('#let48Dep').change(function () {
            //fillAirports('let48Des', $('#let48Dep').val());
            fillLet48Data();
        });
        $('#let48Des').change(function () {
            //fillAirports('let48Dep', $('#let48Des').val());
            fillLet48Data();
        });
        $('#let48MY').change(function () {
            fillLet48Data();
        });

        //fillAirports('let48Des', $('#let48Dep').val());
        //fillAirports('let48Dep', $('#let48Des').val());
        $('div.buttons').remove();
    });
}

function fillLet48Data() {
    $.ajaxSetup({
        cache: false
    });
    if ($('#let48MY').val().length > 0) {
        if ($('#let48Dep').val().length > 0 && $('#let48Des').val().length > 0) {
            $.ajax({
                type: "GET",
                url: "/let48data.cp2?linkid=ajax",
                datatype: "html",
                data:{
                    let48Dep: $('#let48Dep').val(),
                    let48Des: $('#let48Des').val(),
                    let48MY: $('#let48MY').val()
                },
                complete: function(data) {
                    $("#let48s").html(data.responseText);
                }
            });
        } else {
            $.ajax({
                type: "GET",
                url: "/let48data.cp2?linkid=ajax",
                datatype: "html",
                data:{
                    let48MY: $('#let48MY').val()
                },
                complete: function(data) {
                    $("#let48s").html(data.responseText);
                }
            });
        }
    }
}

function fetchOutletConnectedAirports(airportCode) {

    var connectedAirports = [];
    var airport = "";
    if ((airportCode != null) && (airportCode != '')) {
        airport = fetchAirport(airportCode);
        for (var i = 0; i < airport.connections.length; i++) {
            for (var j = 0; j < outletConnections.length; j++) {
                if (outletConnections[j].code == airport.connections[i]) {
                    connectedAirports.push(fetchAirport(airport.connections[i]));
                }
            }
        }
    } else {
        for (var j = 0; j < outletConnections.length; j++) {
            connectedAirports.push(fetchAirport(outletConnections[j].code));
        }
    }
    return connectedAirports;
}

function fillOutletAirports(selectBoxID, airportCode) {

    var airports = fetchOutletConnectedAirports(airportCode);
    var selectedVal = $('#' + selectBoxID + '').val();
    $('#' + selectBoxID + ' option:not(:first)').remove();
    for (var i = 0; i < airports.length; i++) {

        $('#' + selectBoxID).append('<option value="' + airports[i].code + '" title="' + airports[i].name + '"' + (airports[i].code == selectedVal ? ' selected="selected"' : '') + '>' + airports[i].name + '</option>');
    }
}

function initOutletForm() {

    //fillAirports($('#outletDep'),'AMS');

    fillOutletAirports('outletDes', '');
    fillOutletAirports('outletDep', '');

    $(document).bind('ready', function () {
        $('#outletDep').change(function () {
            fillOutletAirports('outletDes', $('#outletDep').val());
            fillPageData(false, "outletdata");
        });
        $('#outletDes').change(function () {
            fillOutletAirports('outletDep', $('#outletDes').val());
            fillPageData(false, "outletdata");
        });
        $('#outletMY').change(function () {
            fillPageData(false, "outletdata");
        });

        $('div.buttons').remove();
    });
}


function initOutletRetForm() {

    fillOutletAirports('outletRetDes', '');
    fillOutletAirports('outletRetDep', '');

    $(document).bind('ready', function () {
        $('#outletRetDep').change(function () {
            fillOutletAirports('outletRetDes', $('#outletRetDep').val());
            fillPageData(true, "outletdata");
        });
        $('#outletRetDes').change(function () {
            fillOutletAirports('outletRetDep', $('#outletRetDes').val());
            fillPageData(true, "outletdata");
        });
        $('#outletRetMY').change(function () {
            fillPageData(true, "outletdata");
        });

        $('div.buttons').remove();
    });
}


function fillPageData(isRet, cp2page) {

    var outletMy = null;
    var outletDep = null;
    var outletDes = null;

    if (isRet) {
        outletMy = $('#outletRetMY').val();
        outletDep = $('#outletRetDep').val();
        outletDes = $('#outletRetDes').val();

    } else {
        outletMy = $('#outletMY').val();
        outletDep = $('#outletDep').val();
        outletDes = $('#outletDes').val();
    }

    $.ajaxSetup({
        cache: false
    });
    if (outletMy.length > 0) {
        if (outletDep.length > 0 && outletDep.length > 0) {
            $.ajax({
                type: "GET",
                url: "/" + cp2page + ".cp2?linkid=ajax",
                datatype: "html",
                data:{
                    outletDep: outletDep,
                    outletDes: outletDes,
                    outletMY: outletMy
                },
                complete: function(data) {
                    if (isRet) {
                        $("#outletRets").html(data.responseText);
                    } else {
                        $("#outlets").html(data.responseText);
                    }
                }
            });
        } else {
            $.ajax({
                type: "GET",
                url: "/" + cp2page + ".cp2?linkid=ajax",
                datatype: "html",
                data:{
                    outletMY: outletMy
                },
                complete: function(data) {
                    if (isRet) {
                        $("#outletRets").html(data.responseText);
                    } else {
                        $("#outlets").html(data.responseText);
                    }
                }
            });
        }
    }
}


$().ready(function() {
    $(".flight-list table tr td:nth-child(2n)").addClass('sum');
});

function initSpecialActionForm(id){
	$(document).bind('ready', function () {
		 $('#'+id+'Des').change(function () {
			  fillSpecialActionPage(id);
		 });
		 $('#'+id+'Dep').change(function () {
			  fillSpecialActionPage(id);
		 });
		 $('#'+id+'MY').change(function () {
			  fillSpecialActionPage(id);
		 });

		 $('div.buttons').remove();
	});

}

function fillSpecialActionPage(id){
    var specialMY = $('#'+id+'MY').val();
    var specialDep = $('#'+id+'Dep').val();
    var specialDes = $('#'+id+'Des').val();
       $.ajaxSetup({
        cache: false
    });
    if (specialMY.length > 0) {
        if (specialDep.length > 0 && specialDes.length > 0) {
            $.ajax({
                type: "GET",
                url: ("/"+id+"_actiondata.cp2?linkid=ajax"),
                datatype: "html",
                data:{
                    specialDep: specialDep,
                    specialDes: specialDes,
                    specialMY: specialMY
                },
                complete: function(data) {
                        $("#"+id).html(data.responseText);

                }
            });
        }
    }
}

function initSpecailActionBookingForm() {
    $(document).bind('ready', function () {


        $('#booking-destination-airport').change(function () {
            checkFlightAvailability();
        });
        $('#booking-departure-month').change(function () {
            updateCalendar('booking-departure');
            checkFlightAvailability();
        });
        $('#booking-return-month').change(function () {
            updateCalendar('booking-return');
            checkFlightAvailability();
        });
        $('#booking-departure-day').change(function () {
            updateCalendar('booking-departure');
            checkFlightAvailability();
        });
        $('#booking-return-day').change(function () {
            updateCalendar('booking-return');
            checkFlightAvailability();
        });
        $('#booking-flight-return').click(function () {
            toggleFlightType('R');
        });
        $('#booking-flight-multi').click(function () {
            toggleFlightType('M');
        });
        $('#booking-flight-oneway').click(function () {
            toggleFlightType('O');
        });
        $('#bookinig-preference-exact').click(function () {
            toggleFareType('schedule');
        });
        $('#bookinig-preference-flexible').click(function () {
            toggleFareType('price');
        });
        $('.tooltip').appendTo('body');
        $('.info').mouseover(function (e) {
            showTooltips(e, $(this).hasClass('left') ? 'left' : 'right')
        });
        $('.info').mouseout(hideTooltips);
        updateCalendar('booking-departure');
        updateCalendar('booking-return');
        updateFlightType();
    });
}


function initDinersInnerForm() {

    $(document).bind('ready', function () {
        $('#outletDes').change(function () {
            fillPageData(false, "dinersdata");
        });
        $('#outletMY').change(function () {
            fillPageData(false, "dinersdata");
        });

        $('div.buttons').remove();
    });
}


function initDinersBookingForm() {
    $(document).bind('ready', function () {


        $('#booking-destination-airport').change(function () {
            checkFlightAvailability();
        });
        $('#booking-departure-month').change(function () {
            updateCalendar('booking-departure');
            checkFlightAvailability();
        });
        $('#booking-return-month').change(function () {
            updateCalendar('booking-return');
            checkFlightAvailability();
        });
        $('#booking-departure-day').change(function () {
            updateCalendar('booking-departure');
            checkFlightAvailability();
        });
        $('#booking-return-day').change(function () {
            updateCalendar('booking-return');
            checkFlightAvailability();
        });
        $('#booking-flight-return').click(function () {
            toggleFlightType('R');
        });
        $('#booking-flight-multi').click(function () {
            toggleFlightType('M');
        });
        $('#booking-flight-oneway').click(function () {
            toggleFlightType('O');
        });
        $('#bookinig-preference-exact').click(function () {
            toggleFareType('schedule');
        });
        $('#bookinig-preference-flexible').click(function () {
            toggleFareType('price');
        });
        $('.tooltip').appendTo('body');
        $('.info').mouseover(function (e) {
            showTooltips(e, $(this).hasClass('left') ? 'left' : 'right')
        });
        $('.info').mouseout(hideTooltips);
        updateCalendar('booking-departure');
        updateCalendar('booking-return');
        updateFlightType();
    });
}