
var map = null;
var geocoder = null;

function load() {

  if (document.getElementById("tutorlocationstatus") != null)
    document.getElementById("tutorlocationstatus").innerHTML = "";
  
  if (GBrowserIsCompatible()) {
    
    var tutorid = window.location.pathname;
    tutorid = tutorid.replace('/tutors/','');
    tutorid = tutorid.substring(0,tutorid.indexOf("/"))
    var address = null;
    
    //ajax section
     $.ajax({
      type: "POST",
      url: "/xmlhttp_files/tutor-address.aspx/GetTutorAddress",
      data: "{tutorid:" + tutorid + "}",
      contentType: "application/json; charset=utf-8",
      dataType: "json",
      success: function(response) {
      if (response.d != "") {
    
            //google maps section
            map = new GMap2(document.getElementById("map"));
            
            map.addControl(new GLargeMapControl());
            //map.addControl(new GMapTypeControl());

            //map.setCenter(new GLatLng(37.4419, -122.1419), 13);
            geocoder = new GClientGeocoder();
            
            if (geocoder) {
              geocoder.getLatLng(
                response, //ajax response
                function(point) {
                  if (!point) {
                    //alert("Tutor location not found");
                    document.getElementById("tutorlocationstatus").innerHTML = "Error: Tutor location not found";
                    map.setCenter(new GLatLng(37.4419, -122.1419), 1);
                    
                  } else {
                    map.setCenter(point, 13);
                    var marker = new GMarker(point);
                    //alert(point);
                    map.addOverlay(marker);
                    //marker.openInfoWindowHtml(address);
                  }
                }
               );
             }
             //end of google maps
       }
      }
    }); //end of ajax
    
   }
}
