function mod_target(el_name) {
	var the_el = document.getElementById(el_name);
	if(the_el)
	{
		if(document.lastTarget) document.lastTarget.className = document.lastTarget.className.replace(new RegExp(" sftarget\\\\b"), "");
		the_el.className+=" sftarget";
		document.lastTarget=the_el;
	}
}

doFrameIn = function() {
	if(window.top == window.self)
	{
		var pathstr = window.self.location.pathname.toString();
		var pathsep = pathstr.lastIndexOf("/");
		if(pathsep != -1) {
			pathstr = pathstr.substr(pathsep+1);
		}
		var thehash = window.self.location.hash.toString();
		if(thehash.length <= 1) {
		 thehash = "";
		} else {
			var hashsep = thehash.indexOf("#");
			if(hashsep != -1) {
				thehash = thehash.substr(hashsep+1);
			}
			if(decodeURIComponent && encodeURIComponent) {
				thehash = decodeURIComponent(thehash);
				thehash = encodeURIComponent(thehash);
			}
			thehash = "#" + thehash;
		}
		window.top.location.href = "link/" + pathstr + thehash;
	}
	else
	{
		var thehash = window.top.location.hash.toString();
		if(thehash.length > 1) {
			var pathstr = window.top.location.pathname.toString();
			var pathsep = pathstr.lastIndexOf("/");
			if(pathsep != -1) {
				pathstr = pathstr.substr(pathsep+1);
			}

			//Set the inner frame hash target jump to the outer frame hash target jump
			var hashsep = thehash.indexOf("#");
			if(hashsep != -1) {
				thehash = thehash.substr(hashsep+1);
			}
			if(decodeURIComponent && encodeURIComponent) {
				thehash = decodeURIComponent(thehash);
				thehash = encodeURIComponent(thehash);
			}
			var thehash_nopound = thehash;
			thehash = "#" + thehash;

			var inner_thehash = window.self.location.hash.toString();
			if(inner_thehash.length > 1) {
				//Set the inner frame hash target jump to the outer frame hash target jump
				var inner_hashsep = inner_thehash.indexOf("#");
				if(inner_hashsep != -1) {
					inner_thehash = inner_thehash.substr(inner_hashsep+1);
				}
				if(decodeURIComponent && encodeURIComponent) {
					inner_thehash = decodeURIComponent(inner_thehash);
					inner_thehash = encodeURIComponent(inner_thehash);
				}
				inner_thehash = "#" + inner_thehash;
			} else {
				inner_thehash = "";
			}

			var inner_pathstr = window.self.location.pathname.toString();
			var inner_pathsep = inner_pathstr.lastIndexOf("/");
			if(inner_pathsep != -1) {
				inner_pathstr = inner_pathstr.substr(inner_pathsep+1);
			}

			if((inner_pathstr.length == pathstr.length) && (inner_pathstr.indexOf(pathstr) == 0)) {
				if((inner_thehash.length != thehash.length) || (inner_thehash.indexOf(thehash) != 0)) {
					window.self.location.href = thehash;

					if(IsIE()) {
						//KLUDGE: Apply the sfTarget class if using IE
						mod_target(thehash_nopound);
					}
				}
			} else {
				var addhash = "";
				if(inner_thehash.length && ((inner_thehash.length != thehash.length) || (inner_thehash.indexOf(thehash) != 0))) {
					if(!((inner_thehash == "#tpp") || (inner_thehash == "#ctp"))) {
						addhash = inner_thehash;
					}
				}
				window.top.location.href = "link/" + inner_pathstr + addhash;
			}
		}
	}
}

window.doFrameInHdlr = doFrameIn;
XBrowserAddHandler(window,'load','doFrameInHdlr');
