    //<![CDATA[
    var map;
    var geocoder;

    function googleload() {
      if (GBrowserIsCompatible()) {
        geocoder = new GClientGeocoder();
		//alert("googleLoad");
        map = new GMap2(document.getElementById('map'));
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        //map.setCenter(new GLatLng(40, -100), 4);
		map.setCenter(new GLatLng(28.601242, -81.721802), 6);
      }
    }

   function searchLocations() {
     var address = document.getElementById('addressInput').value;
     
	 // get lat/long for the address entered
	 geocoder.getLatLng(address, function(latlng) {
       if (!latlng) {
         alert(address + ' not found');
       } else {
         searchLocationsNear(latlng);
       }
     });
   }

   //////////////////////////
   // function SEARCH LOCATIONS NEAR
   function searchLocationsNear(center) {
     var radius = document.getElementById('radiusSelect').value;
	 var ref_page_meta = document.getElementById('referring_page_id');
	 if (ref_page_meta != null){
    	 var ref_page_qstring = '&refpageid=' + document.getElementById('referring_page_id').value;
	 }
	 else {
		 var ref_page_qstring = '';
	 }
     
	 // There is a php file on our server which will query 
	 //		our db and generate an xml file of locations within the desired radius.
	 //		We need to pass the user's lat/long and max radius to the file
	 //		via URL.
	 var searchUrl = 'index.php?option=com_jswlocator&task=genxml&lat=' + center.lat() + '&lng=' + center.lng() + '&radius=' + radius + ref_page_qstring;
	 //alert(searchUrl);
     
	 // This runs some google magic which runs our xml generator, then
	 //		uses the xml to draw the pins on a google map
	 GDownloadUrl(searchUrl, function(data) {
       var xml = GXml.parse(data);
       var markers = xml.documentElement.getElementsByTagName('marker');
       map.clearOverlays();

       // write content in the sidebar div
	   var sidebar = document.getElementById('sidebar');
       sidebar.innerHTML = '';

       // if we have no hits, write "No Results", show US map, then exit fxn
	   if (markers.length == 0) {
         sidebar.innerHTML = 'No results found.';
         map.setCenter(new GLatLng(40, -100), 4);
         return;
       }

       // if we get to this point, we have some hits
	   var bounds = new GLatLngBounds();
       for (var i = 0; i < markers.length; i++) {
         
		 // Get the parameters for each hit
         var hours = markers[i].getAttribute('hours');
         var storeurl = markers[i].getAttribute('url');
		 var link_text = markers[i].getAttribute('link_text');
         var storephone = markers[i].getAttribute('phone');
		 //alert (storeurl);
		 //alert (hourss);
		 var name = markers[i].getAttribute('name');
		 //alert(hours);
         var address = markers[i].getAttribute('address1');
         var city = markers[i].getAttribute('city');
         var state = markers[i].getAttribute('state');
         var zip= markers[i].getAttribute('zip');
         var distance = parseFloat(markers[i].getAttribute('distance'));
         var point = new GLatLng(parseFloat(markers[i].getAttribute('lat')),
                                 parseFloat(markers[i].getAttribute('lng')));
         var marker = createMarker(point, name, address, city, hours, storeurl, link_text, storephone);
         map.addOverlay(marker);
         //var sidebarEntry = createSidebarEntry(marker, name, address, city, state, zip distance, hours, storeurl, link_text, storephone );
		 var sidebarEntry = createSidebarEntry(marker, name, address, city, state, zip, distance, hours, storeurl, link_text, storephone);
		 sidebar.appendChild(sidebarEntry);
         bounds.extend(point);
       }
       // Center and zoom map so that all hits (markers) are visible
	   map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
     });
   }

    // Here we tell it what html to put in the "bubble" when someone clicks a marker
	function createMarker(point, name, address, city, hours, storeurl, link_text, storephone) {
      var marker = new GMarker(point);
      var html = '<b>' + name + '</b>';
	  	html = html + '<br/><b>Ph: </b>' + storephone;
		html = html + "<br/>" + address;
		html = html + "<br/>" + city;
		html = html + '<br/><a target="_blank" href="'+ storeurl +'">' + link_text + '</a>';
		
      GEvent.addListener(marker, 'click', function() {
        marker.openInfoWindowHtml(html);
      });
      return marker;
    }

	// Here we tell it what html to add to the sidebar div for a hit
   // function createSidebarEntry(marker, name, address, city, state, zip, distance, hours, storeurl, link_text, storephone) {
	   function createSidebarEntry(marker, name, address, city, state, zip, distance, hours, storeurl, link_text, storephone){
      var div = document.createElement('div');
      var html = '<p style="width:270px;padding-right:2px;margin-right:0;"><strong>' + name + '</strong> (' + distance.toFixed(1) + ')';
	  html = html + '<br/>Ph: ' + storephone;
	  html = html + '<br/>' + address;
	  html = html + '<br/>' + city;
	  html = html + ', ' + state;
	  html = html + ' ' + zip;
	  //html = html + '<br/>Hours: ' + hours;
	  html = html + '<br><a target="_blank" href="'+ storeurl +'">' + link_text + '</a></p>';
      div.innerHTML = html;
      div.style.cursor = 'pointer';
      div.style.marginBottom = '5px'; 
      GEvent.addDomListener(div, 'click', function() {
        GEvent.trigger(marker, 'click');
      });
      GEvent.addDomListener(div, 'mouseover', function() {
        div.style.backgroundColor = '#eee';
      });
      GEvent.addDomListener(div, 'mouseout', function() {
        div.style.backgroundColor = '#fff';
      });
      return div;
    }
    //]]>

// We need to add to the onload event, so let's include a fxn that makes that easy
function addWindowLoadEvent(func) {
	if (window.onload){
		temp = window.onload;
		window.onload = function(){temp();func();};
		//window.onload = function() {alert('load');temp();func();};
	}
	else {
		// WORKS: window.onload = function() {googleload();};
		window.onload = function() {func();};
	}
}

function addWindowUnloadEvent(func) {
	if (window.onunload){
		temp = window.onunload;
		//temp();
		//alert("inside unload");
		//window.onunload = function(){alert('multi unload');temp();func();};
		window.onunload = function() {func();temp()};
	}
	else {
		// WORKS: window.onload = function() {googleload();};
		window.onunload = function() {func();};
	}
}



