﻿function GMapInitialize() {
  if (GBrowserIsCompatible()) {
    var map = new GMap2(document.getElementById("map_canvas"));
    map.setCenter(new GLatLng(52.483396, -1.896438), 13);
    
    var marker = new GMarker(new GLatLng(52.483396, -1.896438))
    GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml('Wesleyan Head Office'); });                
    map.addOverlay(marker);
    
    map.addControl(new GSmallMapControl());
    map.addControl(new GMapTypeControl());   
  }
}
function disableEnterKey(e){
         var key;
         if(window.event)
              key = window.event.keyCode;     //IE
         else
              key = e.which;     //firefox

         if(key == 13){
              submitGoogleMapsForm();
              return false;
         }else
              return true;
    }

Event.observe(window, 'load', function() {
    $('getDirectionsContainer').innerHTML = '<label for="saddr">Start location: <\/label>' +
                                            '<input type="text" name="saddr" id="saddr" onkeypress="return disableEnterKey(event);" \/>' +
                                            '<input type="button" value="Go &gt;" class="go_button" id="getDirectionsGo" onclick="submitGoogleMapsForm()" onkeypress="submitGoogleMapsForm()" \/>';
});
function submitGoogleMapsForm(){
    newdirectionswindow = window.open("http://maps.google.com/maps?f=d&source=s_d&daddr=Wesleyan%20Assurance%20Society,%20B4%206AR&hl=en&geocode=&saddr=" + $('saddr').value,
    'googleMaps',
    'left=20,top=20,width=750,height=600,toolbar=1,resizable=1');
    if(newdirectionswindow) {
      // Make sure this window receives focus (in case it was already open and minimised)
        newdirectionswindow.focus();
    }
}
