function docReady(fn) {
// checking the DOM
if (document.readyState === "complete" || document.readyState === "interactive") {
// call on next available tick
setTimeout(fn, 1);
} else {
document.addEventListener("DOMContentLoaded", fn);
}
}
docReady(function() {
// DOM is loaded and ready for manipulation
var text = document.getElementById("hmUrl").value;
text = text.replace(
/((http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?)/g,
'<a href="$1">$1</a>'
);
});