var globalCountry;
var geofail = 'xun';
var geocoder;

function strtolower(a){return(a+'').toLowerCase()}
function strlen(d){var e=d+'';var i=0,chr='',lgth=0;if(!this.php_js||!this.php_js.ini||!this.php_js.ini['unicode.semantics']||this.php_js.ini['unicode.semantics'].local_value.toLowerCase()!=='on'){return d.length}var f=function(a,i){var b=a.charCodeAt(i);var c='',prev='';if(0xD800<=b&&b<=0xDBFF){if(a.length<=(i+1)){throw'High surrogate without following low surrogate';}c=a.charCodeAt(i+1);if(0xDC00>c||c>0xDFFF){throw'High surrogate without following low surrogate';}return a.charAt(i)+a.charAt(i+1)}else if(0xDC00<=b&&b<=0xDFFF){if(i===0){throw'Low surrogate without preceding high surrogate';}prev=a.charCodeAt(i-1);if(0xD800>prev||prev>0xDBFF){throw'Low surrogate without preceding high surrogate';}return false}return a.charAt(i)};for(i=0,lgth=0;i<e.length;i++){if((chr=f(e,i))===false){continue}lgth++}return lgth}

function geo() {
	if(sessgo == '') {
		if (navigator.geolocation) {
			navigator.geolocation.getCurrentPosition(geo_success,geo_fail);
		} else {
			geo_fail();
		}
	}
}

function geo_success(pos) {
	var lat = pos.coords.latitude;
	var lng = pos.coords.longitude;
	$.post('/__geo.php',{ilat:lat,ilng:lng},function(d){
		if(strlen(d) != 2) {
			globalCountry = geofail;
		} else {
			globalCountry = d;
		}
		geo_callback();
	}).error(function(){
		globalCountry = geofail;
		geo_callback();
	}); 
}

function geo_fail() {
	var cc = google.loader.ClientLocation.address.country_code;
	if(cc == '') { globalCountry = geofail; } else { globalCountry = cc; }
	geo_callback();
}

function geo_callback() {
	$.post('/__geo.php',{f:'set',c:globalCountry},function(d){
		if(globalCountry == 'be' || globalCountry == 'ch') {
			window.location.href='/block.php';
		}
		return true;
	});
}
