function handleFlexCalls(aMethod,aName,theX,theY,theWidth,theHeight)
{
	switch (aMethod) {
		case "game":
			startGameContainer(aName,theX,theY,theWidth,theHeight);
			break;
		case 'close':
			removeGameContainer();
			break;
	}
}
function startGameContainer(aGame,theX,theY,theWidth,theHeight)
{
	var theContainer = document.getElementById('gameContainer');
	theContainer.style.width = theWidth + "px";
	theContainer.style.height = theHeight + "px";
	theContainer.style.left = theX + "px";
	theContainer.style.top = theY + "px";
	
	if (window["gameframe"] == undefined) {
		theContainer.innerHTML = '<iframe id="gameframe" name="gameframe" style="width: 100%; height: 100%;" frameborder="0" framespacing="0" src="/games/' + aGame + '.html" scrolling="auto"></iframe>';
	} else {
		window["gameframe"].location.href = '/games/' + aGame + '.html';
	}
}
function removeGameContainer()
{
	var theContainer = document.getElementById('gameContainer');
	theContainer.style.width = "1px";
	theContainer.style.height = "1px";
	theContainer.style.left = "-100px";
	theContainer.style.top = "-100px";
	
	var theGameFrame = window["gameframe"];
	theGameFrame.location.href = "blank.html"; 
	theContainer.removeChild(theGameFrame);
	
	theContainer.innerHTML = "";
}
function closeGame()
{
	getMyApp("BasisX").closePopUp();
}
function historyBack()
{
	history.go(-1);
}

function getMyApp(appName)
{
	if (navigator.appName.indexOf ("Microsoft") !=-1) 
	{
		return window[appName];
	} 
	else 
	{
		return document[appName];
	}
}

function doLogin()
{
	getMyApp("BasisX").doLogin();
}

function doRegister()
{
	getMyApp("BasisX").doRegister();
}

function getUserId()
{
	getMyApp("BasisX").getUserId();
}

function setUserId(aUserId)
{
	var theGameFrame = window["gameframe"];
	theGameFrame.setUserId(aUserId);
}

// Function to get parameters from the URL
function getURLParams( name )
{
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );
	if( results == null )
		return "";
	else
		return results[1];
}

//Get the screen height and width (resolution)
function getScreenHeight()
{
	if (screen.height)
		return screen.height;
}

function getScreenWidth()
{
	if (screen.width)
		return screen.width;
}

function getColorDepth()
{
	if (screen.colorDepth)
		return screen.colorDepth;
}

//Opens the site in a new popup window, also setting a search ?fs=1.
function openPopUp()
{
	var url = new String(window.location.href.split("?")[0].split("#")[0]);
	window.open(url +"?fs=1" + window.location.hash, '', 'statusbar=no, scrollbars=auto, width='+screen.availWidth+', height='+screen.availHeight+', top=0, left=0');
}
