
    //<![CDATA[
	//This sets up the map variable and geocoder variable.			   
    //var map;
    var geocoder;

	//This function _load sets up the new map object.
	//This has the small map control for zooming, you can change type of map and this centers the map at 40_-100.
     function searchLoadLocations(btn){
		 var type = btn.value;
      if (GBrowserIsCompatible()) {
        geocoder = new GClientGeocoder();
        map = new GMap2(document.getElementById('gmap'));
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        map.setCenter(new GLatLng(40, -100), 4);
		
		
      }
	  
	  searchLocationsType(type);
    } 

   /*function searchLocations() {																							//function that takes in the search location from index.html
     var address = document.getElementById('addressInput').value;														//sets up variable address that loads address from index.html
     geocoder.getLatLng(address, function(latlng) {																		//gmaps api geocodes the address into lat/lng
       if (!latlng) {																									//checks if latlng exists
         alert(address + ' not found');																					//if not pop up and say address not found
       } else {																											
         searchLocationsNear(latlng);																					//if address available, execute function searchLocationsNear passing latlng
       }
     });
   } */

   function searchLocationsType(type) {
     															//reads value of radius from index.html radiusSelect
     var searchUrl = 'phpsqlsearch_dbtype.php?type=' + type;															//creates variable that has the url to search
	   GDownloadUrl(searchUrl, function(data) {																			//takes the xml from the php script generated in the previous line
       var xml = GXml.parse(data);																						//sets up variable xml that will parse the xml data
       var markers = xml.documentElement.getElementsByTagName('railfandata');										//sets up variable markers 
       map.clearOverlays();																								//removes the existing points on the map
		
       var sidebar = document.getElementById('gmaptext');
       sidebar.innerHTML = '';
       if (markers.length == 0) {
         sidebar.innerHTML = 'No results found.';
         map.setCenter(new GLatLng(40, -100), 4);
         return;
       }  

       var bounds = new GLatLngBounds();
       for (var i = 0; i < markers.length; i++) {
         var name = markers[i].getAttribute('name');
		 var type = markers[i].getAttribute('type');
		 var comments = markers[i].getAttribute('comments');
		 var webaddress = markers[i].getAttribute('webaddress');
         //var address = markers[i].getAttribute('address');
         //var distance = parseFloat(markers[i].getAttribute('distance'));
         var point = new GLatLng(parseFloat(markers[i].getAttribute('lat')),
                                 parseFloat(markers[i].getAttribute('lng')));
         var gmads = new GAdsManager(map, "ca-pub-8178261726045853");
		 gmads.enable();
         var marker = createMarkerType(point, name, type, comments, webaddress, gmads);
         map.addOverlay(marker);
         var sidebarEntry = createSidebarEntryType(marker, name, type);
         sidebar.appendChild(sidebarEntry);
         bounds.extend(point);
       }
       map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
     });
   }

    function createMarkerType(point, name, type, comments, webaddress, gmads) {
      var marker = new GMarker(point);
      var html = '<b>' + name + '</b> <br/>' + comments + '<br/>' + "<iframe scrolling='no' style='border:0px;scrolling:no;height:120px;width:200px;margin:0px;padding:0px;' src='balloonadsense.php' ></iframe>" + '<br/>' + '<a href=' + webaddress + '></a>';
      GEvent.addListener(marker, 'click', function() {
        marker.openInfoWindowHtml(html, 
                                { 
                                        maxWidth:300                                     
                                } 
                                );
      });
      return marker;
    }  

  function createSidebarEntryType(marker, name, type) {
      var div = document.createElement('gmapsidebar');
      var html = '<b>' + name + '</b> (' + type + ')<br/>';
      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 = '#316531';
      });
      GEvent.addDomListener(div, 'mouseout', function() {
        div.style.backgroundColor = '#B57910';
      });
      return div;
    }  
	




    //]]>

  
  
  
  
  

