  var geocoder;
  var map;

  function initialize() {
    geocoder = new google.maps.Geocoder();
    var latlng = new google.maps.LatLng(40.774416,-73.097341);
    var myOptions = {
      zoom: 11,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    
    codeAddress()
  }

  function codeAddress() {
    
    var address = document.getElementById("address").value;
    var displayAddress = "";
    
    if (document.getElementById("displayAddress") != null){
        displayAddress = document.getElementById("displayAddress").value;
    }
    
    geocoder.geocode( { 'address': address}, function(results, status) {

      if (displayAddress.length > 0) {address = displayAddress;}
        
      if (status == google.maps.GeocoderStatus.OK) {
        map.setCenter(results[0].geometry.location);

        var marker = new google.maps.Marker({
            map: map, 
            position: results[0].geometry.location,
            title: address
        });

        var infowindow = new google.maps.InfoWindow({
            content: address 
        });

        google.maps.event.addListener(marker, 'click', function() { infowindow.open(map,marker); });
        //infowindow.open(map,marker);

      } else {
        alert("Geocode was not successful for the following reason: " + status);
      }
    });
  }
 
