	
	var geocoder;
	var map;

function gmps_initialize(zoomLevel,startLatitude,startLongitude) {

  if (zoomLevel == null){
   zoomLevel = 4;
  }
  if (startLatitude == null){
   startLatitude = 38.89774858694348;
  }
  if (startLongitude == null){
   startLongitude = -77.03664248161469;
  }

  geocoder = new google.maps.Geocoder();

  //var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
  var myLatlng = new google.maps.LatLng(startLatitude,startLongitude);

  var myOptions = {
    zoom: zoomLevel,
    center: myLatlng,
    zoomControl: true, 
	mapTypeId: google.maps.MapTypeId.ROADMAP
  }

  map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
  
  //map.addControl(new GMapTypeControl());
  //map.addControl(new GSmallMapControl());
  
  google.maps.event.addListener(map, 'click', function(event) {
    placeMarker(event.latLng);
  });

}
  
function placeMarker(location) {
  var clickedLocation = new google.maps.LatLng(location);
  var marker = new google.maps.Marker({
      position: location, 
	  draggable: true,
      map: map
  });
 
  map.setCenter(location);
  document.getElementById("WPQRLatitude").value = location.lat();
  document.getElementById("WPQRLongitude").value = location.lng();
  document.getElementById("WPQRZoom").value = map.getZoom();

 google.maps.event.addListener(marker, 'dragend', function(event) {
    newlocation = event.latLng;
	document.getElementById("WPQRLatitude").value = newlocation.lat();
	document.getElementById("WPQRLongitude").value = newlocation.lng();
	document.getElementById("WPQRZoom").value = map.getZoom();
	map.setCenter(newlocation);
  });

}

  function codeAddress() {
    var address = document.getElementById("WPQRLocation").value;
    geocoder.geocode( { 'address': address}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
        map.setCenter(results[0].geometry.location);
		map.setZoom(14);

	    newlocation = results[0].geometry.location;
		document.getElementById("WPQRLatitude").value = newlocation.lat();
		document.getElementById("WPQRLongitude").value = newlocation.lng();
		document.getElementById("WPQRZoom").value = map.getZoom();

     // var marker = new google.maps.Marker({
     //       map: map, 
     //       position: results[0].geometry.location
     //   });
      } else {
        alert("Location lookup was not successful for the following reason: " + status);
      }
    });
  }


