// START SHOW AGENCY SELECT
function showAgencySelect() {
	document.getElementById("form-holder_select_agencySelect").style.display = "block";
	document.getElementById("form-holder_select_stopIDLookup").style.display = "none";
	document.getElementById("form-holder_results").style.display = "none";
	document.getElementById("SelectRadioBtn1").checked = true;
}
// END SHOW AGENCY SELECT

// START SHOW STOP ID LOOKUP
function showStopIDLookup() {
	document.getElementById("form-holder_select_agencySelect").style.display = "none";
	document.getElementById("form-holder_select_stopIDLookup").style.display = "block";
	document.getElementById("form-holder_results").style.display = "none";
	document.getElementById("SelectRadioBtn4").checked = true;
}
// END SHOW STOP ID LOOKUP

// Set arrays that receive XML data
var agencies = new Array();
var agenciesHasDirection = new Array();
var agencyModeAttribute = new Array();
var agencyMode = new Array();
var routes = new Array();
var routesCode = new Array();
var routesKeyValue = new Array();
var directions = new Array();
var directionsKeyValue = new Array();
var stops = new Array();
var stopsID = new Array();
var stopsCode = new Array();
var stopsAgency = new Array();
var stopsRoute = new Array();
var departureTimes = new Array();
var departureStopName = new Array();
var departureStopID = new Array();
var departureRouteDirection = new Array();

var routeName = new Array();
var routeName_stopCode = new Array();
var routeName_stopCode_pop = new Array();
var routeName_stopCode_Other = new Array();
var routeDirection = new Array();
var routeDirection_pop = new Array();

// START Set Agency Type for use later in the process in determining the field selections and results layout.
/*

var agencyType = "";

function setAgencyType(theForm) {

	if(theForm.agencies.value == "BART") {
	  agencyType = 1;
	} else if(theForm.agencies.value == "SF-MUNI" || theForm.agencies.value == "WestCAT" || theForm.agencies.value == "AC Transit") {
	  agencyType = 2;
	}	
	
}
*/
// END Set Agency Type for use later in the process in determining the field selections and results layout.

function loadAgencyList(theForm) {
	
	xmlDoc=loadXMLDoc("/inc/xml_proxy.asp?service=GetAgencies.aspx");
	agencyItem=xmlDoc.getElementsByTagName('Agency');
	// Get node value method not need here, but keeping for reference for other functions as needed.
	/*agencyValue=agencyItem[0].childNodes[0].nodeValue;*/
	
}

// START Load Agency menu.

	// Load Agency list.
	loadAgencyList();
	
	// Get Agency list length and populate Agency array.
	for (i=0;i<agencyItem.length;i++) {
		agencyAttribute=xmlDoc.getElementsByTagName('Agency')[i].attributes;
		agencies[i] = agencyAttribute.getNamedItem("Name").nodeValue;
	}
	
// END Load Agency menu.

// START UPDATE MENU FUNCTIONS

	// START Load Routes menu.
	function updateRoutes(theForm) {
	
	  theForm.routes.disabled = false;
	  document.getElementById("error_msg1").innerHTML = "";
	
	  // If invalid item in select list is chosen above this menu, reset this menu.
	  if(theForm.agencies.selectedIndex == 0) {
		resetRoutes(theForm);
		resetDirections(theForm);
		resetStops(theForm);
		return false;
	  } else {
	    var agencySelection = theForm.agencies.value;
	  }
	  
	  // Get Agency Direction indicator list length and populate Agency Direction indication array in order to determine if Directions list gets displayed directions or not.
		
	  // Load Agency list. 
	  loadAgencyList();
	  
	  // Determine if agency has a direction value and set var.
	  for (i=0;i<agencyItem.length;i++) {
	
		  agencyAttribute=xmlDoc.getElementsByTagName('Agency')[i].attributes;
		  agenciesHasDirection[i] = agencyAttribute.getNamedItem("HasDirection").nodeValue;
		  
		  var agenciesHasDirectionValue = agenciesHasDirection[theForm.agencies.selectedIndex-1];
		  
	  }
	  
	  //alert(agenciesHasDirectionValue);
	  
	  // If Agency has a Direction value of "false" make Direction menu invisible.
	  if(agenciesHasDirectionValue == "False") {
		  document.getElementById("directionField").style.display = "none";
		  document.getElementById("routeField").style.display = "block";
	  } else {
		  document.getElementById("directionField").style.display = "block";
		  document.getElementById("routeField").style.display = "block";
	  }
	  
	  theForm.routes.options.length = 0;
	  theForm.routes.options[0] = new Option("Select a Route", "");
	
	  // Load Route list.
	  xmlDoc=loadXMLDoc("/inc/xml_proxy.asp?service=GetRoutesForAgency.aspx&agencyName="+agencySelection);
	  routeItem=xmlDoc.getElementsByTagName('Route');
	
	  // Get Route list length and populate Route array from determined xml file in the line above based on selection from previous menu.
	  for (i=0;i<routeItem.length;i++) {
		routeAttribute=xmlDoc.getElementsByTagName('Route')[i].attributes;
		routes[i] = routeAttribute.getNamedItem("Name").nodeValue;
		routesCode[i] = routeAttribute.getNamedItem("Code").nodeValue;
		theForm.routes.options[i+1] = new Option(routes[i], routesCode[i]);
	  }
	  
	  // Sort the Routes menu alphabetically and numerically since the data in the xml is not sorted
	  var fieldToSort = theForm.routes;
	  fieldTextArray = new Array();
	  fieldValArray = new Array();
	  fieldTextOldArray = new Array();
	
	  for(i=0; i<fieldToSort.length; i++) {
		fieldTextArray[i] = fieldToSort.options[i].text;
		fieldValArray[i] = fieldToSort.options[i].value;
		fieldTextOldArray[i] = fieldToSort.options[i].text;
	  }
	
	  fieldTextArray.sort(function(a,b){return a - b});
	
	  for(i=0; i<fieldToSort.length; i++) {
		 fieldToSort.options[i].text = fieldTextArray[i];
		 for(j=0; j<fieldToSort.length; j++) {
			 if (fieldTextArray[i] ==fieldTextOldArray[j]) {
				 fieldToSort.options[i].value = fieldValArray[j];
				 j = fieldToSort.length;
			  }
		  }
	  }
	  
	  theForm.routes.options[0] = new Option("Select a Route", "");	  
	  theForm.routes.options[0].selected = true;
	  
	  // Remove options in menus below this one upon selecting a new item from this one.
	  resetDirections(theForm);
	  resetStops(theForm);
	  
	}
	// END Load Routes menu.
	
	// START Load Directions menu.
	function updateDirections(theForm) {
	  
	  theForm.directions.disabled = false;
	  document.getElementById("error_msg1").innerHTML = "";
	  
	  // If invalid item in select list is chosen above this menu, reset this menu.
	  if(theForm.routes.selectedIndex == 0) {
		resetDirections(theForm);
		resetStops(theForm);
		return false;
	  }
	  
	  // Get Agency Direction indicator list length and populate Agency Direction indication array in order to determine if Directions list gets populated with directions or not.
	  // Load Agency list to get Agency Direction inidcation.
		
	  // Load Agency list.
	  loadAgencyList();
	  
	  // Determine if agency has a direction value and set var.
	  for (i=0;i<agencyItem.length;i++) {
	
		  agencyAttribute=xmlDoc.getElementsByTagName('Agency')[i].attributes;
		  agenciesHasDirection[i] = agencyAttribute.getNamedItem("HasDirection").nodeValue;
		  
		  var agenciesHasDirectionValue = agenciesHasDirection[theForm.agencies.selectedIndex-1];
		  
	  }
	  
	  // Get Direction list length and populate Direction array based on selections from above menus.
	  for (i=0;i<agencyItem.length;i++) {
	
		  agencyAttribute=xmlDoc.getElementsByTagName('Agency')[i].attributes;
		  agenciesHasDirection[i] = agencyAttribute.getNamedItem("HasDirection").nodeValue;
		  
		  // If Agency has a Direction value of "true" populate Direction menu with actual values.
		  if(agenciesHasDirectionValue == "True") {
		  
			theForm.directions.options.length = 0;
			theForm.directions.options[0] = new Option("Select a Direction", "");
			
			var agencySelection = theForm.agencies.value;
			var routeSelection = theForm.routes.value;
			
			//***START WORKING***//
			// Load direction list
			
			xmlDoc=loadXMLDoc("/inc/xml_proxy.asp?service=GetRoutesForAgency.aspx&agencyName="+agencySelection);
			xmlQuery="//Route[@Code = '" + routeSelection + "']/RouteDirectionList/RouteDirection";
			
			var directionNames = "";
			var directionCodes = "";
			
			// code for IE
			if (window.ActiveXObject) {
				
				var nodes=xmlDoc.selectNodes(xmlQuery);
				for(i=0;i<nodes.length;i++) {
					
					if(i==0) {
						mod = "";
					} else {
						mod = ",";
					}
					directionNames += mod + nodes[i].getAttribute('Name')
					directionCodes += mod + nodes[i].getAttribute('Code');
					
				}
			
			// code for Mozilla, Firefox, Opera, etc.
			} else if (document.implementation && document.implementation.createDocument) {
			
				var nodes=xmlDoc.evaluate(xmlQuery, xmlDoc, null, XPathResult.ANY_TYPE, null);
				var result=nodes.iterateNext();
				
				/*
				while(result) {
					document.write(result.getAttribute('Name'));
					document.write("<br />");
					directions += result.getAttribute('Name');
					result=nodes.iterateNext();
				}
				*/
				
				i=0;
				while(result) {
					
					if(i==0) {
						mod = "";
					} else {
						mod = ",";
					}
					directionNames += mod + result.getAttribute('Name');
					directionCodes += mod + result.getAttribute('Code');
					
					i++;
					
					result=nodes.iterateNext();
					
				}
				
				
			}
			
			//alert(directions);
			
			var directionNameArray = directionNames.split(','); 
			var directionCodeArray = directionCodes.split(','); 
			//alert(directionArray.length);
			
			// Get direction list length and populate direction array based on selections from above menus.
			for (a=0;a<directionNameArray.length;a++) {
								
				theForm.directions.options[a+1] = new Option(directionNameArray[a], directionCodeArray[a]);
				
			}
			//***END WORKING***//
			
			theForm.directions.options[0].selected = true;
			
			// Remove options in menu below this one upon selecting a new item from this one.
	  		resetStops(theForm);
			
			
			return false;
			
		  // If Agency has a Direction value of "False" populate Stop menu with appropriate values.
		  } else {
			
			// Since no direction selection is required and therefore will not be made, automatically update the appropriate stops list.
			updateStops(theForm);
			
			return false;
			
		  }
		  
	  }
	  
	}
	// END Load Directions menu.
	
	// START Load Stops menu.
	function updateStops(theForm) {
	  
	  theForm.stops1.disabled = false;
	  document.getElementById("error_msg1").innerHTML = "";
	  
	  // If Directions menu is showing and an invalid item in select list is chosen, reset this menu.
	  if(document.getElementById("directionField").style.display == "block" && theForm.directions.selectedIndex == 0) {
		resetStops(theForm);
		return false;
	  }
	  
	  var agencySelection = theForm.agencies.value;
	  var routeSelection = theForm.routes.value;
	  var directionSelection = theForm.directions.value;
	  
	  // Load Stops list.
	  xmlDoc=loadXMLDoc("/inc/xml_proxy.asp?service=GetStopsForRoute.aspx&agencyName="+agencySelection+"&routeSelection="+routeSelection+"&directionSelection="+directionSelection);
	  stopItem=xmlDoc.getElementsByTagName('Stop');
	  
	  theForm.stops1.options.length = 0;
	  
	  // Get Stop list length and populate Stop array from determined xml file in the line above based on selection from previous menus.
		  
	  //alert(stopItem.length);
	  
	  for (i=0;i<stopItem.length;i++) {
		
		stopAttribute=xmlDoc.getElementsByTagName('Stop')[i].attributes;
		stops[i] = stopAttribute.getNamedItem("name").nodeValue;
		stopsCode[i] = stopAttribute.getNamedItem("StopCode").nodeValue;
		//alert(stops.sort());
		//alert(stopsCode[i]);
		
		theForm.stops1.options[i+1] = new Option(stops[i], stopsCode[i]);
		
	  }
		  
	  // Sort the Stops menu alphabetically since the data in the xml is not sorted
	  var fieldToSort = theForm.stops1;
	  fieldTextArray = new Array();
	  fieldValArray = new Array();
	  fieldTextOldArray = new Array();
	
	  for(i=0; i<fieldToSort.length; i++) {
		fieldTextArray[i] = fieldToSort.options[i].text;
		fieldValArray[i] = fieldToSort.options[i].value;
		fieldTextOldArray[i] = fieldToSort.options[i].text;
	  }
	
	  fieldTextArray.sort();
	
	  for(i=0; i<fieldToSort.length; i++) {
		 fieldToSort.options[i].text = fieldTextArray[i];
		 for(j=0; j<fieldToSort.length; j++) {
			 if (fieldTextArray[i] ==fieldTextOldArray[j]) {
				 fieldToSort.options[i].value = fieldValArray[j];
				 j = fieldToSort.length;
			  }
		  }
	  }
	  
	  theForm.stops1.options[0] = new Option("Select a Stop", "");
	  theForm.stops1.options[0].selected = true;
	  
	}
	// END Load Stops menu.
	
// END UPDATE MENU FUNCTIONS


// START RESET MENU FUNCTIONS
	
	function resetAgencies(theForm) {
	
	  // Reset agencies menu.
	  theForm.agencies.options[0] = new Option("Select an Agency", "");
	  for (var i=0; i<agencies.length; i++) {
		theForm.agencies.options[i+1] = new Option(agencies[i], agencies[i]);
	  }
	  theForm.agencies.options[0].selected = true;
	  
	}
	
	function resetRoutes(theForm) {
	
	  theForm.routes.disabled = true;
	
	  // Reset routes menu.
	  theForm.routes.options[0] = new Option("Select a Route", "");
	  for (var i=0; i<routes.length; i++) {
		theForm.routes.options[i+1] = new Option(routes[i], routes[i]);
	  }
	  theForm.routes.options[0].selected = true;
	  
	  // Remove options from this menu upon selecting a new item from a menu above.
	  for (var a=theForm.routes.options.length-1; a>=1; a--) {
		  var x=theForm.routes;
		  x.options[a] = null;
	  }
	  
	}
	
	function resetDirections(theForm) { 
	
	  theForm.directions.disabled = true
	
	  // Reset directions menu.
	  theForm.directions.options[0] = new Option("Select a Direction", "");
	  for (var i=0; i<directions.length; i++) {
		theForm.directions.options[i+1] = new Option(directions[i], directions[i]);
	  }
	  theForm.directions.options[0].selected = true;
	  
	  // Remove options from this menu upon selecting a new item from a menu above.
	  for (var a=theForm.directions.options.length-1; a>=1; a--) {
		  var x=theForm.directions;
		  x.options[a] = null;
	  }
	  
	}
	
	function resetStops(theForm) {
	
	  theForm.stops1.disabled = true;
	
	  // Reset stops menu.
	  theForm.stops1.options[0] = new Option("Select a Stop", "");
	  for (var i=0; i<stops.length; i++) {
		theForm.stops1.options[i+1] = new Option(stops[i], stops[i]);
	  }
	  theForm.stops1.options[0].selected = true;
	  
	  // Remove options from this menu upon selecting a new item from a menu above.
	  for (var a=theForm.stops1.options.length-1; a>=1; a--) {
		  var x=theForm.stops1;
		  x.options[a] = null;
	  }
	
	}
	
	function resetForm(theForm) {
	
	  resetAgencies(theForm);
	  resetRoutes(theForm);
	  resetDirections(theForm);
	  resetStops(theForm);
	  theForm.agencies.value == "";
	  document.getElementById("SelectRadioBtn1").checked = true;
	  document.getElementById("stops2").value = "";
	  document.getElementById("routeField").style.display = "block";
	  document.getElementById("directionField").style.display = "block";
	  
	}

// END RESET MENU FUNCTIONS


// START GET RESULTS FOR AGENCY SELECT
	
	function getResults_AgencySelect(theForm) {
	
		// Check for correct Transit Agency existance
		if (theForm.agencies.selectedIndex == 0) {
			document.getElementById("error_msg1").innerHTML = "Error: Transit Agency is required.";
			theForm.agencies.focus();
			return false;
		} else {
			document.getElementById("error_msg1").innerHTML = "";
		}
		
		// Check for correct Route existance
		if (document.getElementById("routeField").style.display == "block" && theForm.routes.selectedIndex == 0) {
			document.getElementById("error_msg1").innerHTML = "Error: Route is required.";
			theForm.routes.focus();
			return false;
		} else {
			document.getElementById("error_msg1").innerHTML = "";
		}
		
		// Check for correct Direction existance
		if (document.getElementById("directionField").style.display == "block" && theForm.directions.selectedIndex == 0) {
			document.getElementById("error_msg1").innerHTML = "Error: Direciton is required.";
			theForm.directions.focus();
			return false;
		} else {
			document.getElementById("error_msg1").innerHTML = "";
		}
		
		// Check for correct Stop existance
		if (theForm.stops1.selectedIndex == 0) {
			document.getElementById("error_msg1").innerHTML = "Error: Stop is required.";
			theForm.stops1.focus();
			return false;
		} else {
			document.getElementById("error_msg1").innerHTML = "";
		}
		
		getResults(theForm);
	
	}
	
// END GET RESULTS FOR AGENCY SELECT

// START GET RESULTS FOR STOP ID LOOKUP
	
	function getResults_StopIDLookup(theForm) {
		
		// Check for correct Stop existance
		if (theForm.stops2.value == "") {
			document.getElementById("error_msg2").innerHTML = "Error: Stop ID is required.";
			theForm.stops2.focus();
			return false;
		} else {
			document.getElementById("error_msg2").innerHTML = "";
		}
		
		// Check if Stop is numeric
		if (theForm.stops2.value == null || !theForm.stops2.value.toString().match(/^[-]?\d*\.?\d*$/)) {
		document.getElementById("error_msg2").innerHTML = "Error: Stop ID must be numeric.";
		theForm.stops2.focus();
		return false;
		} else {
			document.getElementById("error_msg2").innerHTML = "";
		}
		
		getResults(theForm);
	
	}
	
// END GET RESULTS FOR STOP ID LOOKUP

// START GET RESULTS

	function getResults(theForm) {
		
		if(typeof directionFieldVal != "undefined" && directionFieldVal == "") {
			agenciesHasDirectionValue = "False";
		} else {
			agenciesHasDirectionValue = "True";	
		}
		
		//alert(agenciesHasDirectionValue);
		
		// Set the value of the selected agency
		// if this is a StopID search
		if(typeof(theForm.agencies) == 'undefined') {
			//alert("ID item");
			agencyValue = document.getElementById("agencies").value;
		// if this is not a StopID search
		} else {
			agencyValue = theForm.agencies.value;
		}
		
		if(typeof(theForm.routes) == 'undefined') {
			//alert("ID item");
			routeValue = document.getElementById("routes").value;
		// if this is not a StopID search
		} else {
			routeValue = theForm.routes.value;
		}
		
		//alert(document.getElementById("agencies").value.indexOf("BART"));
		//alert(theForm.agencies.value.indexOf("BART"));
		
		//START Set cookies
		if(document.getElementById("SelectRadioBtn1").checked) {
			
			agencyFieldVal = document.getElementById("agencies").options[document.getElementById("agencies").selectedIndex].text;
			agencyFieldIndex = document.getElementById("agencies").selectedIndex;
			routeFieldVal = document.getElementById("routes").options[document.getElementById("routes").selectedIndex].text;
			routeFieldValue = document.getElementById("routes").value;
			routeFieldIndex = document.getElementById("routes").selectedIndex;
			directionFieldVal = document.getElementById("directions").value;
			directionFieldIndex = document.getElementById("directions").selectedIndex;
			stopFieldVal = document.getElementById("stops1").options[document.getElementById("stops1").selectedIndex].text;
			stopFieldIndex = document.getElementById("stops1").selectedIndex;
			
			var exdate=new Date();
			exdate.setDate(exdate.getDate() + 1);
			expireDate = exdate.toUTCString();
			
			del_cookie('511.org-StopIDSearch');
			
			document.cookie = "511.org-AgencySearch=yes; expires=" + expireDate;
			document.cookie = "511.org-AgencyFieldVal" + "=" + agencyFieldVal + "; expires=" + expireDate;
			document.cookie = "511.org-AgencyFieldIndex" + "=" + agencyFieldIndex + "; expires=" + expireDate;
			document.cookie = "511.org-RouteFieldVal" + "=" + routeFieldVal + "; expires=" + expireDate;
			document.cookie = "511.org-RouteFieldValue" + "=" + routeFieldValue + "; expires=" + expireDate;
			document.cookie = "511.org-RouteFieldIndex" + "=" + routeFieldIndex + "; expires=" + expireDate;
			document.cookie = "511.org-DirectionFieldVal" + "=" + directionFieldVal + "; expires=" + expireDate;
			document.cookie = "511.org-DirectionFieldIndex" + "=" + directionFieldIndex + "; expires=" + expireDate;
			document.cookie = "511.org-StopFieldVal" + "=" + stopFieldVal + "; expires=" + expireDate;
			document.cookie = "511.org-StopFieldIndex" + "=" + stopFieldIndex + "; expires=" + expireDate;
			
			//document.cookie = "511.org-AgencyValue" + "=" + agencyValue + "; expires=" + expireDate;
			//document.cookie = "511.org-RouteValue" + "=" + routeValue + "; expires=" + expireDate;
			
		} else if(document.getElementById("SelectRadioBtn4").checked) {
			
			stopFieldVal2 = document.getElementById("stops2").value;
			
			var exdate=new Date();
			exdate.setDate(exdate.getDate() + 1);
			expireDate = exdate.toUTCString();
			
			del_cookie('511.org-AgencySearch');
			del_cookie('511.org-AgencyFieldVal');
			del_cookie('511.org-AgencyFieldIndex');
			del_cookie('511.org-RouteFieldVal');
			del_cookie('511.org-RouteFieldValue');
			del_cookie('511.org-RouteFieldIndex');
			del_cookie('511.org-DirectionFieldVal');
			del_cookie('511.org-DirectionFieldIndex');
			del_cookie('511.org-StopFieldVal');
			del_cookie('511.org-StopFieldIndex');
			
			document.cookie = "511.org-StopIDSearch=yes; expires=" + expireDate;
			document.cookie = "511.org-StopFieldVal2" + "=" + stopFieldVal2 + "; expires=" + expireDate;
			
			//document.cookie = "511.org-AgencyValue" + "=" + agencyValue + "; expires=" + expireDate;
			//document.cookie = "511.org-RouteValue" + "=" + routeValue + "; expires=" + expireDate;
			
		/*} else {
		
			var stopFieldVal1=getCookie("511.org-StopField1");
			var stopFieldVal2=getCookie("511.org-StopField2");
			var AgencyVal=getCookie("511.org-AgencyValue");
			var RouteVal=getCookie("511.org-RouteValue");
			
			if (stopFieldVal1 != null && stopFieldVal1 != "")  {
				stopSelection = stopFieldVal1;
			} else if (stopFieldVal2 != null && stopFieldVal2 != "")  {
				stopSelection = stopFieldVal2;
			}
			agencyValue = AgencyVal;
			routeValue = RouteVal;
			cookieBasedSearch = 'yes';
			*/
			
		}
		//END Set cookies
		
		if(document.getElementById("SelectRadioBtn1").checked) {
			
			var stopSelection = document.getElementById('stops1').value;
			//alert("stop selection 1: "+stopSelection);
			//var stopSelection_Mod = stopSelection.replace(/,/g, ", ");
			//alert("stop selection 1 with spaces: "+stopSelection_Mod);
			
			// Load Agency list. 
			loadAgencyList();
			
			// Determine if agency has a direction value and set var.
			for (i=0;i<agencyItem.length;i++) {
			
			  agencyAttribute=xmlDoc.getElementsByTagName('Agency')[i].attributes;
			  agenciesHasDirection[i] = agencyAttribute.getNamedItem("HasDirection").nodeValue;
			  
			  var agenciesHasDirectionValue = agenciesHasDirection[document.getElementById('agencies').selectedIndex-1];
			  
			}
			
		} else if(document.getElementById("SelectRadioBtn4").checked) {
			
			var stopSelection = document.getElementById('stops2').value;
			//alert("stop selection 2: "+stopSelection);
			
		}
		
		randNum = Math.random();
		//alert(stopSelection);
		
		xmlDoc=loadXMLDoc("/inc/xml_proxy.asp?service=GetNextDeparturesByStopCode.aspx&stopCode="+stopSelection+"&rand="+randNum);
		
		agencyItem=xmlDoc.getElementsByTagName('Agency');
		//alert(agencyItem.length);
		
		if(agencyItem.length > 0) {
			for (i=0;i<agencyItem.length;i++) {
			
			  agencyAttribute=xmlDoc.getElementsByTagName('Agency')[i].attributes;
			  agencyMode[i]=agencyAttribute.getNamedItem("Mode").nodeValue;
			  
			}
		}
		
		//alert(agencyMode);
		
		//Set the departure times lists
		routeList=xmlDoc.getElementsByTagName('Route');
		departureTimesList=xmlDoc.getElementsByTagName('DepartureTimeList');
		
		//alert(routeList.length);
		
		// START Get unique Stop Codes
		var departureStopCode = new Array();
		Array.prototype.unique = function () {
			var r = new Array();
			o:for(var i = 0, n = this.length; i < n; i++)
			{
				for(var x = 0, y = r.length; x < y; x++)
				{
					if(r[x]==this[i])
					{
						continue o;
					}
				}
				r[r.length] = this[i];
			}
			return r;
		}
		
		for (i=0;i<routeList.length;i++) {
			stopCodeAttribute=xmlDoc.getElementsByTagName('Stop')[i].attributes;
			departureStopCode[i] = stopCodeAttribute.getNamedItem("StopCode").nodeValue;
		}
		
		var arr = departureStopCode;
		var uniqueStopCodes = arr.unique();
		var stopCodeLength = uniqueStopCodes.length;
		uniqueStopCodes = uniqueStopCodes.sort(function(a,b){return a - b});
		
		for (i=0;i<uniqueStopCodes.length;i++) {
			
			if(uniqueStopCodes.length == 1) {
				uniqueStopCodesModifier = "";
			} else if(uniqueStopCodes.length > 1) {
				if(i==0) {
					uniqueStopCodesModifier = "";
				} else {
					uniqueStopCodesModifier = " & ";
				}
			}
			
			uniqueStopCodes[i] = uniqueStopCodesModifier + uniqueStopCodes[i];
			
		}
		
		uniqueStopCodes = uniqueStopCodes.join ( "" );
		
		//alert(uniqueStopCodes);
		// END Get unique Stop Codes
		
		// START Get Departure Time list length and populate Departure Time array from determined xml file based on selection from previous menu.				
		if(routeList.length > 0) {
				
			for (i=0;i<routeList.length;i++) {
				
				stopList = routeList[i].getElementsByTagName('Stop');
				stopCount = stopList.length;
				//alert("stops count: " + stopCount);		
				
				depTimesList = routeList[i].getElementsByTagName('DepartureTimeList');
				
				routeNameAttribute=xmlDoc.getElementsByTagName('Route')[i].attributes;
				routeName[i] = routeNameAttribute.getNamedItem("Name").nodeValue;
				
				routeName[i] = routeName[i].toUpperCase();
				
				if(document.getElementById("SelectRadioBtn1").checked && agenciesHasDirectionValue == "True") {
					
					routeDirectionAttribute=xmlDoc.getElementsByTagName('RouteDirection')[i].attributes;
					routeDirection[i] = routeDirectionAttribute.getNamedItem("Code").nodeValue;
					
					routeDirection[i] = " - " + routeDirection[i].toUpperCase();
					
				} else {
				
					routeDirection[i] = "";
					
				}
				
				stopNameAttribute=xmlDoc.getElementsByTagName('Stop')[i].attributes;
				departureStopName[i] = stopNameAttribute.getNamedItem("name").nodeValue;
				
				// Set stopCodeDisplay
				if(agenciesHasDirectionValue == "False") {
					stopCodeDisplay = " (" + departureStopCode[i] + ")";
				} else {
					stopCodeDisplay = "";
				}
				
				routeName_routeDirection = routeName[i] + routeDirection[i];
				
				routeName_stopCode[i] = routeName_routeDirection + stopCodeDisplay;
				routeName_stopCode_pop[i] = routeName_stopCode[i];
				
				if (document.getElementById("SelectRadioBtn1").checked) {
					if((typeof document.getElementById("stops1") != 'undefined' && document.getElementById("stops1").value != "") || (typeof agencySearch != "undefined" && agencySearch == "yes")) {
						if(typeof agencySearch != "undefined" && agencySearch == "yes") {
							stopsTextValue = stopFieldVal;
						} else {
							stopsTextValue = document.getElementById("stops1").options[document.getElementById("stops1").selectedIndex].text;
						}
					} else {
						stopsTextValue = decodeURIComponent(document.getElementById("stopsTextValue").value);
					}
				} else {
					stopsTextValue = departureStopName[i];
				}
				
				// Set pluralModifier
				if(agenciesHasDirectionValue == "False") {
					if(stopCodeLength > 1) {
						pluralModifier = "'s";
					} else {
						pluralModifier = "";
					}
				} else {
					pluralModifier = "";
				}
				
				if(typeof(theForm.routes) != 'undefined' || (typeof agencySearch != "undefined" && agencySearch == "yes")) {
					if(typeof agencySearch != "undefined" && agencySearch == "yes") {
						routesTextValue = routeFieldVal;
					} else {
						routesTextValue = theForm.routes.options[theForm.routes.selectedIndex].text;
					}
					
				} else {
					routesTextValue = decodeURIComponent(document.getElementById("routes").options[document.getElementById("routes").selectedIndex].text);
				}
			
				// Set up secondary results section
				if (document.getElementById("SelectRadioBtn1").checked) {
					
					var primaryItem;
					
					//alert("Selected Val: " + routesTextValue.toUpperCase() + " - Returned Val: " + routeName[i]);
					
					// START Load Departure Times list for the Route selected and the Stop selected only
					if (routesTextValue.toUpperCase() == routeName[i]) {					
						
						var chosenIDNum = i;
						
						var chosenRouteData = "";
						
						for (a=0;a<stopCount;a++) {
														
							if(agenciesHasDirectionValue == "True") {
								
								
								routeDirectionAttribute=routeList[i].getElementsByTagName('RouteDirection')[a].attributes;
								routeDirection[a] = routeDirectionAttribute.getNamedItem("Name").nodeValue;
								//alert(routeDirection[a]);
														
								//routeName_routeDirection = routeName[i] + routeDirection[a].toUpperCase();
					
								//routeName_stopCode[a] = routeName_routeDirection + stopCodeDisplay;
								
								routeName_stopCode_Chosen = routeName[i] + " - " + routeDirection[a].toUpperCase() + stopCodeDisplay;
								routeName_stopCode_Chosen_pop = routeName_stopCode_Chosen
								
							} else {
								
								routeName_stopCode_Chosen = routeName[i] + " - " + stopCodeDisplay;
								routeName_stopCode_Chosen_pop = routeName_stopCode_Chosen
								
							}
							
							chosenRouteData += "<span class='real_time_departures_results_minutes_chosen'>";
							if(routeName_stopCode_Chosen.length > 35) routeName_stopCode_Chosen = routeName_stopCode_Chosen.substring(0,34) + "...";
								
							chosenRouteData += "<a href='javascript:void(0);' title='" + routeName_stopCode_Chosen_pop + "'><div class='ellipsis'>" + routeName_stopCode_Chosen + "</div></a>";
							
							chosenRouteData += "<span class='real_time_departures_results_departures'>";
								
							// START Set the departure times in a comma delimeted list for each route		
							
							// code for IE
							if (window.ActiveXObject) {
								
								for(j = 0; j < depTimesList[a].childNodes.length; j++) {
									
									if(depTimesList[a].childNodes.length == 1) {
										departureModifier = "";
									} else if(depTimesList[a].childNodes.length == 2 && j == 0) {
										departureModifier = ", ";
									} else if(depTimesList[a].childNodes.length >= 3 && (j == 0 || j == 1)) {
										departureModifier = ", ";
									} else {
										departureModifier = "";
									}
										
									departureTime = depTimesList[a].childNodes[j].firstChild.nodeValue;
									
									if(departureTime == 0 || departureTime == 1) {
										departureTime = "<2";
									}
										
									if(j < 3) {
										chosenRouteData += departureTime + departureModifier;
									}	
								
								}
								
								
							// code for Mozilla, Firefox, Opera, etc.
							} else if (document.implementation && document.implementation.createDocument) {
													
								if(depTimesList[a].childNodes.length <= 3) {
									
									depTimesNodeNums = 1;
									
								} else if(depTimesList[a].childNodes.length <= 5) {
									
									depTimesNodeNums = 2;
									
								} else {
									
									depTimesNodeNums = 3;
									
								}
								
								//alert(depTimesNodeNums);
								
								for(j = 0; j < depTimesNodeNums; j++) {	
								
									if(depTimesNodeNums == 1) {
										departureModifier = "";
									} else if(depTimesNodeNums == 2 && j == 0) {
										departureModifier = ", ";
									} else if(depTimesNodeNums >= 3 && (j == 0 || j == 1)) {
										departureModifier = ", ";
									} else {
										departureModifier = "";
									}
								
									nodeMain = depTimesList[a].childNodes[j];
									
									//alert("Type: " + nodeMain.nodeType + "\nName: " + nodeMain.nodeName + "\nValue: " + nodeMain.nodeValue);
									if(typeof nodeMain != "undefined") {
										
										nodeContainer = nodeMain.nextSibling;
										if(nodeMain.nodeType == 1) {
											
											nodeContainer = nodeContainer.nextSibling;
											
										} else if(j == 2 && nodeMain.nodeType == 3) {
											
											nodeContainer = nodeContainer.nextSibling;
											nodeContainer = nodeContainer.nextSibling;
											
										}
										
										//alert("Type: " + nodeContainer.nodeType + "\nName: " + nodeContainer.nodeName + "\nValue: " + nodeContainer.firstChild.nodeValue);
										departureTime = nodeContainer.firstChild.nodeValue;
										
										if(departureTime == 0 || departureTime == 1) {
											departureTime = "<2";
										}
											
										if(j < 3) {
											chosenRouteData += departureTime + departureModifier;
										}	
										
									} else {
										
										departureTime = "";
										chosenRouteData += departureTime + departureModifier;
										
									}
								
								}

							}
								
							// END Set the departure times in a comma delimeted list for each route
							
							if(window.ActiveXObject && depTimesList[a].childNodes.length == 0) {
								chosenRouteData += "<a href='javascript:void(0);' title='No data available'>No data avail...</a>";
							} else if(!window.ActiveXObject && typeof nodeMain == "undefined") {
								chosenRouteData += "<a href='javascript:void(0);' title='No data available'>No data avail...</a>";
							} else {
								chosenRouteData += " min.";
							}
								
							chosenRouteData += "</span>";
							
							chosenRouteData += "<br>";
							
							chosenRouteData += "</span>";

						}
							
						chosenRouteData += "<div style='margin-top: 20px;'></div>";
						if (routeList.length > 1) {
							chosenRouteData += "<div style='font-size: 12px;'><u>Other routes serving this stop:</u></div>";
						}
						chosenRouteData += "<div style='margin-top: 5px;'></div>";
						
						//Set that the primary item has been set already
						primaryItem = "set";
					
					} else {
					
						
						
					}
											
					// ELSE Load Route selected and the "No data available" message	
					if(primaryItem != "set") {
						
						var chosenRouteData = "<span class='real_time_departures_results_minutes_chosen'>";
							chosenRouteData += routesTextValue.toUpperCase();
							chosenRouteData += "<span class='real_time_departures_results_departures'>"
								chosenRouteData += "No data available";
							chosenRouteData += "</span>";
						chosenRouteData += "</span>";
						
						chosenRouteData += "<div style='margin-top: 20px;'></div>";
						chosenRouteData += "<div style='font-size: 12px;'><u>Other routes serving this stop:</u></div>";
						chosenRouteData += "<div style='margin-top: 5px;'></div>";
						
					}
					// END Load Departure Times list for the Route selected and the Stop selected only

				} else {
					
					var chosenRouteData = "";
					
				}
			
			}
		
			for (i=0;i<routeList.length;i++) {	
				
				resultsContent = "<span class='real_time_departures_results_head'>Next departures at "+ stopsTextValue +", Stop ID" + pluralModifier + " " + uniqueStopCodes + ":</span>";
				
				resultsContent += "<div style='margin-top: 10px;'></div>";
				
				resultsContent += "<div class='real_time_departures_results_container'>";
				
				resultsContent += chosenRouteData;
				
				// START Load Departure Times list for all other Routes for the selected Stop other than selected Route
				for (a=0;a<routeList.length;a++) {
					
					//alert(a);
											
					depTimesList = routeList[a].getElementsByTagName('DepartureTimeList');
					
					stopList = routeList[a].getElementsByTagName('Stop');
					stopCount = stopList.length;
					//alert("stops count: " + stopCount);

					if(chosenRouteData == "") {
						resultsContent += "<span class='real_time_departures_results_minutes_chosen'>";
					} else {
						resultsContent += "<span class='real_time_departures_results_minutes'>";
					}
					
					if(a != chosenIDNum) {
						
						// START Load Departure Times list for all other Routes for the selected Stop other than selected Route
						for (b=0;b<stopCount;b++) {	
						
							if(agenciesHasDirectionValue == "True" || document.getElementById("SelectRadioBtn2").checked || (typeof stopIDSearch != "undefined" && stopIDSearch == "yes")) {
							
								if(routeList[a].getElementsByTagName('RouteDirection')[b] != null) {
									
									routeDirectionAttribute = routeList[a].getElementsByTagName('RouteDirection')[b].attributes;
									routeDirection[b] = routeDirectionAttribute.getNamedItem("Name").nodeValue;
									routeDirection_pop[b] = routeDirection[b];
									//alert(routeDirection[b]); 
									//alert(routeName[a].length + routeDirection[b].length);
									
									if(document.getElementById("SelectRadioBtn2").checked) {
									
										truncVal = 31 - routeName[a].length;
									
									} else {
									
										truncVal = 33 - routeName[a].length;
									
									}
									
									if((routeName[a].length + routeDirection[b].length) > 35) routeDirection[b] = routeDirection[b].substring(0,truncVal) + "...";
									//alert(routeDirection[b]);
									
									resultsContent += "<a href='javascript:void(0);' title='" + routeName[a] + " - " + routeDirection_pop[b].toUpperCase() + stopCodeDisplay + "'><span class='ellipsis" + a + "'>" + routeName[a] + " - " + routeDirection[b].toUpperCase() + stopCodeDisplay + "</span></a>";
									
								} else {
									
									if(depTimesList[b].childNodes.length > 0) {
										resultsContent += routeName[a] + stopCodeDisplay;
									} else {
										resultsContent += "<div style='margin-top: -11px;'></div>	";
									}
									
								}
							
							} else {
								
								if(routeName_stopCode[a].length > 35) routeName_stopCode[a] = routeName_stopCode[a].substring(0,34) + "...";
								
								if(depTimesList[b].childNodes.length > 0) {
									resultsContent += "<a href='javascript:void(0);' title='" + routeName_stopCode_pop[a] + "'><span class='ellipsis" + a + "'>" + routeName_stopCode[a] + "</span></a>";
								} else {
									resultsContent += "<div style='margin-top: -11px;'></div>	";
								}								
								
							}
							
							if(depTimesList[b].childNodes.length > 0) {
						
								resultsContent += "<span class='real_time_departures_results_departures'>";
											
								// START Set the departure times in a comma delimeted list for each route
								
								// code for IE
								if (window.ActiveXObject) {
									
									// START Set the departure times in a comma delimeted list for each route
									for(j = 0; j < depTimesList[b].childNodes.length; j++) {
										
										if(depTimesList[b].childNodes.length == 1) {
											departureModifier = "";
										} else if(depTimesList[b].childNodes.length == 2 && j == 0) {
											departureModifier = ", ";
										} else if(depTimesList[b].childNodes.length >= 3 && (j == 0 || j == 1)) {
											departureModifier = ", ";
										} else {
											departureModifier = "";
										}
											
										departureTime = depTimesList[b].childNodes[j].firstChild.nodeValue;
										
										if(departureTime == 0 || departureTime == 1) {
											departureTime = "<2";
										}
											
										if(j < 3) {
											resultsContent += departureTime + departureModifier;
										}	
									
									}
									// END Set the departure times in a comma delimeted list for each route
									
								// code for Mozilla, Firefox, Opera, etc.
								} else if (document.implementation && document.implementation.createDocument) {	
							
									if(depTimesList[b].childNodes.length <= 3) {
										
										depTimesNodeNums = 1;
										
									} else if(depTimesList[b].childNodes.length <= 5) {
										
										depTimesNodeNums = 2;
										
									} else {
										
										depTimesNodeNums = 3;
										
									}
									
									for(j = 0; j < depTimesNodeNums; j++) {
										
										if(depTimesNodeNums == 1) {
											departureModifier = "";
										} else if(depTimesNodeNums == 2 && j == 0) {
											departureModifier = ", ";
										} else if(depTimesNodeNums >= 3 && (j == 0 || j == 1)) {
											departureModifier = ", ";
										} else {
											departureModifier = "";
										}
										
										nodeMain = depTimesList[b].childNodes[j];
										
										if(typeof nodeMain != "undefined") {
											
											//alert("Type: " + nodeMain.nodeType + "\nName: " + nodeMain.nodeName + "\nValue: " + nodeMain.nodeValue);
											nodeContainer = nodeMain.nextSibling;
											if(nodeMain.nodeType == 1) {
												
												nodeContainer = nodeContainer.nextSibling;
												
											} else if(j == 2 && nodeMain.nodeType == 3) {
												
												nodeContainer = nodeContainer.nextSibling;
												nodeContainer = nodeContainer.nextSibling;
												
											}
	
											//alert("Type: " + nodeContainer.nodeType + "\nName: " + nodeContainer.nodeName + "\nValue: " + nodeContainer.firstChild.nodeValue);
											departureTime = nodeContainer.firstChild.nodeValue;
											
											if(departureTime == 0 || departureTime == 1) {
												departureTime = "<2";
											}
											
											if(j < 3) {
												resultsContent += departureTime + departureModifier;
											}
											
										}
									
									}
	
								}
	
								// END Set the departure times in a comma delimeted list for each route
							
								if(window.ActiveXObject && depTimesList[b].childNodes.length == 0) {
									resultsContent += "<a href='javascript:void(0);' title='No data available'>No data avail...</a>";
								} else if(!window.ActiveXObject && typeof nodeMain == "undefined") {
									resultsContent += "<a href='javascript:void(0);' title='No data available'>No data avail...</a>";
								} else {
									resultsContent += " min.";
								}
							
								resultsContent += "</span>";
								
							} else if(agencyMode != "Rail") {
							
								resultsContent += "<span class='real_time_departures_results_departures'>";
								
									resultsContent += "<a href='javascript:void(0);' title='No data available'>No data avail...</a>";
							
								resultsContent += "</span>";
								
							}
							
							if(stopCount == 2) {
								resultsContent += "<br>";
							}

						}
						
						if(stopCount != 2) {
							resultsContent += "<br>";
						}
							
					}
					// END Load Departure Times list for all other Routes for the selected Stop other than selected Route
					
					resultsContent += "</span>";
					

				}
				
				resultsContent += "</div>";
				
				resultsContent += "<div style='margin-top: 10px;'></div>";
				
				//resultsContent += "<span class='real_time_departures_results_head'><a href='http://transit.511.org/511departuretimes.aspx'>Learn more about stop IDs</a>";
				/*
				resultsContent += "<div style='position: absolute; top: 194px; left: 153px;'>";
					resultsContent += "<form name='DepartureTimesLookup_AgencySelect_refresh' id='DepartureTimesLookup_AgencySelect_refresh' action='javascript:void(0);' method='post'>";
						resultsContent += "<input type='hidden' name='stops' id='stops' value="+stopSelection+">";
						resultsContent += "<input type='hidden' name='stopsTextValue' id='stopsTextValue' value=" + encodeURIComponent(stopsTextValue) +">";
						resultsContent += "<input type='hidden' name='agencies' id='agencies' value=" + agencyValue + ">";
						resultsContent += "<input type='hidden' name='routes' id='routes' value=" + routeValue +">";
						resultsContent += "<input type='hidden' name='refresh' id='refresh' value='yes'>";
					resultsContent += "</form>";
				resultsContent += "</div>";
				*/
				
				resultsContent += "</span>";
				
				//resultsContent += "<div style='position: absolute; top: 193px; left: 249px;>";
				//resultsContent += "<div style='position: absolute; top: 180px; left: 249px;>";
					//resultsContent += "<span class='real_time_departures_results'><a href='javascript:void(0);' onclick='startOver_agencySelect();'><input type='image' src='img/buttons/button-start-over.gif' alt='start-over' id='start-over' onmouseover=MM_swapImage('start-over','','img/buttons/button-start-over_over.gif',1) onmouseout='MM_swapImgRestore()' /></a></span>";
					resultsContent += "<span class='real_time_departures_results_refresh_results'>";
						//resultsContent += "<button type='submit' class='buttonAsLink' onclick=javascript:getResults('DepartureTimesLookup_AgencySelect_refresh'); /><span>Refresh results</span></button>";
						resultsContent += "<a href='javascript:void(0);' onClick=getResults('DepartureTimesLookup_AgencySelect'); style='font-size: 12px; font-weight: bold;'>Refresh results</a>";
					resultsContent += "</span>";
					resultsContent += "<span class='real_time_departures_results_pipe'>";
						resultsContent += "|";
					resultsContent += "</span>";
					resultsContent += "<span class='real_time_departures_results_start_over'>";
						resultsContent += "<a href='javascript:void(0);' onclick='startOver_agencySelect();' style='font-size: 12px; font-weight: bold;'>Start over</a>"
					resultsContent += "</span>";
				resultsContent += "</div>";
					
				
				resultsContent += "</div>";
				
				document.getElementById("form-holder_results").innerHTML = resultsContent;

				if(document.getElementById("SelectRadioBtn1").checked) {
					showResults_agencySelect();
				} else if(document.getElementById("SelectRadioBtn4").checked) {
					showResults_stopIDLookup();
				}
				
				//return false;
				
			}
				
		// Else if no Stop found display none found message.
		} else {
			
			//alert("not found");
			
			// Display Departure Times based on stop selection.
			
			if (typeof(theForm.agencies) != "undefined" && typeof(theForm.routes) != "undefined") {
				
				resultsContent = "<span class='real_time_departures_results_head'>No results for the "+ agencyValue +" - "+ theForm.routes.value +" line at the "+ theForm.stops1.options[theForm.stops1.selectedIndex].text + " stop.</span>";
				resultsContent += "<div class='real_time_departures_results_start_over'>";
				//resultsContent += "<div style='position: absolute; top: 167px; left: 259px;'>";
					resultsContent += "<a href='javascript:void(0);' onclick='startOver_agencySelect();' style='font-size: 12px; font-weight: bold;'>Start over</a><br>";
				resultsContent += "</div>";
				
			} else {
				
				resultsContent = "<span class='real_time_departures_results_head'>No results for the stop "+ document.getElementById('stops2').value + "</span>";				
				resultsContent += "<div class='real_time_departures_results_start_over'>";			
				//resultsContent += "<div style='position: absolute; top: 167px; left: 259px;'>";
					resultsContent += "<a href='javascript:void(0);' onclick='startOver_stopIDLookup();' style='font-size: 12px; font-weight: bold;'>Start over</a><br>";
				resultsContent += "</div>";
			
			}
			
			document.getElementById("form-holder_results").innerHTML = resultsContent;
			
			if (typeof(theForm.agencies) != "undefined" && typeof(theForm.routes) != "undefined") {
				showResults_agencySelect();
			} else {
				showResults_stopIDLookup();
			}
			
			return false;
			
		}
		// END Get Departure Time list length and populate Departure Time array from determined xml file based on selection from previous menu.

	}
	
// END GET RESULTS

function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^\s+|\s+$/g,"");
  if (x==c_name)
    {
    return unescape(y);
    }
  }
}

function del_cookie(name) {
	document.cookie = name + '=; expires=Thu, 01-Jan-70 00:00:01 GMT;';
}

// START SHOW RESULTS FOR AGENCY SELECT DIV
function showResults_agencySelect() { 
  document.getElementById("form-holder_results").style.display = "block";
  document.getElementById("form-holder_select_agencySelect").style.display = "none";
}
// END SHOW RESULTS FOR AGENCY SELECT DIV

// START SHOW RESULTS FOR STOP ID LOOKUP DIV
function showResults_stopIDLookup() { 
  document.getElementById("form-holder_results").style.display = "block";
  document.getElementById("form-holder_select_stopIDLookup").style.display = "none";
}
// END SHOW RESULTS FOR STOP ID LOOKUP DIV

// START START OVER FOR AGENCY SELECT DIV
function startOver_agencySelect() { 
  document.getElementById("form-holder_results").style.display = "none";
  document.getElementById("form-holder_select_agencySelect").style.display = "block";
  resetForm(document.DepartureTimesLookup_AgencySelect);
}
// END START OVER FOR AGENCY SELECT DIV

// START START OVER FOR STOP ID DIV
function startOver_stopIDLookup() { 
  document.getElementById("form-holder_results").style.display = "none";
  document.getElementById("form-holder_select_stopIDLookup").style.display = "block";
  document.getElementById("stops2").value = "";
}
// END START OVER FOR STOP id DIV
