//Global utils script

//Action check! ask realy act?
function didYouMean(url,what){
	var userSaid = confirm(what)
	if(userSaid == true){
		window.location=url;
	}else{
		alert("Opération annulé!");
	}
}





var map = null;
var geocoder = null;

function showAddress(address,sname) {
	if (GBrowserIsCompatible()) {
		geocoder = new GClientGeocoder();
		if (geocoder) {
			geocoder.getLatLng(
				address,
				function(point) {
					if (!point) {
						alert("Google map ne peut pas trouver l´adresse de "+sname+" ! "+address+".");
					} else {
						map = new GMap2(document.getElementById("google_map"));
						map.addControl(new GSmallMapControl());
						map.addControl(new GMapTypeControl());
						map.setCenter(point, 13);
						var marker = new GMarker(point);
						map.addOverlay(marker);
						marker.openInfoWindowHtml("<strong>"+sname+"</strong><br/>"+address);
					}
				}
        		);
		}
	}
}
function forceGetAddressGeocodes(fName) {
	address = document.forms[fName]['streetNumber'].value + ' ' + document.forms[fName]['streetType'].value + ' ' + document.forms[fName]['streetName'].value + ' ' + document.forms[fName]['cardinal'].value + ' ' + document.forms[fName]['city'].value + ' '  + document.forms[fName]['state'].value + ' '  + document.forms[fName]['country'].value;
	if (GBrowserIsCompatible()) {
		geocoder = new GClientGeocoder();
		if (geocoder) {
			geocoder.getLatLng(
				address,
				function(point) {
					if (!point) {
						alert("Google map ne peut pas trouver les geocodes de l´adresse : "+address+".");
					} else {
						document.forms[fName]['Latitude'].value = point.y;
						document.forms[fName]['Longitude'].value = point.x;
						alert('Les géocodes de l’adresse de votre organisme ont été ajoutés à la fiche avec succès!  Longitude: ' + point.x + ', Latitude: ' + point.y);
					}
				}
        		);
		}
	}
}
function getAddressGeocodes(fName,address) {
	if (GBrowserIsCompatible()) {
		geocoder = new GClientGeocoder();
		if (geocoder) {
			geocoder.getLatLng(
				address,
				function(point) {
					if (!point) {
						alert("Google map ne peut pas trouver les geocodes de l´adresse : "+address+".");
					} else {
						alert('Les géocodes de l’adresse de votre organisme ont été ajoutés à la fiche avec succès!  Longitude: ' + point.x + ', Latitude: ' + point.y);
						document.forms[fName]['Latitude'].value = point.y;
						document.forms[fName]['Longitude'].value = point.x;
					}
				}
        		);
		}
	}
}

var map = null;
var geocoder = null;

function showMap(lat,long,sname) {
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("google_map"));
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		map.setCenter(new GLatLng(lat,long), 15); 
		var marker = new GMarker(new GLatLng(lat,long));
		map.addOverlay(marker);
		//marker.openInfoWindowHtml("<strong>"+sname+"</strong>");
	}
}
