CmdUtils.CreateCommand({
  name: "websource",
  homepage: "http://www.briandgoad.com/blog/",
  author: { name: "Brian D. Goad", email: "bdgoad@gmail.com"},
  
  description: "Checks Websource.It for a comparison between two terms throughout the web.",
  help: "Compares the popularity of two terms using Websource.It Example: try 'websource google and yahoo'",

  takes: {"first": noun_arb_text},  
  modifiers: {and: noun_arb_text},
  
  preview: function( pblock, first, mods ) {
    var msg = "Compares the popularity of two or more (a limit of 5) terms seperated by 'and'."; 
    msg += "<br /> Example: try '<i>google and yahoo</i>'";
    msg += "<br />";
    if (first && first.text) {
      msg += first.text;
    }
    if (mods.and && mods.and.text){
      msg += " and " + mods.and.text;
    }
    pblock.innerHTML = CmdUtils.renderTemplate( msg );
  },


  execute: function(first, mods) {
    if (mods.and && mods.and.text) {
    var url = "http://websource.it/search/";
    var query = url + first.text + '/' 
    if (mods.and.text){
      if(mods.and.text.match("and")){
        var pdString = mods.and.text.split(" and ", 4);
        var t = 0;
        for (t; t<=pdString.length-1; t++) {
          query += pdString[t] + '/';
        }
      } else {
        query += mods.and.text;
      }
    }
    Utils.openUrlInBrowser(query);
    } else {
    displayMessage("You must include two (or more) entries");
    }
  }
})
