function populateFrom_stag(airports) {

	// airports value can be:
	// LIN = only Linate airport
	// MXP = only Malpensa airport
	// MIL = all SEA airports
	// L = airports reached by Linate
	// M = airports reached by Malpensa
	// A = airports reached by Linate or Malpensa
	// R = reset combo (all airports are loaded, including SEA airports)

	n=1;

	index_from = document.aeroporti_stag.from_stag.selectedIndex;
	value_from = document.aeroporti_stag.from_stag.options[index_from].value;

	document.aeroporti_stag.from_stag.disabled = true;
	
	document.aeroporti_stag.from_stag.options.length = 1;
	
	if ( (airports != "A") && (airports != "L") && (airports != "M") ) {
		for (i=0; i<seaAirports.length; i++) {
			if ((seaAirports[i].cod_iata == "MIL") || (seaAirports[i].cod_iata == airports) || (airports == "R") || (airports == "MIL")) {
				document.aeroporti_stag.from_stag.options[n] = new Option (seaAirports[i].descr_long,seaAirports[i].cod_iata);
				document.aeroporti_stag.from_stag.options[n].style.background="#A3BBCC";
				if ((document.aeroporti_stag.from_stag.options[n].value == value_from) && (airports != "R"))
					document.aeroporti_stag.from_stag.selectedIndex = n;
				n++;
			}
		}
	}
	
	if ( (airports != "MIL") && (airports != "LIN") && (airports != "MXP") ) {
		for (i=0; i<remoteAirports.length; i++) {
			if ((remoteAirports[i].scali_sea == "A") || (remoteAirports[i].scali_sea == airports) || (airports == "R") || (airports == "A")) {
				document.aeroporti_stag.from_stag.options[n] = new Option (remoteAirports[i].descr_long,remoteAirports[i].cod_iata);
				if ((document.aeroporti_stag.from_stag.options[n].value == value_from) && (airports != "R"))
					document.aeroporti_stag.from_stag.selectedIndex = n;
				n++;
			}
		}
	}
	
	document.aeroporti_stag.from_stag.disabled = false;

}

function populateTo_stag(airports) {

	// airports value can be:
	// LIN = only Linate airport
	// MXP = only Malpensa airport
	// MIL = all SEA airports
	// L = airports reached by Linate
	// M = airports reached by Malpensa
	// A = airports reached by Linate and Malpensa
	// R = reset combo (all airports are loaded, including SEA airports)

	n=1;

	index_to = document.aeroporti_stag.to_stag.selectedIndex;
	value_to = document.aeroporti_stag.to_stag.options[index_to].value;

	document.aeroporti_stag.to_stag.disabled = true;
	
	document.aeroporti_stag.to_stag.options.length = 1;
	
	if ( (airports != "A") && (airports != "L") && (airports != "M") ) {
		for (i=0; i<seaAirports.length; i++) {
			if ((seaAirports[i].cod_iata == "MIL") || (seaAirports[i].cod_iata == airports) || (airports == "R") || (airports == "MIL")) {
				document.aeroporti_stag.to_stag.options[n] = new Option (seaAirports[i].descr_long,seaAirports[i].cod_iata);
				document.aeroporti_stag.to_stag.options[n].style.background="#A3BBCC";
				if ((document.aeroporti_stag.to_stag.options[n].value == value_to) && (airports != "R"))
					document.aeroporti_stag.to_stag.selectedIndex = n;
				n++;
			}
		}
	}

	if ( (airports != "MIL") && (airports != "LIN") && (airports != "MXP") ) {
		for (i=0; i<remoteAirports.length; i++) {
			if ((remoteAirports[i].scali_sea == "A") || (remoteAirports[i].scali_sea == airports) || (airports == "R") || (airports == "A")) {
				document.aeroporti_stag.to_stag.options[n] = new Option (remoteAirports[i].descr_long,remoteAirports[i].cod_iata);
				if ((document.aeroporti_stag.to_stag.options[n].value == value_to) && (airports != "R"))
					document.aeroporti_stag.to_stag.selectedIndex = n;
				n++;
			}
		}
	}
	
	document.aeroporti_stag.to_stag.disabled = false;

}


function populateAirline_stag(airports) {

	// airports value can be:
	// L = airlines operating on Linate
	// M = airlines operating on Malpensa
	// A = airlines operating on Linate and Malpensa
	// R = reset combo (all airlines are loaded)  -- in practice R=A

	n=1;

	document.aeroporti_stag.airline_stag.disabled = true;
	
	document.aeroporti_stag.airline_stag.options.length = 1;

	for (i=0; i<seaAirlines.length; i++) {
		if ((seaAirlines[i].scali_sea == "A") || (seaAirlines[i].scali_sea == airports) || (airports == "R") || (airports == "A")) {
			document.aeroporti_stag.airline_stag.options[n] = new Option (seaAirlines[i].airline_name,seaAirlines[i].cod_iata);
			n++;
		}
	}
	
	document.aeroporti_stag.airline_stag.disabled = false;
	
}



/*
######################################
##		COMBO CHANGE EVENT			##
######################################
*/


function changeFrom_stag() {

	//alert("ciao");
	
	index_from = document.aeroporti_stag.from_stag.selectedIndex;
	value_from = document.aeroporti_stag.from_stag.options[index_from].value;
	location_stag = document.aeroporti_stag.location_stag.value;
	document.aeroporti_stag.name_from_stag.value = document.aeroporti_stag.from_stag.options[index_from].text;
	scali_sea = "";
	
	
	if (value_from == "") {
		populateFrom_stag("R");
		populateTo_stag("R");
	}
	else {
		if ( (value_from == "MIL") || (value_from == "LIN") || (value_from == "MXP") ) {
			if (value_from == "MIL") {
				populateTo_stag("A");
				populateAirline_stag("A");
			}
			if (value_from == "LIN") {
				populateTo_stag("L");
				populateAirline_stag("L");
			}
			if (value_from == "MXP") {
				populateTo_stag("M");
				populateAirline_stag("M");
			}
		document.aeroporti_stag.location_stag.value = location_stag;
		}
		else {
		
			for (i=0; i<remoteAirports.length; i++) {
				if (remoteAirports[i].cod_iata == value_from)
					scali_sea = remoteAirports[i].scali_sea;
			}
			if (scali_sea == "A") {
			//	populateTo_stag("MIL");
			}
			if (scali_sea == "L") {
			//	populateTo_stag("LIN");
			}
			if (scali_sea == "M") {
			//	populateTo_stag"MXP");
			}
		}
	}

}


function changeTo_stag() {

	index_to = document.aeroporti_stag.to_stag.selectedIndex;
	value_to = document.aeroporti_stag.to_stag.options[index_to].value;
	document.aeroporti_stag.name_to_stag.value = document.aeroporti_stag.to_stag.options[index_to].text;
	scali_sea = "";
	
	
	if (value_to == "") {
		populateFrom_stag("R");
		populateTo_stag("R");
	}
	else {
		if ( (value_to == "MIL") || (value_to == "LIN") || (value_to == "MXP") ) {
			if (value_to == "MIL") {
				populateFrom_stag("A");
				populateAirline_stag("A");
			}
			if (value_to == "LIN") {
				populateFrom_stag("L");
				populateAirline_stag("L");
			}
			if (value_to == "MXP") {
				populateFrom_stag("M");
				populateAirline_stag("M");
			}
		document.aeroporti_stag.location_stag.value = value_from;	
		}
		else {
		
			for (i=0; i<remoteAirports.length; i++) {
				if (remoteAirports[i].cod_iata == value_to)
					scali_sea = remoteAirports[i].scali_sea;
			}
			if (scali_sea == "A") {
				populateFrom_stag("MIL");
			}
			if (scali_sea == "L") {
				populateFrom_stag("LIN");
			}
			if (scali_sea == "M") {
				populateFrom_stag("MXP");
			}
		}
	}

}



function changeAirline_stag() {

	index_airline = document.aeroporti_stag.airline_stag.selectedIndex;
	document.aeroporti_stag.name_airline_stag.value = document.aeroporti_stag.airline_stag.options[index_airline].text;

}




/*
######################################
##			FORM CHECKING			##
######################################
*/


function check_seasonal_flights_search_stag(form) {

	if (form.from_stag.value == "") {
		alert(user_message["SEARCH_FROM_NOT_SELECTED"]);
		return false;
	}

	if (form.to_stag.value == "") {
		alert(user_message["SEARCH_TO_NOT_SELECTED"]);
		return false;
	}

	return true;

}

