
var G2myGeocoder;var G2reasons=[];var G2checkCountry;function G2initGeocode(){G2myGeocoder=new GClientGeocoder();G2myGeocoder.setBaseCountryCode(null);G2reasons[G_GEO_SUCCESS]="Success";G2reasons[G_GEO_MISSING_ADDRESS]="Missing Address: The address was either missing or had no value.";G2reasons[G_GEO_UNKNOWN_ADDRESS]="Unknown Address:  No corresponding geographic location could be found for the specified address.";G2reasons[G_GEO_UNAVAILABLE_ADDRESS]="Unavailable Address:  The geocode for the given address cannot be returned due to legal or contractual G2reasons.";G2reasons[G_GEO_BAD_KEY]="Bad Key: The API key is either invalid or does not match the domain for which it was given";G2reasons[G_GEO_TOO_MANY_QUERIES]="Too Many Queries: The daily geocoding quota for this site has been exceeded.";G2reasons[G_GEO_SERVER_ERROR]="Server error: The geocoding request could not be successfully processed.";}
google.setOnLoadCallback(G2initGeocode);function G2doPostback(){var button=document.getElementById(G2postbackCtrl);if(button!==null){if(G2doValidation===true){G2callServer('About to validate and post back');if(typeof(Page_ClientValidate)!='function'||Page_ClientValidate()){return __doPostBack(button.name,"OnClick");}}
else{G2callServer('About to post back 2...');return __doPostBack(button.name,"OnClick");}}}
function G2selectResult(lat,lng,address){G2callServer('SelectResult');G2saveLatLng(lat,lng,address);G2doPostback();return false;}
function G2displayClickForMap(){var geocodeMapLinkCtrl=document.getElementById("G2geocodeMapLink");if(geocodeMapLinkCtrl!==null){geocodeMapLinkCtrl.innerHTML="Please <a href='#' onclick='return G2showPopup();'>click here</a> and select your location manually";geocodeMapLinkCtrl.style.display="block";}}
function G2addResult(resultText){var geocodeResultsCtrl=document.getElementById("G2geocodeResults");var geocodeMapResultsCtrl=document.getElementById("G2geocodeMapResults");if(geocodeResultsCtrl!==null){geocodeResultsCtrl.innerHTML+=resultText;geocodeResultsCtrl.style.display="block";}
if(geocodeMapResultsCtrl!==null){geocodeMapResultsCtrl.innerHTML+=resultText;geocodeMapResultsCtrl.style.display="block";}}
function G2parseLocations(response){G2clearMessages();var geocodeErrorCtrl=document.getElementById("G2geocodeError");var geocodeErrorDetailedCtrl=document.getElementById("G2geocodeErrorDetailed");var geocodeMapLinkCtrl=document.getElementById("G2geocodeMapLink");var p;if(response.Status.code==G_GEO_SUCCESS){if(response.Placemark.length>1){var results="Did you mean:";for(var i=0;i<response.Placemark.length;i++){p=response.Placemark[i].Point.coordinates;if(G2popupResults==true){results+="<br>"+(i+1)+": <a href='#' onclick='return G2createMarkerFromLatLng("+p[1]+","+p[0]+",\""+response.Placemark[i].address+"\",true);'>"+response.Placemark[i].address+"</a>";}
else{results+="<br>"+(i+1)+": <a href='#' onclick='return G2selectResult("+p[1]+","+p[0]+",\""+response.Placemark[i].address+"\");'>"+response.Placemark[i].address+"</a>";}}
G2addResult(results);if(G2popupResults==true){G2showPopupWithResults(results);}
else{G2displayClickForMap();}}
else{if(G2checkCountry===true){if(response.Placemark[0].AddressDetails.Country.CountryNameCode!=G2currCountryCode){if(geocodeErrorCtrl!==null){if(G2lastSearch==''){geocodeErrorCtrl.innerHTML='Please enter Town/City detail then Search';}else{geocodeErrorCtrl.innerHTML='Could not find "'+G2lastSearch+'"';}
geocodeErrorCtrl.style.display="block";}
return false;}}
p=response.Placemark[0].Point.coordinates;var point=new google.maps.LatLng(p[1],p[0]);G2saveClickedPoint(point);G2saveSelectedPoint(point);G2saveAddress(response.Placemark[0].address);G2pointSelected=true;G2callServer("SingleResult:"+G2postbackCtrl);G2doPostback();return false;}}
else{var reason="Code "+response.Status.code;if(G2reasons[response.Status.code]){reason=G2reasons[response.Status.code];}
if(geocodeErrorCtrl!==null){if(G2lastSearch==''){geocodeErrorCtrl.innerHTML='Please enter Town/City detail then Search';}else{geocodeErrorCtrl.innerHTML='Could not find "'+G2lastSearch+'"';}
geocodeErrorCtrl.style.display="block";}
if(geocodeErrorDetailedCtrl!==null){geocodeErrorDetailedCtrl.innerHTML='Reason: '+reason;geocodeErrorDetailedCtrl.style.display="block";}
G2displayClickForMap();}}
function G2geoSearchText(searchText,validate,appendCountry){G2checkCountry=appendCountry;G2doValidation=validate;G2callServer("lastCountryCode = "+G2lastCountryCode+" currCountryCode = "+G2currCountryCode+" lastSearch = "+G2lastSearch+" pointSelected = "+G2pointSelected);var tmpSearchText=searchText;if(tmpSearchText=="Found on map"){G2doPostback();return true;}
if(tmpSearchText=="Postal Code/Zip Code or Town/City"||tmpSearchText=="e.g. KY16 9AJ"||tmpSearchText=="Town or Postal/Zip Code"||tmpSearchText=="Postal/Zip Code or Town/City"||tmpSearchText=="Town/City or Postal/Zip Code"){tmpSearchText='';}
if(G2lastCountryCode==G2currCountryCode&&G2lastSearch==tmpSearchText&&G2pointSelected===true){G2doPostback();return true;}
G2clearMessages();G2pointSelected=false;G2lastSearch=tmpSearchText;G2lastCountryCode=G2currCountryCode;if(appendCountry===true){G2myGeocoder.setBaseCountryCode(G2currCountryCode);tmpSearchText=tmpSearchText+" "+G2currCountryCode;}
else{G2myGeocoder.setBaseCountryCode(null);}
G2myGeocoder.getLocations(tmpSearchText,G2parseLocations);return G2pointSelected;}
function G2geoSearch(validate,appendCountry){G2getCountryCode();var searchText=document.getElementById(G2addressCtrl).value;return G2geoSearchText(searchText,validate,appendCountry);}
function G2geoSearchByCountry(countryCode,validate,appendCountry){G2currCountryCode=countryCode;var searchText=document.getElementById(G2addressCtrl).value;return G2geoSearchText(searchText,validate,appendCountry);}
function G2geoSearchByCountryAndText(countryCode,searchText,validate,appendCountry){G2currCountryCode=countryCode;return G2geoSearchText(searchText,validate,appendCountry);}
function G2geoShow(){G2doValidation=false;G2myGeocoder.setBaseCountryCode(G2getCountryCode());var searchText=document.getElementById(G2addressCtrl).value;G2pointSelected=false;G2lastSearch=searchText;G2lastCountryCode=G2currCountryCode;G2clearMessages();if(searchText=="Postal Code/Zip Code or Town/City"||searchText=="e.g. KY16 9AJ"||searchText=="Town or Postal/Zip Code"||searchText=="Postal/Zip Code or Town/City"||searchText=="Town/City or Postal/Zip Code"){G2showPopupMap(true);G2centerMapOnCountry();return false;}
if(G2myGeocoder!==null){G2myGeocoder.getLocations(searchText+" "+G2currCountryCode,function(response){var geocodeErrorCtrl=document.getElementById("geocodeError");var showmap=false;if(response.Status.code==G_GEO_SUCCESS){if(response.Placemark.length>0){for(var i=0;i<response.Placemark.length;i++){if(response.Placemark[i].AddressDetails.Country.CountryNameCode==currCountryCode){G2showPopupMap(true);p=response.Placemark[0].Point.coordinates;var point=new google.maps.LatLng(p[1],p[0]);reverseGeocoder.reverseGeocode(point);callServer("Reversing "+p[1]+", "+p[0]);G2createMarker(point);G2myMap.setCenter(point,5);return false;}}
showmap=true;}
else{showmap=true;}}
else{showmap=true;}
if(showmap===true){G2showPopupMap(true);G2centerMapOnCountry();return false;}});}
return false;}