var framesetPage = "index.html";
var currPage = justTheFilename(self.location.pathname);

if (top.location == self.location && framesetPage != currPage && currPage.length != 0) {
	self.location.replace(framesetPage + "?" + currPage);
}

addOnload(chgFrame);

function addOnload(newFunction) {
	var oldOnload = window.onload;
	
	if (typeof oldOnload == "function") {
		window.onload = function() {
			if (oldOnload) {
				oldOnload();
			}
			newFunction();
		}
	}
	else {
		window.onload = newFunction;
	} 
}

function chgFrame() {
//alert(top.location);
//alert(self.location);
//alert(document.location.search);

	if (top.location == self.location && document.location.search) {
		var linkURL = justTheFilename(document.location.search);
		var contentWin = document.getElementById("main").contentWindow;
		var currURL = justTheFilename(contentWin.location.pathname);

		if (currURL != linkURL) {
			contentWin.location.replace(linkURL);
		}
	}
}

function justTheFilename(thisFile) {
	if (thisFile.indexOf("/") > -1) {
		thisFile = thisFile.substring(thisFile.lastIndexOf("/")+1);
	}

	if (thisFile.indexOf("?") == 0) {
		thisFile = thisFile.substring(1);
	}

	return thisFile;
}
