// JavaScript Document
var destInit = null;
var airlineInit = null;

function doHomePageSubmit(bycode){
	if(bycode){
		document.getElementById('bycode').value='t';
	}
	else{
		document.getElementById('bycode').value='';
	}
	var flightNo = document.getElementById('flightNo');
	if(flightNo.value == 'Flight No'){
		flightNo.value = '';
	}
	document.getElementById('mainForm').submit();
}

function setCityList(){
	var d = document.getElementById("direction").value;
	var depart = 'true';
	var international = 'true';
	if(d == '0' || d == '2'){
		depart = 'true';
	}
	else{
		depart = 'false';
	}
	
	if(d == '0' || d == '1'){
		international = 'false';		
		flightInfoService.findAirline(depart, false, updateAirline);
	}
	else{
		international = 'true';
		document.getElementById("airline").disabled  = true;
	}
	flightInfoService.findCity(depart, international, updateCity);
}

function updateAirline(data){	
	document.getElementById("airline").disabled  = false;
	DWRUtil.removeAllOptions("airline");
	addOption("airline", "Airline", '');
	DWRUtil.addOptions("airline", data);
	if(airlineInit != null){
		DWRUtil.setValue("airline", airlineInit);
		airlineInit = null;
	}
}

function addOption(id, txt, val){
	var target = $(id);
	target.options[target.options.length] = new Option(txt, val, false, false);
}

function updateCity(data){
	var sel = document.getElementById("direction");
	DWRUtil.removeAllOptions("dest");
	if(sel.value == '1' || sel.value == '3'){
		addOption("dest", "Original ", '');
	}
	else{
		addOption("dest", "Destination", '');
	}
	

	DWRUtil.addOptions("dest", data);

	if(destInit != null){
		DWRUtil.setValue("dest", destInit);
		destInit = null;
	}
}