﻿/// <reference path="jquery/jquery-1.3.2.js" />

function Airport() {
    this.icao = "";
    this.name = "";
}

Airport.getClosestAirport = function(lat, lng, zoom) {
	var airport = null;

	$.ajax({
		type: "POST",
		async: false,
		url: "ScheduleService.asmx/GetClosestAirport",
		data: JSONstring.make({ latitude: lat, longitude: lng, zoom: zoom }),
		contentType: "application/json; charset=utf-8",
		dataType: "json",
		success: function(msg) {
			airport = JSONstring.toObject(msg.d);
		},
		error: function(xhr, textStatus, errorThrown) {
			MessageBox.showError(xhr.responseText);
		}
	});
	
	return airport;
};

Airport.validateAirport = function(airport) {
    var valid = (airport.toUpperCase() != ICAO_EMPTY_TEXT.toUpperCase());

    $.ajax({
        type: "POST",
        async: false,
        url: "AirportSearch.asmx/AirportExists",
        data: JSONstring.make({ icao: airport }),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            valid = valid && msg.d;
        },
        error: function(xhr, textStatus, errorThrown) {
            MessageBox.showError(xhr.responseText);
        }
    });

    return valid;
};