// ************************************************************************************************
//
// ************************************************************************************************
function drawAirports( divId )
{
	// something to hold our HTML list of Airports
	var strHTML = "";
	
	// how many Airports per column
	var perColumn = Math.floor(Airports.length/3+1);
  	
	// the Airport name
	var airportName = "";
	
	// some counters
	var i;
	var k;
	
	// begin the list of Airports
	//strHTML += "<a href=\"javascript:airportsModal.close();\" id=\"close_airport_list\" style=\"float:right; padding:0 3px 4px 4px; text-decoration:none; background:#e3120b; color:#fff;\">x</a>\n";
	strHTML += "<h3>Select your airport from the list below</h3>";
	strHTML += "<ul class=airportList>";
	strHTML += "<li class=left>";
	strHTML += "<ol>";

	for( i = 1; i <= Airports.length; i++ )
	{
		// the counter starts at 1, but the array starts at 0
		k = i - 1;
		
		airport_id  = Airports[k]["airport_id"];
		airportName = Airports[k]["airport"];
		airportNameLong = Airports[k]["airport_name_long"];
		
		// create the link
		strHTML += "<li>";
		strHTML += "<a id=\"set_ap_"+airport_id+"\" href=\"#\" ";
		strHTML += "onclick=\"CloseFacebox();setAirport( '" + airport_id + "\', '" + airportName + "' );\" ";
		strHTML += "title=\"" + airportNameLong + "\">" + airportName + "</a></li>";
		
		// if we reached the max Airports for this column, start another column
		if( (i % perColumn) == 0 && i > 1 ) {	strHTML += "</ol></li><li class=left><ol>"; }
	}
	
	// close the last column
	strHTML += "</ol></li></ul>";
	
	// write the list to the browser
	var formObj = document.getElementById( divId );
	formObj.innerHTML = strHTML;
}

// each link in the <ul> list of Airports has an onClick event which passes the Airport name and code
// i.e <a href="" onClick="setAirport( 'LAX', Los Angeles International Airport' );"></a>

function setAirport( airportID, airportName )
{
	$('#airportName').css('color','#000');
	$('#search_airport_id').val(airportID);
	$('#airportName').val(airportName);
  $('#to_from_ap').show('slow');
}