CmdUtils.CreateCommand({
  names: ["dzone", "dz"],
  homepage: "http://eriwen.com/extras/dzone.html",
  icon: "http://www.dzone.com/favicon.ico",
  author: { name: "Eric Wendelin", email: "emwendelin@gmail.com" },
  license: "GPL",
  description: "Submit the current page to DZone",
  help: "Running this command will submit the current page to DZone",
  
  _title: function() {
    var doc = Application.activeWindow.activeTab.document;
    return doc.title;
  },
  
  _location: function() {
    var doc = Application.activeWindow.activeTab.document;
    return doc.location;
  },
  
  _selection: function() {
    return CmdUtils.getWindow().getSelection();
  },
  
  preview: function(pblock) {
    var previewHtml = _('Submit "<em>${title}</em>" to DZone');
    //TODO add selected text 
    //previewHtml += _('<p>With description: <blockquote>' + selectedText + '</blockquote></p>');
    pblock.innerHTML = CmdUtils.renderTemplate(previewHtml, {title: this._title()});
  },
  
  execute: function() {
    var urlBase = "http://www.dzone.com/links/add.html";
    var urlParam = "?url=" + this._location();
    var titleParam = "&title=" + this._title();
    var dzoneUrl = urlBase + urlParam + titleParam;
    var description = this._selection();
    if (description)
      dzoneUrl += "&description=" + description;
    Utils.openUrlInBrowser(dzoneUrl);
  }
});
