
CmdUtils.CreateCommand({
  name: "rfc",
  homepage: "http://greenbytes.de/tech/webdav/",
  author: { name: "Julian Reschke"},
  description: "Lookup RFC information.",

  takes: {"RFC number": noun_arb_text},

  _getLinks: function(no) {
    var i = 0;
    var result = {};
 
    if (no == "2291" || no == "3253" || no == "3648" || no == "3744" || no == "4316" || no == "4331" || no == "4437" || no == "4709" || no == "4791" || no == "4918" || no == "5323" || no == "5397" || no == "5689" || no == "5842" || no == "2045" || no == "2046" || no == "2047" || no == "2109" || no == "2145" || no == "2183" || no == "2231" || no == "2388" || no == "2397" || no == "2616" || no == "2617" || no == "2774" || no == "2817" || no == "2818" || no == "2965" || no == "3339" || no == "3470" || no == "3986" || no == "4122" || no == "4287" || no == "4770" || no == "5005" || no == "5023" || no == "5234" || no == "5322" || no == "5789" || no == "5791" || no == "5829" || no == "5987" || no == "2234" || no == "2396" || no == "2518" || no == "2731" || no == "4234") {
      result[i] = { URL: "http://greenbytes.de/tech/webdav/rfc" + no + ".html", text: "greenbytes.de/tech/webdav" };
      i += 1;
    }

    result[i] = { URL: "http://tools.ietf.org/html/rfc" + no, text: "tools.ietf.org" };
    i += 1;

    result[i] = { URL: "http://www.rfc-editor.org/errata_search.php?rfc=" + no, text: "RFC Editor's Errata" };
    i += 1;

    return result;
  },

  preview: function(pblock, rfcNumber) {
    var msg = '<p>Lookup information for RFC <em>${no}</em>.';

    var links = this._getLinks(rfcNumber.text);

    for (i in links) {
      msg += "<p><a href=" + links[i].URL + ">" + links[i].text + "</a>";
    }

    pblock.innerHTML = CmdUtils.renderTemplate(msg, {no: rfcNumber.text});
  },
  

  execute: function(rfcNumber) {
     var links = this._getLinks(rfcNumber.text);
     Utils.openUrlInBrowser(links[0].URL);
  }
})
