	var map;
    var gdir;
    var geocoder = null;
    var addressMarker;
    var gmarkers = [];
    var request = null;
    var filename = null;
    var baseIcon = null;
    var icons = [];
    var loaded = false;
    var elapsedTime = 0;
    var ggmarkers = [];
    var currentMarker = 0;
    var baseLat = 29.432970;
    var baseLng = -98.492789;

    function load()
    {
		if (document.getElementById("map"))
		{
			if (GBrowserIsCompatible())
			{
				baseIcon = new GIcon();
				baseIcon.iconSize = new GSize(59, 50);
				baseIcon.iconAnchor = new GPoint(29, 50);
				baseIcon.infoWindowAnchor = new GPoint(18, 6);
				show("map");
				map = new GMap2(document.getElementById("map"));
				map.addControl(new GLargeMapControl());
				map.addControl(new GMapTypeControl());
				GEvent.addListener(map, "load", initializeMap);
				map.setCenter(new GLatLng(baseLat,baseLng), 10);
			}
		}
    }
    
    function setDirections(fromAddress, toAddress, locale)
    {
		if (gdir == null)
		{
			gdir = new GDirections(map, document.getElementById("directions"));
			GEvent.addListener(gdir, "load", onGDirectionsLoad);
			GEvent.addListener(gdir, "error", handleErrors);
		}
		show("directions");		
		gdir.load("from: " + fromAddress + " to: " + toAddress,
                { "locale": locale });
		
    }
    
    function getDirections()
    {
		var _addr = document.getElementById("streetAddress").value;
		var _city = document.getElementById("city").value;
		var _state = document.getElementById("state").value;
		var _zip = document.getElementById("zip").value;
		var _location = document.getElementById("startAddress").value;
		if (_location == 'n/a')
		{
			alert('Please select a Destination Address.');
			return;
		}
		
		if ((_addr == '') && (_city == '') && (_state == '') && (_zip == ''))
		{
			alert('Please enter a starting address.');
			document.getElementById("streetAddress").focus();
			return;
		}
		
		var _toAddress = _addr + " " + _city + ", " + _state + " " + _zip;
				
		setDirections(_toAddress, _location, "en_US");
    }
    
    function show(object)
	{
		if (document.getElementById && document.getElementById(object) != null)
			node = document.getElementById(object).style.display='block';
		else if (document.layers && document.layers[object] != null)
			document.layers[object].display = 'block';
		else if (document.all)
			document.all[object].style.display = 'block';
	}
	
	function hide(object)
	{
		if (document.getElementById && document.getElementById(object) != null)
			node = document.getElementById(object).style.display='none';
		else if (document.layers && document.layers[object] != null)
			document.layers[object].display = 'none';
		else if (document.all)
			document.all[object].style.display = 'none';
	}


    function handleErrors(){
	   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	     alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
	   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	     alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
	   
	   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	     alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);

	//   else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
	//     alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gdir.getStatus().code);
	     
	   else if (gdir.getStatus().code == G_GEO_BAD_KEY)
	     alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);

	   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	     alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
	    
	   else alert("An unknown error occurred.");
	   
	}

	function onGDirectionsLoad()
	{ 
		// Use this function to access information about the latest load()
		// results.

		// e.g.
		// document.getElementById("getStatus").innerHTML = gdir.getStatus().code;
		// and yada yada yada...
	}
	
	//	Toggle the markers
	function toggleGGMarkers(_display)
	{
		hideCurrentMarkers();
		displayMarkers(_display);
	}
	
	
	//	Hide Current Markers
	function hideCurrentMarkers()
	{
		map.getInfoWindow().hide();
		var _markers = ggmarkers[currentMarker];
		if (_markers != null)
		{
			for(var i=0; i < _markers.length; i++)
			{
				map.removeOverlay(_markers[i]);
			}
		}
	}
	
	//	Show Markers
	function displayMarkers(_display)
	{
		var _markers = ggmarkers[_display];
		for(var i = 0; i < _markers.length; i++)
		{
			map.addOverlay(_markers[i]);
		}
		currentMarker = _display;
	}
	
	//	Create an XmlHttpRequest
	function createRequest(fileName, processRequest)
	{
		request = GXmlHttp.create(); 
		request.open("GET", fileName, true); 
		request.onreadystatechange = processRequest;
		request.send(null);
	}
	
	//	Create a marker but don't display
	function buildMarker(type, point, image, html)
	{
		var icon = createIcon(type, image);
		var marker = new GMarker(point, icon);
		GEvent.addListener(marker, "click", function()
		{
			marker.openInfoWindowHtml(html);
		});
		return marker;
	}
	
	//	Create Icon
	function createIcon(iconType, imageName)
	{
		if (!icons[iconType])
		{
			var icon = new GIcon(baseIcon);
			icon.image = imageName;
			icons[iconType] = icon;
		}
		return icons[iconType];
	}
