
function locateUser(hideDiv, showDiv, msgDiv, checkBox) {
	var on = document.getElementById(checkBox).checked;
	if(!on) {
		document.getElementById(msgDiv).innerHTML = "";
		return;
	}
	if(navigator.geolocation) {
		document.getElementById(hideDiv).style.display = "none";
		document.getElementById(showDiv).style.display = "block";
		navigator.geolocation.getCurrentPosition( function(position) {
			var user_lat = position.coords.latitude;
			var user_lon = position.coords.longitude;
			var user_position_timestamp = position.timestamp;
			messageLoadLatLon(user_lat, user_lon, user_position_timestamp);
			document.getElementById(msgDiv).innerHTML = "( " + user_lat + "N, " + user_lon + "E )";
			document.getElementById(hideDiv).style.display = "block";
			document.getElementById(showDiv).style.display = "none";
		}, function(error) {
			document.getElementById(msgDiv).innerHTML = "Bummer! Your browser could not find your location. You can still send your message, though."
			document.getElementById(hideDiv).style.display = "block";
			document.getElementById(showDiv).style.display = "none";
			document.getElementById(checkBox).checked = false;
		}, 
		{maximumAge:1000*60*30, timeout:0});
	}	else {
		alert("Bummer! Your browser does not support this feature yet.");
		document.getElementById(checkBox).checked = false;
	}
}

function messageLoadLatLon(user_lat, user_lon, user_position_timestamp) {
	if(user_lat) {
		document.message_form.lat.value = user_lat;
	}
	if(user_lon) {
		document.message_form.lon.value = user_lon;
	}
	if(user_position_timestamp) {
		document.message_form.position_timestamp.value = user_position_timestamp;
	}
}


