// Render a link for searching objects in tel.local.ch.
// version 1.0
// 2006-08-19
// 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 "Look-up in local.ch", and click Uninstall.
//
// --------------------------------------------------------------------
//
// ==TailsScript==
// @name          Look-up in local.ch
// @namespace     http://keepthebyte.ch/tails
// @description   Render a link for searching an objects in tel.local.ch.
// @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']) {
	
    return "http://tel.local.ch/" + hcard.locality.replace(/\s+/g, '+') + "+" + hcard['street-address'].replace(/\s+/g, '+') + "/" + hcard["fn"].replace(/\s+/g, '+')
}
}