//<![CDATA[


    var map;
    var gdir;
    var geocoder = null;
    var addressMarker;


function setDirections(fromAddress, toAddress, locale) {
	gdir.load("from: " + fromAddress + " to: " + toAddress,
			{ "locale": locale });
}


function initialize() {
  if (GBrowserIsCompatible()) {
	map = new GMap2(document.getElementById("map_canvas"));
	map.setCenter(new GLatLng(60.267372, 24.877973), 12);
	map.addControl(new GSmallMapControl());

	gdir = new GDirections(map, document.getElementById("directions"));
	GEvent.addListener(gdir, "load", onGDirectionsLoad);
	GEvent.addListener(gdir, "error", handleErrors);

	geocoder = new GClientGeocoder();
  }
}


function showAddress(address, lang) {
  if (geocoder) {
	geocoder.getLatLng(
	  address,
	  function(point) {
		if (!point) {
		  alert(address + " not found");
		} else {
		  map.setCenter(point, 12);
		  var marker = new GMarker(point);
		  map.addOverlay(marker);
		  if (lang == 'fi') {
			marker.openInfoWindowHtml('<img src="http://www.aldata-loyalty.com/images/sivut2009/aldata_logo_small_googlemaps.gif" border="0" class="logo_small_googlemaps" alt="Aldata" align="left"><b>Aldata</b><br>Vetotie 3<br>Vantaa, Finland');
		  }
		  else if (lang == 'se'){
			marker.openInfoWindowHtml('<img src="http://www.aldata-loyalty.com/images/sivut2009/aldata_logo_small_googlemaps.gif" border="0" class="logo_small_googlemaps" alt="Aldata" align="left"><b>Aldata</b><br>Svärdvägen 23<br>Danderyd, Sweden');
		  }
		  else {
			marker.openInfoWindowHtml('<img src="http://www.aldata-loyalty.com/images/sivut2009/aldata_logo_small_googlemaps.gif" border="0" class="logo_small_googlemaps" alt="Aldata" align="left"><b>Aldata</b><br>Binley Business Park <br>Harry Weston Road<br>Coventry, UK');
		  }
		  
		}
	  }
	);
  }
}

function handleErrors(){
  if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	alert("Tuntematon osoite, tarkista osoitteen oikeaoppisuus. Täydennä tarvittaessa myös kaupunki. Oikea muoto on: 'kadunnimi, kaupunki' ");
  else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
   
  else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);

//   else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
//     alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gdir.getStatus().code);
	 
  else if (gdir.getStatus().code == G_GEO_BAD_KEY)
	alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);

  else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
	
  else alert("An unknown error occurred.");
}

function onGDirectionsLoad(){ 
  // Use this function to access information about the latest load()
  // results.

  // e.g.
  // document.getElementById("getStatus").innerHTML = gdir.getStatus().code;
  // and yada yada yada...


}


function showgooglemaps (country) {
	document.getElementById('map_border').style.display='block';
	document.getElementById('background_opacity').style.display='block';
	initialize();
	if (country == 'finland') {
		document.getElementById('toAddress').value='vetotie 3 vantaa finland';
		document.getElementById('locale').value='fi';
		showAddress('vetotie 3 vantaa finland', 'fi');
	}
	else if (country == 'sweden') {
		document.getElementById('toAddress').value='svärdvägen 23 danderyd sweden';
		document.getElementById('locale').value='se';
		showAddress('svärdvägen 23 danderyd sweden', 'se');
	}
	else {
		document.getElementById('toAddress').value='harry weston road coventry uk';
		document.getElementById('locale').value='en';
		showAddress('harry weston road coventry uk', 'uk');
	}
}

function hidegooglemaps () {
	document.getElementById('map_border').style.display='none';
	document.getElementById('background_opacity').style.display='none';
}


//]]>

