function initLocation() {
	google.load("maps", "2");
	google.setOnLoadCallback(initializeGeoLoc);
}


function initializeGeoLoc() {
	if (google.loader.ClientLocation && google.loader.ClientLocation.latitude && google.loader.ClientLocation.longitude) {
		var jsonRequest = new Request.JSON({url: "/remote.php", onComplete: function(nearly){

		    if ( nearly == null ) {


			}
			else {
				display_nearby_answer(nearly.answer[0]);

			}
		
		}}).get({'lat': google.loader.ClientLocation.latitude, 'lon': google.loader.ClientLocation.longitude});

    }
}


function display_nearby_answer(result) {
	if ( result.follow == 1 ) {
		document.location = '/'+result.name+'-'+result.country+'-'+result.id;
		return false;
	}
	txt  = '<div id="nearbytxt"><a href="/'+result.name+'-'+result.country+'-'+result.id+'">Vous habitez près de ' + result.name + ' ?';
	txt += '<br/>Cliquez ici pour savoir s\'il fait beau ou pas</a></div>';
	$('nearby').innerHTML = txt;

	var fx1 = new Fx.Tween('nearby',{onComplete:function() {var fx2 = new Fx.Tween('nearbytxt'); fx2.start('opacity', 0, 1);}});

	fx1.start('height', 0, '60px');

}

function checkGeo() {
	
			var jsonRequest = new Request.JSON({url: "/remote-api.php", onComplete: function(nearly){

			    if ( nearly == null ) {


				}
				else {
					display_nearby_answer(nearly.answer[0]);


				}

			}}).get({'criteria': document.getElementById('criteria').value + ', '+document.getElementById('selectedInput').value});
}

function chooseCountry(item) {
	if ( item == 'fr' ) {
		html = '<img src="/flags/fr.gif" /> France';
		item_tr = 'France';
	}
	else if ( item == 'be' ) {
		html = '<img src="/flags/be.gif" /> Belgique';
		item_tr = 'belgique';
	}
	else if ( item == 'ca' ) {
		html = '<img src="/flags/ca.gif" /> Canada';
		item_tr = 'canada';
	}
	else if ( item == 'sz' ) {
		html = '<img src="/flags/sz.gif" /> Suisse';
		item_tr = 'suisse';
	}
	else if ( item == 'ag' ) {
		html = '<img src="/flags/dz.gif" /> Algérie';
		item_tr = 'algérie';
	}
	else if ( item == 'ma' ) {
		html = '<img src="/flags/ma.gif" /> Maroc';
		item_tr = 'Maroc';
	}
	else if ( item == 'tu' ) {
		html = '<img src="/flags/tu.gif" /> Tunisie';
		item_tr = 'tunisie';
	}
	
	
	
	
	$('selectedcountry').innerHTML = html;
	$('selectedInput').value = item_tr;
}
