﻿// Creates a marker at the given point with the given number label
window.onload=load;
function createMarker(point, number) {
  var marker = new GMarker(point);
  GEvent.addListener(marker, "click", function() {
    marker.openInfoWindowHtml("Marker #<b>" + number + "</b>");
  });
  return marker;
}
function MarkerHtml()
{
    var r='<div style="width:300px">Per raggiungerci scorri la mappa o inserisci il punto di partenza e premi "Calcola percorso" [es:"piazza Duomo, Milano"]<br><br>';
    r+='<form onsubmit="return f_Percorso();"><input id="mGoogleMapFrom" name="mMap"><input type="submit" value="Calcola percorso"></form></div>';
    return r;
}
function f_Percorso()
{
    if(document.getElementById('mGoogleMapFrom').value==''){
        alert('Inserire un indirizzo di partenza');
        return;
        }
    f_Percorso2(document.getElementById('mGoogleMapFrom').value);
    return false;
}
function f_Percorso2(value)
{                                                         
   window.open('http://maps.google.it/maps?f=d&hl=it&sll=45.589822,9.834845&spn=0.00949,0.01457&saddr='+value+'&daddr=%4045.589822,9.834845')
}                                                          
function load() {
  if (GBrowserIsCompatible()) {
    var map = new GMap2(document.getElementById("map"));
    map.addControl(new GLargeMapControl());
    map.addControl(new GScaleControl());
    map.addControl(new GMapTypeControl());
   
    map.setCenter(new GLatLng(45.589822,9.834845),14);
    
    var marker = new GMarker(map.getCenter());
    GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(MarkerHtml());});
    map.addOverlay(marker);
    marker.openInfoWindowHtml(MarkerHtml());
  }
}



