	//a city array (cityBaseArray and cityUseArray) looks like this:
	//CITY ARRAY
		//0 => (array)
			//0 => KEY1 (airport code)
			//1 => KEY2 (city code)
			//2 => TEXT1 (city name)
			//3 => TEXT 2 (airport name)
		//1 => (array)
			//0 => KEY1 (airport code)
			//1 => KEY2 (city code)
			//2 => TEXT1 (city name)
			//3 => TEXT 2 (airport name)
		//2 => (array)
			//etc.
	
	//FUNCTIONS
	//initializeDropDownInputs
	//fireKeyPress
	//doKeyPress
	//getCityArrayFromDB
	//getCityArrayFromBase
	//updateDropDown
	//openDropDown
	//closeDropDown
	//clearDropDown
	//moveDown
	//moveUp
	//highlightCity
	//setInputValue
	//focusNext
	
	//-j screnock

	var cityBaseArray = new Array();
	var cityUseArray = new Array();
	var currentInputLength = new Array();
	var cityDropOn = false;
	var currentDropDownIndex = -1; //0 is a valid index, so -1 for false
	var arrowCurrentlyPressed = 0; //for compatibility with safari; arrow keys register keydown twice
	
	window.onload = initializeDropDownInputs; //after page loads, set javascript for all inputs having the dynamic dropdown
	
	function initializeDropDownInputs() {
		//inputDivs is an array having the ids of inputs to use the dynamic dropdown;
		//each of these inputs needs to have the alt attribute set to the id of the hidden input that takes the airport code
		inputDivs = new Array('RTOutboundFromInput','RTOutboundToInput');
		
		if (document.getElementById(inputDivs[0])) { //only run initializer if the above elements actually exist on page
			arrayLength = inputDivs.length;
			for (i=0;i<arrayLength;i++) {
				currentDiv = document.getElementById(inputDivs[i]);
				currentDiv.onblur = closeDropDown;
				currentDiv.onfocus = currentDiv.onkeydown = function(e){
					if(!e){var e = window.event;} //for IE compatability
					fireKeyPress(this,e);
					if (e.keyCode==13 || e.keyCode==9) { //enter key or tab was pressed; cancel default action and forward on
						if (typeof(e.preventDefault) == 'function') { //to prevent error in IE
							e.preventDefault(); //to cancel action in safari
						}
						formName = this.form.name;
						myTabIndex = cityInput.tabIndex;
						if (e.keyCode==9 && e.shiftKey) {
							myTabIndex = cityInput.tabIndex - 2;
						}
						setTimeout('focusNext(formName, myTabIndex)',50); //allow doKeyPress to run before tabbing on
						return false;
					}
				};
				currentDiv.onkeypress = function(e) {
					if (e && (e.keyCode==13 || e.keyCode==9)) { //a little fix for mozilla on mac
						return false;
					}
				};
			}
		}
	}
	
	function fireKeyPress(inputElement, eventObject) { //sets the current input, hidden input that takes airport code, pressed key, and forwards to doKeyPress (constructor basically)
		cityInput = inputElement;
		hiddenCityInput = document.getElementById(cityInput.alt);
		pressedKey = eventObject.keyCode;
		setTimeout('doKeyPress()',25); //cityInput.value.length is not updated until AFTER the keypress event; therefore, wait .025 seconds
	}
	
	function doKeyPress() {	//the gateway for most actions
		currentLength = cityInput.value.length;
		if ((pressedKey == 13 || pressedKey == 9) && cityDropOn) { //enter or tab key
			if (currentDropDownIndex != -1) { //if a city is highlighted, set that city
				selectedDiv = document.getElementById('CityDropDown').childNodes[currentDropDownIndex];
				setInputValue(selectedDiv.airportCode, selectedDiv.displayText);
			}
			closeDropDown();
		} else if(pressedKey == 40 && cityDropOn) { //arrows down and up
			moveDown();
			cityInput.selectionStart = cityInput.selectionEnd = cityInput.value.length; //move the cursor back to the end of the text
		} else if (pressedKey == 38 && cityDropOn) {
			moveUp();
			cityInput.selectionStart = cityInput.selectionEnd = cityInput.value.length; //move the cursor back to the end of the text
		} else if (cityInput.value.length > 2) {
			if (!cityBaseArray.length && !cityInput.failed) { //if there is no base array, get it from the DB; set use array to base array; don't go out to the DB if the query has already returned nothing
				cityUseArray = cityBaseArray = getCityArrayFromDB();
			} else if (!cityInput.failed){
				cityUseArray = getCityArrayFromBase(); //if there is a base array, search through it to get use array
			}
			updateDropDown(); //update the html of drop down div
			if (currentDropDownIndex == -1 && cityUseArray.length) { //if there are results, highlight the first one by default (if another one isn't already highlighted)
				highlightCity(0);
			}
		} else if (cityInput.value.length <= 2) {
			cityInput.failed = false;
			closeDropDown();
			clearDropDown();
			hiddenCityInput.value = '';
			cityBaseArray = new Array();
			cityUseArray = new Array();
		}
	}
	
	function getCityArrayFromDB() { //gets cities from DB using search
		returnArray = new Array();
		httpObject = getHTTPObject();
		searchString = cityInput.value.split(' - '); //if a city has been set, gets from db based off of city name only
		httpObject.open("GET", "city_drop.php?s="+searchString[0], false);
		httpObject.send(null);
		response = httpObject.responseText;
		
		if(response.length == 1) { //the array is empty (contrary to common sense)
			cityInput.failed = true; //set this variable so that the DB isn't queried again
			return false;
		}
	
		responseArray = response.split("^^");
		
		responseLength = responseArray.length;
		for (i=0;i<responseLength;i++) {
			cityArray = responseArray[i].split("|");
			returnArray.push(cityArray);
		}
		
		return returnArray; //a city array in the format specified at top
	}
	
	function getCityArrayFromBase() {
		returnArray = new Array();
		arrayLength = cityBaseArray.length;
		for (i=0;i<arrayLength;i++) {
			if (cityBaseArray[i][0].toLowerCase().indexOf(cityInput.value.toLowerCase()) != -1) {
				returnArray.push(cityBaseArray[i]);
			} else if (cityBaseArray[i][1].toLowerCase().indexOf(cityInput.value.toLowerCase()) != -1) {
				returnArray.push(cityBaseArray[i]);
			} else if (cityBaseArray[i][2].toLowerCase().indexOf(cityInput.value.toLowerCase()) != -1) {
				returnArray.push(cityBaseArray[i]);
			}
		}
				
		return returnArray; //a city array in the format specified at top
	}
	
	function updateDropDown() {		
		clearDropDown();
		arrayLength = cityUseArray.length;
		if (arrayLength) {
			for(i=0; i<arrayLength && i<10 ;i++) { //create a div for each city in dropdown menu
				cityDiv = document.createElement('div');				
				cityDiv.className = 'CityOptionOff';
				cityDiv.airportCode = cityUseArray[i][0]; //variable in div to hold the airport code
				
				//set innerHTML as well as variable 'displayText'; 'displayText' will be used later to set the input's value
				cityDiv.innerHTML = cityDiv.displayText = cityUseArray[i][2] + " - " + cityUseArray[i][3] + " (" + cityUseArray[i][0] + ")";				
				
				eval("cityDiv.onmouseover = function() {highlightCity("+i+");}"); //must eval for i value; must eval whole thing for IE
				cityDiv.onmousedown = function() {setInputValue(this.airportCode, this.displayText);closeDropDown();};
				document.getElementById('CityDropDown').appendChild(cityDiv);
			}
			if (!cityDropOn) {
				openDropDown();
			}
			//set the iframe coverup to the correct size
			document.getElementById('CityDropDownBackDrop').style.width = document.getElementById('CityDropDown').offsetWidth;
			document.getElementById('CityDropDownBackDrop').style.height = document.getElementById('CityDropDown').offsetHeight;
			
			if (false) {myDiv = document.createElement('div');myDiv.style.display = 'none';document.body.appendChild(myDiv);}
		} else {
			document.getElementById('CityDropDownBackDrop').style.display = document.getElementById('CityDropDown').style.display = 'none';
			cityDropOn = false;
		}
	}
	
	function openDropDown() {
		cityDropDiv = document.getElementById('CityDropDown');
		backDrop = document.getElementById('CityDropDownBackDrop'); //iframe for IE6 select covering
		
		cityInputPos = findPos(cityInput);
		backDrop.style.left = cityDropDiv.style.left = cityInputPos[0];
		backDrop.style.top = cityDropDiv.style.top = cityInputPos[1] + cityInput.offsetHeight - 1;
		
		cityDropDiv.style.display = 'block'; //must display div before getting offsetWidth and Height
		
		backDrop.style.width = cityDropDiv.offsetWidth;
		backDrop.style.height = cityDropDiv.offsetHeight;
		backDrop.style.display = 'block';
		
		cityDropOn = true;
	}
	
	function closeDropDown() {
		if (hiddenCityInput.value == '') {
			hiddenCityInput.value = cityInput.value;
		}
		document.getElementById('CityDropDownBackDrop').style.display = document.getElementById('CityDropDown').style.display = 'none';
		cityDropOn = false;
		cityBaseArray = new Array();
		cityUseArray = new Array();
	}
	
	function clearDropDown() { //removes all the HTML from the CityDropDown div
		dropDownDiv = document.getElementById('CityDropDown');
		if (dropDownDiv.hasChildNodes()) {
		    while (dropDownDiv.childNodes.length >= 1) {
		        dropDownDiv.removeChild(dropDownDiv.firstChild);       
		    } 
		}
		currentDropDownIndex = -1;
	}
	
	function moveDown() { //moves through the drop down divs
		dropDownDiv = document.getElementById('CityDropDown');
		if (dropDownDiv.hasChildNodes() && !arrowCurrentlyPressed) {
			nextIndex = (currentDropDownIndex + 1)%dropDownDiv.childNodes.length;
			highlightCity(nextIndex);
			
			//for compatibility with safari, set boolean to keep second keypress event from getting inside this if statement
			arrowCurrentlyPressed = 1;
			setTimeout('resetArrowCurrentlyPressed()',10);
		}
	}
	
	function moveUp() { //moves through the drop down divs
		dropDownDiv = document.getElementById('CityDropDown');
		if (dropDownDiv.hasChildNodes() && !arrowCurrentlyPressed) {
			if (currentDropDownIndex <= 0 ) {
				nextIndex = dropDownDiv.childNodes.length - 1;
			} else {
				nextIndex = (currentDropDownIndex - 1)%dropDownDiv.childNodes.length;
			}
			highlightCity(nextIndex);
			
			//for compatibility with safari, set boolean to keep second keypress event from getting inside this if statement
			arrowCurrentlyPressed = 1;
			setTimeout('resetArrowCurrentlyPressed()',10);
		}
	}
	
	function resetArrowCurrentlyPressed() {
		arrowCurrentlyPressed = 0;
	}
	
	function highlightCity(indexNumber) { //highlights a city and unhighlights the old city
		dropDownDiv = document.getElementById('CityDropDown');
		if (currentDropDownIndex > -1) {
			dropDownDiv.childNodes[currentDropDownIndex].className = 'CityOptionOff';
		}
		dropDownDiv.childNodes[indexNumber].className = 'CityOptionOn';
		currentDropDownIndex = indexNumber; //sets currentDropDownIndex so that the correct value is used when tab or enter is pressed
	}
	
	function setInputValue(airportCode, displayText) { //sets the value of the hidden input and display input
		hiddenCityInput.value = airportCode;
		cityInput.value = displayText;
	}

	function focusNext(currentFormName, currentTabIndex) { //tabs to next input element in tabindex
		currentForm = eval(currentFormName);
		i = currentTabIndex;
		while (i < currentTabIndex + 25) { //start at the (i)th element in the form, looking for the correct tab index; stop looking after 25
			if (currentForm.elements[i].tabIndex == currentTabIndex + 1) {
				currentForm.elements[i].focus();
				i = currentTabIndex + 25;
			}
			i++;
		}
	}
	
	function findPos(obj) { //to find position (openDropDown) in table; thanks to Peter-Paul Koch
		var curleft = curtop = 0;
		if (obj.offsetParent) {
			curleft = obj.offsetLeft
			curtop = obj.offsetTop
			while (obj = obj.offsetParent) {
				curleft += obj.offsetLeft
				curtop += obj.offsetTop
			}
		}
		return [curleft,curtop];
	}
