

function load() {
     if (document.getElementById("gmap")) {  // dont call this until map div is visible.  It is NOT visible when page opens with the search form.
      if (GBrowserIsCompatible()) 
      {
       map = new GMap2(document.getElementById("gmap"));
//  Add map controls     
map.addMapType(G_PHYSICAL_MAP);
map.addControl(new GLargeMapControl());
map.addControl(new GScaleControl());
map.addControl(new GMapTypeControl());
map.enableDoubleClickZoom();
//map.enableScrollWheelZoom();
//map.enableContinuousZoom();
      
// Set initial x,y center and zoom to nationwide map.
var x = -94.4824
var y = 40.447
definecenter(y,x,4);
 getTabledata();
      }
      
  else  {
  document.getElementById("map").innerHTML="Your browser is not compatible to view the Google map on this page."
        }          
}
    }


////////////////////////////////////////////////////////////
function getTabledata()
   {
/*
Kevin Knapp
Gets x and y values from table in the html page.  Table is generated dynamically as a gridview or datagrid.
Sets map boundary and zoom around all the selected points. From the table.
Add this function to the onload and it will create new map each time the table is paged and the page gets reloaded.
*/
var mytable = document.getElementsByTagName("table")[0];
var ctype = document.getElementById("hdnCommunityType");
//alert(mytable.innerHTML);
//Get boundary of original map.  Will use this for setting the boundary after adding points.
var bound = new GLatLngBounds();

        // Loop through the table rows and get the value for each cell.
        // I start at i=2 because the top rows are column headers and other crap 
                  for (var i=2; i < mytable.rows.length;i++)
                   {
                    var row       = mytable.rows[i];
                    var cel1      = row.getElementsByTagName("td")[0];      //lat
                    var cel2      = row.getElementsByTagName("td")[1];      //long
                    var cel3      = row.getElementsByTagName("td")[2];      //address link
                    var cel4      = cel3.getElementsByTagName("a")[0];      //address inside the link anchor <a>
                    var cel5      = row.getElementsByTagName("td")[3];     //city/county name LINK
                    var cel6      = cel5.getElementsByTagName("a")[0];     //name inside the community link anchor <a>                    
                    var cel7      = row.getElementsByTagName("td")[5];     //property type
                    
                    var type="property";  // type is for icon type.  
                    lat=cel1.childNodes[0];
                    lng=cel2.childNodes[0];
                    var add = cel3.childNodes[0];
                    var add2 = cel4.childNodes[0].data;
                    var community = cel6.childNodes[0];                    
                    var ptype = cel7.childNodes[0];
                    
                    var strhtml='<div class="mapbubble"><span class="link"><a href=' + add + '>' + add2 +'</a></span>';
                    strhtml += '<br><h4>' + (community.data) + ' ' + ctype.value + '</h4>'
                    strhtml += '<br><h4>Type: </h4> ' + (ptype.data)   
                    strhtml += '<br /></div>';
                    
                    var strname=strhtml;
                    var point = new GLatLng(parseFloat(lat.data),parseFloat(lng.data));
                                
                   if (lat.data.length>2 )
                    {
                    map.addOverlay(createMarker(point,strhtml,strname,type));   
                  //Each time a point is read, extend the map boundary to include the point.  
                   bound.extend(point);              
                    }                 
                    }
        //Get best zoom level after adding all points:
        map.setZoom(map.getBoundsZoomLevel(bound));
        //Reset the map center based on the boundary after adding all points.
        map.setCenter(bound.getCenter());  
         
}