//=================================================================================================================
var overlayPolyg; 
var overlayLink;

/**
* @desc shows boundaries on GoogleMap
*
*/
function showOnMap(minLat, maxLat, minLon, maxLon, tooltip) {
 
  var MapBoundary = [];
  // create array with points for boundary
  MapBoundary.push(new GLatLng(minLat, minLon));
  MapBoundary.push(new GLatLng(minLat, maxLon));
  MapBoundary.push(new GLatLng(maxLat, maxLon));
  MapBoundary.push(new GLatLng(maxLat, minLon));
  MapBoundary.push(new GLatLng(minLat, minLon));
  
  // remove existing overlay
  if (overlayPolyg != null) {
    MyMap.removeOverlay(overlayPolyg);
  }
  // add new overlay
  overlayPolyg = new BDCCPolygon(MapBoundary,"#008000",3,0.9,"#C0FFC0",0.2,tooltip,"dot");
  MyMap.addOverlay(overlayPolyg)
  
  // zoom in
  var neededLevel = MyMap.getBoundsZoomLevel(new GLatLngBounds(new GLatLng(minLat, minLon), new GLatLng(maxLat, maxLon)));
  if (MyMap.getZoom() > neededLevel) {
    MyMap.setZoom(neededLevel);
  }  
  // Center around the middle of the points
	var centerLat = (maxLat + minLat) / 2;
	var centerLon = (maxLon + minLon) / 2;
	MyMap.setCenter(new GLatLng(centerLat, centerLon));

  // events: on mouseover change appearance of overlay
  GEvent.addListener(overlayPolyg,"mouseover", function(){overlayPolyg.setFillOpacity(0.4);});
  GEvent.addListener(overlayPolyg,"mouseover", function(){overlayPolyg.setStrokeDash("solid");});
  GEvent.addListener(overlayPolyg,"mouseout",  function(){overlayPolyg.setFillOpacity(0.2);});
  GEvent.addListener(overlayPolyg,"mouseout",  function(){overlayPolyg.setStrokeDash("dot");});
  // on click remove overlay
  GEvent.addListener(overlayPolyg,"click",     function(){MyMap.removeOverlay(overlayPolyg);});
          
}  

// GetDirections
var gdir;
// ===== request the directions =====
function getDirections() {
  // ==== Set up the walk and avoid highways options ====
  var opts = {};
  opts.locale='de';
  //opts.locale = 'de';
  //if (document.getElementById("walk").checked) {
  //   opts.travelMode = G_TRAVEL_MODE_WALKING;
  //}
  if (document.getElementById("highways").checked) {
     opts.avoidHighways = true;
  }
  // ==== set the start and end locations ====
  var saddr = document.getElementById("saddr").value
  var daddr = document.getElementById("daddr").value

  // paint ployline with route
  gdir.load("from: "+saddr+" to: "+daddr, opts);
  
}


