//setting up flash environment for communication
//easoMain.SetVariable("bBrowserHost", true);
//easoMain.SetVariable("flashObjectId", "easoMain");

var FlashJSProxy =
{
	doFSCommand:function(sFuncSpec, sArgString)
	{
		if(sFuncSpec==null)
			return;
		eval(sFuncSpec + "(" + sArgString + ")");
		
	}
};

function setValueFromJSFunction(targetFlashObject,targetVariable,strFunction)
{
	var o = eval(targetFlashObject);
	o.SetVariable(targetVariable, eval(strFunction));
}

function easoMain_OnLoad()
{
	window.document.easoMain.LoadMovie(0,"easoMain.swf?bBrowserHost=true");
	/*
	Don't delete this comment! For some reason this
	comment stops winME/tiger crash when you quit the game.
	*/
	easoMain.SetVariable("bBrowserHost", true);
	easoMain.SetVariable("flashObjectId", "easoMain");
	window.document.easoMain.focus()
	disconnect();
}

function easoMain_OnUnload()
{
	//don't need to do anything.
}

//Start: Html Frame Functions

function loadEasoHtml(strUrl,x,y,w,h,scrolling)
{
	document.all.easoHtmlIframe.style.pixelLeft = x;
	document.all.easoHtmlIframe.style.pixelTop = y;
	document.all.easoHtmlIframe.style.width=w;
	document.all.easoHtmlIframe.style.height=h;
	document.all.easoHtmlIframe.src=strUrl;
	document.all.easoHtmlIframe.scrolling = scrolling;
}

function displayEasoHtml()
{
	//For some reason click on the iframe then the flash object
	//cause a zorder swap.  This seems to fix it.
	easoHtml.style.visibility = "hidden";
	easoHtml.style.visibility = "visible";
}

function showEasoHtml(strUrl,x,y,w,h,scrolling)
{
	easoHtml.style.pixelLeft = x;
	easoHtml.style.pixelTop = y;
	document.all.easoHtmlIframe.style.width=w;
	document.all.easoHtmlIframe.style.height=h;
	document.all.easoHtmlIframe.src = strUrl;
	document.all.easoHtmlIframe.scrolling = scrolling;
	easoHtml.style.visibility = "visible";
}

function hideEasoHtml()
{
	document.all.easoHtmlIframe.src = "../../commonHtml/blankPage.html";
	easoHtml.style.visibility = "hidden";
}

function resizeEasoHtml(x,y,w,h)
{
	easoHtml.style.pixelLeft = x;
	easoHtml.style.pixelTop = y;
	document.all.easoHtmlIframe.style.width=w;
	document.all.easoHtmlIframe.style.height=h;
}

//End: Html Frame Functions

function gotoPatcher(gameId,nPatchVersion,manifestDirective,nLanguage)
{
	var url = "../../commonHtml/patcher.html?" + gameId + "|" + nPatchVersion + "|" + manifestDirective + "|" + nLanguage;
	top.document.location=url;
}


function launchExternalWebPage(strUrl)
{
	window.external.SpawnCmd(strUrl);
}

// EA-Trax Setup

function AudioCallback()
{
}

AudioCallback.prototype.ShowNewSong = function( trackStr  )
{
	var arrSongData = trackStr.split("::");
	
	easoMain.SetVariable("/chiron:artist", arrSongData[0] );
	easoMain.SetVariable("/chiron:album", arrSongData[1] );
	easoMain.SetVariable("/chiron:song",arrSongData[2] );
}

var gCallback;
function prepareAudioCallback()
{
	gCallback = new AudioCallback();
	gapi.setAudioCallback ( gCallback ) ;
}

function unloadRootMovie() {
	easoMain.SetVariable("_root.unloadRoot", "1");
}

// Get Computer Country-Language

function getCountryLanguage()
{
	var countryLanguage = new String(navigator.userLanguage);
	return countryLanguage;
}

function easoLoaded()
{
	//call madden front end to hide loading screen.
	gapi.setEASOLoaded();
	
}

function initConstants(gameId)
{
	if(gameId=="MADDEN")
		main.gblRegistryKey = "SOFTWARE\\Electronic Arts\\EA Sports\\Madden NFL 2004\\ergc";
	else if(gameId=="NHL")
		main.gblRegistryKey = "SOFTWARE\\Electronic Arts\\EA Sports\\NHL 2004\\ergc";
	else if(gameId=="TW")
		main.gblRegistryKey = "SOFTWARE\\Electronic Arts\\EA Sports\\Tiger Woods PGA TOUR 2004\\ergc";
	else if(gameId=="NBA")
		main.gblRegistryKey = "SOFTWARE\\Electronic Arts\\EA Sports\\NBA LIVE 2004\\ergc";
	else if(gameId=="FIFA")
		main.gblRegistryKey = "SOFTWARE\\Electronic Arts\\EA Sports\\FIFA 2004\\ergc";
	else if(gameId=="MVP")
		main.gblRegistryKey = "SOFTWARE\\Electronic Arts\\EA Sports\\MVP 2004\\ergc";
}
