
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.addControl(new GLargeMapControl());
map.addControl(new GScaleControl());
map.addMapType(G_PHYSICAL_MAP);
map.addControl(new GMapTypeControl());
map.enableDoubleClickZoom();
//map.enableScrollWheelZoom();
//map.enableContinuousZoom();
 
      // Create a Hierercical map type control
     // var hierarchy = new GHierarchicalMapTypeControl();
       // make Google Satellite Hybrid be the satellite default
      //hierarchy.addRelationship(G_SATELLITE_MAP, G_HYBRID_MAP, null, true);
      
      //var hterhybrid = new GHierarchicalMapTypeControl();
      //hterhybrid.addRelationship(G_PHYSICAL_MAP,G_HYBRID_MAP, null, false);

      //map.addControl(hierarchy);
      //map.addControl(hterhybrid);
      
// 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("gmap").innerHTML="Your browser is not compatible to view the Google map on this page."
        } 
        }         
    }
 
////////
 function test(string)
 {
 var test;
 if (typeof string=="undefined")
  test=0
 else
  test = 1
 
   return test
 } 
     
////////////////////////////////////////////////////////////
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];
//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];      //name                                                           
                    var cel4      = row.getElementsByTagName("td")[3];      //link to community detail page
                    var cel5      = row.getElementsByTagName("td")[4];      //score
                    var cel6      = row.getElementsByTagName("td")[5];      //link to ED profile if one exists (contact link)
                    var cel7      = row.getElementsByTagName("td")[6];      //link to client website (search link)
                    var cel8      = row.getElementsByTagName("td")[7];      //population 
                    var cel9      = row.getElementsByTagName("td")[8];       //labor force
                    var cel10     = cel6.getElementsByTagName("a")[0];     //name inside the ED Contact link anchor <a>
                    var cel11     = cel7.getElementsByTagName("a")[0];      //link to client site
                    
                    var type  // type is for icon type.  
                    lat=cel1.childNodes[0];
                    lng=cel2.childNodes[0];
                    link=cel4.childNodes[0];
                    var score=cel5.childNodes[0].data;
                    edlink = cel10.childNodes[0];
                                        
                    var linkclient = cel11 == null ? null : cel11.childNodes[0];
                    
                    var strname=cel3.childNodes[0].data;
                    pop=cel8.childNodes[0];
                    lf=cel9.childNodes[0];
               
		            var strhtml='<div class="mapbubble">'
		            strhtml += '<h3><a href=' + link + '>' + strname +'</a></h3>'
                    strhtml += '<h4>Population:</h4> ' + (pop.data) + '<br>'
                    strhtml += '<h4>Labor Force:</h4> ' + (lf.data) + '<br>'                  
                    
                    //Client site links and ED links dont always exist, so test them and iuse conditional operator:
                    //define links for client sites and ED progiles. 
                    var searchlink1='<span class=link><a href=' + cel7.childNodes[0] + ' target=blank>Search Properties</a></span>'
                    var searchlink2=''
                    var edlink1='<span class=link><a href=' + cel6.childNodes[0] + ' target=blank>Contact</a></span>'
                    var edlink2=''
                    
                    // only display searchpropertes link if the find properties column is defined
                    var searchlinktest=test(linkclient);  
                   // alert(typeof linkclient);
                    strhtml += (searchlinktest==1?searchlink1:searchlink2)   

                    var edlinktest=test(edlink);                
                    //only display a  contact link if there is text in the contact anchor.
                    strhtml += (edlinktest==1?edlink1:edlink2)
                    strhtml +='</div>'

                    var strname = strhtml

                   if (lat.data.length>2 )
                    {  
                    //name= mycel3.childNodes[0] 
                    var point = new GLatLng(parseFloat(lat.data),parseFloat(lng.data)); 
                   //alert(score.data);
                   if (score>=0)
                     {type="community7";}
                   if (score>=70)
                     {type="community6";}
                   if (score>=75)
                     {type="community5";}
                   if (score>=80)
                     {type="community4";}
                   if (score>=85)
                     {type="community3";}
                  if (score>=90)
                     {type="community2";}
                  if (score>=95)
                     {type="community1";}
//type="community";
                     
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());   

                    }         // END of lat.data.length      
                    }          // END of loop           
   }                            // END funtion
  
