 $(document).ready(function(){
	var url = "pulldown.tk";
	$.getJSON(url, function(JSON){
		var options = ''; var cityinit='';
		$.each(JSON.results, function(i, results){
			options += '<option value="' + results.optionValue + '">' + results.optionDisplay + '</option>';
		});
	$("select#ctlCountry").html(options);
	$("select#ctlCountry").val("TR");
	getCities("TR");
	});
 });


 $("select#ctlCountry").change(function(){
	var url ="pulldown.tk?ccode="+$(this).val();
	$.getJSON(url, function(JSON){
	var options = '';
		$.each(JSON.results, function(i, results){
			options += '<option value="' + results.optionValue + '">' + results.optionDisplay + '</option>';
		});
	$("select#ctlCity").html(options);
	});
}); 


$("select#ctlCity").click(function(event){
	var values = new Array();
	values=this.value.split('|');
	if($("#hdnFromTo").val()=='from'){
		document.getElementById('from').value=values[0];
		$("#from").val(values[0]);
		$("#nereden").val(this.options[this.selectedIndex].text);
	}else{
		$("#to").val(values[0]);
		$("#nereye").val(this.options[this.selectedIndex].text);
	}
	$("select#ctlCountry").val("TR");
	getCities("TR");
	event.preventDefault();
	overlayAirportSelector.hide();
	configureForm();
}) ;

 function getCities(Country){
	var url ="pulldown.tk?ccode="+Country;
	$.getJSON(url, function(JSON){
		var options = '';
		$.each(JSON.results, function(i, results){
			options += '<option value="' + results.optionValue + '">' + results.optionDisplay + '</option>';
		});
	$("select#ctlCity").html(options); 
	});
}

