﻿if ( !window.Utils )
    window.Utils = {};
    
Utils.AirportCollection = function( data )
{
    var lines = data.split( String.fromCharCode(13) );
    for ( var i=0; i<lines.length; i++ )
    {
        var airport = new Entities.Airport( lines[i] );
        this[airport.getCode()] = airport;
    }
}

Utils.AirportCollection.prototype.lookupAirport = function( name )
{
    if ( this[name] != undefined )
        return this[name];
    else
    {
        // lookup for airport by city name:
        for ( var i in this )
        {
            try
            {
                if ( this[i].getCity().toLowerCase() == name.toLowerCase() )
                    return this[i];
            }
            catch (e) { /* item under i is a Function */ }
        }
    }
    return null;
}