
	//AJAX stuff
	var xmlHttp;
	var is_ie = (navigator.userAgent.indexOf('MSIE') >= 0) ? 1 : 0;
	var is_ie5 = (navigator.appVersion.indexOf("MSIE 5.5")!=-1) ? 1 : 0;
	var is_opera = ((navigator.userAgent.indexOf("Opera6")!=-1)||(navigator.userAgent.indexOf("Opera/6")!=-1)) ? 1 : 0;
	//netscape, safari, mozilla behave the same???
	var is_netscape = (navigator.userAgent.indexOf('Netscape') >= 0) ? 1 : 0;

	// XMLHttp send GET request
	function xmlHttp_Get(xmlhttp, url) 
	{
		xmlhttp.open('GET', url, true);
		xmlhttp.send(null);
	}

	function GetXmlHttpObject(handler) {
		var objXmlHttp = null;    //Holds the local xmlHTTP object instance

		//Depending on the browser, try to create the xmlHttp object
		if (is_ie){
			//The object to create depends on version of IE
			//If it isn't ie5, then default to the Msxml2.XMLHTTP object
			var strObjName = (is_ie5) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP';
		    
			//Attempt to create the object
			try{
				objXmlHttp = new ActiveXObject(strObjName);
				objXmlHttp.onreadystatechange = handler;
			}
			catch(e){
			//Object creation errored
				alert('IE detected, but object could not be created. Verify that active scripting and activeX controls are enabled');
				return;
			}
		}
		else if (is_opera){
			//Opera has some issues with xmlHttp object functionality
			alert('Opera detected. The page may not behave as expected.');
			return;
		}
		else{
			// Mozilla | Netscape | Safari
			objXmlHttp = new XMLHttpRequest();
			objXmlHttp.onload = handler;
			objXmlHttp.onerror = handler;
		}

		//Return the instantiated object
		return objXmlHttp;
	}
 
	function PerformAsyncRequest(url, oReturnHandler)
	{
		//Create the xmlHttp object to use in the request
		//stateChangeHandler will fire when the state has changed, i.e. data is received back
		// This is non-blocking (asynchronous)
		xmlHttp = GetXmlHttpObject(oReturnHandler);
		
		//Send the xmlHttp get to the specified url
		xmlHttp_Get(xmlHttp, url);
	}
	function  GatherResults()
	{
		//readyState of 4 or 'complete' represents that data has been returned
		if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete'){
			//Gather the results from the callback
			var xml = GXml.parse(xmlHttp.responseText);
			
			return xml;
		}
		return null;
	}
	
	
	
	var map = null;
	var geocoder = null;
	var iconArrow= null;
	
	function AddGMapLocationsHandler()
	{
		var xml = GatherResults();
		if (xml != null)
		{
			var markers = xml.documentElement.getElementsByTagName("Facility");
			var facilityName = "";
			
			var bounds = new GLatLngBounds;
			var lat = 0;
			var lng = 0;
			for (var i = 0; i < markers.length; i++) 
			{
				facilityName = markers[i].getAttribute("FacilityName");
				
				var popupDesc = '<table id="mapfloater" cellspacing="0" cellpadding="0" ><tr>';
				popupDesc +=  '<td><span class = "greenMessageText">' + facilityName + '</span></td></tr></table>';
				
				lat = parseFloat(markers[i].getAttribute("Latitude"));
				lng = parseFloat(markers[i].getAttribute("Longitude"));
				if(!isNaN(lat) && !isNaN(lng))
				{
					var point = new GLatLng(lat,lng);
					var facID = markers[i].getAttribute("FacilityId");
					// create the marker
					var marker = CreateMarker(point, facID, popupDesc, iconArrow);
					map.addOverlay(marker);
	            
					// ==== Each time a point is found, extent the bounds to include it =====
					bounds.extend(point);

				}
			}
			map.setZoom(map.getBoundsZoomLevel(bounds));
			var clat = (bounds.getNorthEast().lat() + bounds.getSouthWest().lat()) /2;
			var clng = (bounds.getNorthEast().lng() + bounds.getSouthWest().lng()) /2;
			map.setCenter(new GLatLng(clat,clng));
		}
	}

	function CreateMarker(point, facID, popupHTML, icon)
	{
		
		var marker = new GMarker(point, icon);
		GEvent.addListener(marker, 'mouseover', function() { floater(popupHTML);});
		GEvent.addListener(marker, 'mouseout', floaterDone );
		GEvent.addListener(marker, 'click', function() { window.location = 'JobShadowingFacilityDetail.aspx?FacilityID=' +facID; });
		return marker;
	
	}
	
	function AddGMapLocations()
	{
		var requestURL = window.location.href;
		var randomNumber=Math.floor(Math.random()*1001);
		requestURL = requestURL.substring(0,requestURL.lastIndexOf("/")+1);
		requestURL = requestURL + "JobShadowingSearch.aspx";
		//build the query string
		var url = requestURL +"?Request=jobLocations&random=" +randomNumber ;
		
		PerformAsyncRequest(url, AddGMapLocationsHandler);

	}
	
	function loadMap(){
		if (GBrowserIsCompatible()) 
		{
			InitializeMap();
			//add map points
			AddGMapLocations();	
		}
	}
	
	function InitializeMap()
	{
		map = new GMap2(document.getElementById("map"));
		geocoder = new GClientGeocoder();
		
		//add controls
		map.addControl(new GLargeMapControl());;

		//center map, adjust zoom
		map.setCenter(new GLatLng(0, 0), 0);
		
		//create map marker icon
		iconArrow = new GIcon(G_DEFAULT_ICON);
		iconArrow.image = "assets/images/mapmarker.gif";
		iconArrow.shadow = "";
		iconArrow.size = new GSize(20,21);
		iconArrow.iconAnchor = new GPoint(13,13);
		iconArrow.infoWindowAnchor = new GPoint(13,13);
		
		
	}
	
	
