// JavaScript Document

function openTripReportWindow() {
	tripReportHref = top.frames.MainFrame.location.href;
	open(tripReportHref);
}
	
function loadFrames(subject) {
	alert("Running loadFrames. subject = " + subject);

	if (subject == "climbing/speed") {
		parent.MenuFrame.location.replace(subject + "/menu.php?type=Climbing");
		parent.MainFrame.location.replace(subject + "/speed_news.html");
		parent.BannerFrame.location.replace(subject + "/banner2.php")
	} else {
		parent.MenuFrame.location.replace(subject + "/menu.htm");
		parent.MainFrame.location.replace(subject+ "/main.htm"); 
		parent.BannerFrame.location.replace(subject + "/banner.htm")
	}
}

function initSubject() {
	alert("Running initSubject()...");
}
	
// Functions for jumping right to a page within a framed document.
// It is assumed that the main document frame has the name: "main"

// Parse location and return parameters 
function parseArguments(locationString) {
	var arguments = new Array();
	//alert("Location string is: " + locationString);
	//alert("The length of this string is: " + locationString.length)
	var currentPos = locationString.indexOf("?");
	//alert("Location of ? is " + currentPos);
	if (currentPos != -1) {
		var i = 1;
		while (currentPos < locationString.length) {
			var argName, argValue;
			var equalsPos = locationString.indexOf("=", currentPos);
			//alert("Location of = is " + equalsPos);
			argName = locationString.substring(currentPos+1, equalsPos);
			var ampPos = locationString.indexOf("&", equalsPos);
			//alert("Location of & is " + ampPos);
			if (ampPos == -1) {
				argValue = locationString.substring(equalsPos+1, locationString.length);
				currentPos = locationString.length + 1;
			} else {
				argValue = locationString.substring(equalsPos+1, ampPos);
				currentPos = ampPos;
			}
		
			//alert("Found argument: " + argName + " = " + argValue);
			arguments[i] = argName;
			arguments[i+1] = argValue;
			i = i + 2;
		}
	}
	return arguments;
}

function getArgValue(arguments, argName) {
	for (var i = 1; i < arguments.length; i = 1 + 2) {
		if (arguments[i] == argName) {
			return arguments[i+1];
		}
	}
	
	return "";
}

function loadInfoRequest(frameName, argumentName) {
	var args = parseArguments(top.location.href);
	var value = getArgValue(args, argumentName);
	if (value != "") {
		top.frames(frameName).location.href = value;
	} 
}		

function checkForPage() {
		alert("Source path is: " + window.location)
	}
	
function removeTrailingChar (inputString, removeChar)
{
	var returnString=inputString;
	if (removeChar.length) {
	    while('' + returnString.charAt(returnString.length-1)==removeChar) {
	    	returnString=returnString.substring(0,returnString.length-1);
	  }
	}
	return returnString;
}

function printAllFrames() {
	alert("There are " + parent.frames.length + " frames on this page.");
	for (var i = 0; i < parent.frames.length-1; i++) {
		alert("Frame " + i + " is " + parent.frames(i).name);
	}
}
