// JavaScript Document
window.addEventListener?window.addEventListener('load',GLoad,false):window.attachEvent('onload',GLoad);

var map;
var geocoder;

function GLoad() {
  map = new GMap2($id("banner_img"));
  map.addControl(new GSmallMapControl());
  map.addControl(new GOverviewMapControl());
  map.addControl(new GZoomControl({sColor:'#000',nOpacity:.3,sBorder:'2px solid #729700'}), new GControlPosition(G_ANCHOR_TOP_RIGHT,new GSize(6,6))); 
  map.setCenter(new GLatLng(30, 15), 2);
  geocoder = new GClientGeocoder();
}

/*function load() {
  map = new GMap2(document.getElementById("banner_img"));
  //map.setCenter(new GLatLng(48.850992, 2.363434), 13);
  map.addControl(new GMapTypeControl());
  map.addControl(new GLargeMapControl());
  map.setCenter(new GLatLng(34, 0), 2);
  geocoder = new GClientGeocoder();
}*/

// addAddressToMap() is called when the geocoder returns an
// answer.  It adds a marker to the map with an open info window
// showing the nicely formatted version of the address and the country code.
function addAddressToMap(response) {
  map.clearOverlays();
  if (!response || response.Status.code != 200) {
	alert("Désolé, impossible de trouver cette adresse");
  } else {
	place = response.Placemark[0];
	point = new GLatLng(place.Point.coordinates[1],
						place.Point.coordinates[0]);
	marker = new GMarker(point);
	map.addOverlay(marker);
	marker.openInfoWindowHtml(place.address + '<br>' +
	  '<b>Code:</b> ' + place.AddressDetails.Country.CountryNameCode + '<br>' +
	  '<b>Coordonnées:</b> ' + place.Point.coordinates[1] + ',' + place.Point.coordinates[0]);
  }
}

// showLocation() is called when you click on the Search button
// in the form.  It geocodes the address entered into the form
// and adds a marker to the map at that location.
function showLocation() {
  document.getElementById("ancre_banner").focus();
  var address = document.forms[0].q.value;
  geocoder.getLocations(address, addAddressToMap);
}

// findLocation() is used to enter the sample addresses into the form.
function findLocation(address) {
  document.forms[0].q.value = address;
  showLocation();
}