function getGeoCity(feedbackHTMLElement, suffixString, errorString, auxHTMLElement, auxHTMLElementClass, auxHTMLElementToggleAtError, accuracyThreshold, cookielife_secs) {
	getGeoLoc(function(pos){
			var latLng = new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude);
			var gcd = new google.maps.Geocoder();
			gcd.geocode({'latLng': latLng}, function(results, status) {
				if (status == google.maps.GeocoderStatus.OK && results[0]) {							
					for(var i=0; i<results[0].address_components.length; i++) {
						var address_component = results[0].address_components[i];
						for(var j=0; j<address_component.types.length; j++) {									
							if (address_component.types[j] == "locality"){								
								feedbackHTMLElement.html(address_component.long_name + suffixString);
								if (auxHTMLElement !== null && auxHTMLElementClass !== null) auxHTMLElement.toggleClass(auxHTMLElementClass);
								return;
							}
						}
					}
				}else{
					if (errorString !== null) feedbackHTMLElement.html(errorString);
					if (auxHTMLElement !== null && auxHTMLElementClass !== null && auxHTMLElementToggleAtError) auxHTMLElement.toggleClass(auxHTMLElementClass);
				}
			});
		}, feedbackHTMLElement, errorString, auxHTMLElement, auxHTMLElementClass, auxHTMLElementToggleAtError, accuracyThreshold, cookielife_secs);
}

function getGeoLoc(callback_function, feedbackHTMLElement, errorString, auxHTMLElement, auxHTMLElementClass, auxHTMLElementToggleAtError, accuracyThreshold, cookielife_secs) {
	if(navigator.geolocation){
		navigator.geolocation.getCurrentPosition(		
			function(pos) {				
				if(pos.coords.accuracy <= accuracyThreshold){
					var expdate = new Date();
					expdate.setTime(expdate.getTime() + (cookielife_secs * 1000));
					$.cookie("geo_lat",pos.coords.latitude,{expires: expdate});
					$.cookie("geo_lng",pos.coords.longitude,{expires: expdate});
					callback_function(pos);
				}else{					
					if (errorString !== null) feedbackHTMLElement.html(errorString);
					if (auxHTMLElement !== null && auxHTMLElementClass !== null && auxHTMLElementToggleAtError) auxHTMLElement.toggleClass(auxHTMLElementClass);
				}
		}, function(err) {							
				if (errorString !== null) feedbackHTMLElement.html(errorString);
				if (auxHTMLElement !== null && auxHTMLElementClass !== null && auxHTMLElementToggleAtError) auxHTMLElement.toggleClass(auxHTMLElementClass);
		}, {
			'enableHighAccuracy' : true,
			'timeout' : 60000,
			'maximumAge' : 120000
		});
	}else{
		if (errorString !== null) feedbackHTMLElement.html(errorString);
		if (auxHTMLElement !== null && auxHTMLElementClass !== null && auxHTMLElementToggleAtError) auxHTMLElement.toggleClass(auxHTMLElementClass);
	}
}
