
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();
          
            // 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.
    KK removed ED contact link
    */
    var mytable = $("table[id$=dgCommunity]")[0];
    //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 cel6      = row.getElementsByTagName("td")[4];      //link to client website (search link)
        var cel7      = row.getElementsByTagName("td")[5];      //population 
        var cel8      = row.getElementsByTagName("td")[6];      //labor force
        var cel10 = null;
        if (cel6 !== undefined) {
            cel10=cel6.getElementsByTagName("a")[0];      //client website link text
        }

        var type="community";  // type is for icon type.  
        lat=cel1.childNodes[0];
        lng=cel2.childNodes[0];
        link=cel4.childNodes[0];

        var linkclient = null;
        if (cel10 !== undefined) {
            linkclient = cel10.childNodes[0];
        }

        var strname=cel3.childNodes[0].data;
        pop=cel7.childNodes[0];
        lf=cel8.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=' + cel6.childNodes[0] + ' target=blank>Search Properties</a></span>'
        var searchlink2=''

        // only display searchpropertes link if the find properties column is defined
        var searchlinktest=test(linkclient);  
        strhtml += (searchlinktest==1?searchlink1:searchlink2)   

        //only display a  contact link if there is text in the contact anchor.

        strhtml +='</div>'
        var strname = strhtml
        if (lat.data.length>2 )
        {  
            var point = new GLatLng(parseFloat(lat.data),parseFloat(lng.data)); 
           
            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
  

