function var_dump(obj) {
    var out = '';
    for (var i in obj) {
        out += i + ": " + obj[i] + "\n";
    }
    return out;
}
function manageError(data){
    $('#loader').hide();
    $('#error').text(data.localizedMessage).show();
}
function getSegmentDateTimeString(timeInMillis, getTimeBool){
    var myDate = new Date();
    myDate.setTime(timeInMillis);
    if (getTimeBool) {
        var hours = (myDate.getHours()<10) ? '0'+myDate.getHours() : myDate.getHours();
        var mins = (myDate.getMinutes()<10) ? '0'+myDate.getMinutes() : myDate.getMinutes();
        return hours + ":" + mins;
    } else {
        var week_days = new Array(7);
        week_days[0] = "Domenica";
        week_days[1] = "Lunedì";
        week_days[2] = "Martedì";
        week_days[3] = "Mercoledì";
        week_days[4] = "Giovedì";
        week_days[5] = "Venerdì";
        week_days[6] = "Sabato";

        var months = new Array(12);
        months[0]  = "Gennaio";
        months[1]  = "Febbraio";
        months[2]  = "Marzo";
        months[3]  = "Aprile";
        months[4]  = "Maggio";
        months[5]  = "Giugno";
        months[6]  = "Luglio";
        months[7]  = "Agosto";
        months[8]  = "Settembre";
        months[9]  = "Ottobre";
        months[10] = "Novembre";
        months[11] = "Dicembre";

        var day = (myDate.getDate()<10) ? '0'+myDate.getDate() : myDate.getDate();
        //var month = myDate.getMonth() + 1; // months go from 0 to 11
        return week_days[myDate.getUTCDay()] + ' ' + day + " " + months[myDate.getMonth()]; // + "/" + myDate.getFullYear();
    }
}
function getSegmentDateHour(timeInMillis){
    var myDate = new Date();
    myDate.setTime(timeInMillis);
    return myDate.getHours();
}
function hoursAndMinutesBetweenTwoDates(firstDateInMillis, secondDateInMillis){
    //var one_day=1000*60*60*24;
    //Calculate difference btw the two dates, and convert to days
    //return Math.ceil((christmas.getTime()-today.getTime())/(one_day))
    var one_minute = 1000*60;
    var one_hour = 1000*60*60;
    var result = '';
    if (firstDateInMillis > secondDateInMillis) {
        var diffInMillis = (firstDateInMillis - secondDateInMillis);
        var fullHours = Math.floor(diffInMillis / one_hour);
        var totalMinutes = Math.floor(diffInMillis / one_minute);
        var fullHoursInMinutes = fullHours * 60;
        var minutesRemaining = totalMinutes - fullHoursInMinutes;
        var formattedMinutes = (minutesRemaining<10) ? ('0'+minutesRemaining) : minutesRemaining;
        result = fullHours + 'h ' + formattedMinutes + 'min';
    }
    return result;
}
function hoursAndMinutesBetweenTwoCalendars(firstDate, secondDate){
    var firstDateInMillis = firstDate.timeInMillis;
    var secondDateInMillis = secondDate.timeInMillis;
    var timeZoneHoursDiff = (parseInt(firstDate.timeZone.rawOffset) - parseInt(secondDate.timeZone.rawOffset));
    //alert(parseInt(firstDate.timeZone.rawOffset) + ' - ' + parseInt(secondDate.timeZone.rawOffset));

    //Calculate difference btw the two dates, and convert to days
    var one_minute = 1000*60;
    var one_hour = 1000*60*60;
    var result = '';
    if (firstDateInMillis > secondDateInMillis) {
        var diffInMillis = (firstDateInMillis - secondDateInMillis) + timeZoneHoursDiff;
        var fullHours = Math.floor(diffInMillis / one_hour);
        var totalMinutes = Math.floor(diffInMillis / one_minute);
        var fullHoursInMinutes = fullHours * 60;
        var minutesRemaining = totalMinutes - fullHoursInMinutes;
        var formattedMinutes = (minutesRemaining<10) ? ('0'+minutesRemaining) : minutesRemaining;
        result = fullHours + 'h ' + formattedMinutes + 'min';
    }
    return result;
}
function hideResults(){
    $('#results').hide();
    $('#flight-results').hide();
    $('#loader').show();
}
function showResults(){
    $('#loader').hide();
    $('#wl-results').show();
    $('#results').show();
    $('#flight-results').show();
}
function showErrors(messageHTML){
    $('#loader').hide();
    //$('#wl-main').hide();
    $('#wl-main').empty();
    $('#wl-main').append(messageHTML);
}
function setUpModalBoxes(){
    //select all the a tag with name equal to modal
    $('a[name="modal"]').click(function(e) {
        //Cancel the link behavior
        e.preventDefault();
        //Get the A tag
        var id = $(this).attr('href').indexOf('#')>-1 ? $(this).attr('href').slice($(this).attr('href').indexOf('#')) : $(this).attr('href');

        //Get the screen height and width
        var changeFlightBoxHeight = $('#changeFlightBox').height();
        var documentHeight = getDocHeight();//$(document).height();
        //Get the window height and width
        var winH = $(window).height();
        var winW = $(window).width();
        var marginFromTop = Math.ceil(winH/8);

        //MASK STUFF
        //alert('document: '+ documentHeight + ' - changeFlightBox: ' + changeFlightBoxHeight);
        var maskHeight = ((documentHeight>changeFlightBoxHeight) ? documentHeight : changeFlightBoxHeight) + (marginFromTop*2);
        var maskWidth = $(window).width();

        //Set height and width to mask to fill up the whole screen
        $('#mask').css({'width':maskWidth, 'height':maskHeight});

        //transition effect
        $('#mask').fadeIn(800);
        $('#mask').fadeTo("normal", 0.8);

        //MODAL STUFF
        //Set the popup window to center
        //$(id).css('top',  winH/2-$(id).height()/2);
        $(id).css('top', $(document).scrollTop() + marginFromTop);
        $(id).css('left', (winW/2) - ($(id).width()/2));

        //transition effect
        $(id).fadeIn(1000);
    });

    //if close button is clicked
    $('.window .close').click(function (e) {
        //Cancel the link behavior
        e.preventDefault();
        hideMask();
    });

    //if mask is clicked
    $('#mask').click(function () {
        //$('.window').hide();
        hideMask();
    });
}
function hideMask(){
    $('#mask, .window').hide("normal");
}
function getDocHeight() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}
//VIAGGIATORI E STANZE
//hotel
function add1HotelAdult(){
    var actualAdults = parseInt($('#num_adt_h').val());
    if (actualAdults>0 && actualAdults<9) {
        $('#num_adt_h').val(actualAdults+1);
    } else {
        alert('Il limite massimo di adulti è 9.');
    }
    return false;
}
function remove1HotelAdult(){
    var actualRooms = parseInt($('#numCamere').val());
    var actualAdults = parseInt($('#num_adt_h').val());
    if (actualRooms == actualAdults) {
        alert('Non è possibile cercare un numero di stanze maggiore del numero di adulti.');
    } else if (actualAdults>1 && actualAdults<=9) {
        $('#num_adt_h').val(actualAdults-1);
    } else {
        alert('Dev\'esserci sempre almeno un adulto.');
    }
    return false;
}
function add1Room(){
    var actualRooms = parseInt($('#numCamere').val());
    var actualAdults = parseInt($('#num_adt_h').val());
    if (actualRooms == actualAdults) {
        alert('Non è possibile cercare un numero di stanze maggiore del numero di adulti.');
    } else if (actualRooms>0 && actualRooms<4) {
        $('#numCamere').val(actualRooms+1);
    } else {
        alert('Il limite massimo di stanze prenotabili è 4.');
    }
    return false;
}
function remove1Room(){
    var actualRooms = parseInt($('#numCamere').val());
    if (actualRooms>1 && actualRooms<=4) {
        $('#numCamere').val(actualRooms-1);
    } else {
        alert('Dev\'esserci sempre almeno una stanza nella tua ricerca.');
    }
    return false;
}
//flight
function add1FlightAdult(){
    var actualAdt = $('#num_adt_v').val();
    if (parseInt(actualAdt)>0 && parseInt(actualAdt)<9) {
        $('#num_adt_v').val(parseInt(actualAdt)+1);
    } else {
        alert('Il limite massimo di adulti per volo è 9.');
    }
    return false;
}
function remove1FlightAdult(){
    var actualAdt = $('#num_adt_v').val();
    var actualInf = $('#num_inf_v').val();
    if (parseInt(actualAdt)>1 && parseInt(actualAdt)<=9) {
        if (parseInt(actualAdt)<=parseInt(actualInf)) {
            $('#num_inf_v').val(parseInt(actualAdt)-1);    
        }
        $('#num_adt_v').val(parseInt(actualAdt)-1);
    } else {
        alert('Dev\'esserci sempre almeno un adulto per volo.');
    }

    return false;
}
function add1Child(){
    var actualChd = $('#num_chd_v').val();
    if (parseInt(actualChd)>=0 && parseInt(actualChd)<9) {
        $('#num_chd_v').val(parseInt(actualChd)+1);
    } else {
        alert('Il limite massimo di bambini è 9.');
    }
    return false;
}
function remove1Child(){
    var actualChd = $('#num_chd_v').val();
    if (parseInt(actualChd)>0 && parseInt(actualChd)<=9) {
        $('#num_chd_v').val(parseInt(actualChd)-1);
    } else {
        //alert('Il limite massimo di bambini è 9.');
    }
    return false;
}
function add1Infant(){
    var actualInf = $('#num_inf_v').val();
    var actualAdults = parseInt($('#num_adt_v').val());
    if (actualInf == actualAdults) {
        alert('Non è possibile portare a bordo del volo un numero di neonati superiore al numero di adulti.');
    } else if (parseInt(actualInf)>=0 && parseInt(actualInf)<9) {
        $('#num_inf_v').val(parseInt(actualInf)+1);
    } else {
        alert('Il limite massimo di neonati è 9.');
    }
    return false;
}
function remove1Infant(){
    var actualInf = $('#num_inf_v').val();
    if (parseInt(actualInf)>0 && parseInt(actualInf)<=9) {
        $('#num_inf_v').val(parseInt(actualInf)-1);
    } else {
        //alert('Il limite massimo di neonati è 9.');
    }
    return false;
}
//flighthotel
function add1FlightHotelAdult(){
    var actualAdt = $('#num_adt_vh').val();
    if (parseInt(actualAdt)>0 && parseInt(actualAdt)<9) {
        $('#num_adt_vh').val(parseInt(actualAdt)+1);
    } else {
        alert('Il limite massimo di adulti per viaggio è 9.');
    }
    return false;
}
function remove1FlightHotelAdult(){
    var actualAdt = $('#num_adt_vh').val();
    if (parseInt(actualAdt)>1 && parseInt(actualAdt)<=9) {
        if (actualAdt == $('#num_inf_vh').val()) {
            $('#num_inf_vh').val(parseInt(actualAdt)-1);    
        }
        $('#num_adt_vh').val(parseInt(actualAdt)-1);
    } else {
        alert('Dev\'esserci sempre almeno un adulto per il tuo viaggio.');
    }
    return false;
}
function add1FlightHotelChild(){
    var actualChd = $('#num_chd_vh').val();
    if (parseInt(actualChd)>=0 && parseInt(actualChd)<9) {
        $('#num_chd_vh').val(parseInt(actualChd)+1);
    } else {
        alert('Il limite massimo di bambini è 9.');
    }
    return false;
}
function remove1FlightHotelChild(){
    var actualChd = $('#num_chd_vh').val();
    if (parseInt(actualChd)>0 && parseInt(actualChd)<=9) {
        $('#num_chd_vh').val(parseInt(actualChd)-1);
    } else {
        //alert('Il limite massimo di bambini è 9.');
    }
    return false;
}
function add1FlightHotelInfant(){
    var actualInf = $('#num_inf_vh').val();
    var actualAdults = parseInt($('#num_adt_vh').val());
    if (actualInf == actualAdults) {
        alert('Non è possibile portare a bordo del volo un numero di neonati superiore al numero di adulti.');
    } else if (parseInt(actualInf)>=0 && parseInt(actualInf)<9) {
        $('#num_inf_vh').val(parseInt(actualInf)+1);
    } else {
        alert('Il limite massimo di neonati è 9.');
    }
    return false;
}
function remove1FlightHotelInfant(){
    var actualInf = $('#num_inf_vh').val();
    if (parseInt(actualInf)>0 && parseInt(actualInf)<=9) {
        $('#num_inf_vh').val(parseInt(actualInf)-1);
    } else {
        //alert('Il limite massimo di neonati è 9.');
    }
    return false;
}
function add1FlightHotelBedPlace(){
    var actualBedPlaces = $('#posti_letto_vh').val();
    if (parseInt(actualBedPlaces)>=0 && parseInt(actualBedPlaces)<9) {
        $('#posti_letto_vh').val(parseInt(actualBedPlaces)+1);
    } else {
        alert('Il limite massimo di posti letto riservabili è 9.');
    }
    return false;
}
function remove1FlightHotelBedPlace(){
    var actualBedPlaces = $('#posti_letto_vh').val();
    var actualAdults = parseInt($('#num_adt_vh').val());
    //var actualChildren = parseInt($('#num_chd_vh').val());
    if (parseInt(actualBedPlaces)>0 && parseInt(actualBedPlaces)>(parseInt(actualAdults)/*+parseInt(actualChildren)*/)) {
        $('#posti_letto_vh').val(parseInt(actualBedPlaces)-1);
    } else {
        //alert('Il limite massimo di neonati è 9.');
    }
    return false;
}
function add1FlightHotelRoom(){
    var actualRooms = parseInt($('#numCamere_vh').val());
    var actualAdults = parseInt($('#num_adt_vh').val());
    if (actualRooms == actualAdults) {
        alert('Non è possibile cercare un numero di stanze maggiore del numero di adulti.');
    } else if (actualRooms>0 && actualRooms<4) {
        $('#numCamere_vh').val(actualRooms+1);
    } else {
        alert('Il limite massimo di stanze prenotabili è 4.');
    }
    return false;
}
function remove1FlightHotelRoom(){
    var actualRooms = parseInt($('#numCamere_vh').val());
    if (actualRooms>1 && actualRooms<=4) {
        $('#numCamere_vh').val(actualRooms-1);
    } else {
        alert('Dev\'esserci sempre almeno una stanza nella tua ricerca.');
    }
    return false;
}
//other stuff
function selectHomePageTab(tabId){
    $('#flight,#hotel,#flighthotel,#hertz').hide();
    if (tabId=='flight') {
        $('input[value="flight"]').attr('checked', true);
        $('input[value="hotel"]').attr('checked', false); //useful to validation
        $('input[value="flighthotel"]').attr('checked', false); //useful to validation
        $('input[value="hertz"]').attr('checked', false);
        $('#flight').show();
    } else if(tabId=='hotel') {
        $('input[value="flight"]').attr('checked', false);
        $('input[value="hotel"]').attr('checked', true);
        $('input[value="flighthotel"]').attr('checked', false);
        $('input[value="hertz"]').attr('checked', false);
        $('#hotel').show();
    } else if(tabId=='flighthotel') {
        $('input[value="flight"]').attr('checked', false);
        $('input[value="hotel"]').attr('checked', false);
        $('input[value="flighthotel"]').attr('checked', true);
        $('input[value="hertz"]').attr('checked', false);
        $('#flighthotel').show();
    } else if(tabId=='hertz') {
        $('input[value="flight"]').attr('checked', false);
        $('input[value="hotel"]').attr('checked', false);
        $('input[value="flighthotel"]').attr('checked', false);
        $('input[value="hertz"]').attr('checked', true);
        $('#hertz').show();
    }
}
function openCloseDiv(divId){
    if ($('#'+divId).attr('style').indexOf('DISPLAY: none')>-1 || $('#'+divId).attr('style').indexOf('display: none;')>-1 || $('#'+divId).attr('style').indexOf('display:none;')>-1 ) {
        $('#'+divId).show('slow');
    } else {
        $('#'+divId).hide('slow');
    }
}
//date stuff in main search form
function dateDiff(biggerDateStr, lesserDateStr, absoluteDiff){
    var applyAbsValueOnDiff = (absoluteDiff==null) ? true : absoluteDiff;
    var date1 = new Date(
            lesserDateStr.substr(6),
            lesserDateStr.substr(3,2)-1,
            lesserDateStr.substr(0,2));
    var date2 = new Date(
            biggerDateStr.substr(6),
            biggerDateStr.substr(3,2)-1,
            biggerDateStr.substr(0,2));
    var difftime = date2.getTime()-date1.getTime();
    if (applyAbsValueOnDiff) {
        difftime = Math.abs(difftime);
    }
    return parseInt(difftime/1000/60/60/24);
}
$('#depDate').bind('dpClosed', function(e, selectedDates){
    if (selectedDates[0]) {
        var depDate = new Date(selectedDates[0]);
        $('#retDate').dpSetStartDate(depDate.asString());
        var dateDifference = dateDiff($('#depDate').val(), $('#retDate').val(), false);
        if (dateDifference>0) {
            $('#retDate').val($('#depDate').val());
        }
    }
});
var hotelAndFlightHotelCheckInCssSelector = '#flighthotel #checkIn, #hotel #checkIn, #hertz #pickupDate';
var hotelAndFlightHotelCheckOutCssSelector = '#flighthotel #checkOut, #hotel #checkOut, #hertz #dropoffDate';
$(hotelAndFlightHotelCheckInCssSelector).bind('dpClosed', function(e, selectedDates){
    if (selectedDates[0]) {
        var checkInDate = new Date(selectedDates[0]);
        $(hotelAndFlightHotelCheckInCssSelector).val(checkInDate.asString());
        var checkOutDate = (new Date((selectedDates[0]))).addDays(1);
        $(hotelAndFlightHotelCheckOutCssSelector).dpSetStartDate(checkOutDate.asString());
        var dateDifference = dateDiff($(hotelAndFlightHotelCheckInCssSelector).val(), $(hotelAndFlightHotelCheckOutCssSelector).val(), false);
        if (dateDifference>=0) {
            $(hotelAndFlightHotelCheckOutCssSelector).val(checkOutDate.asString());
        }
    }
});
//filters' stuff
function changeRelatedLabelStyle(forAttribute){
    if ($('input[id="'+forAttribute+'"]').is(':checked')) {
        $('label[for="'+forAttribute+'"]').attr('class', 'wl-filter-label-checked');
    } else {
        $('label[for="'+forAttribute+'"]').attr('class', '');
    }
}
function getRightLabel(descr_type){
    if (descr_type == 'HOTEL_INFORMATION') {
        descr_type = 'La struttura';
    } else if (descr_type == 'ROOM_INFORMATION') {
        descr_type = 'Stanze';
    } else if (descr_type == 'FOOD_AND_BEVERAGE') {
        descr_type = 'Informazioni alimentari';
    } else if (descr_type == 'AREA_INFORMATION') {
        descr_type = 'Area informazioni';
    } else if (descr_type == 'TRAVEL_INFORMATION') {
        descr_type = 'Il viaggio';
    } else if (descr_type == 'QUICK_DESCRIPTION') {
        descr_type = 'Breve descrizione';
    } else if (descr_type == 'IMPORTANT_INFORMATION') {
        descr_type = 'Importante';
    } else if (descr_type == 'CANCELLATION_POLICY') {
        descr_type = 'Cancellazione';
    } else if (descr_type == 'CHILD_POLICY') {
        descr_type = 'Bambini';
    } else if (descr_type == 'PHOTO_ALBUM') {
        descr_type = 'Album fotografici';
    } else if (descr_type == 'STRAP') {
        descr_type = 'Strap';
    } else if (descr_type == 'APARTMENT') {
        descr_type = 'Appartamento';
    } else if (descr_type == 'EXTERIOR') {
        descr_type = 'Exterior';
    } else if (descr_type == 'LOBBY') {
        descr_type = 'Lobby';
    } else if (descr_type == 'INCLUSIVE') {
        descr_type = 'Servizi inclusi';
    }
    return descr_type;
}
function makeSEOFriendly(str) {
    //str = str.toLowerCase(); //change everything to lowercase
    str = str.replace(/^s+|s+$/g, ''); //trim leading and trailing spaces
    str = str.replace(/[_]+/g, '-'); //change underscores to a hyphen
    str = str.replace(/[ ]+/g, '-'); //change all spaces to a hyphen
    str = str.replace(/[']+/g, '-'); //change all spaces to a hyphen
    str = str.replace(/[^a-zA-Z0-9\-]+/g, ''); //remove all non-alphanumeric characters except the hyphen
    str = str.replace(/[-]+/g, '-'); //replace multiple instances of the hyphen with a single instance
    str = str.replace(/^-+|-+$/g, ''); //trim leading and trailing hyphens
    return str;
}
//HOTEL
function printHotel(h, hotel, currentHotelId, divWhereToAppendId, servletBaseUrl){
    hotel_resume.push('<div class="wl-hotel wl-radius" id="'+currentHotelId+'">');
    if (hotel.thumbUrl!=null && hotel.thumbUrl!='') {
        hotel_resume.push('<div class="wl-hotel-img"><a href="#" onclick="prepareDataToShowDetail(\''+currentHotelId+'\');"><img alt="'+hotel.name+'" src="'+servletBaseUrl+'imageservlet/'+hotel.thumbUrl+'?w=90&h=90" /></a></div>');
    } else {
        hotel_resume.push('<div class="wl-hotel-img"><img height="90" width="90" alt="Immagine non presente." src="/images/default.jpg" /></div>');        
    }
    hotel_resume.push('<div class="wl-hotel-resume">');
    hotel_resume.push('<h3 class="wl-hotel-name"><a class="wl-hotel-first-color" href="#" onclick="prepareDataToShowDetail(\''+currentHotelId+'\');">'+hotel.name+'</a></h3>');
    if (hotel.address==null) {
        hotel.address='&nbsp;';
    }
    hotel_resume.push('<p class="wl-hotel-via">'+hotel.address+'</p>');
    if (hotel.stars>0) {
        hotel_resume.push('<div class="wl-sprite-tools wl-stars wl-'+hotel.stars+'star"> </div>');
    } else {
        hotel_resume.push('<br />');
    }
    var itemDescription = '';
    if (hotel.mainDescription!=null) {
        itemDescription = hotel.mainDescription;
        if (itemDescription.length > 300) {
            itemDescription = itemDescription.substr(0, 300) + ' ...';
        }
    } else {
        itemDescription = 'Descrizione non disponibile.';
    }
    hotel_resume.push('<p class="wl-hotel-shortdescription">'+ itemDescription +'</p>');
    hotel_resume.push('<p><br />');
    var fc_tot = 0;
    for (var hfc in hotel.facilityClass) {
        fc_tot++;
    }
    var fc_count = 0;
    for (var fc in hotel.facilityClass) {
        fc_count++;
        hotel_resume.push(hotel.facilityClass[fc]);
        if (fc_count < fc_tot) {
            hotel_resume.push(', ');
        }
    }
    hotel_resume.push('</p>');
    //hotel_resume.push('<a class="wl-hotel-first-color" href="#" onclick="prepareDataToShowDetail(\''+currentHotelId+'\');">Maggiori Informazioni</a>');
    if (hotel.providerName == 'BookingCom') {
        hotel_resume.push('<div class="wl-sprite-tools wl-hotel-booking"> </div>');
    } else if (hotel.providerName == 'Venere') {
        hotel_resume.push('<div class="wl-sprite-tools wl-hotel-venere"> </div>');
    }
    /* if (hotel.longitude!=null && hotel.latitude!=null && hotel.longitude!=0 && hotel.latitude!=0) {
        //alert(hotel.longitude);
        hotel_resume.push('<a class="wl-sprite-tools wl-hotel-map" href="#">mappa</a>');
        var hotelMarker = createMarker('', hotel.latitude, hotel.longitude, 0, hotel.name, hotel.address);
        var html = "";//"<strong>" + hotel.name + "</strong><br />" + hotel.address;
        addDestinationToMap(hotelMarker, html);
        map.setCenter(hotelMarker);
        showMapFlag = true;
    } */

    //dati per il form di dettaglio
    hotel_resume.push('<input type="hidden" disabled="disabled" name="hotelName" id="hotelName_'+currentHotelId+'" value="'+hotel.name+'" />');
    hotel_resume.push('<input type="hidden" disabled="disabled" name="providerName" id="providerName_'+currentHotelId+'" value="'+hotel.providerName+'" />');
    hotel_resume.push('<input type="hidden" disabled="disabled" name="hotelName" id="providerSpecificEstablishmentId_'+currentHotelId+'" value="'+hotel.providerSpecificEstablishmentId+'" />');
    if (hotel.discountedPrice < hotel.price) {
        /*
        <div class="wl-prezzi_hotel wl-radius"><div class="nonsocio"><p>A partire da:</p><span class="wl-prezzostandard wl-prezzostandard-scontato">85  €</span></div><div class="socio"><p>Per i soci</p><span class="wl-prezzosocio">85  €</span></div><button class="wl-radius wl-hotel-prenota wl-hotel-second-bg wl-sprite-tools"> Prenota</button></div>
        */
        //hotel_resume.push('<button class="wl-radius wl-hotel-prenota wl-hotel-second-bg" onclick="prepareDataToShowDetail(\''+currentHotelId+'\');">Prezzo scontato: <span class="wl-sprite-tools wl-radius wl-hotel-price"><strike>'+Math.round(hotel.price*100)/100 +'</strike> '+ Math.round(hotel.discountedPrice*100)/100+' &euro;</span></button>');
        hotel_resume.push('<div class="wl-prezzi_hotel wl-radius"><div class="nonsocio"><p>A partire da:</p><span class="wl-prezzostandard">'+Math.round(hotel.price*100)/100 +' &euro;</span></div><div class="socio"><p>Per i soci</p><span class="wl-prezzosocio">'+ Math.round(hotel.discountedPrice*100)/100+' &euro;</span></div><button class="wl-radius wl-hotel-prenota wl-hotel-second-bg wl-sprite-tools" onclick="prepareDataToShowDetail(\''+currentHotelId+'\');"> Prenota</button></div>');
    } else {
        /*
        <div class="wl-prezzi_hotel wl-radius"><div class="nonsocio"><p>A partire da:</p><span class="wl-prezzostandard">85  €</span></div><button class="wl-radius wl-hotel-prenota wl-hotel-second-bg wl-sprite-tools"> Prenota</button></div>
        */
        //hotel_resume.push('<button class="wl-radius wl-hotel-prenota wl-hotel-second-bg" onclick="prepareDataToShowDetail(\''+currentHotelId+'\');">A partire da: <span class="wl-sprite-tools wl-radius wl-hotel-price">'+Math.round(hotel.price*100)/100 +' ['+ Math.round(hotel.discountedPrice*100)/100+'] &euro;</span></button>');
        hotel_resume.push('<div class="wl-prezzi_hotel wl-radius"><div class="nonsocio"><p>A partire da:</p><span class="wl-prezzostandard">'+Math.round(hotel.price*100)/100 +' &euro;</span></div><button class="wl-radius wl-hotel-prenota wl-hotel-second-bg wl-sprite-tools" onclick="prepareDataToShowDetail(\''+currentHotelId+'\');"> Prenota</button></div>');
    }
    hotel_resume.push('</div>');
    hotel_resume.push('</div>');
}
//FLIGHT
function printFlight(i, item, currentFlightId, divWhereToAppendId, selectedIdForChangeFlight){
    var onlyDetail = (parseInt(selectedIdForChangeFlight) >= 0);
    if (item.outboundLeg) {
        if (! onlyDetail) {
            $('<div />').attr('class', 'wl-fly wl-radius').attr('id', currentFlightId).appendTo('#'+divWhereToAppendId);
            var tr_th = '<thead><tr><th class="wl-fly-date">Partenza</th><th class="wl-fly-partenza">&nbsp;</th><th class="wl-fly-ora-partenza">Arrivo</th><th class="wl-fly-arrivo"> </th><th class="wl-fly-ora-arrivo">Scali</th><th class="wl-fly-compagnia">Compagnia</th><th class="wl-fly-scali">Volo</th></tr></thead>';
            var tr_andata_result = [];
        }
        var tr_andata = '<tr><td colspan="7" class="wl-fly-tdunico wl-sprite-tools wl-fly-andata">Andata</td></tr>';
        var tr_th_dett = '<thead><tr><th class="wl-fly-date">Partenza</th><th class="wl-fly-partenza">&nbsp;</th><th class="wl-fly-ora-partenza">Arrivo</th><th class="wl-fly-arrivo"> </th><th class="wl-fly-compagnia">Compagnia</th><th class="wl-fly-scali">Volo</th></tr></thead>';
        var tr_andata_result_dett = [];
        var depDateStr, depTimeStr, depDateInMillis, arrDateStr, arrTimeStr, arrDateInMillis, depAirport, arrAirport, depMarketingAirline, arrMarketingAirline, depUid, retUid;
        //andata
        var segment = null;
        for (var o in item.outboundLeg.segments) {
            segment = item.outboundLeg.segments[o];
            depDateStr = getSegmentDateTimeString(segment.departureDate.timeInMillis, false);
            depTimeStr = getSegmentDateTimeString(segment.departureDate.timeInMillis, true);
            arrDateStr = getSegmentDateTimeString(segment.arrivalDate.timeInMillis, false);
            arrTimeStr = getSegmentDateTimeString(segment.arrivalDate.timeInMillis, true);
            if (o==0) {
                tr_andata = '<tr><td colspan="7" class="wl-fly-tdunico wl-sprite-tools wl-fly-andata"><strong>Andata</strong> &raquo; '+depDateStr+'</td></tr>';
            }
            tr_andata_result_dett.push('<tr>');
            tr_andata_result_dett.push('<td class="wl-fly-date"><strong>'+ depTimeStr +'</strong></td><td>' + segment.departureAirportDescr +'</td>');
            tr_andata_result_dett.push('<td class="wl-fly-ora-partenza"><strong>'+ arrTimeStr + '</strong></td><td>'+ segment.arrivalAirportDescr +'</td>');
            tr_andata_result_dett.push('<td class="wl-fly-compagnia"><img src="/images/ico-compagnie/'+ segment.marketingAirline +'.gif" alt="'+ airline_map[segment.marketingAirline] +'" title="'+ airline_map[segment.marketingAirline] +'" /><br />'+ airline_map[segment.marketingAirline] +'</td>');
            tr_andata_result_dett.push('<td>'+ segment.marketingAirline + segment.flightNumber +'</td>');
            //tr_andata_result_dett.push('<td>'+ hoursAndMinutesBetweenTwoDates(segment.arrivalDate.timeInMillis, segment.departureDate.timeInMillis) +'</td>');
            tr_andata_result_dett.push('</tr>');
        }
        if (! onlyDetail) {
            var depStops = -1;
            for (var os in item.outboundLeg.segments) {
                segment = item.outboundLeg.segments[os];
                if (os == 0) {
                    depDateInMillis = segment.departureDate.timeInMillis;
                    depDateStr = getSegmentDateTimeString(depDateInMillis, false);
                    depTimeStr = getSegmentDateTimeString(depDateInMillis, true);
                    depAirport = segment.departureAirportDescr;
                    //depAirports[segment.departureAirport] = {id : segment.departureAirport, name: segment.departureAirportDescr};
                    depMarketingAirline = segment.marketingAirline;
                    depUid = segment.flightNumber;
                }
                if (os == item.outboundLeg.segments.length-1) {
                    arrDateInMillis = segment.arrivalDate.timeInMillis;
                    arrTimeStr = getSegmentDateTimeString(arrDateInMillis, true);
                    arrAirport = segment.arrivalAirportDescr;
                    //arrAirports[segment.arrivalAirport] = {id : segment.arrivalAirport, name: segment.arrivalAirportDescr};
                }
                depStops ++;
            }
            tr_andata_result.push('<tr>');
            tr_andata_result.push('<td class="wl-fly-date"><strong>'+ depTimeStr +'</strong></td><td>'+ depAirport +'</td>');
            tr_andata_result.push('<td class="wl-fly-ora-partenza"><strong>'+ arrTimeStr +'</strong></td><td>'+ arrAirport +'</td>');
            tr_andata_result.push('<td>'+ depStops +'</td>');
            tr_andata_result.push('<td><img src="/images/ico-compagnie/'+ depMarketingAirline +'.gif" alt="'+ airline_map[depMarketingAirline] +'" title="'+ airline_map[depMarketingAirline] +'" /><br />'+ airline_map[depMarketingAirline] +'</td>');
            tr_andata_result.push('<td>'+ depMarketingAirline +' '+ depUid +'</td>');
            //tr_andata_result.push('<td>'+ hoursAndMinutesBetweenTwoDates(arrDateInMillis, depDateInMillis) +'</td>');
            //tr_andata_result.push('<td>'+ hoursAndMinutesBetweenTwoCalendars(segment.arrivalDate, segment.departureDate) +'</td>');
            tr_andata_result.push('</tr>');
        }
        //ritorno
        if (item.returnLegList!=null && item.returnLegList[0].segments!=null && item.returnLegList[0].segments.length>0) {
            var tr_ritorno = '<tr><td colspan="7" class="wl-fly-tdunico wl-sprite-tools wl-fly-ritorno">Ritorno</td></tr>';
            var tr_ritorno_result = [];
            var tr_ritorno_result_dett = [];
            var returnLeg = null;
            for (var l in item.returnLegList) {
                returnLeg = item.returnLegList[l];
                for (var s in returnLeg.segments) {
                    segment = returnLeg.segments[s];
                    depDateStr = getSegmentDateTimeString(segment.departureDate.timeInMillis, false);
                    depTimeStr = getSegmentDateTimeString(segment.departureDate.timeInMillis, true);
                    //var arrDateStr = getSegmentDateTimeString(segment.arrivalDate.timeInMillis, false);
                    arrTimeStr = getSegmentDateTimeString(segment.arrivalDate.timeInMillis, true);
                    if (s==0) {
                        tr_ritorno = '<tr><td colspan="7" class="wl-fly-tdunico wl-sprite-tools wl-fly-ritorno"><strong>Ritorno</strong> &raquo; '+depDateStr+'</td></tr>';
                    }
                    tr_ritorno_result_dett.push('<tr>');
                    tr_ritorno_result_dett.push('<td class="wl-fly-date"><strong>'+ depTimeStr +'</strong></td><td>'+ segment.departureAirportDescr +'</td>');
                    tr_ritorno_result_dett.push('<td class="wl-fly-ora-partenza"><strong>'+ arrTimeStr +'</strong></td><td>'+ segment.arrivalAirportDescr +'</td>');
                    tr_ritorno_result_dett.push('<td class="wl-fly-compagnia"><img src="/images/ico-compagnie/'+segment.marketingAirline+'.gif" alt="'+ airline_map[segment.marketingAirline] +'" title="'+ airline_map[segment.marketingAirline] +'" /><br />'+ airline_map[segment.marketingAirline] +'</td>');
                    tr_ritorno_result_dett.push('<td>'+ segment.marketingAirline + segment.flightNumber +'</td>');
                    //tr_ritorno_result_dett.push('<td>'+ hoursAndMinutesBetweenTwoDates(segment.arrivalDate.timeInMillis, segment.departureDate.timeInMillis) +'</td>');
                    tr_ritorno_result_dett.push('</tr>');
                }
            }
            if (! onlyDetail) {
                var arrStops = -1;
                for (var rl in item.returnLegList) {
                    returnLeg = item.returnLegList[rl];
                    for (var rs in returnLeg.segments) {
                        segment = returnLeg.segments[rs];
                        if (rs == 0 && rl == 0) {
                            depDateInMillis = segment.departureDate.timeInMillis;
                            depDateStr = getSegmentDateTimeString(depDateInMillis, false);
                            depTimeStr = getSegmentDateTimeString(depDateInMillis, true);
                            depAirport = segment.departureAirportDescr;
                            arrMarketingAirline = segment.marketingAirline;
                            retUid = segment.flightNumber;
                        }
                        if (rs == returnLeg.segments.length-1 && rl == item.returnLegList.length-1) {
                            arrDateInMillis = segment.arrivalDate.timeInMillis;
                            arrTimeStr = getSegmentDateTimeString(arrDateInMillis, true);
                            arrAirport = segment.arrivalAirportDescr;
                        }
                        arrStops ++;
                    }
                }
                tr_ritorno_result.push('<tr>');
                tr_ritorno_result.push('<td class="wl-fly-date"><strong>'+ depTimeStr +'</strong></td><td>'+ depAirport +'</td>');
                tr_ritorno_result.push('<td class="wl-fly-ora-partenza"><strong>'+ arrTimeStr +'</strong></td><td>'+ arrAirport +'</td>');
                tr_ritorno_result.push('<td>'+ arrStops +'</td>');
                tr_ritorno_result.push('<td><img src="/images/ico-compagnie/'+ arrMarketingAirline +'.gif" alt="'+ airline_map[arrMarketingAirline] +'" title="'+airline_map[arrMarketingAirline]+'" /><br />'+ airline_map[arrMarketingAirline] +'</td>');
                tr_ritorno_result.push('<td>'+ arrMarketingAirline +' '+ retUid + '</td>');
                //tr_ritorno_result.push('<td>'+ hoursAndMinutesBetweenTwoDates(arrDateInMillis, depDateInMillis) +'</td>');
                tr_ritorno_result.push('</tr>');
            }
        }
        $('#boxes div#detail_box_flight:regex(^\\d+$)').empty();
        //$('#flight-results div#detail_box_flight'+selectedIdForChangeFlight).empty();
        if (! onlyDetail) {
            $('<div />').attr('class', 'wl-fly wl-radius window').attr('id', 'detail_box_'+currentFlightId).append('<h1>Dettaglio del volo</h1>').appendTo('#boxes');
        } else {
            $('<div />').attr('class', 'wl-fly wl-radius').attr('id', 'detail_box_'+currentFlightId).appendTo('#'+divWhereToAppendId);
        }
        if (item.returnLegList!=null && item.returnLegList[0].segments!=null && item.returnLegList[0].segments.length>0) {
            if (! onlyDetail) {
                $('<table border="0" cellspacing="0" cellpadding="0" />').append(tr_th).append('<tbody>').append(tr_andata).append(tr_andata_result.join("").toString()).append(tr_ritorno).append(tr_ritorno_result.join("").toString()).append('</tbody>').appendTo('#'+currentFlightId);
            }
            if (divWhereToAppendId != 'selectedFlight') {
                $('<table border="0" cellspacing="0" cellpadding="0" />').append(tr_th_dett).append('<tbody>').append(tr_andata).append(tr_andata_result_dett.join("").toString()).append(tr_ritorno).append(tr_ritorno_result_dett.join("").toString()).append('</tbody>').appendTo('#detail_box_'+currentFlightId);
            }
        } else {
            //senza ritorni
            if (! onlyDetail) {
                $('<table border="0" cellspacing="0" cellpadding="0" />').append(tr_th).append('<tbody>').append(tr_andata).append(tr_andata_result.join("").toString()).append('<tr><td colspan="8" /></tr>').append('</tbody>').appendTo('#'+currentFlightId);
            }
            if (divWhereToAppendId != 'selectedFlight') {
                $('<table border="0" cellspacing="0" cellpadding="0" />').append(tr_th_dett).append('<tbody>').append(tr_andata).append(tr_andata_result_dett.join("").toString()).append('<tr><td colspan="8" /></tr>').append('</tbody>').appendTo('#detail_box_'+currentFlightId);
            }
        }
        if (onlyDetail) {
            $('<div class="wl-sprite-tools wl-fly-shadow" />').appendTo('#detail_box_'+currentFlightId);
            $('<div class="wl-fly-price wl-fly-first-bg"><span>'+item.pricingInfo.totalFare+' &euro;</span><br />tasse incluse<br /><button class="wl-sprite-tools wl-radius wl-volohotel-prenota" onclick="doChangeFlight('+i+');">Scegli<br/>Volo</button></div>').appendTo('#detail_box_'+currentFlightId);
        }
    }
}
function addFlightToChangeFlightBox(id, flight, selectedId){
    printFlight(id, flight, 'flight'+id, 'changeFlightBox', selectedId);   
}
function doChangeFlight(newSelectedId){
    for (var f in filteredFlightResults) {
        if (f==newSelectedId) {
            var newSelectedFlight = filteredFlightResults[f];
            $('#selectedFlight').empty();
            printFlight(f, newSelectedFlight, 'flight'+f, 'selectedFlight', -1);
            $('<div class="wl-sprite-tools wl-fly-shadow" />').appendTo('#flight'+f);
            //$('<div class="wl-fly-price wl-fly-first-bg"><span>'+ newSelectedFlight.pricingInfo.totalFare +' &euro;</span><br />tasse incluse<br /><br /><a href="#changeFlightBox" name="modal"><button class="wl-sprite-tools wl-radius wl-volohotel-prenota">Cambia<br/>Volo</button></a></div>').appendTo('#flight'+f);
            $('<div class="wl-fly-price wl-fly-first-bg"><span>'+ newSelectedFlight.pricingInfo.totalFare +' &euro;</span><br />tasse incluse<br /><br /><a href="#" onclick="showFlightZone();"><button class="wl-sprite-tools wl-radius wl-volohotel-prenota">Cambia<br/>Volo</button></a></div>').appendTo('#flight'+f);
            $('#selectedFlightResume').empty().append(getResumeFromFlight(newSelectedFlight));
        }
    }
    //setUpModalBoxes();
    selectedFlightId = newSelectedId;
    //hideMask();
    $(document).scrollTop(0);
    showHotelZone();
}
function showFlightZone(){
    $('#hotelZone').hide('slow');
    setTimeout('$(\'#hotelFiltersBox\').hide();', 300);
    setTimeout('$(\'#flightFiltersBox\').show();', 200);
    setTimeout('$(\'#flightZone\').show(\'slow\');', 500);
}
function showHotelZone(){
    $('#flightZone').hide('slow');
    setTimeout('$(\'#flightFiltersBox\').hide();', 300);
    setTimeout('$(\'#hotelFiltersBox\').show();', 200);
    setTimeout('$(\'#hotelZone\').show(\'slow\');', 500);
}
function getResumeFromFlight(flight){
    var resume_html=[];
    /*resume_html.push('<p>');
    resume_html.push('Hai scelto un volo che parte dall\'aeroporto di <strong>'+flight.depStartAirport + '</strong> e atterra all\'aeroporto di <strong>' + flight.depArrAirport+'</strong>.<br />');
    resume_html.push('Il decollo è previsto per il <strong>'+ getSegmentDateTimeString(flight.depTime, false) + '</strong> alle <strong>'+getSegmentDateTimeString(flight.depTime, true)+'</strong> ');
    resume_html.push('mentre l\'atterraggio sarà il <strong>' + getSegmentDateTimeString(flight.retTime, false) + '</strong> alle <strong>'+getSegmentDateTimeString(flight.retTime, true)+'</strong>.');
    resume_html.push('</p><br />');
    if(1){
        resume_html.push('<p>');
        resume_html.push('Il volo di ritorno parte dall\'aeroporto di <strong>'+flight.retDepIataCodeDescr + '</strong> e atterra all\'aeroporto di <strong>' + flight.retEndAirport+'</strong>.<br />');
        resume_html.push('Il decollo è previsto per il <strong>'+ getSegmentDateTimeString(flight.retDepTime, false) + '</strong> alle <strong>'+getSegmentDateTimeString(flight.retDepTime, true)+'</strong> ');
        resume_html.push('mentre l\'atterraggio sarà il <strong>' + getSegmentDateTimeString(flight.retArrTime, false) + '</strong> alle <strong>'+getSegmentDateTimeString(flight.retArrTime, true)+'</strong>.');
        resume_html.push('</p><br />');
    }*/
    resume_html.push('<p>');
    resume_html.push('Per rivedere tutti i dettagli o cambiare volo, consulta la scheda "Dettagli volo".');
    resume_html.push('</p>');
    resume_html.push('<p>');
    resume_html.push('Il prezzo del volo che hai scelto è di <strong style="font-size:1.2em;">'+ flight.price + ' &euro;</strong>.');
    resume_html.push('</p>');

    return resume_html.join("").toString();
}
function disableReturnIfOneWayTrip(){
    var roundtrip = $('input[name="roundTrip"]:checked').val();
    $('input[name="retDate"]').attr('disabled', roundtrip == 'false');
    if (roundtrip=='false') {
        $('#returnDateContainer').hide();
    } else {
        $('#returnDateContainer').show();
    }
}
function enableDifferentDropoff(){
    var differentDropoff = $('input[name="differentDropoff"]:checked').val();
    $('input[name="dropoffCarLocationName"]').attr('disabled', differentDropoff != 'true');
    if (differentDropoff=='true') {
        $('#dropoffCarContainer').show();
    } else {
        $('#dropoffCarContainer').hide();
    }
}
function getCobranded(isSocio){
    var value = 'TCINS';
    if (isSocio=='true') {
        value = 'TCIS';
    }
    return value;
}

