  var directionsDisplay=0;
  var directionsService = new google.maps.DirectionsService();
  var map=0;
  var geocoder=new google.maps.Geocoder();


  function initgoogledirections() {
    directionsDisplay = new google.maps.DirectionsRenderer( { draggable: true } );
    var budapest = new google.maps.LatLng(47.50121376007543, 19.046452045440674);
    var myOptions = {
      zoom:14,
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      center: budapest
    }
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    directionsDisplay.setMap(map);
    directionsDisplay.setPanel(document.getElementById("directionsPanel"));

    for(var i in GoogleMarekerPoints){
      PlaceMarker(GoogleMarekerPoints[i][0],GoogleMarekerPoints[i][1],GoogleMarekerPoints[i][2],GoogleMarekerPoints[i][3]);
    }

  }
  
  function calcRoute() {
    var start = document.getElementById("startpoint").value;
    var end = document.getElementById("endpoint").value;
    if (!start) {
      alert(missing_error);
      return true;
      }
    eval("var mycoords="+end);
    if (mycoords.constructor==Array) end=new google.maps.LatLng(mycoords[0],mycoords[1]);
    var request = {
        origin:start, 
        destination:end,
        travelMode: google.maps.DirectionsTravelMode.DRIVING
    };
    directionsService.route(request, function(response, status) {
      if (status == google.maps.DirectionsStatus.OK) {
        directionsDisplay.setDirections(response);
        document.getElementById('printing_link').style.display='block';
      }
    });
  }

  function PlaceMarker(address,title,icon,description){
    if (address.constructor==Array) {
      var newmarker=new google.maps.LatLng(address[0],address[1]);
      map.setCenter(newmarker);
      var marker = new google.maps.Marker({
          map: map, 
          position: newmarker,
          title: title,
          icon: icon
      });
      var infowindow = new google.maps.InfoWindow({
          content: description
      });
      google.maps.event.addListener(marker, 'click', function() {
        infowindow.open(map,marker);
      });     
    } else {
      geocoder.geocode( { 'address': address}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
          map.setCenter(results[0].geometry.location);
          var marker = new google.maps.Marker({
              map: map, 
              position: results[0].geometry.location,
              title: title,
							icon: icon
          });
          var infowindow = new google.maps.InfoWindow({
              content: description+'<br />'+address
          });
          google.maps.event.addListener(marker, 'click', function() {
            infowindow.open(map,marker);
          });
        } else {
          alert("Error: " + status);
        }
      });
    }
  }

function printRoute(){

  var content=document.getElementById('directionsPanel').innerHTML;
  var pwin=window.open('','print_content','width=100,height=100');

  pwin.document.open();
  pwin.document.write('<html><body onload="window.print()">'+content+'</body></html>');
  pwin.document.close();
 
  setTimeout(function(){pwin.close();},1000);

}

function checkmykeypress(myfield,e){
  var keycode;
  if (window.event) keycode = window.event.keyCode;
  else if (e) keycode = e.which;
  else return true;

  if (keycode == 13) {
      calcRoute();
     return false;
  }
  else return true;
  
}


