
    //<![CDATA[
	//This sets up the map variable and geocoder variable.			   
    //var map;
    var geocoder;
	var markers;
	var x = 0;
	var y = 10;
	//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 searchLoad() {
      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);
		
		searchLocations();
      }
    } 

   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 searchLocationsNear(center) {
     var radius = document.getElementById('radiusSelect').value;														//reads value of radius from index.html radiusSelect
     var searchUrl = 'phpsqlsearch_dbinfo.php?lat=' + center.lat() + '&lng=' + center.lng() + '&radius=' + radius;		//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 address = markers[i].getAttribute('address');
		 var comments = markers[i].getAttribute('comments');
		 var webaddress = markers[i].getAttribute('webaddress');
         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 = createMarkerSearch(point, name, address, comments, webaddress, gmads);
         map.addOverlay(marker);
         var sidebarEntry = createSidebarEntrySearch(marker, name, address, distance);
         sidebar.appendChild(sidebarEntry);
         bounds.extend(point);}
       
       map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
     });
   }
   

    function createMarkerSearch(point, name, address, 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 createSidebarEntrySearch(marker, name, address, distance) {
	
     
	  var div = document.createElement('gmapsidebar');
      var html = '<b>' + name + '</b> (' + distance.toFixed(1) + ')<br/>' + address + '<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;
	  //addGoogleAdsense();
	
    }  
	
      /* function addGoogleAdsense()
      {
	   
	   var newDiv = document.createElement("div");
	   newDiv.innerHTML = '<iframe scrolling="no" style="border:0px;scrolling:no;height:100px;width:738px;margin:0px;padding:0px;" src="adsense.php?size=banner" ></iframe> ';
	   var my_div = document.getElementById("test");
	   my_div.parentNode.insertBefore(newDiv, my_div);
       } */ 



    //]]>

  
  
  
  
  

