function LinkRepL (a) {
var b = a.split(/^(?:[^.:\/]*?[.:])?(?:\/\/){0,1}|\/(?!\/)/ig).join('|');
if(b==a) return false;
return b;
}
var arr =[
'//www.sitename.domain/dir/dir2/file.jpg',
'http://www.sitename.domain/dir/dir2/file.jpg',
'www.sitename.domain/dir/file.jpg',
'dasd.asdas/~sad.js',
'sub.sitename.domain/dir/dir2/file.jpg',
'site.do/file.pjg',
'htttp://google.com/ansdjnaskd/najskd/inasd.jf',
'https://go.do/dir/file.png',
'ftp://site.dom/file.blah_blah'
]
for (var i=0; i<arr.length; i++) {
alert(LinkRepL (arr[i]) );
}