
CmdUtils.makeSearchCommand({
  name: "stockholm-se-search",
  author: {
    name: "pedagogstockholm.se",
    email: "pedagogstockholm@stockholm.se"
  },
  url: "http://www.pedagogstockholm.se/-/Sok/?q={QUERY}",
  icon: "http://www.pedagogstockholm.se/favicon.ico",
  description: "Searches pedagogstockholm.se for your words.",
  preview: function (pblock, directObject) {
    var searchTerm = directObject.text;
    if (searchTerm.length > 0) {
      var pTemplate = "Searches pedagogstockholm.se for <b>${query}</b>";
      var pData = {query: searchTerm};
      pblock.innerHTML = CmdUtils.renderTemplate(pTemplate, pData);
      Utils.parseRemoteDocument("http://www.pedagogstockholm.se/-/Sok/?q=" + encodeURI(searchTerm), null, 
        function (doc) {          var searchResults = [];
          jQuery(".search dt a", doc).each(function () {
            searchResults[searchResults.length] = {url: jQuery(this)[0].href, title: jQuery(this).text()};
          });
          pblock.innerHTML = CmdUtils.renderTemplate("<ul>{for result in results}<li><a href=\"${result.url}\">${result.title}</a></li>{forelse}<li><b>Your search - ${searchTerm} - did not match any documents.</b></li>{/for}</ul>", {results:searchResults, searchTerm:searchTerm});
        },        function () {          pblock.innerHTML = "Error!";        })
    } else {
      pblock.innerHTML = "Searches pedagogstockholm.se";
    }
  }
});
