var jsVersion = "10.3.1";	// Aug 27th, 2007 
var Country = "US"; // default
var debugOn = 0; // debug on/off (can't set console to non-null)
var progressUpdate = 0; // update/don't
var progressTest = 0; // open window for progress (testing)
var LANflag = 0;
var flashDebug = 0;
var k_demoMode = 1;
var k_runMode = 2;
var flashMode = k_runMode; // 1 demo, 2 run
//var flashMode = k_demoMode; // 1 demo, 2 run
var g_bWriteDemoData = 0; // write demo data to file?
var b_GotoPreview = 0; // preview for goto: do not set to 1, as not tested yet!!!
var audioquality = 1; // default audio quality (2 = higher)
var macIEOff = 0; // disable IE on mac?
var dynParVersion = 1;
var g_iUseLMS = 1;	// flag of existence LMS
// the ___API___ token shall be replaced with the LMSAPI.asp URL by installer
// example - var g_sLMSAPI_URL = "http://"+location.host+"/lms/api/LMSAPI.asp";
var g_sLMSAPI_URL = "/servlet/LegacyContentListener";
var g_sRedirect_URL = ""; // URL required to redirect user to other LMS page on exit from Menu
// for PA testing:
var PADisabled = 1; // set to 1 in "initVars" if we are in demo mode
var testSessionID = "aq1sw2de3";
var testUser = "NB004";
var PAReturnURL = "http://www.nebula.ie";
var useTestVals = 0;
////////***********************
var putProductStatus = 4;
var fetchProductStatus = 5;
var fetchProductPrefs = 7;
////////*********************

var g_bSCORM = 0; // only set for testing, normally would be passed in as part of URL
var g_iScormType = -1;
var g_bDisableContinue = 0; // disable continue button (will be set to 1 if Assignment mode)
var g_bTestAssign = 0; // set this if you want to test content in assignment mode
//var g_bCSRTE = 0; // Class Server RTE? will be set when content is generated
var g_strTableHeight = "100%"; // height (used for "embed" browser height in LRM format)

var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
var MacPlatform = navigator.platform == "MacPPC";
var vers = navigator.appVersion;
vers = eval(vers.substring(0,1)); 

var _console = null;
var exploreWindow = null;
var PAWindow = null;
var sessionWindow = null;
var glossaryWindow = null;
var calculatorWindow = null;
var folderCount = 6; // num folders to root
var k_loadDelay = 180; // timeout
var KPReadAhead = (InternetExplorer && ! MacPlatform) ? 9 : 1; //1;
var callbackKP = 1;
var PAInLayer = 0; // PA in layer/window for IE  
var g_dtStartTime = new Date();
var relativeRoot = "../../../../../";
var relativeCourse = "../../../../";
var explorePath = relativeRoot+"explore.html";
var PAPath = "http://asmt.riverdeep.net/riverdeep/classes/PAreaInterfaceController"; //////////// change when have real path
var parsePAString = 1; // parse PA string (from BID)
var taskBarHeight = 55; // for netscape 
var g_iTOTLimit = 240; // time on task
var useKPWindow = 1; // use KP window for relative sizes (explorations)
///// relative sizes to KP window: //
var leftStart = 0.9;  // 10 pixels
var topStart = 6.75;  // percentage
var interfaceWidth = 10.3;  // width of right side of interface (%)
var interfaceHeight = 18.5;
var movieWidth = 640;
var movieHeight = 480;
var netscapeBorderWidth = 5; // window border (explorations)
var IEMacOffsetWidth = 15;
var IEMacOffsetHeight = 25;
var dragBarHeight = 20;
// window position (navigator only)
var currentWindowTop = 0;
var currentWindowLeft = 0;
var exploreRelX = 0; // relative x position (exploration)
var exploreRelY = 0;



///////////////////////////////// plug-in version detection /////////////////////////////////////////

var g_iFlashVerRequired = 5; // minimum version required

var downLoadPromptPage = "download.html";	// send user to Macromedia
var downLoadURL = (typeof menuName != "undefined") ? ("../" + downLoadPromptPage) : (relativeRoot + downLoadPromptPage);

var g_bVerCorrect = false; // is the correct version (or above) installed?
var g_bFlashMin6 = false; // is version 6 or above installed? (if this is true then use "FlashVars" parameter)

var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.indexOf("Windows") != -1) ? true : false;

if(isIE && isWin)
{
	// purpose is to set the g_bFlashVerMin6 boolean for IE/PC
	// if plug-in installed is at least 6, then both g_bFlashVerMin5 and g_bFlashVerMin5 will be set to true
	document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
	document.write('on error resume next \n');
	document.write('g_bVerCorrect = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.');
	document.write(g_iFlashVerRequired);
	document.write('")) \n');	
	document.write('g_bFlashMin6 = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6")) \n');	
	document.write('</SCR' + 'IPT\> \n'); // break up end tag so it doesn't end our script
}


function detectFlash()
{	
	// purpose is to set the g_bFlashVerMin5 an 6 booleans for NS and IE/Mac
	// use javascript detection using navigator.plugins array
	if(navigator.plugins && navigator.plugins["Shockwave Flash"])
	{
		var flashDescription = navigator.plugins["Shockwave Flash"].description;

		// plugin-description looks like 'Shockwave Flash 5.0 r5'
		// get the major version
		var descArray = flashDescription.split(" ");
		var tempArrayMajor = descArray[2].split(".");
		var majorVersion = parseInt(tempArrayMajor[0]);		


		g_bVerCorrect = (majorVersion >= g_iFlashVerRequired);
		g_bFlashVerMin6 = (majorVersion >= 6);
		
	}
	if (! g_bVerCorrect)
		DownLoadPrompt();

}

function DownLoadPrompt()
{
	if(! g_bVerCorrect)
	{
		window.location = downLoadURL;
	}
}

detectFlash();


///////////////////////////////// end plug-in version detection /////////////////////////////////////////





if (typeof g_strDynamoSessionID == "undefined")
	g_strDynamoSessionID = "";
if (typeof g_iDynamoUserID == "undefined")
	g_iDynamoUserID = "";
/////////////////////////////////////
// default for launch from Menu

var UserID = 0;
if (typeof tutorialName == "undefined")
	tutorialName = "";
if (typeof ActivityType == "undefined")
	ActivityType = "";
if (typeof ActivityID == "undefined")
	ActivityID = "0";
if (typeof AssignmentID == "undefined")
	AssignmentID = 0;
if (typeof AtomID == "undefined")
	AtomID = "";
if (typeof Keypress == "undefined")
	Keypress = 0;
if (typeof g_bCSRTE == "undefined")
	g_bCSRTE = 0;
if (typeof g_bHideExit == "undefined")
	g_bHideExit = 0;
if (typeof g_bDisableStartEndBlock == "undefined")
	g_bDisableStartEndBlock = 0;

/////////////////////////////////////
var SessionID = 0;
var Score = 0;  // score from dynamic pars
var SMP = 0;    // SMP from dynamic pars
var asgnid = 0;
var dparams = "";
var V = "d1"; // product version
var ppath = "";

function DM_Layer(name,parValue1,parValue2,x,y,width,height)
{//***the DM_Layer class *********
	var windowHeight = getWindowHeight();
	var windowWidth = getWindowWidth();
	var heightScale = windowHeight/movieHeight;
	var widthScale = windowWidth/movieWidth;
	var xOffset = leftStart*windowWidth/100;
	var yOffset = topStart*windowHeight/100;
	if (!(movieWidth*heightScale > windowWidth))
		xOffset = xOffset + (windowWidth - (movieWidth * heightScale))/2
	else if (!(movieHeight*widthScale > windowHeight))
	{
		// fine height with given widthScale
	}
	var startX = useKPWindow ? getWindowLeft() + xOffset : getWindowLeft();
	var startY = useKPWindow ? getWindowTop() + yOffset : getWindowTop();
	if(!width || width < 50) width = 50;
	if(!height || height < 75) height = 75;
	if (useKPWindow)
	{
		windowWidth = windowWidth - startX- (windowWidth*interfaceWidth/100);
		windowHeight = windowHeight - (windowHeight*interfaceHeight/100);
	}
	this.name = name;
	if (! InternetExplorer)
		startY = startY + dragBarHeight;
	this.x = x*windowWidth/100 + startX;
	this.y = y*windowHeight/100 + startY;
	this.height = height*windowHeight/100;
	this.width = width*windowWidth/100;
	if (MacPlatform && InternetExplorer)
	{
		this.height = this.height - IEMacOffsetHeight;
		this.width = this.width - IEMacOffsetWidth;
	}
	if (!InternetExplorer)
	{
		this.width = this.width - netscapeBorderWidth*2;
		this.height = this.height - netscapeBorderWidth;
		this.x = this.x - netscapeBorderWidth*2;
	}
	this.parValue1 = parValue1;
	this.parValue2 = parValue2;
}
new DM_Layer("","","",0,0,0,0); // create/discard an initial Layer
function LayerWrite()
{ // method for writing layer to document
	var frameName = (this.name)+"_frame";
	document.write('<DIV ID='); 
	document.write(this.name);
	document.write(' style="position:absolute;');
	document.write(' top:');
	document.write(eval(this.y));
	document.write('; left:');
	document.write(eval(this.x));
	document.write('; background-color:black;');
	document.write(' visibility:hidden;">');
	if(InternetExplorer)
	{
		document.write('<IFRAME NAME=');
		document.write(frameName);
		document.write(' src="" marginheight=0 marginwidth=0 scrolling=no');
		document.write(' frameborder=0 width=');
		document.write(eval(this.width));
		document.write(' height=');
		document.write(eval(this.height));
		document.write('></IFRAME>');
	}
	document.write('</DIV>');
}
DM_Layer.prototype.write = LayerWrite;// *******end DM_Layer class****
var layerArray = new Array(); // the DM_Layer array
function generateLayers()
{
	for(i=0;i<layerArray.length;i++)
	{
		layerArray[i].write();
	}
}
var theLayer = ""; // the currently open layer (explorations)
var theFrame = ""; // the current layer frame
function getWindowHeight() // can't get browser dimensions with IE so assume full screen:
{
	return (InternetExplorer ? screen.availHeight : (screen.height)-taskBarHeight);
}
function getWindowWidth()
{
	return (InternetExplorer ? screen.availWidth : screen.width); 
}
function getWindowLeft()
{ // (need this and windowTop before window is open so simply return 0)
	return 0; 
}
function getWindowTop()
{
	return 0; 
}
function currentLeft()
{
	return InternetExplorer ? 0 : window.screenX;
}
function currentTop()
{
	return InternetExplorer ? 0 : window.screenY;
}
function setExploreFocus()
{ // onBlur=focus not consistent
	if ((exploreWindow != null) && (! exploreWindow.closed))
		exploreWindow.focus();		
}
function focusExplore()
{ 
		if (MacPlatform)
			closeExploreWin() // close it so that repeat can work
		else
			setExploreFocus();
}
function positionExplore()
{ // used by netscape
// unfortunately need universalbrowserwrite to move off screen (so no moveTo)
	var xPos = currentLeft();
	var yPos = currentTop();
	var relX = xPos + exploreRelX;
	var relY = yPos + exploreRelY;
	// exploreWindow will always be null if IE
	if ((exploreWindow != null) && (! exploreWindow.closed))
	{
		exploreWindow.moveTo(relX, relY);
		exploreWindow.focus();		
	}
	currentWindowTop = yPos;
	currentWindowLeft = xPos;
}
function openDebugWnd()
{
   if (InternetExplorer && debugOn)
   { // open a wnd the first time we call this function, or after existing has been closed
	if ((_console == null) || (_console.closed)) {
		_console = window.open("", "console", "width=600,height=300,resizable,scrollbars");
		_console.document.open("text/plain");
	}
   }
}
function debug(msg)
{
   if(InternetExplorer && debugOn)
   { // open a wnd the first time we call this function, or after existing has been closed
	if ((_console == null) || (_console.closed)) {
		return;
	}
	_console.document.writeln(msg);
   }
}
function closeWindow()
{ //need this in here till solve problem of window close in netscape
	//updateProgress();
	progressUpdate = 0;
	window.close();
}
function getExploration(theName)
{
	for(i=0; i< layerArray.length; i++)
	{
		if(layerArray[i].name == theName)
			return layerArray[i];
	}
	return null;
}
function encodeSpace(inString)
{
// not ideal! what we really want is to urlencode the string
	var theString = new String(inString);
	var newString = "";
	var theLength = theString.length;
	while (theLength >= 0)
	{
		if(theString.substr(theLength,1) == " ")
			newString = "%20" + newString
		else
			newString = theString.substr(theLength,1) + newString;
		theLength = theLength - 1;
	}

	return newString;	
}
function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}
function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v;
 }
}

function updateProgress()
{
  if(g_bSCORM)
  {

	osker_DoFSCommand("LMSFinish", "");
  }

   if (! InternetExplorer)
   { // can't call closeExploreWin from netscape (won't execute both functions)
		if ((exploreWindow != null) && (! exploreWindow.closed))
			exploreWindow.close();
   }
   if ((glossaryWindow != null)&&(! glossaryWindow.closed))
		glossaryWindow.close();
   if ((calculatorWindow != null)&&(! calculatorWindow.closed))
		calculatorWindow.close();  
   if ((PAWindow != null) && (! PAWindow.closed))
	PAWindow.close();

   if(0)    // doesn't work for netscape so disable for both for now
   {
	if (progressUpdate)
	{
  		var oskerObj = InternetExplorer ? osker : document.osker;
		var theBlock = oskerObj.GetVariable("currentBlock");
		if (theBlock != -1) // not uninitialised cos of missing blocks
		{	
			var theKPIndex = oskerObj.GetVariable("currentKPIndex");
			if (InternetExplorer) // netscape doesn't like the stop command!
				oskerObj.Stop();	
			oskerObj.SetVariable("/progressTarget:progressBlock",theBlock);
			oskerObj.SetVariable("/progressTarget:KPIndex",theKPIndex);
			oskerObj.SetVariable("/progressTarget:sendProgress",0);
			oskerObj.TCallLabel("/progressTarget","updateProgress");
			var theType = oskerObj.GetVariable("/progressTarget:theType");
			var theBID = oskerObj.GetVariable("/progressTarget:theID");
			var theRKP = oskerObj.GetVariable("/progressTarget:RKP");
			var theHKP = oskerObj.GetVariable("/progressTarget:HKP");
			var theTKP = oskerObj.GetVariable("/progressTarget:TKP");
			var theNs = oskerObj.GetVariable("/progressTarget:Ns");
			var theIs = oskerObj.GetVariable("/progressTarget:Is");
			var theS = oskerObj.GetVariable("/progressTarget:S");
doProgress(theType,theBID,theRKP,theHKP,theTKP,theNs,theIs,theS,0,0);
			progressUpdate = 0;
		}
	}
   }
}
function getDynPars(theType,atomID,resumeKP,highestKP,totalKPs,theScore)
{
	var dParamObj = "";
	var Showme = 0;
	dParamObj = dParamObj+"V="+V+";ID="+atomID+";KP="+resumeKP;
	if (theType == "W")
	{
		if (highestKP > 0)
			Showme = Math.round((highestKP/totalKPs)*100);
		if (AssignmentID != 0)
		{
			if (Showme < SMP)
				Showme = SMP;
		}
		dParamObj = 	dParamObj+";S="+theScore+";SMP="+Showme;		
	}
	return dParamObj;
}
function loadNextSession(URL)
{
	progressUpdate = 0; // don't want progress to update onUnload

	if(flashMode == 1) // demo mode
	{
		URL = URL + "?flashMode=1";
		if(g_bWriteDemoData == 1)
			URL = URL + "&g_bWriteDemoData=1";
	}

	debug("next session: "+URL);
	if (!InternetExplorer)
	{
		var thePath = self.location;
		self.location.href = getSession(thePath) + URL;
	}
	else
		self.location.href = URL;
}
function sendInfo(type, bid, rkp, hkp, tkp, ns, is, s, in_bLastUpdate, in_strNextSessionURL, in_strUnitName, in_iSessionNumber, in_strOpenPar)
{ // need last three vars for PA if reqd. (can't issue two GETURL at same level)
	if (in_strUnitName != "")
		openPA(in_strUnitName, in_iSessionNumber, in_strOpenPar);
	doProgress(type, bid, rkp, hkp, tkp, ns, is, s, in_bLastUpdate, in_strNextSessionURL);
}
//--------------------------------------
// to use with new LMSAPI functionality

function processInfo(in_bLastUpdate, in_strNextSessionURL, in_strUnitName, in_iSessionNumber, in_strOpenPar, in_iUseLMS, in_iLMSOptions)
{ // need last three vars for PA if reqd. (can't issue two GETURL at same level)
	//alert("processInfo("+in_bLastUpdate+","+in_strNextSessionURL+","+in_strUnitName+","+in_iSessionNumber+","+in_strOpenPar+","+in_iUseLMS+","+in_iLMSOptions+").");
	if (in_strUnitName != "")
		openPA(in_strUnitName, in_iSessionNumber, in_strOpenPar);
	if (in_strNextSessionURL)
	{
		debug("processInfo: call to load next session.");
		loadNextSession(in_strNextSessionURL);
	}
	else if (in_bLastUpdate)
	{
		debug("processInfo: last update - close everything.");
		closeGlossary();
		closeCalculator();
		
		if (in_iUseLMS == 1)
		{
			// load new content for this window,
			// for example, "http://arcas/riverdeep/lms/api/lmsapi.asp?ACTIONTYPE=1&USERID=3&ASSIGNID=43&ISTEST=0&FL=0"
			if (in_iLMSOptions == 0)
			{
				// Exit button pressed in CM
				self.location.href = g_sLMSAPI_URL+"?ACTIONTYPE=1&USERID="+UserID+"&ASSIGNID="+AssignmentID+"&ISTEST=0&FL=0";
			}
			if (in_iLMSOptions == 1)
			{
				// Assignment finished in CM
				self.location.href = g_sLMSAPI_URL+"?ACTIONTYPE=1&USERID="+UserID+"&ASSIGNID="+AssignmentID+"&ISTEST=0&FL=1";
			}
			if (in_iLMSOptions == 2)
			{
				// Exit from Menu
				self.location.href = g_sRedirect_URL;
			}
		}
		else if (! MacPlatform || ! InternetExplorer)
		{
			closeWindow();
		}	

	}
}

function closeExploreWin()
{
	if ((exploreWindow != null) && (! exploreWindow.closed))
		exploreWindow.close();
}
function doProgress(type,bid,rkp,hkp,tkp,ns,is,s,in_bLastUpdate,in_strNextSessionURL)
{ // need in_bLastUpdate for netscape (can't update then close window).
// in_strNextSessionURL needs to be here rather than in osker to allow
// pars to update properly (if call doProgress then attempt to go to next session
// the onUnload is issued before progress is updated (delaying doesn't help either)
	var Pcmpt = 0;
	var TOT = 0;
	var Actid = "";
	var dynPars = getDynPars(type,bid,rkp,hkp,tkp,s);
	var postString = "";
	if (! InternetExplorer)
		closeExploreWin();

	if (progressUpdate)
	{
		TOT = Math.round(getTOT());
		if (type == "T")
		{
			Actid = ActivityID;

			// note: "is/ns" not "(is-1)/ns"
			Pcmpt = Math.round((is/ns + (hkp/tkp)/ns)*100);
			if (Pcmpt == 0)
				Pcmpt = 1; // always show some percentage
		}
		else
		{
			if (AssignmentID != 0)
				Actid = ActivityID
			else
				Actid = bid;
 			if (type == "W")
			{
				if (s != 0)
					Pcmpt = 100;
			}
			else // screen/summary:
				Pcmpt = Math.round((hkp/tkp)*100);	
		}
		if (LANflag == 1)
		{
			debug ("updateLANProgress");
			updateLANProgress (Actid, bid, rkp, hkp, tkp, s, ns, is, in_bLastUpdate);
		}
		else
		{
			var progURL = g_sLMSAPI_URL+"?ACTIONTYPE="+putProductStatus+"&USERID="+UserID+"&ASSIGNID="+AssignmentID+"&ACTID="+Actid+"&TOT="+TOT+"&PERCDONE="+Pcmpt+"&XPROG="+dynPars;
			//debug("progress URL: "+progURL);
			if (progressTest)
			{ // for testing 
				var winProperties = "top=50,left=50,height=60,width=200,menubar=no,status,scrollbar=no";
				var updateWindow=window.open(progURL, "updateWin", winProperties);
				updateWindow.focus();
			}
			else
			{
				sendProgress(progURL);
			}
		}
	}
	if (in_strNextSessionURL)
	{
		loadNextSession(in_strNextSessionURL);
	}
	else if (in_bLastUpdate)
	{
		closeGlossary();
		closeCalculator();
		
		closeWindow();
	}
}
function getSession(thePath)
{
	var theString = new String(thePath);
	var theLength = theString.length;
	while (theLength > 0 && theString.substr(theLength-1,1) != "/")
	{
		theLength = theLength - 1;
	}
	var theSession = new String(theString.substr(0,theLength));
	return theSession
}
function removeName(fullPath)
{
	var theString = new String(fullPath);
	var theLength = theString.length;
	var folderIndex = 0;
	var thePath = new String();
	while (theLength > 0 && folderIndex < folderCount)
	{
		if (folderIndex != 0)
		{
			thePath = theString.substr(theLength-1,1) + thePath;
		}
		if (theString.substr(theLength-1,1) == '/')
		{
			folderIndex = folderIndex + 1;
		}
		theLength = theLength - 1;
	}
	if (theLength == 0)
		showError('sessionPath incorrect: ' + fullPath);
	return thePath.substr(1);
}
function removePath(theName)
{
	var theLength = theName.length;
	while (theLength > 0 && theName.substr(theLength-1,1) != '/')
	{
		theLength = theLength - 1;
	}
	return theName.substring(theLength);
}
function loadLayer(URL, layerObj, checkFilled)
{ // if checkfilled true then only load exploration if not already filled
	if(InternetExplorer)
	{
		if (! checkFilled || (layerObj.location.href == "about:blank"))
		{
			layerObj.location.href = URL;
			debug ('loadLayer ' + URL);
		}
	}
	else
		layerObj.src = URL;
}
function sendProgress(ProgressPath)
{ 
	var theLayerObj = InternetExplorer ? progressFrame : document.dummyProgress;
	loadLayer(ProgressPath, theLayerObj);
	

}
function loadPA(in_strUnitName,in_iSessionNumber,screenID)
{

	debug ("streaming PA: "+screenID);
	if (useTestVals)
	{
		UserID = testUser;
		SessionID = testSessionID;
	}
	var theLayerObj = InternetExplorer ? PAFrame : document.dummyLayer;
	var Title = in_strUnitName+" Tutorial "+in_iSessionNumber+" Practice Area";
	if(!InternetExplorer)
		Title = encodeSpace(Title);
	var thePath = PAPath+"?cms_session_id="+SessionID+"&student_user_id="+UserID+"&screen_id="+screenID+"&Title="+Title+"&tutorial_url="+PAReturnURL+"&start=0";
	loadLayer(thePath, theLayerObj);
   
}
function loadExplore(exploreName)
{
	if (LANflag == 0){	// no preload for content on LAN / CD
		exploreName = removePath(exploreName);
		var theExploration = getExploration(exploreName);
		if (theExploration == null)
			alert("Exploration: "+exploreName+" does not exist")
		else
		{
			var parVal1 = theExploration.parValue1;
			var parVal2 = theExploration.parValue2;
			var winHeight = theExploration.height;
			var winWidth = theExploration.width;
			var theURL = explorePath+"?parValue1="+parVal1+"&parValue2="+parVal2+"&height="+winHeight+"&width="+winWidth+"&doPlugin=0&country="+Country;
			var theLayerObj = InternetExplorer ? eval(exploreName+"_frame") : document.dummyLayer;
			loadLayer(theURL, theLayerObj, 1);
		}
	}
}
function closePA(arg)
{ // close practice area (see PAInlayer variable)
	if (InternetExplorer && PAInLayer)
		MM_showHideLayers('PALayer','','hide')
	else
		PAWindow.close();
	if(arg == "goMenu") window.close();
	return 1;
}
function showError(theName)
{
	alert(theName);
	closeWindow();
}
function openPA(in_strUnitName,in_iSessionNumber,screenID)
{ // if 'inLayer' set, open in layer (ie), else open window


	var Title = in_strUnitName+" Tutorial "+in_iSessionNumber+" Practice Area";
	if(!InternetExplorer)
		Title = encodeSpace(Title);
	if (useTestVals)
	{
		UserID = testUser;
		SessionID = testSessionID;
	}
	var thePath = PAPath+"?cms_session_id="+SessionID+"&student_user_id="+UserID+"&screen_id="+screenID+"&Title="+Title+"&tutorial_url="+PAReturnURL+"&start=1";
	debug("PA path: "+thePath);
	if(InternetExplorer && PAInLayer)
	{
		PAFrame.location.href = thePath;
		MM_showHideLayers('PALayer','','show');
	}
	else
	{
		// loading into layer doesn't work (inactive and shows through)
		var winProps = "top=0,left=0,height="+getWindowHeight()+",width="+getWindowWidth();

		PAWindow=window.open(thePath,"PAWin",winProps);
		if (MacPlatform && InternetExplorer)
		{ // use vars cos doesn't always work if pass vals directly to resize
			var theHeight = screen.height;
			var theWidth = screen.width;
			PAWindow.resizeTo(theWidth, theHeight);
		}
		PAWindow.focus();
	}
   
}
function openExploreWin(exploreName)
{
   exploreName = removePath(exploreName);
   var theExploration = getExploration(exploreName);
   if (theExploration == null)
	alert("The exploration: "+exploreName+" does not exist")
   else
   {
   	var x = theExploration.x;
   	var y = theExploration.y;
   	var height = theExploration.height;
   	var width = theExploration.width;
   	var parValue1 = theExploration.parValue1;
   	var parValue2 = theExploration.parValue2;
   	var theURL = explorePath+"?parValue1="+parValue1+"&parValue2="+parValue2+"&height="+height+"&width="+width+"&LANflag="+LANflag+"&country="+Country;
   	if(! InternetExplorer)
   	{
		if (MacPlatform)
			theURL = theURL + "&doPlugin=1";
		var winProps = "alwaysRaised=yes,";
// in ie no way to get the window dimensions so assume playing full screen, no re-size
		currentWindowTop = currentTop();
		currentWindowLeft = currentLeft();
		exploreRelX = x;  // globals for relative position of exploration
		exploreRelY = y;
		x = x + currentWindowLeft;
		y = y + currentWindowTop;
		winProps = winProps+"top="+y+",left="+x+",height="+height+",width="+width;
		exploreWindow=window.open(theURL,"exploreWin",winProps);
		exploreWindow.focus();
   	}
   	else
   	{
		theLayer = MM_findObj(exploreName).style;
		theFrame = eval(exploreName+"_frame");
		if(theFrame.location.href == "about:blank")
			theFrame.location.href = theURL;
		theLayer.visibility = 'visible';
    	}
   }
}
function closeExplore()
{
		if(InternetExplorer)
		{

			if(MacPlatform)
			{
				if (theFrame != "")
					theFrame.location.href = "about:blank";
			}
			theLayer.visibility = 'hidden';
			
		}
		else
			closeExploreWin();
}

function sendToLoad(theIndex)
{
	var theKP = parseInt(theIndex);
	theKP++;
	if (MacPlatform && InternetExplorer)
	{ // the session path is retrieved from the html file
		if(!LANflag)
		{
			var varFile = tutorialName + "var.txt";
			var SessionPath = removeName(document.location);
			var fullString = relativeRoot+ "stream.html" + "?macIE=1&varFile=" + SessionPath + "/" + varFile + "&k_loadDelay=" + k_loadDelay + "&KPReadAhead=" + KPReadAhead + "&callbackKP=" + callbackKP + "&currentKPIndex=" + theKP + "&SessionPath="+SessionPath + "/&parsePAString="+parsePAString;
			document.streamFrame.location.href = fullString;
		}
	}
	else
	{
		document.loadKPs6.TGotoLabel("/","begin")
		document.loadKPs6.SetVariable("currentKPIndex",theKP)
		document.loadKPs6.Play()
	}
}



function GenerateHTML (flashPath) {// Create Main HTML
	initVars();
	document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"')
	document.write(' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0"');
	document.write(' ID=osker WIDTH=100% HEIGHT=100%>\n');
	document.write(' <PARAM NAME=movie VALUE="' + flashPath + '/osker.swf');
	if(g_bFlashMin6)
	{
		document.write('"> <PARAM NAME=FlashVars VALUE="macIE=0');
	}
	else
	{
		document.write('?macIE=0');
	}
	document.write('&AssignmentID=');
	document.write(AssignmentID);
	if(AssignmentID != 0)
	{
		document.write('&g_bDisableContinue=1');
	}
	else
	{
		document.write('&g_bDisableContinue=');
		document.write(g_bDisableContinue);
	}
	document.write('&debug=');
	document.write(flashDebug);
	document.write('&theMode=');
	document.write(flashMode);
	document.write('&theScore=');
	document.write(Score);
	document.write('&ActivityType=');
	document.write(ActivityType);
	document.write('&AtomID=');
	document.write(AtomID);
	document.write('&Keypress=');	
	document.write(Keypress);
	document.write('&tutorialName=');
	document.write(tutorialName);
	document.write('&k_loadDelay=');
	document.write(k_loadDelay);
	document.write('&numReadAhead=');
	document.write(KPReadAhead);
	document.write('&numCallback=');
	document.write(callbackKP);
	document.write('&parsePAString=');
	document.write(parsePAString);
	document.write('&LANFlag=');
	document.write(LANflag);
	document.write('&jsVersion=');
	document.write(jsVersion);
	document.write('&b_GotoPreview=');
	document.write(b_GotoPreview);
	document.write('&audioquality=');
	document.write(audioquality);
	document.write('&PADisabled=');
	document.write(PADisabled);
	document.write('&ActivityID=');
	document.write(ActivityID);
	document.write('&g_iUseLMS=');
	document.write(g_iUseLMS);
	document.write('&g_sLMSAPI_URL=');
	document.write(g_sLMSAPI_URL);
	document.write('&UserID=');
	document.write(UserID);
	document.write('&g_sCountry=');
	document.write(Country);
	document.write('&InternetExplorer=');
	if (InternetExplorer)
		document.write(1)
	else
		document.write(0);
	document.write('&MacPlatform=');
	if (MacPlatform)
		document.write(1)
	else
		document.write(0);
	document.write('&BrowserVersion=');
	document.write(vers);
	document.write('&FlashVersionRequired=');
	document.write(g_iFlashVerRequired);
	document.write('&g_bSCORM=');
	document.write(g_bSCORM);
	document.write('&g_bCSRTE=');
	document.write(g_bCSRTE);
	document.write('&g_bHideExit=');
	document.write(g_bHideExit);
	document.write('&g_bDisableStartEndBlock=');
	document.write(g_bDisableStartEndBlock);
	document.write('"><PARAM NAME=loop VALUE=false><PARAM NAME=menu VALUE=false>\n');
	document.write(' <PARAM NAME=quality VALUE=high><PARAM NAME=bgcolor VALUE=#000000>\n');
	document.write(' <EMBED src="'+flashPath+'/osker.swf');
	if(g_bFlashMin6)
	{
		document.write('"  FlashVars="macIE=0');
	}
	else
	{
		document.write('?macIE=0');
	}
	document.write('&AssignmentID=');
	document.write(AssignmentID);
	if(AssignmentID != 0)
	{
		document.write('&g_bDisableContinue=1');
	}
	else
	{
		document.write('&g_bDisableContinue=');
		document.write(g_bDisableContinue);
	}
	document.write('&debug=');
	document.write(flashDebug);
	document.write('&theMode=');
	document.write(flashMode);
	document.write('&theScore=');
	document.write(Score);
	document.write('&ActivityType=');
	document.write(ActivityType);
	document.write('&AtomID=');
	document.write(AtomID);
	document.write('&Keypress=');	
	document.write(Keypress);
	document.write('&tutorialName=');
	document.write(tutorialName);
	document.write('&k_loadDelay=');
	document.write(k_loadDelay);
	document.write('&numReadAhead=');
	document.write(KPReadAhead);
	document.write('&numCallback=');
	document.write(callbackKP);
	document.write('&parsePAString=');
	document.write(parsePAString);
	document.write('&LANFlag=');
	document.write(LANflag);
	document.write('&jsVersion=');
	document.write(jsVersion);
	document.write('&b_GotoPreview=');
	document.write(b_GotoPreview);
	document.write('&audioquality=');
	document.write(audioquality);
	document.write('&PADisabled=');
	document.write(PADisabled);
	document.write('&ActivityID=');
	document.write(ActivityID);
	document.write('&g_iUseLMS=');
	document.write(g_iUseLMS);
	document.write('&g_sLMSAPI_URL=');
	document.write(g_sLMSAPI_URL);
	document.write('&UserID=');
	document.write(UserID);
	document.write('&g_sCountry=');
	document.write(Country);
	document.write('&InternetExplorer=');
	if (InternetExplorer)
		document.write(1)
	else
		document.write(0);
	document.write('&MacPlatform=');
	if (MacPlatform)
		document.write(1)
	else
		document.write(0);
	document.write('&BrowserVersion=');
	document.write(vers);
	document.write('&FlashVersionRequired=');
	document.write(g_iFlashVerRequired);
	document.write('&g_bSCORM=');
	document.write(g_bSCORM);
	document.write('&g_bCSRTE=');
	document.write(g_bCSRTE);
	document.write('&g_bHideExit=');
	document.write(g_bHideExit);
	document.write('&g_bDisableStartEndBlock=');
	document.write(g_bDisableStartEndBlock);
	document.write('" loop=false menu=false quality=high bgcolor=#000000  WIDTH=100% HEIGHT=100% swLiveConnect=true');
	document.write(' NAME=osker TYPE="application/x-shockwave-flash" ');
	document.write('		PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">\n');
	document.write('</EMBED></OBJECT>\n');

	if(flashMode == k_demoMode && g_bWriteDemoData)
	{
		document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="550" height="400" id="debugSWF" align="middle">');
		document.write('<param name="allowScriptAccess" value="sameDomain" />');
		document.write('<param name="movie" value="' + flashPath + '/debug.swf" />');
		document.write('<param name="quality" value="high" />');
		document.write('<param name="bgcolor" value="#ffffff" />');
		document.write('<embed src="'+flashPath+'/debug.swf" quality="high" bgcolor="#ffffff" width="550" height="400" name="debugSWF" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
		document.write('</object>');
		
	}

	if (! InternetExplorer)/// dummy layer for netscape
	{
		document.write('<LAYER ID="dummyLayer"></LAYER>\n');
		document.write('<LAYER ID="dummyProgress" VISIBILITY="hidden" TOP=400 LEFT=10 WIDTH=400 HEIGHT=300 BGCOLOR="red">Progress layer</LAYER>\n');
	}
///////// PRACTICE AREA LAYER /////////
	document.write('<DIV ID="PALayer" style="position:absolute; top:0; left:0; background-color:black; visibility:hidden;">\n');
	if(InternetExplorer)
	{
		document.write('<IFRAME NAME="PAFrame"');
		document.write(' src="" marginheight=0 marginwidth=0 scrolling=no frameborder=0 width=');
		document.write(getWindowWidth());
		document.write(' height=');
		document.write(getWindowHeight());
		document.write('></IFRAME>\n');	
		document.write('<IFRAME NAME="progressFrame"');
		document.write(' src="" marginheight=0 marginwidth=0');
		document.write(' scrolling=no frameborder=0 width=18 height=18');
		document.write('></IFRAME>\n');		
	}
	document.write('</DIV>');
}
/////////////////// START INIT VARIABLES /////////////////////////
function getArgs(query, separator){
	var args = new Object();
	if (query != null)
	{
		var pairs = query.split(separator);
		for(var i = 0; i < pairs.length; i++){
			var pos = pairs[i].indexOf('=');
			if (pos == -1) continue;
			var argname = pairs[i].substring (0, pos);
			var value = pairs[i].substring (pos+1);
			args[argname] = unescape (value);
			// document.writeln ("args " + argname + " " + args[argname]);
		}
	}
	return args;	
}
function getTOT()
{
	var stopTime = new Date();
	var iTOT = (stopTime.getTime() - g_dtStartTime.getTime())/(1000*60);
	g_dtStartTime = new Date();
	if (iTOT < 1)
		iTOT = 1 // always show some TOT
	else if (iTOT > g_iTOTLimit)
		iTOT = g_iTOTLimit;
	return iTOT;
}
function ProblemHeightBrowser()
{
	// needing to add more and more browser/version combinations to run within CS LRM format, so just apply
	// workaround for all browsers within CS LRM format (will apply to embed browsers only since height is only set
	// in that case:
	
	return 1;
}
function getCSHeight()
{

	var iRetVal = 0;
	// HACK!! 100% height does not work within CS3 with LRM format and some embed browsers. So
	// here we're attempting to calculate a height
	// this is really naff but it is what Microsoft do in the LRM env to calculate vertical space, it probably won't work with CS 4!!!!
	// also means activity won't resize properly since height will be constant (may be better to make width constant also?
	var ecs_windowOverhead = 13+44+28+13;  // nav bars, etc.
	
	if(typeof g_bCSRTE != "undefined")
	{

		if (g_bCSRTE == 1)
		{
			// LRM rather than SCORM
			if (ProblemHeightBrowser())
			{
			
				if (window.innerHeight)
				{
					 iRetVal = (window.innerHeight-ecs_windowOverhead-30);  //NSCP (needs more room)
				}
				else if (document.body && document.body.offsetHeight)
				{ 
					iRetVal = (document.body.offsetHeight-ecs_windowOverhead);  //IE
				}

			}


		}

	}
	return (iRetVal == 0 ? "100%" : new String(iRetVal));
}
function initVars()
{
	if (macIEOff && MacPlatform && InternetExplorer)
	{
		showError("IE on Macintosh not supported at present");
	}
	openDebugWnd();
	g_strTableHeight = getCSHeight();

	var DynamicParameters;
	if (LANflag == 1){	
		var loc2 = unescape (location);
		var iPos = loc2.indexOf ('?');
		if (iPos < 0)
			return;	// no args
		var argString = loc2.substring(iPos+1, loc2.length);
		var theString = unescape (argString);
		}
		else {
			var theString = unescape (location.search.substring(1));
		}
	debug ('theString..: ' + theString);
	debug ('g_sLMSAPI_URL: ' + g_sLMSAPI_URL);
	var args = getArgs (theString,"&");
	// new
	if(args.SCORM)
	{
		//alert("USE SCORM");
		g_bSCORM = args.SCORM;
	}

	if(args.relativeRoot)
	{
		relativeRoot = args.relativeRoot == 0 ? "" : args.relativeRoot;
	}
	if(args.relativeCourse)
	{
		relativeCourse = args.relativeCourse == 0 ? "" : args.relativeCourse;
	}

	if (args.USERID)
		UserID = args.USERID;
	//
	if (UserID == 0  && (typeof DynamoUserid != "undefined"))
		UserID = DynamoUserid;
	if(SessionID == 0  && (typeof DynamoSessionid != "undefined"))
		SessionID = DynamoSessionid;
	// new
	if (args.ASSIGNID)
		AssignmentID = args.ASSIGNID;
	//
	if (args.ppath)
		ppath = args.ppath;
	if (args.flashMode)
		flashMode = args.flashMode;

	if (args.g_bWriteDemoData)
		g_bWriteDemoData = args.g_bWriteDemoData;


	if (flashMode == k_demoMode)
		PADisabled = 1;

	if (args.audioquality)
		audioquality = args.audioquality;
	if (args.country)
		Country = args.country;
/*		
	if (args.dparams)
		DynamicParameters = args.dparams;
*/	
	// new

	//if (args.XPROG)
	//	DynamicParameters = args.XPROG;
	//
	var args2 = getArgs(DynamicParameters, ";");
	if (args2.V)
	{
	}
	if (args2.ID)
		AtomID = args2.ID;
	if (args2.KP)
		Keypress = args2.KP;
	if (args2.S)
		Score = args2.S;
	if (args2.SMP)
		SMP = args2.SMP;
	if (!AssignmentID)
		AssignmentID = 0;	// default for launch from Menu
	if (!ActivityType)
		debug ("ActivityType not defined");	// defined in HTML
	if (!tutorialName)
		debug ("tutorialName not defined");	// defined in HTML
	if (!AtomID)
		AtomID = "";			// Optional, for resume
	if (!Keypress)	
		Keypress = 0;		// Optional, for resume
        if (!Score)
                Score = 0; // not attempted
	if (!SMP)
		SMP = 0;
	if (typeof dynamoSession == "undefined")
		dynamoSession = "";		// empty session ID (for non Dynamo server)
	g_dtStartTime = new Date();
	
	// default for launch from Menu - we do not update the product status
	if (AssignmentID == 0)
		g_iUseLMS = 0;
	
	debug ("Init vars: UserID " + UserID + ", SessionID " + SessionID + 
			", AssignmentID " + AssignmentID +
			", DynamicParameters " + DynamicParameters +
			",ppath " + ppath);
	if(AssignmentID == 0 && g_bTestAssign)
		AssignmentID = 1;

	if (g_bSCORM || g_bCSRTE)
	{
		g_bHideExit = args.bHideExit ? args.bHideExit : 1;
	}
}
function InitVariables()
{

	if(g_bSCORM)
	{
		osker_DoFSCommand("LMSInitialize", "");
	}

}
function InitMenuVariables()
{
	if (LANflag == 1) {	
		var loc2 = unescape (location);
		var iPos = loc2.indexOf ('?');
		if (iPos < 0)
			return;	// no args
		var argString = loc2.substring(iPos+1, loc2.length);
		var theString = unescape (argString);
	}
	else {
		var theString = unescape (location.search.substring(1));
	}
	
	var args = getArgs (theString,"&");
	if (args.USERID)
		UserID = args.USERID;
	if (args.RURL)
		g_sRedirect_URL = args.RURL;
	if (g_sRedirect_URL == "")
		g_iUseLMS = 0;
	if (typeof dynamoSession == "undefined")
		dynamoSession = "";		// empty session ID (for non Dynamo server)
}
function openMenuWin(URL)
{
	var theHeight = InternetExplorer ? screen.availHeight : (screen.height)-taskBarHeight;
	var theWidth = InternetExplorer ? screen.availWidth : screen.width;
	//var windowProperties = "top=0,left=0,resizable=no,height="+theHeight+",width="+theWidth;
	var windowProperties = "top=0,left=0,resizable=yes,menubar=yes,toolbar=yes,status=yes,height=200,width=400";
	var fullURL = URL + dynamoSession + "?USERID=" + UserID;
	var menuWindow=window.open(fullURL, "menuWin", windowProperties);
	menuWindow.focus();
}

function openWin(in_strURL)
{
	g_strDynamoSessionID = "";
	g_iDynamoUserID = UserID;
	openProductWindow(in_strURL, 0);
}

function openProductWindow(in_strURL, in_iAssignmentID)
{
	var theHeight = InternetExplorer ? screen.availHeight : (screen.height)-taskBarHeight;
	var theWidth = InternetExplorer ? screen.availWidth : screen.width;
	var windowProperties = "top=0,left=0,resizable=no,scrollbars=no,height="+theHeight+",width="+theWidth;
	var theURL = in_strURL + g_strDynamoSessionID +"?USERID=" + g_iDynamoUserID + "&ASSIGNID=" + in_iAssignmentID;
	sessionWindow=window.open(theURL, "sessionWin", windowProperties);
	if (MacPlatform && InternetExplorer)
		sessionWindow.resizeTo(theWidth, theHeight);
	sessionWindow.focus();

}

function closeGlossary()
{
	if (glossaryWindow != null && !glossaryWindow.closed)
		glossaryWindow.close();
}
function closeCalculator()
{
	if (calculatorWindow != null && !calculatorWindow.closed)
		calculatorWindow.close();
}
function openGlossary()
{
	var strRelativeCourse = (g_bSCORM || g_bCSRTE) ? "" : relativeCourse;

	var URL = strRelativeCourse + "Glossary.html";
	if (glossaryWindow == null || glossaryWindow.closed)
	{
		var theHeight = InternetExplorer ? screen.availHeight*0.6 : ((screen.height)-taskBarHeight)*0.6;
		var theWidth = 520
		var windowProperties = "top=50,left=30,resizable=no,scrollbars=yes,height="+theHeight+",width="+theWidth;
		glossaryWindow=window.open(URL, "glossaryWin", windowProperties);
		glossaryWindow.focus();
	}
	else 
		glossaryWindow.focus();
}
function openCalculator()
{
	var strRelativeRoot = (g_bSCORM || g_bCSRTE) ? "" : relativeRoot;
	var URL = strRelativeRoot + "Calculator.html";

	if (calculatorWindow == null || calculatorWindow.closed)
	{
		var windowProperties = "top=50,left=50,resizable=no,height=220,width=420";	
		calculatorWindow=window.open(URL, "calculatorWin", windowProperties);
		calculatorWindow.focus();
	}
	else
		calculatorWindow.focus();
}

function openSessionWin(URL)
{
	var theHeight = InternetExplorer ? screen.availHeight : (screen.height)-taskBarHeight;
	var theWidth = InternetExplorer ? screen.availWidth : screen.width;
	var windowProperties = "top=0,left=0,resizable=no,scrollbars=no,height="+theHeight+",width="+theWidth;
	var fullURL = URL + dynamoSession + "?USERID=" + UserID + "&ASSIGNID=" + asgnid + "&XPROG=" + dparams;
	sessionWindow=window.open(fullURL, "sessionWin", windowProperties);
	if (MacPlatform && InternetExplorer)
		sessionWindow.resizeTo(theWidth, theHeight);
	sessionWindow.focus();
}




/***************************** LAN-specific functions ************************/

function updateLANProgress (Actid, bid, rkp, hkp, tkp, s, ns, is, in_bLastUpdate)
{
	// default ppath for testing
	if (ppath == "")
	{
		if(MacPlatform)
			ppath = "/Macintosh HD/temp/ProgressPipeG.dat";
		else
			ppath = "C:/temp/progress.txt";
	}

	// strip quotes if necessary
	if (ppath.charAt (0) == '\'')
		ppath = ppath.substring (1, ppath.length - 1);

	debug ('updateLANProgress path: ' + ppath);
	
	var lanRkp;
	if (in_bLastUpdate)
		lanRkp = eval(rkp);
	else
		lanRkp = -1;

		// Load progress applet / MRJ plugin in hidden frame
		var theLayerObj = InternetExplorer ? progressFrame : document.dummyProgress;
		if (MacPlatform)				// create new applet in hidden frame with all parameters
		{
			if (InternetExplorer)
				var LANProgressPath = relativeRoot+"IE_Mac/ProgressUpdate.html";
			else
				var LANProgressPath = relativeRoot+"Netscape_Mac/ProgressUpdate.html";		
		}
		else
		{
			if (InternetExplorer)
				var LANProgressPath = relativeRoot+"IE/ProgressUpdate.html";
			else
				var LANProgressPath = relativeRoot+"Netscape/ProgressUpdate.html";		
		}
			
		var theQuery = LANProgressPath+"?ppath='"+ppath+"'&Actid="+Actid+"&bid="+bid+"&rkp="+lanRkp+"&hkp="+hkp+"&hkp="+hkp+"&tkp="+tkp+"&s="+s+"&ns="+ns+"&is="+is;	

		var winProperties = "top=5,left=5,height=40,width=200,menubar=no,status,scrollbar=no";
		var updateWindow=window.open(theQuery, "updateWin", winProperties);
		updateWindow.focus();
}




// To refresh window which has opened this window
function topOpen()
{
	if (window.opener)
		window.opener.location.reload(true);
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// NEW SCORM STUFF:

// define global var as handle to API object
var mm_adl_API = null;
// mm_getAPI, which calls findAPI as needed
window.status = 'script 1';
function getAPI(in_win)
{
	var myAPI = null;
	var iScormType = -1; // version of SCORM (-1 = no scorm)
	var tries = 0, triesMax = 500;
  	while (tries < triesMax && myAPI == null)
  	{
		myAPI = findAPI_2(window);
		if(myAPI == null)
		{
			myAPI = findAPI_1(window);
		} 
		else
		{
			iScormType = 2;
		}
   	 	if (myAPI == null && typeof(window.parent) != 'undefined')
		{ 
			myAPI = findAPI_2(window.parent);
			if(myAPI == null)
			{
				myAPI = findAPI_1(window.parent);
			}
			else
			{
				iScormType = 2;
			}
		}
   	 	if (myAPI == null && typeof(window.top) != 'undefined')
		{ 
			myAPI = findAPI_2(window.top);
			if(myAPI == null)
			{
				myAPI = findAPI_1(window.top);
			}
			else
			{
				iScormType = 2;
			}			
		}
   	 	if (myAPI == null && typeof(window.opener) != 'undefined')
		{ 
			if (window.opener != null && !window.opener.closed)
			{ 
				myAPI = findAPI_2(window.opener);
				if(myAPI == null)
				{
					myAPI = findAPI_1(window.opener);
				}
				else
				{
					iScormType = 2;
				}				
			}
		}
    		tries++;
  	}
	g_iScormType = (myAPI && iScormType == -1) ? 1 : iScormType;
	return myAPI;
}
function mm_getAPI()
{
  	var myAPI = null;
  	//var tries = 0, triesMax = 500;
	window.status = 'mm_getAPI()...';
	myAPI = getAPI(window);
	var iRetVal = (typeof g_bSCO == "undefined") ? 0 : g_bSCO;

  	if (myAPI == null)
  	{
    		window.status = 'API not found';
    		//alert('JavaScript Warning: API object not found in window or opener.');
  	}
  	else
  	{
    		mm_adl_API = myAPI;
    		window.status = 'API found, type: ' + g_iScormType;
		iRetVal = 1;
  	}
	return iRetVal;
}
// returns LMS API object (or null if not found)
function findAPI_OLD(win)
{
  // look in this window
  if (typeof(win) != 'undefined' ? typeof(win.API) != 'undefined' : false)
  {
    if (win.API != null )  return win.API;
  }
  // look in this window's frameset kin (except opener)
  if (win.frames.length > 0)  for (var i = 0 ; i < win.frames.length ; i++);
  {
    if (typeof(win.frames[i]) != 'undefined' ? typeof(win.frames[i].API) != 'undefined' : false)
    {
	     if (win.frames[i].API != null)  return win.frames[i].API;
    }
  }
  return null;
}
/*******************************************************************************
**
** Function findAPI(win)
** Inputs:  win - a Window Object
** Return:  If an API object is found, it's returned, otherwise null is returned
**
** Description:
** This function looks for an object named API in parent and opener windows
**
*******************************************************************************/
function findAPI_2(win)
{

   	return win.API_1484_11;
}
function findAPI_1(win)
{

   	return win.API;
}
g_bSCORM = mm_getAPI();
//g_bSCORM = 1;
/*
if(g_bSCORM)
{
	// get the API
	mm_getAPI();
}
*/
var showLmsWarn = true ;
//window.status = 'script 2';
// Handle FSCommand messages from a Flash movie
function osker_DoFSCommand(command, args)  {

  var myArgs = new String( args );
  //var OskerObj = InternetExplorer ? osker : document.osker;
  var OskerObj = (document.osker == null)  ? window.osker : document.osker;

  // all 'LMS' calls handled here
  if (mm_adl_API != null && command.substring(0,3) == "LMS")
  {
    	var err = 1;
    	var sep, arg1, arg2, value;

	if( command == "LMSInitialize" )
	{
		err = g_iScormType == 1 ? mm_adl_API.LMSInitialize("") : mm_adl_API.Initialize( myArgs );
	}
	else if ( command == "LMSSetValue" )
	{
          		sep = myArgs.indexOf(",");
          		arg1 = myArgs.substr(0, sep);
          		arg2 = myArgs.substr(sep+1);
		err = g_iScormType == 1 ? mm_adl_API.LMSSetValue(arg1,arg2) : mm_adl_API.SetValue(arg1,arg2);
		//err = eval('mm_adl_API.SetValue(\"' + arg1 + '\",\"'+arg2+'\")');

        	}
	else if ( command == "LMSFinish" )
	{
		err = g_iScormType == 1 ? mm_adl_API.LMSFinish("") : mm_adl_API.Terminate(args);
	}
	else if ( command == "LMSCommit" )
	{
		err = g_iScormType == 1 ? mm_adl_API.LMSCommit(args) : mm_adl_API.Commit(args);
	}
	else if ( command == "LMSFlush" )
	{
		err = g_iScormType == 1 ? mm_adl_API.LMSFlush(args) : mm_adl_API.Flush(args);
	}
	else if ( command == "LMSGetValue" )
	{
         		 // for LMSGetValue,LMSGetLastError,LMSGetErrorString,LMSGetDiagnostic, or ??
         		sep = myArgs.indexOf(",");
         		arg1 = myArgs.substr(0, sep);
         		arg2 = myArgs.substr(sep+1);
		value = g_iScormType == 1 ? mm_adl_API.LMSGetValue(arg1) : mm_adl_API.GetValue(arg1);
         		//value = eval('mm_adl_API.GetValue(\"' + arg1 + '\")');
		var errCode = g_iScormType == 1 ? mm_adl_API.LMSGetLastError().toString() : mm_adl_API.GetLastError().toString();
      		//var errCode = mm_adl_API.GetLastError().toString();


         		if (sep != 0 && arg2 != "")  OskerObj.SetVariable(arg2,value);
         		else err = "-2: No Flash variable specified";
	}
	else
	{
          		// for LMSGetValue,LMSGetLastError,LMSGetErrorString,LMSGetDiagnostic, or ??
         		sep = myArgs.indexOf(",");
         		arg1 = myArgs.substr(0, sep);
         		arg2 = myArgs.substr(sep+1);
         		value = eval('mm_adl_API.' + command + '(\"' + arg1 + '\")');
         		if (sep != 0 && arg2 != "")  OskerObj.SetVariable(arg2,value);
         		else err = "-2: No Flash variable specified";
	}

   	 // handle LMS error returns
    	if ((err == 0 || err == "false") && showLmsWarn)  {
      		if (! confirm('LMS API adapter returns error code: ' + err + '\rWhen calling API.' + command + 'with ' + args + '\r\rSelect cancel to disable future warnings'))  showLmsWarn = false;
    	}
  } // end of 'LMS' handling if
  // put code to handle non-LMS FSCommands below
  if(command == "sendDebug" && g_bWriteDemoData)
  {
	document.debugSWF.SetVariable("szDebug",args)
	document.debugSWF.TCallLabel("/","writeData");
		
  }

}
/***************************** Script for Flash commands on IE ************************/

if (navigator.appName && InternetExplorer && 
	  navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	
	document.write('<SCRIPT LANGUAGE=VBScript\> \n');
	document.write('on error resume next \n');
	document.write('Sub osker_FSCommand(ByVal command, ByVal args)\n');
	document.write('  call osker_DoFSCommand(command, args)\n');
	document.write('end sub\n');
	document.write('</SCRIPT\> \n');
}



