// Render a link to get directions with maps.msn.com
// version 1.0
// 2006-08-20
// Copyright (c) 2006, Cedric Huesler
//
// --------------------------------------------------------------------
//
// This is a Tails script.
//
// To install, you need Tails: http://blog.codeeg.com/tails-firefox-extension/
// Then restart Firefox and revisit this script and click on 'Install'.
//
// To uninstall, go to Tools/Manage Tails Scripts...,
// select "Directions with MSN", and click Uninstall.
//
// --------------------------------------------------------------------
//
// ==TailsScript==
// @name          Directions with MSN
// @namespace     http://keepthebyte.ch/tails
// @description   Render a link to get directions with maps.msn.com
// @include       hcard
// @include       hcalendar
// @include       hreview
// ==/TailsScript==

getURL: function() {
  if (this.object.__name == "hcard") {
    return this.buildURL(this.object);
  } else if (this.object.__name == "hcalendar" && this.object.location_hcard) {
    return this.buildURL(this.object.location_hcard);
  } else if (this.object.__name == "hreview" && this.object.item_hcard) {
    return this.buildURL(this.object.item_hcard);
  }
},
buildURL: function(hcard) {
  if ((hcard.locality && hcard.region)
      || hcard['postal-code']) {

// documentation: http://www.microsoft.com/mappoint/msnmaps/mws_linking.mspx

// Note: destination county &cnty2 is hardcoded to Switzerland!
  return "http://maps.msn.com/directionsFind.aspx?strt2=" + hcard['street-address'].replace(/\s+/g, '+') + "&city2=" + hcard.locality.replace(/\s+/g, '+') + "&zipc2=" + hcard['postal-code'] + "&cnty2=6&rtyp=1&unit=1"
}
}