
function openGeocodePopup()
{
        var obj_calwindow = window.open('/gps/geocode_address.php','geocoder', 'width=300,height=400,status=no,resizable=no,top=200,left=200,dependent=yes,alwaysRaised=yes,resizable=yes');
//	obj_calwindow.opener = self;
        obj_calwindow.focus();
}

var callback = new Array();

function registerGeolocationCallbackfields(callbackFunction ){
        callback['callback'] = callbackFunction;
}

function updateCoordinates( latitude, longitude )
{
	// Call callback function
	callback['callback']( latitude, longitude );
}

function getIPLocation(){
        // This will provide approximate location on the network IP address by mobile operator gateway
        // (http://code.google.com/apis/ajax/documentation/#ClientLocation)
        if (typeof(google.loader.ClientLocation) != 'undefined')
        {
                try {
                        updateCoordinates(google.loader.ClientLocation.latitude, google.loader.ClientLocation.longitude);
                } catch (e) {
                        // Failed/denied
                }
        }
}


function getW3CLocation(){
        // W3C geolocation API provides location from GPS if available (iPhone OS3.0+ , Nokia symbian^3)
        // see http://dev.w3.org/geo/api/spec-source.html
        if (typeof(navigator.geolocation) != 'undefined')
        {
                try {
                        navigator.geolocation.getCurrentPosition(
                                function(position)
                                {
                                        // Success callback
                                        updateCoordinates( position.coords.latitude,  position.coords.longitude);
                                }, function( error ) {
                                        // Permission denied / Position not available or timed out. What ever, we can't do nothing more here.
					i = 1;
                        });
                        // Third parameter could also be "{maximumAge:60000,timeout:10000}"
                } catch (e)
                {
                        alert( e );
                }
        }
}

function getGoogleGearsLocation(){
        // Google Gears uses GPS and/or cell location (This is available in Android 1.0+ using Chrome Lite browser)
        if (typeof(google.gears) != 'undefined') {
                try {
                        var geo = google.gears.factory.create('beta.geolocation');
                        geo.getCurrentPosition(
                                function(position) {
                                        updateCoordinates( position.latitude, position.longitude);
                                }, function() {
                                        // Failed/denied
                                });
                } catch (e) {}
        }
}

function getDeviceLocation()
{
        // Get Approximate IP location
        getIPLocation();

        // Try to get W3C Location
        getW3CLocation();

        // Try to get Google Gears location
        getGoogleGearsLocation();
}


