// ****************** Bank Machine ATM Finder Javascript ******************
function GeocodePostcode(strPostcode)
{
	var strURL;
	
	strURL = "/geocode/geocode.php?postcode=" + strPostcode;
	 	
	new Ajax.Request(strURL,{method:'get',onSuccess:GeocodePostcode_cb});
   
}

function GeocodePostcode_cb(t)
{
	var lat;
	var lng;
	var intStart;
	var intEnd;
	
	lat = "0";
	lng = "0";
	
	if (t.responseText.indexOf("<lat>") != -1)
	{
		intStart = t.responseText.indexOf("<lat>") + 5;
		intEnd = t.responseText.indexOf("</lat>");
			
		lat = t.responseText.substring(intStart,intEnd);
		lat = lat * 1;
			
	}
	
	if (t.responseText.indexOf("<lng>") != -1)
	{
		intStart = t.responseText.indexOf("<lng>") + 5;
		intEnd = t.responseText.indexOf("</lng>");
			
		lng = t.responseText.substring(intStart,intEnd);
		lng = lng * 1;
			
	}
	
	if (lat != "0" && lng != "0")
	{
		strURL = "/atmfinder/index.php?lat=" + lat + "&lng=" + lng;
		document.location.href = strURL;
	}
	else
	{
		alert('Bank Machine ATM Finder\n\nSorry we could not find the address you entered');
	}
	
}

function GetCurrentLocation()
{
	var location;
	
	// Try W3C Geolocation (Preferred)
	if(navigator.geolocation) 
  	{
    	browserSupportFlag = true;
    	navigator.geolocation.getCurrentPosition(function(position){
      		strURL = "/atmfinder/index.php?lat=" + position.coords.latitude + "&lng=" + position.coords.longitude;
      		document.location.href = strURL;
	    },function() {alert('Bank Machine ATM Finder\n\nSorry, we could not calculate your location, please enter a postcode');return(null)});
  	}
  	else if (google.gears) 
  	{
    	browserSupportFlag = true;
    	var geo = google.gears.factory.create('beta.geolocation');
    	geo.getCurrentPosition(function(position){
      		strURL = "/atmfinder/index.php?lat=" + position.latitude + "&lng=" + position.longitude;
      		document.location.href = strURL;
	    },function() {alert('Bank Machine ATM Finder\n\nSorry, we could not calculate your location, please enter a postcode');return(null);});
  	} 
  	else 
  	{
    	alert('Bank Machine ATM Finder\n\nSorry, we could not calculate your location, please enter a postcode');
    	return(null);
  	}
  	

}		


