var rimPath = null;
var rjsPath = null;
var rPath2Root = null;

function InitRelCode() {
	var iImg;
	var jImg;
	var tObj;
	
	if(!document.layers) {
		iImg = document.images['DMBImgFiles'];
		jImg = document.images['DMBJSCode'];
		tObj = jImg;
	} else {
		tObj = document.layers['DMBRI'];
		if(tObj) {
			iImg = tObj.document.images['DMBImgFiles'];
			jImg = tObj.document.images['DMBJSCode'];
		}
	}
	if(!tObj) {
		window.setTimeout("InitRelCode()", 1500);
		return false;
	}
	
	rimPath = _gp(iImg.src);
	rjsPath = _gp(jImg.src);
	rPath2Root = rjsPath + "";
	
	return true;
}

function _purl(u) {
	return xrep(xrep(u, "%%REP%%", rPath2Root), "\\", "/");
}

function _fip(img) {
	if(img.src.indexOf("%%REL%%")!=-1)
		img.src = rimPath + img.src.split("%%REL%%")[1];
	return img.src;
}

function _gp(p) {
	return p.substr(0,p.lastIndexOf("/")+1);
}

function FixImages() {
	var h = null;

	if(typeof(hStyle)!="undefined") h = hStyle;
	if(typeof(hS)!="undefined") h = hS;
	if(h)
		for(var i=0; i<h.length; i++)
			h[i] = xrep(h[i], "%%REL%%", rimPath);
}

function xrep(s, f, n) {
	return s.split(f).join(n);
}

InitRelCode();
