From http://recurial.com/programming/javascript-snippet-replace-urls-with-hyperlinks/