﻿    
  var geocoder;
  var directionDisplay;
  var directionsService = new google.maps.DirectionsService();
  var map;
  
    geocoder = new google.maps.Geocoder();
    var latlng = new google.maps.LatLng(-34.397, 150.644);
    var myOptions = {
      zoom: 14,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    map = new google.maps.Map(document.getElementById("map"), myOptions);
    
    directionsDisplay = new google.maps.DirectionsRenderer();
    
    var address = document.getElementById("<%=area_text.ClientID%>").value;
    
    if (address == 'UNKNOWN') {
    var dlat = document.getElementById("<%=dlat.ClientID%>").value;
    var dlng = document.getElementById("<%=dlng.ClientID%>").value;
    var phys = document.getElementById("<%=phys.ClientID%>").value;
    //var image = "D:\websiteClient\myproperty3_new\myproperty3_new\images\house.png";
    
    var latlng2 = new google.maps.LatLng(dlat, dlng);
    var myOptions = {
      zoom: 17,
      center: latlng2,
      mapTypeId: google.maps.MapTypeId.HYBRID
    }

    map = new google.maps.Map(document.getElementById("map"), myOptions);
    directionsDisplay.setMap(map);
    
    var marker = new google.maps.Marker({
        position: latlng2,
        map: map,
        title: phys
    });
   
    
    
    } else {
    
    if (geocoder) {
      geocoder.geocode( { 'address': address}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            map.setCenter(results[0].geometry.location);
            
          
        } else {

          //alert("Geocode was not successful for the following reason: " + status);
          document.getElementById("map").style.visibility = 'hidden';
          document.getElementById('map').innerHTML="<p>LOCATION COULD NOT BE FOUND</p>";
          document.getElementById("map").style.visibility = 'visible';
        }
      });
    }

}
     
 <!--
function printContent(id){
str=document.getElementById(id).innerHTML
newwin=window.open('','printwin','left=100,top=100,width=400,height=400')
newwin.document.write('<HTML>\n<HEAD>\n')
newwin.document.write('<TITLE>Print Directions</TITLE>\n')
newwin.document.write('<script>\n')
newwin.document.write('function chkstate(){\n')
newwin.document.write('if(document.readyState=="complete"){\n')
newwin.document.write('window.close()\n')
newwin.document.write('}\n')
newwin.document.write('else{\n')
newwin.document.write('setTimeout("chkstate()",2000)\n')
newwin.document.write('}\n')
newwin.document.write('}\n')
newwin.document.write('function print_win(){\n')
newwin.document.write('window.print();\n')
newwin.document.write('chkstate();\n')
newwin.document.write('}\n')
newwin.document.write('<\/script>\n')
newwin.document.write('</HEAD>\n')
newwin.document.write('<BODY onload="print_win()">\n')
newwin.document.write(str)
newwin.document.write('</BODY>\n')
newwin.document.write('</HTML>\n')
newwin.document.close()
}
//-->


     function calcRoute() {

         var myOptions = {
             zoom: 17,
             center: latlng2,
             mapTypeId: google.maps.MapTypeId.HYBRID
         }

         map = new google.maps.Map(document.getElementById("map"), myOptions);
         directionsDisplay.setMap(map);
         directionsDisplay.setPanel(document.getElementById("directionsPanel"));
     
         var start = document.getElementById("locationA").value;
         var end = document.getElementById("<%=locationB.ClientID%>").value;
               
         var request = {
             origin: start,
             destination: end,
             travelMode: google.maps.DirectionsTravelMode.DRIVING
         };
         directionsService.route(request, function(response, status) {
          if (status == google.maps.DirectionsStatus.OK) {
                 directionsDisplay.setDirections(response);
                 
                 document.getElementById('btn_print').style.visibility = "visible";
             }else {
             
             var myOptions = {
             zoom: 17,
             center: latlng2,
             mapTypeId: google.maps.MapTypeId.HYBRID
         }

         map = new google.maps.Map(document.getElementById("map"), myOptions);
             
                 var marker = new google.maps.Marker({
                 position: latlng2,
                 map: map,
                 title: phys
                });
             alert("invalid address");
             }
         });
     }