Can't you just:
var a = document.createElement('a'); // or keep a cached one
a.href = input;
return a.href;

it will return the protocol based on the one from the page, and fix relative uris.