function findPlayer(win) {
	// Search the window hierarchy for an object named "Player"
	// Look in the current window (win) and recursively look in any child frames
	if (win.player != null) return win.player;

	if (win.length > 0) {
		for(var i = 0; i < win.length; i++) {
			var thePlayer = findPlayer(win.frames[i]);
			if (thePlayer != null) return thePlayer;
		}
		if (win.parent != null) {
			var thePlayer = findPlayer(win.parent);
			if (thePlayer != null) return thePlayer;
		}
	}
	return null;
}

function getPlayer() {
	// start at the topmost window - findPlayer will recurse down through
	// all of the child frames
	
	if (parent.parent.player != null) return parent.parent.player;
	if (parent.player != null) return parent.player;

	var thePlayer = findPlayer(parent);
	// the Player wasn't found in the current window's hierarchy.  If the
	// current window has an opener (was launched by another window),
	// check the opener's window hierarchy.
	if (thePlayer == null) {
		if (typeof(opener) != "undefined") {
			if (opener != null) thePlayer = findPlayer(opener.top);
		}
	}
	return thePlayer;
}

function findLMS(win) {
	// Search the window hierarchy for an object named "Player"
	// Look in the current window (win) and recursively look in any child frames
	if (win.lms != null) return win.lms;

	if (win.length > 0) {
		for(var i = 0; i < win.length; i++) {
			var theLMS = findLMS(win.frames[i]);
			if (theLMS != null) return theLMS;
		}
	}
	return null;
}

function getLMS()
{
	// start at the topmost window - findLMS will recurse down through
	// all of the child frames
	var theLMS = findLMS(parent);
	if (theLMS == null) theLMS = findLMS(top);
	// the LMS wasn't found in the current window's hierarchy.  If the
	// current window has an opener (was launched by another window),
	// check the opener's window hierarchy.
	if (theLMS == null) {
		if (typeof(opener) != "undefined") {
			if (opener != null) theLMS = findLMS(opener.top);
		}
	}
	return theLMS;
}

function findPage(win) {
	// Search the window hierarchy for an object named "Player"
	// Look in the current window (win) and recursively look in any child frames
	if (win.page != null) return win.page;

	if (win.length > 0) {
		for(var i = 0; i < win.length; i++) {
			var thePage = findPage(win.frames[i]);
			if (thePage != null) return thePage;
		}
	}
	return null;
}

function getPage()
{
	// start at the topmost window - findLMS will recurse down through
	// all of the child frames
	var thePage = findPage(parent);
	if (thePage == null) thePage = findPage(top);
	// the LMS wasn't found in the current window's hierarchy.  If the
	// current window has an opener (was launched by another window),
	// check the opener's window hierarchy.
	if (thePage == null) {
		if (typeof(opener) != "undefined") {
			if (opener != null) thePage = findPage(opener.top);
		}
	}
	return thePage;
}

function findFrame(name, frame)
{
	var oldFrameName = null;
	if (name == "navigation") {
		oldFrameName = "header";
	}

	if (typeof(frame) == "undefined") {
		frame = frames;
	}
	for (var i = 0; i < frame.length; i++) {
		if (frame[i].name == name || (oldFrameName && frame[i].name == oldFrameName)) {
			return frame[i];
		} else {
			var result = findFrame(name, frame[i]);
			if (result) return(result);
		}
	}
	return(null);
}

function InitializeStandardTree()
{
	var tree_frame = player.findFrame("tree");
	if (tree_frame) {
		tree_frame.initialize();
	}
}

function findStruct(win)
{
	if (win.struct != null) return win.struct;

	if (win.length > 0) {
		for(var i = 0; i < win.length; i++) {
			var theStruct = findStruct(win.frames[i]);
			if (theStruct != null) return theStruct;
		}
	}
	return null;
}

function getStruct()
{
	var theStruct = findStruct(parent);
	if (theStruct == null) theStruct = findStruct(top);

	if(theStruct == null) {
		if(typeof(opener) != "undefined") {
			if(opener != null) theStruct = findStruct(opener.top);
		}
	}
	return theStruct;
}

function showConfiguration(isNew, x, y, w, h) {
	var url = "ds_configuration.html";
	if (isNew) url = "configuration.html";
	
	if (w == null) w = 600;
	if (h == null) h = 280;
	
	var opt = "";
	opt += (x != null) ? ', left=' + x : ', left=' + ((screen.availWidth - w) / 2);
	opt += (y != null) ? ', top=' + y : ', top=' + ((screen.availHeight - h) / 2);
	opt += ', width=' + w;
	opt += ', height=' + h;
	
	window.open(url, "", opt);
	
	return false;
}

function getURIParam(name)
{
	var r = "";
	name = name.toLowerCase();
	var paramsList = location.search.slice(1).split('&');
	for (var i = 0; i < paramsList.length; i++)
	{
		keyName = paramsList[i].slice(0, paramsList[i].indexOf('=')).toLowerCase();
		if (keyName == name)
		{
			r = paramsList[i].slice(paramsList[i].indexOf('=') + 1);
			break;
		}
	}
	return r;
}

