

//<![CDATA[
     if (GBrowserIsCompatible())
     {
      //*************
      //* VARIABLES *
      //***************** initialize the map (downtown)
	  var txtHomeLon = -83.000633;  //***** broad/high
	  var txtHomeLat = 39.962231;
	  var txtMsg = "";
	  var txtLineUI = "";  //User Interface
	  var txtLineRT = "";  //Real Time
	  var gmarkers = [];
	  var gmarkers1 = [];
	  var htmls = [];
	  var i = 0;
	  var j = 0;
	  var marker1= [];
	  var clearover = 0;
	  var map = "";

      var icon = new GIcon();
      icon.image = "./Maps/Images/blank.png";
	  icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
	  icon.iconSize = new GSize(12, 20);
	  icon.shadowSize = new GSize(22, 20);
	  icon.iconAnchor = new GPoint(6, 20);
	  icon.infoWindowAnchor = new GPoint(5, 1);

	  var icon1 = new GIcon();
	  //icon1.image = "./Images/lightbluebus.gif";
	  icon1.image = "./Maps/Images/darkbluebus.gif";
	  icon1.shadow = "";
	  icon1.iconSize = new GSize(19, 20);
	  icon1.shadowSize = new GSize(22, 20);
	  icon1.iconAnchor = new GPoint(6, 20);
	  icon1.infoWindowAnchor = new GPoint(5, 1);

      var icon01 = new GIcon();
      icon01.image = "./Maps/Images/iconr.png";
	  icon01.shadow = "";
	  icon01.iconSize = new GSize(19, 20);
	  icon01.shadowSize = new GSize(22, 20);
	  icon01.iconAnchor = new GPoint(6, 20);
	  icon01.infoWindowAnchor = new GPoint(5, 1);

	  
//***********************************************************************
// FUNCTIONS
//***********************************************************************

 function StartMeUp()
 {
   map = new GMap(document.getElementById("map"));
   map.addControl(new GLargeMapControl());
   map.addControl(new GMapTypeControl());
   map.centerAndZoom(new GPoint(txtHomeLon,txtHomeLat), 6);

 }//end of function
 
 function DateTime(option)
 {
  var currentTime = new Date();
  var mm = currentTime.getMonth();
  var dd = currentTime.getDate();
  var yyyy = currentTime.getFullYear();
  var dowN = currentTime.getDay();
  if (dowN==0) dow="Sunday";
  if (dowN==1) dow="Monday";
  if (dowN==2) dow="Tuesday";
  if (dowN==3) dow="Wednesday";
  if (dowN==4) dow="Thursday";
  if (dowN==5) dow="Friday";
  if (dowN==6) dow="Saturday";

  var dt = mm+"/"+dd+"/"+yyyy;

  var hh = currentTime.getHours();
  var mi = currentTime.getMinutes();
  if (mi <10) mi = "0" + mi;

  var ti = hh + ":" + mi;

  if (option == "full"){return(dt + " " + ti);}
  if (option == "dt"){return(dt);}
  if (option == "ti"){return(ti);}
  if (option == "dow"){return(dow);}
 }

//***********************************************************************
// process user input
//***********************************************************************
	 function subUI(button)
	 {
	  if (button == "route")
	   {
	    subMapRoute(document.frmUI.cbRoutes.value);
		//alert("Not Available At This Time");
	   }

      if (button == "all")
       {
		window.open('http://www.cota.com/RealTimeCIC.asp');
	    //alert("Not Available At This Time");
       }

      if (button == "choose")
       {
       // window.opener='x';
       // window.close();
	   // history.go(-1)
	    window.location = "http://infoweb.cota.com/hiwire?.a=iScheduleLookupSearch&LineAbbr=" + document.frmUI.cbRoutes.value;
       }
     }


//***********************************************************************
// Create a marker at the given point with the given html
//***********************************************************************
function CreateMarker(point, iconImage, html)
 {
  icon01.image = iconImage;
  var marker = new GMarker(point, icon01);
  GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(html);});
  return marker;
 }


//***********************************************************************
//* plot route onto map
//***********************************************************************
	   function subMapRoute(number){
       var request = GXmlHttp.create();
       var txtRouteFound = "No";
       if (number.length == 1) {number = "00" + number;}
       if (number.length == 2) {number = "0" + number;}
       strStatusLine = "Gathering Route Data. Please Wait.";
	   window.document.getElementById('divStatusLine').innerHTML = strStatusLine;

       request.open("GET", "../cotamaps/xml/webpolyline.xml?lineabbr1=" + number, true);

       request.onreadystatechange = function()
         {
         if (request.readyState == 4)
           {
           var pts = [];
           var i = 0;
           var xmlDoc = request.responseXML;
           var lines = xmlDoc.documentElement.getElementsByTagName("row");
           //* read each line
           if (lines.length > 0)
            {
            for (var a = 0; a < lines.length; a++)
             {
              var lineabbr = lines[a].getAttribute("Lineabbr");
              pts[i] = new GPoint(parseFloat(lines[a].getAttribute("Lon")),
                         parseFloat(lines[a].getAttribute("Lat")));
              i = i + 1;
             }
             map.clearOverlays();
             map.addOverlay(new GPolyline(pts));
             strStatusLine = "Route Found";
	         window.document.getElementById('divStatusLine').innerHTML = strStatusLine;
	         map.centerAndZoom(new GPoint(txtHomeLon,txtHomeLat), 6);
	         rereadXml(number);
            }
           else
            {
             strStatusLine = "Route " + number + " Not Found";
	         window.document.getElementById('divStatusLine').innerHTML = strStatusLine;
            }
           }
         } //** end of onreadystatechange event

         request.send(null);

	     }

//***********************************************************************
// Real Time Data Processing
//***********************************************************************
function rereadXml (number)
{
    strStatusLine = "Gathering Real Time Data. Please Wait.";
    window.document.getElementById('divStatusLine').innerHTML = strStatusLine;

    var request1 = GXmlHttp.create();
    request1.open("GET", "../cotamaps/xml/realtime2.xml?vehicleid1=*&block1=*&lineabbr1=" + number, true);

    request1.onreadystatechange = function()    //* event processing logic
    {
        if (request1.readyState == 4 && request1.status == 200)
        {
            j = 0;
            var xmlDoc = request1.responseXML;
            var markers = xmlDoc.documentElement.getElementsByTagName("row");
            for (j = 0; j < markers.length; j++)
            {
             // obtain the attribues of each marker
             var route = markers[j].getAttribute("routeid");
             var direction = markers[j].getAttribute("direction");
             var vehicleid = markers[j].getAttribute("vehicleid");
             var block = markers[j].getAttribute("block");
             var lat = parseFloat(markers[j].getAttribute("lat"));
             var lon = parseFloat(markers[j].getAttribute("lon"));
             var point = new GPoint(lon,lat);
             var html = markers[j].getAttribute("html");
             var iconimage = "./Maps/Images/" + direction.slice(0,1) + ".png";
             map.addOverlay(CreateMarker(point, iconimage, html, "Y"));
            }
            strStatusLine = j + " vehicles found (as of " + DateTime("ti") + ")";
	        window.document.getElementById('divStatusLine').innerHTML = strStatusLine;
        }

        if (request1.readyState == 4 && request1.status != 200)
        {
            //* problem with the results - try again
            strStatusLine = "OOPS (as of " + DateTime("ti") + ")";
	        window.document.getElementById('divStatusLine').innerHTML = strStatusLine;
        }

    } //* end onreadystatechange

    request1.send(null);
}
//* }




     }//* end of the big question
     else
     {
	  alert("Sorry, the Google Maps API is not compatible with this browser");
     }

    //]]>

	window.onload = StartMeUp;

