﻿$().ready(function() {
    function format(row) {
        var strDspl = "(" + row.AirportCode + ") " + row.CityName + ", " + row.StateCode + ", " + row.CountryCode + "<br />" + row.AirportName;
        return strDspl.replace(", ,",",");
    }

    $(".autosuggest").autocomplete('/GetAirportCodesByCity', {
        dataType: 'json',
        minChars: 2,
        multiple: false,
        scroll: true,
        scrollHeight: 500,
        max: 35,
        parse: function(data) {
            $(".goButton").attr("disabled", false);

            return $.map(data, function(row) {

                return {
                    data: row,
                    value: row.AirportCode,
                    result: "(" + row.AirportCode + ") " + row.CityName + ", " + row.AirportName
                }

            });
        },
        formatItem: function(item) {
            $(".goButton").attr("disabled", false);
            return format(item);
        },
        formatResult: function(row) {
            return row.AirportCode
        }

    });
    var txtConnectOriginClientID = '<%=txtConnectOrigin.ClientID%>';
    var txtConnectDestinationClientID='<%=txtConnectDestination.ClientID%>';
    $("#" + txtConnectOriginClientID).focus(function() {
    
        $('.ac_results').hide();
    });
    $("#" + txtConnectDestinationClientID).focus(function() {
        $('.ac_results').hide();
    });

    $('#tblConnecting, #tblArriving, #tblDeparting').bind('mouseover', function() {
        $('.ac_results').hide();
    });
    $('#tblArriving .thirdCol,#tblConnecting .secondCol,  #tblDeparting .thirdCol').mouseover(function() {
      
        $('#tblConnecting, #tblArriving, #tblDeparting').unbind('mouseover');
    }).mouseout(function() {
        $('#tblConnecting, #tblArriving, #tblDeparting').bind('mouseover', function() {
            $('.ac_results').hide();
        });
    });

});




