   Event.observe(window, 'load', init, false);
function init() {
Event.observe('nearme', 'click', findLoc, false);
Event.observe('subbutton', 'click', runSub, false);
}

function findLoc() 
{	
/// based on code by merged.ca! thanks so much!	
	if (navigator.geolocation) 
	{
		navigator.geolocation.getCurrentPosition( function (position) {  
			
			// Did we get the position correctly?
			// alert (position.coords.latitude);
			//alert("yo!");
			// To see everything available in the position.coords array:
			 //for (key in position.coords) {alert(key)}

		geoResult(position.coords.latitude,position.coords.longitude);
	  //alert(position.coords.latitude+', '+position.coords.longitude);	  			
 		}, // next function is the error callback
 			function (error)
 			{
 				switch(error.code) 
 				{
       				case error.TIMEOUT:
 						alert ('Timeout');
 						break;
 					case error.POSITION_UNAVAILABLE:
 						alert ('Position unavailable');
 						break;
 					case error.PERMISSION_DENIED:
 						alert ('Permission denied');
 						break;
 					case error.UNKNOWN_ERROR:
 						alert ('Unknown error');
 						break;
 				}
 			}
 		);
 	} 
 	else 
 	{
	  alert("I'm sorry, but geolocation services are not supported by your browser or you do not have a GPS device in your computer.");
	
	}  
}
function geoResult(latitude,longitude) {
var url = 'result.php';
var pars = 'location='+escape(latitude) + ','+escape(longitude);
//alert(pars);
var target = 'results';	
var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars});
$('form').hide();
return false;
}
function runSub() {
var url = 'result.php';
var pars = $('searchform').serialize();
//alert(pars);
var target = 'results';	
var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars});
$('form').hide();
return false;
}

