function $(elt){
	return document.getElementById(elt);
}
function verif_form_map() {
	if(document.google.saddr.value == "") {
		alert("Veuillez saisir le lieu de d�part.");
		$('lien_itineraire').style.display='none';
		$('formulaire_itineraire').style.display='block';
		$('saddr').focus();
		return false;
	}
	return true;
}
//recuperer les parametres pass�s dans une balise type "<script src='mon_script.js?param=truc'></script>
 var ParseScriptParam = function(basename){
  this.basename        = basename;
  this.paramsAvailable = false;
  this.count           = 0;
  this.params          = new Object(); 


  this.hasParam = function(key){
    if(this.params[key]){
      return true;
    } else {
      return false;
    }
  }

  this.parse = function(){
    var src;  
    var re       = new RegExp(this.basename + '.js\?.+');
    var scripts  = document.getElementsByTagName('script');

    for(var i = 0; i < scripts.length; i++){
      src = scripts[i].getAttribute('src');
      if(src != null && re.test(src)){
        if(src.indexOf('?') > 0){
          var splitURL = src.split('?');
          var params   = splitURL[1].split('&');
          var keyValue = new Array();


          if(splitURL[1].length > 0){
            this.paramsAvailable = true;
            this.count = params.length;
          }

          if(this.count > 0){
            for(var j = 0; j < this.count; j++){
              keyValue = params[j].split('=');
              this.params[keyValue[0]] = decodeURIComponent(keyValue[1]);
            }
          } else {
            this.params[splitURL[1]] = '';
          }
        }
      }
    }
  }
}

// a enleve apres dev
//function similaire a print_r() de php
function print_r(obj) {
  win_print_r = window.open('about:blank', 'win_print_r');
  win_print_r.document.write('<html><body>');
  r_print_r(obj, win_print_r);
  win_print_r.document.write('</body></html>');
 }

 function r_print_r(theObj, win_print_r) {
  if(theObj.constructor == Array ||
   theObj.constructor == Object){
   if (win_print_r == null)
    win_print_r = window.open('about:blank', 'win_print_r');
   }
   for(var p in theObj){
    if(theObj[p].constructor == Array||
     theObj[p].constructor == Object){
     win_print_r.document.write("<li>["+p+"] =>"+typeof(theObj)+"</li>");
     win_print_r.document.write("<ul>")
     r_print_r(theObj[p], win_print_r);
     win_print_r.document.write("</ul>")
    } else {
     win_print_r.document.write("<li>["+p+"] =>"+theObj[p]+"</li>");
    }
   }
  win_print_r.document.write("</ul>")
 }
 
 function getOffsets(obj) {
    var offsetTop = obj.offsetTop;
    var offsetLeft = obj.offsetLeft;
    while ((obj = obj.offsetParent )!=null) {
        offsetTop += obj.offsetTop;
        offsetLeft += obj.offsetLeft;
    	}
    return [offsetTop,offsetLeft];
}

function pop(adresse,la,ha) {
  var maFenetre = window.open(adresse,'aper�u','resizable=no,scrollbars=no,status=no,menubar=no,toolbar=no,directories=no,location=no,width='+la+',height='+ha+',closed=no,opener=no');
  if (window.focus) maFenetre.focus();
  return false;
}
function load() {
  if (GBrowserIsCompatible()) {
  if (document.getElementById("mapfr")){
    var map = new GMap2(document.getElementById("mapfr"));
    map.addControl(new GLargeMapControl());
    map.addControl(new GMapTypeControl());
    map.setMapType(G_SATELLITE_MAP);
    var geocoder = new GClientGeocoder();

    var monAdresse = "Place Royale, 1000 Bruxelles Belgique";
    var monLibelle = '<div style="width:240px; height:100px;">';
	monLibelle += '<div><img src="fileadmin/templates/images/logo_map.jpg" align="left" style="margin-right:10px;"/>Musée Magritte Museum<br/>';
	monLibelle += '1, Place Royale<br/>';
	monLibelle += '1000 Bruxelles<br/>';
	monLibelle += 'tél. : 32 (0)2 508 32 11';
	monLibelle += '</div>';
	monLibelle += '<div id="lien_itineraire" style="margin-top:20px;"><a href="http://maps.google.fr/maps?hl=fr&tab=wl" onclick="$(\'lien_itineraire\').style.display=\'none\';$(\'formulaire_itineraire\').style.display=\'block\';$(\'saddr\').focus();return false">Itinéraire : Vers ce lieu</a></div>';
	monLibelle += '<div id="formulaire_itineraire" style="display:none;margin-top:20px;">';
	monLibelle += '<form action="http://maps.google.fr/maps" method="get" target="_blank"  name="google" OnSubmit="return verif_form_map()">';
	//monLibelle += '<input type="hidden" name="f" value="d" />';
	//monLibelle += '<input type="hidden" name="source" value="s_d" />';
	//monLibelle += '<input type="hidden" name="hl" value="fr" />';
	monLibelle += '<input type="hidden" name="ie" value="ISO-8859" />';
	monLibelle += '<input type="hidden" name="daddr" value="Place Royale, 1000 Bruxelles Belgique" />';
	monLibelle += '<span class="txt10gris">Lieu de départ</span><br/>';
	monLibelle += '<input type="text" id="saddr" name="saddr" value="" class="champ_plan"/> <input type="submit" value="ok" onclick="$(\'lien_itineraire\').style.display=\'block\';$(\'formulaire_itineraire\').style.display=\'none\';" class="btnO"/>';
	monLibelle += '</form>';
	monLibelle += '</div>';
	monLibelle += '</div>';
    fixPoint(map,geocoder,monAdresse,monLibelle,true);
  }
    if (document.getElementById("mapnl")){
    var map = new GMap2(document.getElementById("mapnl"));
    map.addControl(new GLargeMapControl());
    map.addControl(new GMapTypeControl());
    map.setMapType(G_SATELLITE_MAP);
    var geocoder = new GClientGeocoder();

    var monAdresse = "Koningsplein, 1000 Brussel België";
    var monLibelle = '<div style="width:240px; height:100px;">';
	monLibelle += '<div><img src="fileadmin/templates/images/logo_map.jpg" align="left" style="margin-right:10px;"/>Musee Magritte Museum<br/>';
	monLibelle += 'Koningsplein 1<br/>';
	monLibelle += '1000 Brussel<br/>';
	monLibelle += 'tel. : 32 (0)2 508 32 11';
	monLibelle += '</div>';
	monLibelle += '<div id="lien_itineraire" style="margin-top:20px;"><a href="http://maps.google.be/maps?hl=nl&tab=wl" onclick="$(\'lien_itineraire\').style.display=\'none\';$(\'formulaire_itineraire\').style.display=\'block\';$(\'saddr\').focus();return false">Routebeschrijving</a></div>';
	monLibelle += '<div id="formulaire_itineraire" style="display:none;margin-top:20px;">';
	monLibelle += '<form action="http://maps.google.be/maps" method="get" target="_blank"  name="google" OnSubmit="return verif_form_map()">';
	//monLibelle += '<input type="hidden" name="f" value="d" />';
	//monLibelle += '<input type="hidden" name="source" value="s_d" />';
	//monLibelle += '<input type="hidden" name="hl" value="fr" />';
	monLibelle += '<input type="hidden" name="ie" value="ISO-8859" />';
	monLibelle += '<input type="hidden" name="daddr" value="Koningsplein, 1000 Brussel België" />';
	monLibelle += '<span class="txt10gris">Vertrekpunt</span><br/>';
	monLibelle += '<input type="text" id="saddr" name="saddr" value="" class="champ_plan"/> <input type="submit" value="Uitvoeren" onclick="$(\'lien_itineraire\').style.display=\'block\';$(\'formulaire_itineraire\').style.display=\'none\';" class="btnO"/>';
	monLibelle += '</form>';
	monLibelle += '</div>';
	monLibelle += '</div>';
    fixPoint(map,geocoder,monAdresse,monLibelle,true);
  }
    if (document.getElementById("mapen")){
    var map = new GMap2(document.getElementById("mapen"));
    map.addControl(new GLargeMapControl());
    map.addControl(new GMapTypeControl());
    map.setMapType(G_SATELLITE_MAP);
    var geocoder = new GClientGeocoder();

    var monAdresse = "Place Royale, 1000 Bruxelles Belgique";
    var monLibelle = '<div style="width:240px; height:100px;">';
	monLibelle += '<div><img src="fileadmin/templates/images/logo_map.jpg" align="left" style="margin-right:10px;"/>Musee Magritte Museum<br/>';
	monLibelle += 'Place Royale 1 Koningsplein<br/>';
	monLibelle += '1000 Brussels<br/>';
	monLibelle += 'tel. : 32 (0)2 508 32 11';
	monLibelle += '</div>';
	monLibelle += '<div id="lien_itineraire" style="margin-top:20px;"><a href="http://maps.google.fr/maps?hl=fr&tab=wl" onclick="$(\'lien_itineraire\').style.display=\'none\';$(\'formulaire_itineraire\').style.display=\'block\';$(\'saddr\').focus();return false">Get directions</a></div>';
	monLibelle += '<div id="formulaire_itineraire" style="display:none;margin-top:20px;">';
	monLibelle += '<form action="http://maps.google.com/maps" method="get" target="_blank"  name="google" OnSubmit="return verif_form_map()">';
	//monLibelle += '<input type="hidden" name="f" value="d" />';
	//monLibelle += '<input type="hidden" name="source" value="s_d" />';
	//monLibelle += '<input type="hidden" name="hl" value="fr" />';
	monLibelle += '<input type="hidden" name="ie" value="ISO-8859" />';
	monLibelle += '<input type="hidden" name="daddr" value="Place Royale, 1000 Bruxelles Belgique" />';
	monLibelle += '<span class="txt10gris">Start address</span><br/>';
	monLibelle += '<input type="text" id="saddr" name="saddr" value="" class="champ_plan"/> <input type="submit" value="ok" onclick="$(\'lien_itineraire\').style.display=\'block\';$(\'formulaire_itineraire\').style.display=\'none\';" class="btnO"/>';
	monLibelle += '</form>';
	monLibelle += '</div>';
	monLibelle += '</div>';
    fixPoint(map,geocoder,monAdresse,monLibelle,true);
  }

  }
} 
function fixPoint(map,geocoder,monAdresse,monLibelle,centre) {
  geocoder.getLatLng(
    monAdresse,
    function(point) {
      if (point) {
        if (centre) map.setCenter(point, 17);
        if (monLibelle != "") {
          var marker = new GMarker(point);
          GEvent.addListener(marker, "click", function() {
            marker.openInfoWindowHtml(monLibelle);
          });
          map.addOverlay(marker);
          marker.openInfoWindowHtml(monLibelle);
        }
      }
    }
  );
}
