﻿var address = '';
var gBtn;
function GeocodeAddress(addressIn,btn) {
  gBtn = btn;
  address = addressIn;
  addVal = document.getElementById(address).value;
  geocoder = new GClientGeocoder();
  geocoder.getLatLng(
    addVal+', uk',
    function(point) {
      if (!point) {
        alert("Sorry, the address '" + addVal + "' could not be found.\n\nIf you entered a postcode, try including more address information.");
      } else {
        document.getElementById(btn).value = "GO";
        document.getElementById(address+'-lt').value = point.lat().toString();
        document.getElementById(address+'-ln').value = point.lng().toString();
        document.forms[0].submit();
      }
    }
  );
}

function CheckKeyPress(btn,e,fld){
    var kc;
    if (window.event)
        kc = window.event.keyCode;
    else
        kc = e.which;
    
    if (kc == 13){
        GeocodeAddress(fld.id,btn);
        return false;
    }
    return true;
}