var mainAirports = ['PRN', 'SKP', 'TIA'];

$(function()
{
	$('#date-view1')
		.datePicker({inline:true})
		.bind(
			'dateSelected',
			function(e, selectedDate, $td)
			{
				if(new Date(selectedDate) > new Date($('#date-view2').dpGetSelected()))
				{
					$('#date-view2').dpSetSelected(selectedDate.asString());
				}
		 	}
		);
		
	$('#outd').change(function() { SyncAirports($('#outd').val(), $('#outa'), $('#ina'), true) });
	$('#outa').change(function() { SyncAirports($('#outa').val(), $('#outd'), $('#ind'), true)});
	$('#ind').change(function() { SyncAirports($('#ind').val(), $('#ina'), $('#outa'), false)});
	$('#ina').change(function() { SyncAirports($('#ina').val(), $('#ind'), $('#outd'), false)});
	
	$('#formFrontSearch').submit(function() {
		// Check one-way settings
		if ($('#radioOneWay').attr('checked') == true)
		{
			$('#indate').val('');
			$('#ind').val('');
			$('#ina').val('');
		}
	});	
});

function SyncAirports(value, legAirport, airportDropDownToSync, isOutbound)
{
	if (value != '' && (jQuery.inArray(value, mainAirports) != -1 && jQuery.inArray(legAirport.val(), mainAirports) != -1
		|| jQuery.inArray(value, mainAirports) == -1 && jQuery.inArray(legAirport.val(), mainAirports) == -1))
	{
		legAirport.attr("selectedIndex", 0);
		legAirport.trigger("change");
		//legAirport.val("");
	}

	if (isOutbound)
	{
		if (value != '')
			airportDropDownToSync.val(value);
		else
			airportDropDownToSync.attr("selectedIndex", 0);
	}
	else
	{
		if (value != '' && (jQuery.inArray(value, mainAirports) != -1 ^ jQuery.inArray(airportDropDownToSync.val(), mainAirports) != -1))
		{
			airportDropDownToSync.val(value);
			airportDropDownToSync.trigger("change");
		}
	}
}
			
function dropDownAirport_Changed()
{
}
