function tohere(k) { infowindow.setContent(to_htmls[k]); }
function fromhere(k) { infowindow.setContent(from_htmls[k]); }

function AddMarker(map,lat,lon,msg,image) {
  var icon = new google.maps.MarkerImage(image);
  var point = new google.maps.LatLng(lat,lon);
  bounds.extend(point);
  map.fitBounds(bounds);
  var marker = new google.maps.Marker({
    position: point, 
    map: map,
    icon: icon
    }); 

  // The info window version with the 'to here' form open
  if (msg) {
    var to_directions = '<br>Directions: <b>To here</b> -'
                    + '<a href="javascript:fromhere(' + i + ')">From here</a>' 
                    + '<br>Start address:<form action="http://maps.google.com/maps" method="get" target="_blank">' 
                    + '<input type="text" size=40 maxlength=80 name="saddr" id="saddr" value="" /><br>' 
                    + '<input value="Get Directions" type="submit">' 
                    + '<input type="hidden" name="daddr" value="'
                    + point.lat() + ',' + point.lng() + '"/>';
        // The info window version with the 'to here' form open
    var from_directions = '<br>Directions: <a href="javascript:tohere(' + i + ')">To here</a> - <b>From here</b>' 
                    + '<br>Start address:<form action="http://maps.google.com/maps" method="get" target="_blank">' 
                    + '<input type="text" size=40 maxlength=80 name="daddr" id="saddr" value="" /><br>' 
                    + '<input value="Get Directions" TYPE="submit">' 
                    + '<input type="hidden" name="daddr" value="'
                    + point.lat() + ',' + point.lng() + '"/>';
    var inactive = '<br />Directions: <a href="javascript:tohere('+i+')">To here</a> - <a href="javascript:fromhere('+i+')">From here</a>';
      }
      // The inactive version of the direction info
      //msg = name + msg + '<br />Directions: <a href="javascript:tohere('+i+')">To here</a> - <a href="javascript:fromhere('+i+')">From here</a>';

    to_htmls[i] = msg + to_directions;
    from_htmls[i] = msg + from_directions;
    msg = msg + inactive;
    google.maps.event.addListener(marker, 'click', (function(marker) {
      return function() {
        infowindow.setContent(msg);
        infowindow.open(map, marker);
      }
    })(marker));
  htmls[i] = msg;
  i++;
  return marker;
}