MyMap = new Object();

MyMap.draw = function(map_id,is_geocoded,lat,lng,address_text,zoom_level)
{
  if (is_geocoded)
  {
    var latlng = new google.maps.LatLng(lat,lng);
    MyMap.drawFromLatLng(map_id, latlng,address_text,zoom_level)
  }
  else
  {
    MyMap.drawFromAddress(map_id,address_text,zoom_level);
  }
}

MyMap.drawFromAddress = function(map_id,address_text,zoom_level)
{
  var geocoder = new google.maps.Geocoder();
  geocoder.geocode({'address': address_text}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
        var latlng = results[0].geometry.location;
        MyMap.drawFromLatLng(map_id,latlng,address_text,zoom_level);
      } else {
        alert("Google Maps failed (Geocoder) due to: " + status);
      }
    });
}

MyMap.drawFromLatLng = function(map_id, latlng,address_text,zoom_level)
{
  var myOptions = {
    zoom: zoom_level,
    center: latlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };
  
  var map = new google.maps.Map(document.getElementById(map_id), myOptions);
  var marker = new google.maps.Marker({
      position: latlng,
      title:address_text
  });
  marker.setMap(map);
  var infowindow = new google.maps.InfoWindow({ content: address_text});
  google.maps.event.addListener(marker, 'click', function(event) {
    infowindow.open(map,marker);
  });
}
