//
// rte launch.html support functions
//



// ie eolas workaround
function writeRTE() {
// function writes out the RTE object reference

  	var temp =
		"	<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000'  "
		+ "	        codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,24,0'  "
		+ "	        id='rteObject'  "
		+ "	        width='100%' "//MSJ changed 100% to 1000
		+ "			height='100%' > "//MSJ changed 100% to 600
		+ "	    <param name='movie' value='myShell.swf' > "
		+ "	    <param name='loop' value='false' > "
		+ "	    <param name='quality' value='best' > "
		+ "	    <param name='bgcolor' value='#E9E7E2' > "//MSJ changed #FFFFFF to #8998B4
		+ "	    <param name='salign' value='' > "
		+ "	    <param name='scale' value='noscale' > "//MSJ was showall
		+ "	    <param name='AllowScriptAccess' value='always' > "
		+ "	    <embed src='myShell.swf'  "
		+ "	    	   id='rteEmbed'  "
		+ "	    	   width='100%'  "//MSJ changed 100% to 1000
		+ "	    	   height='100%'  "//MSJ changed 100% to 600
		+ "	    	   type='application/x-shockwave-flash'  "
		+ "	    	   pluginspage='http://www.macromedia.com/go/getflashplayer'  "
		+ "	    	   loop='false'  "
		+ "	    	   quality='best'  "
		+ "	    	   bgcolor='#E9E7E2'  "//MSJ changed #FFFFFF to #8998B4 (med blue) or #3E4754 (interface dark blue) or #505663 (interface med blue) or #E9E7E2 (interface lt gray) or #C5C0B7 (interface med gray/tan)
		+ "	    	   salign=''  " //MSJ possible values = l, t, r, b, tl, tr, bl, br (or '' which = center,center)
		+ "	    	   scale='noscale'  "//MSJ was noscale; noscale = keep swf at its native size & center in viewer if w100%h100%| showall = fit into viewer (usually results in vert or horiz bars | exactfit = fill viewer 100% both ways (no bars, but distorted) | noborder = opposite of showall (fit into viewer, but cut off the equivalent of horiz or vert bars)
		+ "	    	   allowScriptAccess='always' >"
		+ "	</object>";
		
		document.writeln(temp);
}



function getRTE() {

  if (document.getElementById("rteEmbed") != null) {
      return document.getElementById("rteEmbed");
  } else {
    return document.getElementById("rteObject");
  }
}
  

// window events
//
function onKeyDown(e) {
// suppress selected keys

	if (e == null) e = window.event;

	switch (e.keyCode) {
		case 112: // F1 (help - use "onHelp" with IE)
		case 114: // F3 (search)
		case 116: // F5 (refresh)
			e.keyCode = 0;
			e.returnValue = 0;
			break;
	}
}

function onHelp() {
// cancel IE's built-in help
	window.event.returnValue = 0;
}

function onBeforeUnload() {
// store the cmi data, close the api adapter

	var rte = getRTE(); 
	var lessonStatus = rte.GetVariable("command.lessonStatus");
	
	switch(lessonStatus) {
		case "incomplete":
		case "complete":
			doLMSSetValue("cmi.core.lesson_status",lessonStatus);
			break;
		case "passed":
		case "failed":
			doLMSSetValue("cmi.core.lesson_status",lessonStatus);
			doLMSSetValue("cmi.core.score.min",rte.GetVariable("command.scoreMin"));
			doLMSSetValue("cmi.core.score.max",rte.GetVariable("command.scoreMax"));
			doLMSSetValue("cmi.core.score.raw",rte.GetVariable("command.scoreRaw"));
			break;
	}		
	doLMSSetValue("cmi.core.location",rte.GetVariable("command.location"));
	
	doLMSCommit();
	doLMSFinish();
}



//
// rte callbacks (using the actionscript External API)
//
//
function onShellReady() {
// start loading the lesson

	var rte = getRTE();

	rte.SetVariable("command.lessonXMLFile","./data/lesson.xml");
	rte.SetVariable("command.mediaPath","./media/");
	rte.SetVariable("command.debugMode","false");
	rte.SetVariable("command.action","loadLesson");
}

function onLessonStatusRequest() {
	return doLMSGetValue("cmi.core.lesson_status");
}

function onLocationRequest() {
	return doLMSGetValue("cmi.core.location");
}




