function allowedAirport(tlc) {
	for(k = 0; k < allowedAirports.length; k++)
		if(allowedAirports[k] == tlc)
			return true;
	return false;
}

function allowedDestAirport(tlc) {
  if (allowedDestAirports.length > 0)
	{
		for(k = 0; k < allowedDestAirports.length; k++)
			if(allowedDestAirports[k] == tlc)
				return true;

		return false;
	}
	else
		return true;
}

function createOptions(what,where,mode) {
	if(mode == "departures") {
		for (i = 0; i < what.length; ++i) {
			if(what[i][0] == "Deutschland" || what[i][0] == "Österreich" || what[i][0] == "Schweiz") {
				og = document.createElement("optgroup");
				og.label = what[i][0];
				for (j = 1; j < what[i].length; j += 2) {
					if(allowedAirport(what[i][j])) {
						o = document.createElement("option");
						o.value = what[i][j];
						o.innerHTML = what[i][j+1];
						og.appendChild(o);
					}
				}
				where[where.length] = og;
			}
		}
	}
	else {
		for (i = 0; i < what.length; ++i) {
			og = document.createElement("optgroup");
			og.label = what[i][0];
			for (j = 1; j < what[i].length; j += 2) {
				if(allowedDestAirport(what[i][j])) {
					o = document.createElement("option");
					o.value = what[i][j];
					o.innerHTML = what[i][j+1];
					og.appendChild(o);
				}
			}
			where[where.length] = og;
		}
	}
}
function createOptionsOld(what,where) {
	for (i = 0; i < what.length; ++i) {
		r = new Option(what[i][0],"");
		r.setAttribute("class","region");
		where[where.length] = r;
		for (j = 1; j < what[i].length; j += 2) {
			where[where.length]=new Option((typeof window.opera != "undefined" ? "-----" : "     ") + what[i][j+1],what[i][j]);
		}
	}
}

function filter(s, all, airports, def) {
	presel = def != null ? def : s.options[s.options.selectedIndex].value;
	while (s.hasChildNodes()) {
		s.removeChild(s.lastChild);
	}
	for (i = 0, n = all.length; i < n; ++i) {
		og = all[i];
		var group = null;
		var empty = true;
		for (j = 0, m = og.childNodes.length; j < m; ++j) {
			var option = og.childNodes[j];
			if (airports.indexOf(option.value) != -1) {
				if (empty) {
					group = document.createElement("optgroup");
					group.label = og.label;
					empty = false;
				}
				o = document.createElement("option");
				o.innerHTML = option.innerHTML;
				o.value = option.value;
				if (o.value == presel) o.setAttribute("selected", "true");
				group.appendChild(o);
			}
			if (j + 1 == m && !empty) {
				s.appendChild(group);
			}
		}
	}
}
function filterOld(s, all, airports, def) {
	presel = def != null ? def : s.options[s.options.selectedIndex].value;
	s.length = 0;
	var curr = null;
	for (i = 0, n = all.length; i < n; ++i) {
		option = all[i];
		if (option.getAttribute("class") == "region") {
			curr = option;
		}
		else {
			if (airports.indexOf(option.value) != -1) {
				if (curr != null) {
					o = new Option(curr.text, "");
					o.setAttribute("class", "region");
					s.options[s.length] = o;
					curr = null;
				}
				s.options[s.length] = new Option(option.text, option.value);
				if (option.value == presel) s.options.selectedIndex = s.options.length - 1;
			}
		}
	}
}


function oldBrowser() {
	return typeof document.createElement("optgroup").label == "undefined" || (navigator.userAgent.indexOf("Mac") != -1 && navigator.userAgent.indexOf("MSIE") != -1) || (navigator.product == 'Gecko' && !window.find);
}
function generateDepartures(arp) {
	filter(document.getElementById("da"), allDepartures, ft[arp]);
}
function generateArrivals(arp){
	filter(document.getElementById("aa"), allArrivals, ff[arp]);
}
function selOpt(s, v) {
	for (i = 0; i < s.options.length; ++i) {
		if (s.options[i].value == v) {
			s.options.selectedIndex = i;
			break;
		}
	}
}
function checkAirport(s) {
	if (s.value == "") {
		alert("Bitte wählen Sie direkt Ihren Ab- oder Zielflughafen (kein Land).");
		s.focus();
		return false;
	}
	return true;
}

