Edit in JSFiddle

var getImageUrl = function (imageId) {	
	var mainUrl = window.location.href;	
	var parts = mainUrl.match(/ps[pc]\/(.+?)(?:_\d)*?\/(.+?)\/(.+?)\/[chs]\//);	
	return window.location.origin + "/psc/" + parts[1] + "/" + parts[2] + "/" + parts[3] + "/s/WEBLIB_FL_CSK.ISCRIPT1.FieldFormula.IScript_CSK_GET_IMG?img=" + imageId;
};