  var geocoder;
  var map;

  function codeAddress() {
    geocoder = new google.maps.Geocoder();
    var latlng = new google.maps.LatLng(-34.397, 150.644);
    var myOptions = {
      zoom: 13,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
	var geocode_lat = '';
	var geocode_long = '';
	var location_title = '';
	if(document.getElementById("geocode_lat")){
	  geocode_lat = document.getElementById("geocode_lat").value;
	}
	if(document.getElementById("geocode_long")){
	  geocode_long = document.getElementById("geocode_long").value;
	}
	if(document.getElementById("location_title")){
	  location_title = document.getElementById("location_title").value;
	}
	if(geocode_lat != '' && geocode_long != ''){
    	var latlng = new google.maps.LatLng(geocode_lat,geocode_long);
        map.setCenter(latlng);
	    var marker = new google.maps.Marker({
	        position: latlng, 
	        map: map,
	        title: location_title
	    });
	}else{
	    var address = document.getElementById("location_address").value;
	    if (geocoder) {
	      geocoder.geocode( { 'address': address}, function(results, status) {
	        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
	          });
	        } else {
	          alert("Geocode was not successful for the following reason: " + status);
	        }
	      });
	    }
	}
  }

Element.observe(window,'load',function(){codeAddress();});