
    //<![CDATA[
	//This sets up the map variable and geocoder variable.			   
    //var map;
    var geocoder;
	var comSearch;
	//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 searchComments(){
		 
      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);
		
      }
	  
	  searchLocationsComments();
    } 

   /*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 searchLocationsComments() {
       var comSearch = document.getElementById("commentsInput").value;												//reads value of radius from index.html radiusSelect
	   var searchUrl = 'phpsqlsearch_dbcomments.php?comments=' + comSearch;															//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 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 marker = createMarkerComments(point, name, type, comments);
         map.addOverlay(marker);
         var sidebarEntry = createSidebarEntryComments(marker, name, type);
         sidebar.appendChild(sidebarEntry);
         bounds.extend(point);
       }
       map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
     });
   }

    function createMarkerComments(point, name, type, comments) {
      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>";
      GEvent.addListener(marker, 'click', function() {
        marker.openInfoWindowHtml(html, {maxWidth:250} 
                                );
      });
      return marker;
    }  

   function createSidebarEntryComments(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;
    }  
	




    //]]>

  
  
  
  
  


