function activate_gps_button()
{
    if (navigator.geolocation) {

        if (document.getElementById("gpsButtonContainer") && document.getElementById("gpsButton")) {
            document.getElementById("gpsButtonContainer").style.display = "block";
            document.getElementById("gpsButton").addEventListener('click', function() {
                navigator.geolocation.getCurrentPosition(set_location_from_gps);
                return false;
                },
           false);

           // Also set the text input to clear on focus
           if (document.getElementById("locationInput")) {
               document.getElementById("locationInput").addEventListener('focus', function() {
                   document.getElementById("locationInput").value="";
               }, false);
           }
        }

        if (document.getElementById("headerGPSButton")) {
           document.getElementById("headerGPSButton").addEventListener('click', function(e) {
		navigator.geolocation.getCurrentPosition(set_location_from_gps_header, failure_go_to_where_page);
                return kill_event(e);
                },
           false);
           /* if (document.getElementById("headerLocationForm")) {
               document.getElementById("headerLocationForm").addEventListener('submit', ajax_where, false);
           } */
        }
    }
}

failure_go_to_where_page = function() {
        window.location.href = document.getElementById('headerGPSButton').href;
}

set_location_from_gps = function(location) {

    if (document.getElementById("jsLocationInput") && document.getElementById("locationForm")) {
        document.getElementById("jsLocationInput").value = location.coords.latitude + ", " + location.coords.longitude;
        document.getElementById("locationForm").submit();
    }
}

set_location_from_gps_header = function(location) {

    if (document.getElementById("headerJSLocationInput") && document.getElementById("headerLocationForm")) {
        document.getElementById("headerJSLocationInput").value = location.coords.latitude + ", " + location.coords.longitude;
        document.getElementById("headerLocationForm").submit();
    }
}

ajax_where = function(e) {
    // Save this for later.
    /* $.post("/where.php", $(this).serialize(), where_callback, "text");
    
    return kill_event(e); */
    return true;
}

where_callback = function(data, textStatus) {

    
}