// VARIABLE DEFINITIONS
var _mSvgForced = true;
var _mSvgEnabled = true;
var varColorVar = "";
var T;
var map;
var lastPoint;
var lastX;
var lastY;
var activeCode = 0;
var fCenterLat = 0;
var fCenterLong = 0;
var codeIsOn = false;
var thisLine = "";
var lines = "";
var tempPoint = "";
var encodedBusLine = null;

var lat = 0;
var lng = 0;
var zoom = 1;
var maptype = 0;
var lastRoute = 0;

var cookiename = "mapinfo";
var expiredays = 7;


// SET UP THE ARRAYS
var arrLocation = new Array();
var arrZip = new Array();
var arrAMslug = new Array();
var arrPMslug = new Array();
var arrLocationMD = new Array();
var arrLocationNonStop = new Array();
var arrBusRoute = new Array();
var arrBusRouteCenter = new Array();


// ARRAY FUNCTIONS - Null out array values
function ZIP_Location() {
   this.point = null;
   this.marker = null;
   this.theIcon = null;
   }
function Slug_Location() {
   this.point = null;
   this.marker = null;
   this.theIcon = null;
   }
function ART_Location() {
   this.point = null;
   this.marker = null;
   this.theIcon = null;
   }
   
// ARRAY FUNCTIONS - Clean out the arrays to remove inactive stops
function cleanArrays() {
   var count1 = 0;
   var count2 = 0;
   for (i in arrLocationMD) {
      if ((arrLocationMD[i] != "") && (arrLocationMD[i] != null)) {
         count1 = count1 + 1;
         }
      }
   for (j in arrLocation) {
      if ((arrLocation[j] != "") && (arrLocation[j] != null)) {
         count2 = count2 + 1;
         }
      }
   if (count2 == 0) {
      arrLocation.splice(0, arrLocation.length);
      }
   if ((count2 == 0) && (count1 != 0)) {
      arrLocationMD.splice(0, arrLocationMD.length);
      }
   }

// SWITCH BETWEEN TABS
function showTab(arg1, arg2) {  
   if (document.all) {
      // make the tab appear active
	  document.all('tab1').className = "tabinInactive";
      document.all('tab2').className = "tabinInactive";
      document.all('tab3').className = "tabinInactive";
      document.all(arg1).className = "tabinActive";
      // show the correct tab
	  document.all('tab1body').className = "divHidden";
      document.all('tab2body').className = "divHidden";
      document.all('tab3body').className = "divHidden";
      document.all(arg2).className = "@map-list divVisible";
      }
   else {
      // make the tab appear active
	  document.getElementById('tab1').className = "tabinInactive";
      document.getElementById('tab2').className = "tabinInactive";
      document.getElementById('tab3').className = "tabinInactive";
      document.getElementById(arg1).className = "tabinActive";
      // show the correct tab
	  document.getElementById('tab1body').className = "divHidden";
      document.getElementById('tab2body').className = "divHidden";
      document.getElementById('tab3body').className = "divHidden";
      document.getElementById(arg2).className = "@map-list divVisible";
      }
   }



// BROWSER - Get Window width
function getWindowWidth() {
   var widthOffset = 0;
   if (window.self && self.innerWidth) {
      widthOffset = 20;
      }
   widthOffset = 20;
   return (document.body.clientWidth - widthOffset);
   }
   
// BROWSER - Get Window height
function getWindowHeight() {
   var heightOffset = 0;
   if (window.self && self.innerHeight) {
      heightOffset = 20;
      }
   heightOffset = 20;
   return(document.body.clientHeight - heightOffset);

   }

/*
function saveMapState(){
	var currCenter = map.getCenter();
	var currMapType = map.getCurrentMapType();
	var currZoomLvl = map.getZoom();
}
*/

// MAP FUNCTIONS - Cookie Functions
if (document.cookie.length > 0) {
	cookieStart = document.cookie.indexOf(cookiename + "=");
	//lastRoute = document.cookie.indexOf(";",lastRoute + "=");
	//alert(document.cookie);
	if (cookieStart!=-1) {
	  cookieStart += cookiename.length+1; 
	  cookieEnd=document.cookie.indexOf(";",cookieStart);
	  if (cookieEnd==-1) {
		cookieEnd=document.cookie.length;
	  }
	  cookietext = document.cookie.substring(cookieStart,cookieEnd);
	
	  bits = cookietext.split("|");
	  lat = parseFloat(bits[0]);
	  lng = parseFloat(bits[1]);
	  zoom = parseInt(bits[2]);
	  maptype = parseInt(bits[3]);
	  lastRoute = parseInt(bits[4]);
	} 
}

//alert(lastRoute);

// MAP FUNCTIONS - Resize the map 
function ResizeMap(afterRefresh) {
   var controls = document.getElementById('@map-routes-controls');
   var id_map = document.getElementById('@map-gm');
   id_map.style.height = controls.clientHeight + "px";
   if(afterRefresh) {
      map.setCenter(new GLatLng(fCenterLat, fCenterLong));
      }
   }

// MAP FUNCTIONS - Load the map
function LoadMap() {
   var zoomp = 13;
   var normalProj = G_NORMAL_MAP.getProjection();
   var closeness = 2;
   var lineThickness = 4;
   var lineOpacity = 0.5;
   ResizeMap(0);
   if (GBrowserIsCompatible()) {
      map = new GMap2(document.getElementById('@map-gm'), {
         draggableCursor : "pointer"}
      );
      
	  if ((lat != 0)&&(lng != 0)){
	  	fCenterLat = lat;
	  	fCenterLong = lng;
	  }
	  else{
	  	fCenterLat = 38.86997;
	  	fCenterLong = - 77.11203;
	  }

	  if (zoom != 1){
	  	zoomp = zoom;
	  }
	  else{
	  	zoomp = 13;
	  }
	  
	  if (lastRoute != 0){
		if(document.getElementById("chkRoute" + lastRoute) && (document.getElementById("chkRoute" + lastRoute).checked == false)) {
            document.getElementById("chkRoute" + lastRoute).click();
        }  
	  }
	  map.setCenter(new GLatLng(fCenterLat, fCenterLong), zoomp);
  	  map.addControl(new GMapTypeControl());
	  	  
	  // Small +/- Zoom Control
	  map.addControl(new GSmallMapControl());
	  
	  
	  
	       
	  //Lower Right-Hand corner draggable overview
	  //map.addControl(new GOverviewMapControl());
	  
	  // Google Search Bar instead of regular Google logo
	  map.enableGoogleBar();
      map.enablePinchToZoom();
	  
      ShowAllMetroLines();
      GEvent.addListener(map, "zoomend", function(oldzoomlevel, zoomlevel) {
         HandleZoomedMap(oldzoomlevel, zoomlevel); }
      );
      GEvent.addListener(map, "mousemove", function(point) {
         var latLngStr4 = point.lat().toFixed(4) + ', ' + point.lng().toFixed(4); lastPoint = latLngStr4; lastX = point.lat(); lastY = point.lng(); }
      );
      var marker;
      var bounds = map.getBounds();
      GEvent.addListener(map, "click", function(overlay, point) {
         if ((!point) && (overlay != marker)) {
            }
         }
      );
      }
   }

// MAP FUNCTIONS - Change/Update map zoom levels
function HandleZoomedMap(oldzoomlevel, zoomlevel) {
   if(oldzoomlevel < 15 && zoomlevel >= 15) {
      if (arrBusRoute) {
         for(i in arrBusRoute) {
            if(arrBusRoute[i]) {
               HandleNonTimedStops(i, 1);
               }
            }
         }
      }
   else if(oldzoomlevel >= 15 && zoomlevel < 15) {
      if (arrBusRoute) {
         for(i in arrBusRoute) {
            if(arrBusRoute[i]) {
               HandleNonTimedStops(i, 0);
               }
            }
         }
      }
   else {
      //do nothing
      }
   }
   
// MAP FUNCTIONS - Open the Google Maps Info Window
function infoWindowPop() {
   if (thisLine != "") {
      thisLine = "<br><b style='font-size:11px;'>Clicked area is serviced by the<br>following active bus route(s):</b><br>" + thisLine + "<font style='font-size:10px;'></font>";
      map.openInfoWindowHtml(tempPoint, thisLine);
      map.updateInfoWindow();
      }
   }
   
// MAP FUNCTIONS - Look at a mouse click on a polyline and determine what open routes the point is in.
function polyScan() {
   lines = "";
   thisLine = "";
   tempPoint = "";
   //for (i in arrBusRoute) {
   for (i=0;i<arrBusRoute.length;i++) {
	
	   if (arrBusRoute[i]){
	  var bounds = arrBusRoute[i].getBounds();
      tempPoint = new GLatLng(lastX, lastY);
      if (!bounds.contains(tempPoint)) {
         lines = lines;
         }
      else {
         if (lines.length == 0) {
            lines = lines + i;
            }
         else {
            lines = lines + "," + i;
            }
         }
      }
   }
   if (lines != "") {
      getRouteNames(lines);
      T = setTimeout("infoWindowPop();", 400);
      }
   }

// AJAX - Detect ActiveX or XMLHTTP Request for AJAX calls
function CreateXmlHttp() {
   var xmlHttp;
   if (window.XMLHttpRequest) {
      xmlHttp = new XMLHttpRequest();
      }
   else if (window.ActiveXObject) {
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
   else {
      alert("Your browser does not support AJAX!");
      xmlHttp = null;
      return false;
      }
   return(xmlHttp);
   }

// AJAX - Get bus route names
function getRouteNames(varPolylineID) {
   var xmlHttp = CreateXmlHttp();
   var oDate = new Date();
   xmlHttp.onreadystatechange = function() {
      if(xmlHttp.readyState == 4) {
         thisLine = xmlHttp.responseText;
         }
      }
   xmlHttp.open("GET", "ajax_polyline_to_route-alpha.cfm?nocache=" + oDate.getTime() + Math.floor(Math.random() * 101) + "&switching=1&PolylineID=" + varPolylineID);
   xmlHttp.send(null);
   }
   
// AJAX - Open or Close a route depending on checkbox state   
function HandleRoutePolyClick(iPolylineID, strCode, element, colorVar, strSet) {
   varColorVar = colorVar;
   document.getElementById("@map-routes-controls").className = "@map-controls @map-processing";
   if(element.checked) {
      LoadRoutePoly(iPolylineID, strCode, colorVar, strSet);
      }
   else {
      HideRoutePoly(iPolylineID, strCode, colorVar, strSet);
      }
   }
// AJAX - Open or Close a rail line depending on checkbox state   
function HandleRailPolyClick(iPolylineID, strCode, element, colorVar, strSet) {
   varColorVar = colorVar;
   document.getElementById("@map-routes-controls").className = "@map-controls @map-processing";
   if(element.checked) {
      LoadRailPoly(iPolylineID, strCode, colorVar, strSet);
      }
   else {
      HideRailPoly(iPolylineID, strCode, colorVar, strSet);
      }
   }
   
// AJAX - Hide a route
function HideRoutePoly(iPLID, strCode, colorVar, strSet) {
   var xmlHttp = CreateXmlHttp();
   var oDate = new Date();
   var target = document.getElementById("id_route" + strCode);
   document.getElementById("@map-routes-controls").className = "@map-controls";
   xmlHttp.onreadystatechange = function() {
      if(xmlHttp.readyState == 4) {
         if(document.getElementById("id_route" + iPLID)) {
            document.getElementById("id_route" + iPLID).innerHTML = "";
            }
         eval(xmlHttp.responseText);
         document.getElementById("@map-routes-controls").className = "@map-controls";
         }
      }
   //alert("ajax_routeclose-alpha.cfm?nocache=" + oDate.getTime() + Math.floor(Math.random() * 101) + "&routeID=" + strField + "&codeid=" + iPLID + "&color=" + colorVar + "&strSet=" + strSet + "");
   xmlHttp.open("GET", "ajax_routeclose-alpha.cfm?nocache=" + oDate.getTime() + Math.floor(Math.random() * 101) + "&routeID=" + strField + "&codeid=" + iPLID + "&color=" + colorVar + "&strSet=" + strSet + "");
   xmlHttp.send(null);
   }

// AJAX - Load a route
function LoadRoutePoly(iCodeID, strCode, colorVar, strSet) {
   var xmlHttp = CreateXmlHttp();
   var oDate = new Date();
   var target = document.getElementById("id_route" + strCode);
   xmlHttp.onreadystatechange = function() {
      if(xmlHttp.readyState == 4) {
         strInnerCode = "";
         strInnerCode += "<dt>Route Results:</dt>";
         strInnerCode += "<DD><A HREF=\"../schedules/sched.cfm?id=" + iCodeID + "&day=all\" target=\"_blank\">View Schedule</A></DD>";
         strInnerCode += "<DD><A HREF=\"info.cfm?code=" + iCodeID + "\" target=\"_blank\">View Information</A></DD>";
         eval(xmlHttp.responseText);
         strField = iCodeID;
         activeCode = strField;
         if (target) {
            target.innerHTML = strInnerCode;
            target.style.display = "block";
            }
         }
      }
   strAdded = "";
   if(strSet == "single") {
      strAdded = "&single=1";
      }
   
   lastRoute = iCodeID;
   //alert(iCodeID);
   xmlHttp.open("GET", "ajax_routeinfo-alpha.cfm?nocache=" + oDate.getTime() + Math.floor(Math.random() * 101) + "&codeid=" + iCodeID + "&color=" + colorVar + "&strSet=" + strSet + strAdded);
   xmlHttp.send(null);
   }

// AJAX - Hide a rail
function HideRailPoly(iPLID, strCode, colorVar, strSet) {
   var xmlHttp = CreateXmlHttp();
   var oDate = new Date();
   var target = document.getElementById("id_route" + strCode);
   document.getElementById("@map-routes-controls").className = "@map-controls";
   xmlHttp.onreadystatechange = function() {
      if(xmlHttp.readyState == 4) {
         if(document.getElementById("id_route" + iPLID)) {
            document.getElementById("id_route" + iPLID).innerHTML = "";
            }
         eval(xmlHttp.responseText);
         document.getElementById("@map-routes-controls").className = "@map-controls";
         }
      }
   //alert("ajax_railclose-alpha.cfm?nocache=" + oDate.getTime() + Math.floor(Math.random() * 101) + "&railID=" + strField + "&codeid=" + iPLID + "&color=" + colorVar + "&strSet=" + strSet + "");
   xmlHttp.open("GET", "ajax_railclose-alpha.cfm?nocache=" + oDate.getTime() + Math.floor(Math.random() * 101) + "&railID=" + strField + "&codeid=" + iPLID + "&color=" + colorVar + "&strSet=" + strSet + "");
   xmlHttp.send(null);
   }

// AJAX - Load a rail
function LoadRailPoly(iCodeID, strCode, colorVar, strSet) {
   var xmlHttp = CreateXmlHttp();
   var oDate = new Date();
   var target = document.getElementById("id_route" + strCode);
   xmlHttp.onreadystatechange = function() {
      if(xmlHttp.readyState == 4) {
         strInnerCode = "";
         strInnerCode += "<dt>Rail Results:</dt>";
         strInnerCode += "<DD><A HREF=\"../schedules/sched.cfm?id=" + iCodeID + "&day=all\" target=\"_blank\">View Schedule</A></DD>";
         strInnerCode += "<DD><A HREF=\"info.cfm?code=" + iCodeID + "\" target=\"_blank\">View Information</A></DD>";
         eval(xmlHttp.responseText);
         strField = iCodeID;
         activeCode = strField;
         if (target) {
            target.innerHTML = strInnerCode;
            target.style.display = "block";
            }
         }
      }
   strAdded = "";
   if(strSet == "single") {
      strAdded = "&single=1";
      }
   //alert("ajax_railinfo-alpha.cfm?nocache=" + oDate.getTime() + Math.floor(Math.random() * 101) + "&codeid=" + iCodeID + "&color=" + colorVar + "&strSet=" + strSet + strAdded);
   xmlHttp.open("GET", "ajax_railinfo-alpha.cfm?nocache=" + oDate.getTime() + Math.floor(Math.random() * 101) + "&codeid=" + iCodeID + "&color=" + colorVar + "&strSet=" + strSet + strAdded);
   xmlHttp.send(null);
   }

// AJAX - Draw a polyline overlay
function HandleBusLine(strPoints, strLevels, iPolylineID, colorVar, strLine, strRoute) {
   codeIsOn = false;
   for(i in arrBusRoute) {
      if(i == iPolylineID && arrBusRoute[i]) {
         codeIsOn = true;
         }
      }
   arrBusRoute[iPolylineID] = new GPolyline.fromEncoded( {
      color : "#666666", weight : 8, opacity : .7, points : strPoints, levels : strLevels, zoomFactor : 32, numLevels : 4 }
   );
   var colorFMT;
   colorFMT = "#" + colorVar;
   arrBusRouteCenter[iPolylineID] = new GPolyline.fromEncoded( {
      color : colorFMT, weight : 4, opacity : .7, points : strPoints, levels : strLevels, zoomFactor : 32, numLevels : 4 }
   );
   map.addOverlay(arrBusRoute[iPolylineID]);
   map.addOverlay(arrBusRouteCenter[iPolylineID]);
   GEvent.addListener(arrBusRoute[iPolylineID], "click", function() {
      polyScan(); }
   );
   GEvent.addListener(arrBusRouteCenter[iPolylineID], "click", function() {
      polyScan(); }
   );
   }
   
// AJAX - Hide or show ZipCar locations when a checkbox is active or not
function HandleZipcar(element) {
   if (element.checked == true) {
      showhide = "show";
      }
   else {
      showhide = "hide";
      }
   var xmlHttp = CreateXmlHttp();
   var oDate = new Date();
   xmlHttp.onreadystatechange = function() {
      if(xmlHttp.readyState == 4) {
         eval(xmlHttp.responseText);
         }
      }
   xmlHttp.open("GET", "ajax_routeinfo-zipcar.cfm?nocache=" + oDate.getTime() + Math.floor(Math.random() * 101) + "&showhide=" + showhide);
   xmlHttp.send(null);
   }
   
// AJAX - Hide or show Slug locations when a checkbox is active or not
function HandleSlug(element, ampm) {
   if (element.checked == true) {
      showhide = "show";
      }
   else {
      showhide = "hide";
      }
   var xmlHttp = CreateXmlHttp();
   var oDate = new Date();
   xmlHttp.onreadystatechange = function() {
      if(xmlHttp.readyState == 4) {
         eval(xmlHttp.responseText);
         }
      }
   xmlHttp.open("GET", "ajax_routeinfo-slug.cfm?nocache=" + oDate.getTime() + Math.floor(Math.random() * 101) + "&showhide=" + showhide + "&ampm=" + ampm);
   xmlHttp.send(null);
   }

// AJAX - Hide or show Commuter Store locations when a checkbox is active or not
function HandleCS(element) {
   if (element.checked == true) {
      showhide = "show";
      }
   else {
      showhide = "hide";
      }
   var xmlHttp = CreateXmlHttp();
   var oDate = new Date();
   xmlHttp.onreadystatechange = function() {
      if(xmlHttp.readyState == 4) {
         eval(xmlHttp.responseText);
         }
      }
   xmlHttp.open("GET", "ajax_routeinfo-cs.cfm?nocache=" + oDate.getTime() + Math.floor(Math.random() * 101) + "&showhide=" + showhide);
   xmlHttp.send(null);
   }

// AJAX - Show route information for the opposite direction, when a route is clicked in the info window
function SwitchDirections(routeID, stopSeqID, strStopName, currentdirection, stopSeqID2, stopID) {
   var xmlHttp = CreateXmlHttp();
   var oDate = new Date();
   xmlHttp.onreadystatechange = function() {
      if(xmlHttp.readyState == 4) {
         var detail = document.getElementById("@map-detail");
         detail.innerHTML = xmlHttp.responseText;
         detail.style.height = "auto";
         detail.style.height = detail.clientHeight;
         map.updateInfoWindow();
         }
      }
   xmlHttp.open("GET", "ajax_stopinfo-alpha.cfm?nocache=" + oDate.getTime() + Math.floor(Math.random() * 101) + "&switching=1&direction=" + currentdirection + "&routeID=" + routeID + "&stopSeqID=" + stopSeqID + "&strTopName=" + strStopName + "&stopSeqID2=" + stopSeqID2 + "&stopID=" + stopID);
   xmlHttp.send(null);
   }
   
// AJAX - Handle Stop information from the List
function HandleStopInfoFromList(codeid, routeID, stopSeqID, strStopName, currentdirection, stopID) {
   var xmlHttp = CreateXmlHttp();
   var xmlHttpLoadRoute = CreateXmlHttp();
   var oDate = new Date();
   xmlHttp.onreadystatechange = function() {
      if(xmlHttp.readyState == 4) {
         if(document.getElementById("chkRoute" + codeid) && (document.getElementById("chkRoute" + codeid).checked == false)) {
            document.getElementById("chkRoute" + codeid).click();
            }
         var detail = document.getElementById("@map-detail");
         detail.innerHTML = xmlHttp.responseText;
         document.getElementById("@map-routes-controls").className = "@map-controls";
         detail.style.height = "auto";
         detail.style.height = detail.clientHeight;
         map.updateInfoWindow();
         }
      }
   document.getElementById("@map-routes-controls").className = "@map-controls @map-processing";
   xmlHttp.open("GET", "ajax_stopinfo-alpha.cfm?nocache=" + oDate.getTime() + Math.floor(Math.random() * 101) + "&switching=1&direction=" + currentdirection + "&routeID=" + routeID + "&stopSeqID=" + stopSeqID + "&strTopName=" + strStopName + "&stopID=" + stopID);
   xmlHttp.send(null);
   }

// AJAX - Handle Non-Timed Stops
function HandleNonTimedStops(CodeID, showStops) {
   var xmlHttp = CreateXmlHttp();
   var oDate = new Date();
   xmlHttp.onreadystatechange = function() {
      if(xmlHttp.readyState == 4) {
         eval(xmlHttp.responseText);
         }
      }
   xmlHttp.open("GET", "ajax_routenontimedstops.cfm?nocache=" + oDate.getTime() + Math.floor(Math.random() * 101) + "&show=" + showStops + "&CodeID=" + CodeID);
   xmlHttp.send(null);
   }

// AJAX - Get PID info
function pidInfo(stationID) {
   thisLine = "";
   tempPoint = new GLatLng(lastX, lastY);
   
   var xmlHttp = CreateXmlHttp();
   var oDate = new Date();
   xmlHttp.onreadystatechange = function() {
      if(xmlHttp.readyState == 4) {
         thisLine = xmlHttp.responseText;
		 }
      }
   
   xmlHttp.open("GET", "ajax_pid_info-alpha.cfm?nocache=" + oDate.getTime() + Math.floor(Math.random() * 101) + "&switching=1&stopid=" + stationID);
   xmlHttp.send(null);
   T = setTimeout("pidWindowPop();", 400);  
   }
   
// AJAX - Open the Google Maps infowindow and display PID info   
function pidWindowPop() {
   if (thisLine != "") {
      map.openInfoWindowHtml(tempPoint, thisLine);
	   var EventInfowindowopen = GEvent.bind(map, "infowindowopen", this, function() {
			var detail = document.getElementById("@map-detail"); 
			
			if (detail) {			            
				detail.style.height = "auto"; detail.style.height = detail.clientHeight; map.updateInfoWindow(); 
			}
            GEvent.removeListener(EventInfowindowopen); }
         );
      }
   }




// AJAX - Display other bus routes that stop at a particular time point, other than the route that is already active
function DisplayOtherRoutes(iStopID, iRouteID, iStopSeqID, strStopName, iStopSeqID2) {
   var xmlHttp = CreateXmlHttp();
   var oDate = new Date();
   xmlHttp.onreadystatechange = function() {
      if(xmlHttp.readyState == 4) {
         var detail = document.getElementById("@map-detail");
         detail.innerHTML = xmlHttp.responseText;
         detail.style.height = "auto";
         detail.style.height = detail.clientHeight;
         map.updateInfoWindow();
         }
      }
   xmlHttp.open("GET", "ajax_stoproutelist-alpha.cfm?nocache=" + oDate.getTime() + Math.floor(Math.random() * 101) + "&switching=1&iStopSeqID=" + iStopSeqID + "&iRouteID=" + iRouteID + "&iStopID=" + iStopID + "&strTopName=" + strStopName + "&iStopSeqID2=" + iStopSeqID2);
   xmlHttp.send(null);
   }

// AJAX - Load schedule times into the Google Maps Info Window
function LoadTimes(routeID, stopSeqID, strStopName, oMarker, stopSeqID2, stopID) {
   clearTimeout(T);
   var xmlHttp = CreateXmlHttp();
   var oDate = new Date();
   xmlHttp.onreadystatechange = function() {
      if(xmlHttp.readyState == 4) {
         oMarker.openInfoWindowHtml(xmlHttp.responseText);
         var EventInfowindowopen = GEvent.bind(map, "infowindowopen", this, function() {
            var detail = document.getElementById("@map-detail"); if (detail) {
               detail.style.height = "auto"; detail.style.height = detail.clientHeight; map.updateInfoWindow(); }
            GEvent.removeListener(EventInfowindowopen); }
         );
         }
      }
   xmlHttp.open("GET", "ajax_stopinfo-alpha.cfm?nocache=" + oDate.getTime() + Math.floor(Math.random() * 101) + "&switching=0&direction=1&routeID=" + routeID + "&stopSeqID=" + stopSeqID + "&strTopName=" + strStopName + "&stopSeqID2=" + stopSeqID2 + "&stopID=" + stopID);
   xmlHttp.send(null);
   }

// AJAX - Load schedule times into the Google Maps Info Window
function LoadRailTimes(routeID, stopSeqID, strStopName, oMarker, stopSeqID2, stopID) {
   clearTimeout(T);
   var xmlHttp = CreateXmlHttp();
   var oDate = new Date();
   xmlHttp.onreadystatechange = function() {
      if(xmlHttp.readyState == 4) {
         oMarker.openInfoWindowHtml(xmlHttp.responseText);
         var EventInfowindowopen = GEvent.bind(map, "infowindowopen", this, function() {
            var detail = document.getElementById("@map-detail"); if (detail) {
               detail.style.height = "auto"; detail.style.height = detail.clientHeight; map.updateInfoWindow(); }
            GEvent.removeListener(EventInfowindowopen); }
         );
         }
      }
   xmlHttp.open("GET", "ajax_railtimes-alpha.cfm?nocache=" + oDate.getTime() + Math.floor(Math.random() * 101) + "&switching=0&direction=1&routeID=" + routeID + "&stopSeqID=" + stopSeqID + "&strTopName=" + strStopName + "&stopSeqID2=" + stopSeqID2 + "&stopID=" + stopID);
   xmlHttp.send(null);
   }