
CmdUtils.CreateCommand({
  name: "tpg",
  icon: "http://www.tpg.ch/favicon.ico",
  homepage: "http://kelvin-lew.com/blog/geek-stuff/ubiquity-commands/tpg-command/",
  author: { name: "Kelvin Lew", email: "im@kelvin-lew.com"},
  license: "GPL",
  description: "Searches Geneva public transportation website for current timetable (v1.5)",
  help: "E.g. 'tpg hautains to avanchet' will give you timetable with current time. If you want specific time, use: tpg hautains to avanchet at 2234.  Only works with 24 hour time.  This command is done especially for my lovely girlfriend.",
  takes: {"departure": noun_arb_text},
  modifiers: {to:noun_arb_text, at:noun_arb_text},
  execute: function(searchTPG, mods) {

  var departure = searchTPG.text;
  var destination = mods.to.text;
  var time = mods.at.text;
    
    var url = "http://tpg.hafas.de/hafas/tp/query.exe/en?S={DEP}&Z={DEST}&T={TIME}&start=1"
      
  url = url.replace( /{DEP}/g, departure);
  url = url.replace( /{DEST}/g, destination);
  
/*checks if there is time from user*/  
if (time == "") {
    var day = new Date();
    var curr_hour = day.getHours();
    var curr_min = day.getMinutes();
    time = curr_hour +""+ curr_min;
  }
  url = url.replace (/{TIME}/g, time);
  
/*opens url*/ 
Utils.openUrlInBrowser(url);
  
  }
});
