var jsVersion = "1.4";	// 21th Aug, 2002
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 g_iTestCM = 0; // CM for testing questions?
var flashDebug = 0;
var repeatMode = 0; // do we repeat the kp once (for demo mode)
var testIncorrect = 0; // test incorrect (for demo mode)
var skipPA = 0; // skip practice (for demo mode at present)
var k_demoMode = 1;
var k_runMode = 2;
var flashMode = k_runMode; // 1 demo, 2 run
var g_bClearLog = 0; // clear the error log (set in initVars)
var g_bPauseReturn = 1; // pause on return from tools e.t.c.


var b_GotoPreview = 0; // preview for goto
var audioquality = 1; // default audio quality (2 = higher)
var macIEOff = 0; // disable IE on mac?
var dynParVersion = 1;
var g_bUseTestOptions = 1; // read teacher options from file (options.txt in CM folder)


// LMS ////////////


var g_iUseLMS = 0;	// flag of existence LMS
//var g_sLMSAPI_URL = "http://"+location.host+"/lms/LMSAPI.jhtml";
var g_TestProg_URL = "http://dmxserver/cgi-bin/CGIParse.exe";

///////////////////////////////// plug-in version detection /////////////////////////////////////////

var g_iFlashVersionRequired = 6;

var downLoadPromptPage = "download.html";	// send user to Macromedia

var g_bReqFlashInstalled = false; // is at least the required version installed?

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_bReqFlashInstalled boolean for IE/PC
	// if plug-in installed is at least the version required, then g_bReqFlashInstalled will be set to true
	document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
	document.write('on error resume next \n');
	document.write('g_bReqFlashInstalled = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.');
	document.write(g_iFlashVersionRequired);
	document.write('")) \n');
	document.write('</SCR' + 'IPT\> \n'); // break up end tag so it doesn't end our script
}


function detectFlash()
{
	// for NS and IE/Mac
	// use javascript detection using navigator.plugins array
	//alert("niit"+navigator.plugins);
	if(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 majorVersion = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));
		var majorVersion=parseInt(flashDescription.substr(16,(flashDescription.indexOf(".")-16)));		
		g_bReqFlashInstalled = (majorVersion >= g_iFlashVersionRequired);
		//
		//alert();
		//
		//alert(g_bReqFlashInstalled);
		//alert("majorversion: "+majorVersion+", req installed: "+g_bReqFlashInstalled);
	}
	if (! g_bReqFlashInstalled){
		DownLoadPrompt();
	}
}

function DownLoadPrompt(){
	//alert("nitin");
	//window.location = downLoadPromptPage;
}

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;
var SE = 0; // not student edition
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;
//=============================

// for PA testing:
var PADisabled = 0;
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 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 manipWindow = null;
var folderCount = 3; // num folders to root
var k_loadDelay = 180; // timeout
var KPReadAhead = (InternetExplorer && ! MacPlatform) ? 9 : 1; //1;

//var KPReadAhead = 1;
var callbackKP = 1;
var PAInLayer = 0; // PA in layer/window for IE
var startTime = 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 TOTLimit = 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;

var UserID = 0;
var Score = 4;  // score from dynamic pars
var g_iPcmpt = 0;    // percent done from dynamic pars
var asgnid = 0;
var prod = "d1";
var ppath = "";
var NumQuestions = 5; // default for unit practice


function generateLayers()
{

}
function positionExplore()
{
}
function focusExplore()
{
}

function closeExploreWin()
{
}

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 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 EncodeChars(in_str)
{
// not ideal! what we really want is to urlencode the string
// encoding "/" and space here
	var objString = new String(in_str);
	var strReturn = "";
	var iLength = objString.length;
	while (iLength >= 0)
	{
		if(objString.substr(iLength,1) == " ")
		{
			strReturn = "%20" + strReturn;
		}
		else if(objString.substr(iLength,1) == "/")
		{
			strReturn = "%2F" + strReturn;
		}
		else
			strReturn = objString.substr(iLength,1) + strReturn;
		iLength--;
	}

	return strReturn;
}

function updateProgress()
{
	//closeGlossary();
	//closeCalculator();
	closeSWF();

   // To refresh opening page (for LMS pages)
   if (g_iUseLMS)
		topOpen();
}
function getWOPerc(highestKP,totalKPs)
{
	var iPcmpt = 0;

	if (highestKP > 0)
		iPcmpt = Math.round((highestKP/totalKPs)*100);

	if (iPcmpt < g_iPcmpt)
	{
		iPcmpt = g_iPcmpt;
	}
	else
	{
		g_iPcmpt = iPcmpt;
	}
	return iPcmpt;
}
function getDynPars(theType,atomID,resumeKP,highestKP,totalKPs,theScore,theAtt)
{
	var dParamObj = "";
	var iPcmpt = 0;
	dParamObj = dParamObj+"prod="+prod+";ID="+atomID+";KP="+resumeKP;
	if (theType == "W")
	{
		iPcmpt = getWOPerc(highestKP,totalKPs);

		dParamObj = 	dParamObj+";S="+theScore+";att="+theAtt+";pcmpt="+iPcmpt;
	}
	return dParamObj;
}
function loadNextSession(URL)
{
	progressUpdate = 0; // don't want progress to update onUnload

	var strURL = "lesson.html?" + URL;

	if(flashMode == 1) // demo mode
	{
		strURL = strURL + "&flashMode=1";
		if(repeatMode == 1)
			strURL = strURL + "&kprepeat=1";
		if(testIncorrect == 1)
			strURL = strURL + "&testIncorrect=1";
		if(skipPA == 1)
			strURL = strURL + "&skipPA=1";
	}


	//alert("URL: "+strURL);

	if (!InternetExplorer)
	{
		var thePath = self.location;
		self.location.href = getSession(thePath) + strURL;
	}
	else
		self.location.href = strURL;
}
function sendInfo(type, bid, rkp, hkp, tkp, ns, is, s, att, lastUpdate, goNextSession, sessionNumber, openPar)
{ // last three vars for PA if reqd. (can't issue two GETURL at same level)
	doProgress(type, bid, rkp, hkp, tkp, ns, is, s, att, lastUpdate, goNextSession);
}


// to use with new LMSAPI functionality
//=====================================
function processInfo(lastUpdate, goNextSession)
{

	if (goNextSession)
	{
		//alert("URL: "+goNextSession);
		loadNextSession(goNextSession);
	}
	else if (lastUpdate)
	{

		closeAllWindows();

	}
}
function closeAllWindows()
{
	//closeGlossary();
	//closeCalculator();
	//closeManip();
	//closeWindow();
	if (! MacPlatform || ! InternetExplorer)
		closeWindow();
}

function doProgress(type,bid,rkp,hkp,tkp,ns,is,s,att,lastUpdate,goNextSession)
{ // need lastUpdate for netscape (can't update then close).
// goNextSession 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,att);
	var postString = "";
	var progURL = "";
	if (! InternetExplorer)
		closeExploreWin();

	if (progressUpdate)
	{
		TOT = Math.round(getTOT());
		if (TOT < 1)
			TOT = 1 // always show some TOT
		else if (TOT > TOTLimit)
			TOT = TOTLimit;
		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")
			{
				Pcmpt = getWOPerc(hkp,tkp);

			}
			else // screen/summary:
				Pcmpt = Math.round((hkp/tkp)*100);
		}
		if (LANflag == 1)
		{

			updateLANProgress (Actid, bid, rkp, hkp, tkp, s, ns, is, lastUpdate);
		}
		else
		{
			//var progURL = g_sLMSAPI_URL+"?ACTIONTYPE="+putProductStatus+"&USERID="+UserID+"&ASSIGNID="+AssignmentID+"&ACTID="+Actid+"&TOT="+TOT+"&PERCDONE="+Pcmpt+"&XPROG="+dynPars;

			if (progressTest)
			{ // for testing
				progURL = g_TestProg_URL+"?ACTIONTYPE="+putProductStatus+"&USERID="+UserID+"&ASSIGNID="+AssignmentID+"&ACTID="+Actid+"&TOT="+TOT+"&PERCDONE="+Pcmpt+"&XPROG="+dynPars;
				var winProperties = "top=50,left=50,height=400,width=800,menubar=no,status,scrollbar=yes";
				var updateWindow=window.open(progURL, "updateWin", winProperties);
				updateWindow.focus();
			}
			else
			{
				//progURL = g_sLMSAPI_URL+"?ACTIONTYPE="+putProductStatus+"&USERID="+UserID+"&ASSIGNID="+AssignmentID+"&ACTID="+Actid+"&TOT="+TOT+"&PERCDONE="+Pcmpt+"&XPROG="+dynPars;
				sendProgress(progURL);
			}
		}
	}
	if (goNextSession)
	{
		loadNextSession(goNextSession);
	}
	else if (lastUpdate)
	{
		closeGlossary();
		closeCalculator();
		closeSWF();
		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();
	var iNumFolders = folderCount;

	if (ActivityType == "U")
		iNumFolders--;
	while (theLength > 0 && folderIndex < iNumFolders)
	{
		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;

		}
	}
	else
		layerObj.src = URL;
}
function sendProgress(ProgressPath)
{
	var theLayerObj = InternetExplorer ? progressFrame : document.dummyProgress;
	loadLayer(ProgressPath, theLayerObj);
}

function showError(theName)
{
	alert(theName);
	closeWindow();
}


function sendToLoad(theIndex, subIndex, in_strSessionKPRefs)
{

	var theKP = parseInt(theIndex);
	var theSubIndex = parseInt(subIndex);
// increment kpindex here for now:
	//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 SessionsString = "";
			var strPath = (ActivityType == "U") ? relativeRoot.substring(0, relativeRoot.length - 3) : relativeRoot;
			var fullString = strPath + "stream.html?macIE=1";

			if (typeof arSessions != "undefined")
			{

				for (iz = 0; iz < arSessions.length; iz++)
				{

					SessionsString = SessionsString + "&Session"+ (iz + 1) + "=" + arSessions[iz];
				}
				fullString = fullString + "&NumSessions="+arSessions.length+SessionsString+"&unitKPRefs="+in_strSessionKPRefs+"&unitPath="+SessionPath + "/";

			}



			fullString = fullString + "&varFile=" + SessionPath + "/" + varFile + "&k_loadDelay=" + k_loadDelay + "&KPReadAhead=" + KPReadAhead + "&callbackKP=" + callbackKP + "&currentKPIndex=" + theKP + "&iSubMovieIndex=" + theSubIndex + "&SessionPath="+SessionPath + "/&parsePAString="+parsePAString+"&ActivityType="+ActivityType+"&TutorialName="+SessionPath + "/" + tutorialName;


			document.streamFrame.location.href = fullString;
		}
	}
	else
	{
		document.loadKPs6.TGotoLabel("/","begin");
		document.loadKPs6.SetVariable("currentKPIndex",theKP);
		document.loadKPs6.SetVariable("iSubMovieIndex",theSubIndex);
		document.loadKPs6.Play();
	}
}
function GetNumFolders(in_strPath)
{
	var ix = 0;
	var iNumFolders = 0;

	if(in_strPath.length > 1)
	{
		while (ix < in_strPath.length)
		{
			while (in_strPath.substr(ix,1) == "." && ix < in_strPath.length)
			{
				ix++;
			}
			iNumFolders++;
			ix++;
		}
	}

	return iNumFolders;
}
function GenerateHTML (flashPath) {// Create Main HTML
	var iz = 1; // counter for sessions in unit practice
	var sessionName = "";

	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=6,0,0,0"');
	document.write(' ID=oskerPlayback4 WIDTH=100% HEIGHT=98%>\n');

	document.write(' <PARAM NAME=movie VALUE="' + flashPath + '/holtLCM.swf"> <PARAM NAME=FlashVars VALUE="macIE=0');
/*
	if (MacPlatform && InternetExplorer)
		document.write(1)
	else
		document.write(0);
*/
	document.write('&AssignmentID=');
	document.write(AssignmentID);
	document.write('&debug=');
	if (g_iTestCM)
		document.write(1)
	else
		document.write(flashDebug);
	document.write('&repeatMode=');
	document.write(repeatMode);
	document.write('&theMode=');
	document.write(flashMode);
	document.write('&g_bClearLog=');
	document.write(g_bClearLog);
	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('&testIncorrect=');
	document.write(testIncorrect);
	document.write('&skipPA=');
	document.write(skipPA);
	document.write('&TestQuestions=');
	document.write(g_iTestCM);
	document.write('&g_bUseTestOptions=');
	document.write(g_bUseTestOptions);

	document.write('&g_bPauseReturn=');
	document.write(g_bPauseReturn);

	document.write('&NumFoldersToRoot=');
	document.write(GetNumFolders(flashPath));
	document.write('&NumQuestions=');
	document.write(NumQuestions);

	if (typeof arSessions != "undefined")
	{

		for (iz = 0; iz < arSessions.length; iz++)
		{

			document.write('&Session'+(iz+1)+'=');

			document.write(arSessions[iz]);
		}

	}
	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('&SE=');
	document.write(SE);
	document.write('&FlashVersionRequired=');
	document.write(g_iFlashVersionRequired);
	document.write("&calc=");
	document.write(calc);
	document.write("&actCourse=");
	document.write(actCourse);

	document.write('"><PARAM NAME=loop VALUE=false><PARAM NAME=menu VALUE=false>\n');
	//MARK DAVE
	//document.write(' <PARAM NAME=quality VALUE=high><PARAM NAME=bgcolor VALUE=#000000><PARAM NAME=scale VALUE=exactfit>\n');
	document.write(' <PARAM NAME=quality VALUE=high><PARAM NAME=bgcolor VALUE=#000000>\n');
	document.write(' <EMBED src="'+flashPath+'/holtLCM.swf"  FlashVars="macIE=0');
/*
	if (MacPlatform && InternetExplorer)
		document.write(1)
	else
		document.write(0);
*/
	document.write('&AssignmentID=');
	document.write(AssignmentID);
	document.write('&debug=');
	if (g_iTestCM)
		document.write(1)
	else
		document.write(flashDebug);
	document.write('&repeatMode=');
	document.write(repeatMode);
	document.write('&theMode=');
	document.write(flashMode);
	document.write('&g_bClearLog=');
	document.write(g_bClearLog);
	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('&testIncorrect=');
	document.write(testIncorrect);
	document.write('&skipPA=');
	document.write(skipPA);
	document.write('&TestQuestions=');
	document.write(g_iTestCM);
	document.write('&g_bUseTestOptions=');
	document.write(g_bUseTestOptions);
	document.write('&g_bPauseReturn=');
	document.write(g_bPauseReturn);
	document.write('&NumFoldersToRoot=');
	document.write(GetNumFolders(flashPath));
	document.write('&NumQuestions=');
	document.write(NumQuestions);
	if (typeof arSessions != "undefined")
	{

		for (iz = 0; iz < arSessions.length; iz++)
		{

			document.write('&Session'+(iz+1)+'=');

			document.write(arSessions[iz]);
		}

	}
	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('&SE=');
	document.write(SE);
	document.write('&FlashVersionRequired=');
	document.write(g_iFlashVersionRequired);
	document.write("&calc=");
	document.write(calc);
	document.write("&actCourse=");
	document.write(actCourse);

//MARK DAVE
	//document.write('" loop=false menu=false quality=high scale=exactfit bgcolor=#000000  WIDTH=100% HEIGHT=98% swLiveConnect=true');
	document.write('" loop=false menu=false quality=high bgcolor=#000000  WIDTH=100% HEIGHT=98% swLiveConnect=true');
	document.write(' NAME=oskerPlayback4 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');



}
/////////////////// 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);
			//alert( argname + " " + args[argname] )
			// document.writeln ("args " + argname + " " + args[argname]);
		}
	}
	return args;
}
function getTOT()
{
	var stopTime = new Date();
	var diff = (stopTime.getTime() - startTime.getTime())/(1000*60);
	startTime = new Date();
	return diff;
}
function initVars()
{
	if (macIEOff && MacPlatform && InternetExplorer)
	{
		showError("IE on Macintosh not supported at present");
	}
	openDebugWnd();



	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 (UserID == 0  && (typeof DynamoUserid != "undefined"))
		UserID = DynamoUserid;
	if (args.ASSIGNID)
		AssignmentID = args.ASSIGNID;
	if (args.ppath)
		ppath = args.ppath;
	if (args.flashMode)
		flashMode = args.flashMode;
	if (args.bClearLog)
		g_bClearLog = args.bClearLog;
	if (args.kprepeat)
		repeatMode = args.kprepeat;
	if (args.testIncorrect)
		testIncorrect = args.testIncorrect;
	if (args.skipPA)
		skipPA = args.skipPA;
	if (args.audioquality)
		audioquality = args.audioquality;
	if (args.country)
		Country = args.country;
	if (args.numquestions)
		NumQuestions = args.numquestions;
	if (args.SE)
		edition = SE = args.SE;
	if (args.GRADE)
		g_iGrade = args.GRADE;
	if (args.calc)
		calc = args.calc;
	if (args.state)
		state = args.state;
	else
		state = "xx"
	if (args.actCourse)
		actCourse = args.actCourse;
	else {
		actCourse = 0;
	}

	if (args.CSID) {
		CSID = args.CSID;
	} else {
		CSID = "";
	}
	if (args.USERID) {
		USERID = args.USERID;
	} else {
		USERID = "";
	}
	if (args.ACTID) {
		ACTID = args.ACTID;
	} else {
		ACTID = "";
	}
	if( args.g_sLMSAPI_URL ) {
		g_sLMSAPI_URL = args.g_sLMSAPI_URL;
	} else {
		g_sLMSAPI_URL = "";
	}
	if (!AssignmentID)
		AssignmentID = 0;	// default for launch from Menu
	if (!ActivityType)
		debug ("ActivityType not defined");	// in HTML
	if (!tutorialName)
		debug ("tutorialName not defined");	// in html
	if (!AtomID)
		AtomID = "";			// Optional, for resume
	if (!Keypress)
		Keypress = 0;		// Optional, for resume
        if (!Score)
                Score = 0; // not attempted
	if (!g_iPcmpt)
		g_iPcmpt = 0;
	if (typeof dynamoSession == "undefined")
		dynamoSession = "";		// empty session ID (for non Dynamo server)

	// default for launch from Menu - we do not update the product status
	if (AssignmentID == 0)
		g_iUseLMS = 0;

	startTime = new Date();

}
function InitVariables()
{
}
function InitMenuVariables()
{
	var args = getArgs();
	if (args.userid)
		UserID = args.userid;
	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 fullURL = URL + dynamoSession + "?USERID=" + UserID;
var menuWindow=window.open(fullURL, "menuWin", windowProperties);
menuWindow.focus();
}
function closeGlossary()
{
	if (glossaryWindow != null && !glossaryWindow.closed)
		glossaryWindow.close();
}
function closePlanner()
{
	if (plannerWindow != null && !plannerWindow.closed)
		plannerWindow.close();
}
function closeSWF()
{
	if (manipWindow != null && !manipWindow.closed)
		manipWindow.close();
}
function closeCalculator()
{
	if (calculatorWindow != null && !calculatorWindow.closed)
		calculatorWindow.close();
}

function openPlanner()
{
	var strPath = (ActivityType == "U") ? relativeCourse.substring(0, relativeCourse.length - 3) : relativeCourse;


	var URL = strPath + "holt_planner/holt_planner.html";

	if (plannerWindow == null || plannerWindow.closed)
	{
		//alert("open glossary");
		var theHeight = InternetExplorer ? (screen.availHeight)*0.6 : (((screen.height)-taskBarHeight))*0.6;
		var theWidth = 520
		var windowProperties = "top=50,left=30,resizable=yes,scrollbars=yes,height="+theHeight+",width="+theWidth;
		plannerWindow=window.open(URL, "plannerWin", windowProperties);
		plannerWindow.focus();
	}
	else
		plannerWindow.focus();

}

function openGlossaryTerm(I_glossaryTerm, I_GradeNum)
{
	var URL = "manipulatives/Glossary/Glossary.html?sz_term="+I_glossaryTerm;

	//if (glossaryWindow == null || glossaryWindow.closed)
	//{
		var theHeight = InternetExplorer ? (screen.availHeight)*0.8 : (((screen.height)-taskBarHeight))*0.8;
		var theWidth = InternetExplorer ? (screen.availWidth)*0.8 : (screen.width)*0.8;
		var windowProperties = "top=0,left=0,toolbar=no,status=no,resizable=no,scrollbars=no,height="+theHeight+",width="+theWidth;
		glossaryWindow=window.open(URL, "glossaryWin", windowProperties);
		glossaryWindow.focus();
	//}
	//else
	//glossaryWindow.focus();

}

function openCalculator()
{

}

function openSWF(in_strURL, in_strWinName)
{
	var szParList = "swf="+in_strURL+"&title="+in_strWinName;
	//var szParList = "swf="+in_strURL+"&title="+in_strWinName+"&var1="+var1+"&var2="+var2;
	openManipulative(szParList)
}

function openManipulative(in_szParList)
{
// in_szParList is list of pars (including (optionally) swf
// (path relative to manip.html), title, bgcolour, var1..n)

// NOTE: function opens "manipWindow", could be modified
// to accept window as par

	g_szParList = in_szParList; // needs to be global cos MacPlatform browsers
					// can't close then immediately open a window
					// so use setTimeout and check status (setTimeout
					// function can't accept parameters). The check
					// window status also can't be done in same block
					// of code (i.e. can't wait till closed then open)

        if (NewManipLocation(manipWindow, in_szParList))
	{
		CloseWin(manipWindow);
		setTimeout("ShowManip()",100);
	}
	else
		manipWindow.focus();


}

function ShowManip()
{
   	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";
    	var args = getArgs(g_szParList, "&");
    	var strPath = (ActivityType == "U") ? relativeRoot.substring(0, relativeRoot.length - 3) : relativeRoot;
    	var URL = EncodeChars(strPath + "manip.html?" + g_szParList);


    	if(args.height)
       		theHeight = args.height;
    	if(args.width)
       		theWidth = args.width;
    	windowProperties = windowProperties+",height="+theHeight+",width="+theWidth;


	while(manipWindow != null && ! manipWindow.closed); // loop till closed

	//alert(URL);

	manipWindow = window.open(URL, "manipWin", windowProperties);

	if (MacPlatform && InternetExplorer)
		manipWindow.resizeTo(theWidth, theHeight);
	manipWindow.focus();

}

function NewManipLocation(in_objWin, in_szParList)
{
       return (in_objWin == null || in_objWin.closed || GetParList(in_objWin) != in_szParList);
}

function GetParList(in_objWin)
{
	var szLocation = new String(in_objWin.location);
        var szReturn = new String();
        var ix = szLocation.length;
        while (ix > 0 && szLocation.substr(ix - 1, 1) != '?')
        {
                szReturn = szLocation.substr(ix - 1, 1) + szReturn;
                ix--;
        }

        if (ix > 0)
             return szReturn
        else
             return "";
}

function CloseWin(in_objWin)
{
	if (in_objWin != null && ! in_objWin.closed)
		in_objWin.close();

}


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=yes,scrollbars=yes,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();
}


/***************************** LAN-specific functions ************************/

function updateLANProgress (Actid, bid, rkp, hkp, tkp, s, ns, is, lastUpdate)
{
	// 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);



	var lanRkp;
	if (lastUpdate)
		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);
}

function loadCSC( sz_chapter, sz_type, sz_typeNum, sz_audio)		//chapter specific content folder
{

	var tmpCourse = course.substring( 1, 2 )

	if( actCourse == 4 ) {
		tmpCourse = 4;
	}

	var URL;

	if( sz_typeNum == "") {
		self.location.href = "chapter.html?sz_edition="+SE+"&sz_course="+tmpCourse+"&sz_chapter="+sz_chapter+"&sz_type="+sz_type+"&sz_audio="+sz_audio+"&calc="+calc+"&state="+state;
	} else {

		self.location.href = "chapter.html?sz_edition="+SE+"&sz_course="+tmpCourse+"&sz_chapter="+sz_chapter+"&sz_type="+sz_type+"&sz_typeNum="+sz_typeNum+"&sz_audio="+sz_audio+"&calc="+calc+"&state="+state;
	}

	//alert( "URL " + URL )
	/*
	if (ChapCMWindow == null || ChapCMWindow.closed) {
		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;

		ChapCMWindow=window.open(URL, "ChapCMWindow", windowProperties);
		ChapCMWindow.focus();
	} else
		ChapCMWindow.focus();
		*/

}

function goBack( sz_chapter, sz_audio) {
	var tmpCourse = course.substring( 1, 2 )

	if( actCourse == 4 ) {
		tmpCourse = 4;
	}

	self.location.href = "ls.html?edition="+SE+"&course="+tmpCourse+"&chapter="+sz_chapter+"&sz_audio="+sz_audio+"&calc="+calc;
}
