function openInTab( url ) {
  var sel=CmdUtils.getSelection();
  var pat=/^((ht|f)tp(s?)\:\/\/|~\/|\/)?([\w]+:\w+@)?([a-zA-Z]{1}([\w\-]+\.)+([\w]{2,5}))(:[\d]{1,5})?((\/?\w+\/)+|\/?)(\w+\.[\w]{3,4})?((\?\w+=\w+)?(&\w+=\w+)*)?/;
  if(!url.length) url=sel;
  if(!url.match(pat)) {
  	if(sel.match(pat)) {
  		url=sel;
  	} else {
		displayMessage('That doesn\'t look like a URL.  Please select a URL and try again.');
		return;
	}
  }
  Utils.openUrlInBrowser( url );
}

CmdUtils.CreateCommand({
  name: "open in tab",
  description: "Opens a plain-text URL in a new tab",
  help: "You can quickly and easily open a plain-text URL in a new tab",
  takes: {"URL to open": noun_arb_text},
  homepage: "http://next.gen.nz/ubiquity/open-in-tab/",
  author: {name: "Paul Nicholls", homepage: "http://fubar.school.nz/techblog/"},
  execute: function( directObj ) {
    openInTab( directObj.text );
  },

  preview: function( pblock, directObj ) {
    pblock.innerHTML = "Opens the selected URL in a new tab<br/>";
     }
})

