/*
 *	kmiPlatformSpecific.js
 *	Build 3.2.0.27
 *	Copyright 1999-2003 Accenture
 *	File Size: 16149
 *	(KMI Implementation)
 */

function ccData_constructor()
{
	this.get = ccData_ItemGetValue;
	this.set = ccData_ItemSetValue;
	this.clear = ccData_ItemClearValue;
	this.SetPackageUser = ccData_PackageUserSet;
	this.GetPackageUser = ccData_PackageUserGet;
	this.ClearPackageUser = ccData_PackageUserClear;
	this.ClearElement = ccData_ElementClear;
	this.SetElement = ccData_ElementSet;
	this.GetElement = ccData_ElementGet;
	this.GetStorageName = ccData_GetStorageName;
	this.getErrorCode = ccData_ErrorCodeGet;
	this.getErrorDescription = ccData_ErrorDescriptionGet;
	this.getErrorMethod = ccData_ErrorMethodGet;
	this.getItem = ccData_ItemGetExplicit;
	this.setItem = ccData_ItemSetExplicit;
	this.clearItem = ccData_ItemClearValueExplicit;
	this.clearNode = ccData_ItemClearNodeExplicit;
	this.getUsers = ccData_GetDefinedUsers;
	this.aValues = new Array();
	this.sUserId = "";
	return this;
}
function ccData_ElementClear(sModule, sPage, sItem, sItemKey)
{
	return true;
}
function ccData_GetStorageName()
{
	return "";
}
function ccData_ElementGet(sModule, sPage, sItem, sItemKey)
{
	return "";
}
function ccData_ElementSet(sXML, sModule, sPage, sItem, sItemKey)
{
	return true;
}
function ccData_ErrorCodeGet()
{
	return 0;
}
function ccData_ErrorDescriptionGet()
{
	return "";
}
function ccData_ErrorMethodGet()
{
	return "";
}
function ccData_ItemClearValue(sItem, sItemKey, sPackageGlobalKey)
{
	var sPageKey = private_GetPageID();
	var sModuleKey = sModuleID;

	switch (arguments.length)
	{
		case 2:
		{
			if (this.aValues[sModuleKey] == null)
			{	this.aValues[sModuleKey] = new Array();	}
			if (this.aValues[sModuleKey][sPageKey] == null)
			{	this.aValues[sModuleKey][sPageKey] = new Array();	}
			if (this.aValues[sModuleKey][sPageKey][sItem] == null)
			{	this.aValues[sModuleKey][sPageKey][sItem] = new Array();	}
			this.aValues[sModuleKey][sPageKey][sItem][sItemKey] = "";
			break;
		}
		case 3:
		{
			if (this.aValues[sModuleKey] == null)
			{	this.aValues[sModuleKey] = new Array();	}
			if (this.aValues[sModuleKey][sPackageGlobalKey] == null)
			{	this.aValues[sModuleKey][sPackageGlobalKey] = new Array();	}
			if (this.aValues[sModuleKey][sPackageGlobalKey][sItem] == null)
			{	this.aValues[sModuleKey][sPackageGlobalKey][sItem] = new Array();	}
			this.aValues[sModuleKey][sPackageGlobalKey][sItem][sItemKey] = "";
			break;
		}
		default:
		{
			alert('Internal logic error in ccData_ItemClearValue, unexpected number of parameters: ' + arguments.length);
			return false;
		}
	}
	return true;
}
function ccData_ItemGetValue(sItem, sItemKey, sPackageGlobalKey)
{
	var sPageKey = private_GetPageID();
	var sModuleKey = sModuleID;
	switch (arguments.length)
	{
		case 2:
		{
			if (this.aValues[sModuleKey] == null)
			{	return "";	}
			else if (this.aValues[sModuleKey][sPageKey] == null)
			{	return "";	}
			else if (this.aValues[sModuleKey][sPageKey][sItem] == null)
			{	return "";	}
			else if (this.aValues[sModuleKey][sPageKey][sItem][sItemKey] == null)
			{	return "";	}
			else
			{	return this.aValues[sModuleKey][sPageKey][sItem][sItemKey];	}
			break;
		}
		case 3:
		{
			if (this.aValues[sModuleKey] == null)
			{	return "";	}
			else if (this.aValues[sModuleKey][sPackageGlobalKey] == null)
			{	return "";	}
			else if (this.aValues[sModuleKey][sPackageGlobalKey][sItem] == null)
			{	return "";	}
			else if (this.aValues[sModuleKey][sPackageGlobalKey][sItem][sItemKey] == null)
			{	return "";	}
			else
			{	return this.aValues[sModuleKey][sPackageGlobalKey][sItem][sItemKey];	}
			break;
		}
		default:
		{
			alert('Internal logic error in ccData_ItemGetValue, unexpected number of parameters: ' + arguments.length);
			return "";
		}
	}
}
function ccData_ItemSetValue(sItem, sItemKey, sItemValue, sPackageGlobalKey)
{
	var sPageKey = private_GetPageID();
	var sModuleKey = sModuleID;

	switch (arguments.length)
	{
		case 3:
		{
			if (this.aValues[sModuleKey] == null)
			{	this.aValues[sModuleKey] = new Array();	}
			if (this.aValues[sModuleKey][sPageKey] == null)
			{	this.aValues[sModuleKey][sPageKey] = new Array();	}
			if (this.aValues[sModuleKey][sPageKey][sItem] == null)
			{	this.aValues[sModuleKey][sPageKey][sItem] = new Array();	}
			this.aValues[sModuleKey][sPageKey][sItem][sItemKey] = sItemValue;
			break;
		}
		case 4:
		{
			if (this.aValues[sModuleKey] == null)
			{	this.aValues[sModuleKey] = new Array();	}
			if (this.aValues[sModuleKey][sPackageGlobalKey] == null)
			{	this.aValues[sModuleKey][sPackageGlobalKey] = new Array();	}
			if (this.aValues[sModuleKey][sPackageGlobalKey][sItem] == null)
			{	this.aValues[sModuleKey][sPackageGlobalKey][sItem] = new Array();	}
			this.aValues[sModuleKey][sPackageGlobalKey][sItem][sItemKey] = sItemValue;
			break;
		}
		default:
		{
			alert('Internal logic error in ccData_ItemSetValue, unexpected number of parameters: ' + arguments.length);
			return false;
		}
	}
	return true;
}
function ccData_PackageUserClear(sMyPackage)
{
	this.sUserId = "";
	return true;
}
function ccData_PackageUserGet(sMyPackage)
{
	return this.sUserId;
}
function ccData_PackageUserSet(sMyPackage, sUser)
{
	this.sUserId = sUser;
	return true;
}
function private_ccData_IsNetscape()
{
	return (navigator.appName == "Netscape");
}
function ccData_ItemClearValueExplicit(sPackage, sModuleKey, sPageKey, sItemKey, sItemTag)
{
	if (this.aValues[sModuleKey] == null)
	{	this.aValues[sModuleKey] = new Array();	}
	if (this.aValues[sModuleKey][sPageKey] == null)
	{	this.aValues[sModuleKey][sPageKey] = new Array();	}
	if (this.aValues[sModuleKey][sPageKey][sItemKey] == null)
	{	this.aValues[sModuleKey][sPageKey][sItemKey] = new Array();	}
	this.aValues[sModuleKey][sPageKey][sItemKey][sItemTag] = "";
	return true;
}
function ccData_ItemGetExplicit(sPackage, sModuleKey, sPageKey, sItemKey, sItemTag)
{
	if (this.aValues[sModuleKey] == null)
	{	return "";	}
	else if (this.aValues[sModuleKey][sPageKey] == null)
	{	return "";	}
	else if (this.aValues[sModuleKey][sPageKey][sItemKey] == null)
	{	return "";	}
	else if (this.aValues[sModuleKey][sPageKey][sItemKey][sItemTag] == null)
	{	return "";	}
	else
	{	return this.aValues[sModuleKey][sPageKey][sItemKey][sItemTag];	}
}
function ccData_ItemSetExplicit(sPackage, sModuleKey, sPageKey, sItemKey, sItemTag, sItemValue)
{
	if (this.aValues[sModuleKey] == null)
	{	this.aValues[sModuleKey] = new Array();	}
	if (this.aValues[sModuleKey][sPageKey] == null)
	{	this.aValues[sModuleKey][sPageKey] = new Array();	}
	if (this.aValues[sModuleKey][sPageKey][sItemKey] == null)
	{	this.aValues[sModuleKey][sPageKey][sItemKey] = new Array();	}
	this.aValues[sModuleKey][sPageKey][sItemKey][sItemTag] = sItemValue;
	return true;
}
function ccData_ItemClearNodeExplicit(sPackage, sModule, sPage, sItem, sItemKey)
{
	return true;
}
function ccData_GetDefinedUsers(sPackage, sDelim)
{
	return this.GetPackageUser();
}
function private_GetPageID()
{
	var iHash = document.location.href.lastIndexOf('#');

	if (iHash == -1)
	{	iHash = document.location.href.length;	}

	var iEnd = document.location.href.lastIndexOf('.', iHash-1);

	if (iEnd == -1)
	{	iEnd = iHash;	}

	var iStart = document.location.href.lastIndexOf('/', iEnd)

	if (iStart == -1)
	{	iStart = 0;	}

	return document.location.href.toLowerCase().substring(iStart+1, iEnd);
}
function ccWindow_constructor()
{
	this.oSDWAPI = null;
	this.SetPopupProperties = ccWindow_sdwapi_SetPopupProperties;
	this.VerifyLocalInstallation = ccWindow_sdwapi_VerifyLocalInstallation;
	this.SetBrowserProperties = ccWindow_sdwapi_SetBrowserProperties;
	this.GetDisplayConfiguration = ccWindow_sdwapi_GetDisplayConfiguration;
	this.InitializeModule = ccWindow_server_InitializeModule;
	this.TerminateModule = ccWindow_server_TerminateModule;
	this.InitializePage = ccWindow_server_InitializePage;
	this.TerminatePage = ccWindow_server_TerminatePage;
	this.PostAssessmentResults = ccWindow_server_PostAssessmentResults;
	this.IsSectionEnd = private_ccWindow_server_IsSectionEnd;
	this.GetPageKey = private_ccWindow_server_GetPageKey;
	//this.BuildPostRequest = private_ccWindow_server_BuildPostRequest;
	this.sScope = "page";
	this.sPageKey = "";
	this.aSectionPages = new Array();
	for (var iInx in cfgSectionPages)
	{	this.aSectionPages[cfgSectionPages[iInx]] = true;	}
	return this;
}
function ccWindow_server_InitializeModule(oStorage, sPath)
{
	ccAICC.DataStorage.SetPackageUser(COURSE_ID, STUDENT_NAME);

	oStorage.setItem(COURSE_ID, sCourseID, COURSE_LVL_DATA, COURSE_LVL_DATA, COURSE_VERSION_TIMESTAMP, COURSE_VERSION);
	oStorage.setItem(COURSE_ID, sCourseID, COURSE_LVL_DATA, COURSE_LVL_DATA, COURSE_PROGRESS, COURSE_PROG_STRING);
	oStorage.setItem(COURSE_ID, sCourseID, COURSE_LVL_DATA, COURSE_LVL_DATA, LAST_VISITED_FRAMESET, RESTORE_FRAMESET);

	if ("undefined" == typeof(sPath))
	{
		oStorage.setItem(COURSE_ID, sModuleID, MODULE_LVL_DATA, MODULE_LVL_DATA, MODULE_VERSION, VERSION);
		oStorage.setItem(COURSE_ID, sModuleID, MODULE_LVL_DATA, MODULE_LVL_DATA, MODULE_PROGRESS, PROG_STRING);
		oStorage.setItem(COURSE_ID, sModuleID, MODULE_LVL_DATA, MODULE_LVL_DATA, LAST_VISITED_PAGE, RESTORE_PAGE);
	}

	oStorage.SetPackageUser(COURSE_ID, STUDENT_NAME);
	return true;
}
function ccWindow_server_TerminateModule(oStorage)
{
	this.sScope = "module";
	this.sPageKey = "" + util_GetPageKey(window.parent.frames.fra_content.location.href) + ".htm";

	if (true == this.IsSectionEnd(this))
	{
		var mainSTAWin = util_GetSTAFramesetWindow(window);
		var oController = mainSTAWin.crse_Controller();
		oController.MessageHandler(MSG_REQUESTPAGELOAD, "blank.htm");
	}

	return true;
}
function ccWindow_server_InitializePage(oStorage)
{
	window.frames["fra_server"].location.href="../cCourse/blank.htm";
	return true;
}
function ccWindow_server_TerminatePage(oStorage)
{
    
	var iQuery = 0;

	//if ((true == this.IsSectionEnd(this)) || ("module" == this.sScope))
	//{
		
		var sStudent = STUDENT_NAME;
		var sCourseID = COURSE_ID;
		var sScore = ccAICC.DataStorage.get(cAICC_ITEM_CORE, cAICC_KEY_SCORE, cAICC_PAGE);
		var sStatus = ccAICC.DataStorage.get(cAICC_ITEM_CORE, cAICC_KEY_STATUS, cAICC_PAGE);
		var sTimeSpent = ccAICC.DataStorage.get(cAICC_ITEM_CORE, cAICC_KEY_TIME, cAICC_PAGE);
		
		var sCourseVersion = sCourseTimeStamp;
		var sCourseProgString = MyItems[0];
		var sVersion = MyItems[0];
		var sProgString = oStorage.getItem(sCourseID, sModuleID, MODULE_LVL_DATA, MODULE_LVL_DATA, MODULE_PROGRESS);

		var sLastVisitedFrameset = document.location.href;

		iQuery = sLastVisitedFrameset.indexOf("?");
		if (-1 != iQuery)
		{
			sLastVisitedFrameset = sLastVisitedFrameset.slice(0, iQuery);
			sLastVisitedFrameset = sLastVisitedFrameset.valueOf();
		}

		var sLastPage = oStorage.getItem(sCourseID, sModuleID, MODULE_LVL_DATA, MODULE_LVL_DATA, LAST_VISITED_PAGE);

		if ("module" == this.sScope)
		{	sLastPage = this.sPageKey;	}

		
		
		kmisavearray(g_array_COURSE_PROG_STRING,sCourseProgString);
		kmisavearray(g_array_PROG_STRING,sProgString);
		kmisavearray(g_array_RESTORE_FRAMESET,sLastVisitedFrameset);
		kmisavearray(g_array_RESTORE_PAGE,sLastPage);
		kmisavearray(g_array_VERSION,sVersion);
		kmisavearray(g_array_COURSE_VERSION,sCourseVersion);
		
		
		
	//}
	return true;
}
function ccWindow_server_PostAssessmentResults(oStorage)
{
    
	var sStudent = STUDENT_NAME;
	var sCourseID = COURSE_ID;

	var sScore = ccAICC.DataStorage.get(cAICC_ITEM_CORE, cAICC_KEY_SCORE, cAICC_PAGE);
	var sStatus = ccAICC.DataStorage.get(cAICC_ITEM_CORE, cAICC_KEY_STATUS, cAICC_PAGE);
	var sTimeSpent = ccAICC.DataStorage.get(cAICC_ITEM_CORE, cAICC_KEY_TIME, cAICC_PAGE);

	var sCourseVersion = sCourseTimeStamp;
	var sCourseProgString = MyItems[0];
	var sVersion = MyItems[0];
	var sProgString = oStorage.getItem(sCourseID, sModuleID, MODULE_LVL_DATA, MODULE_LVL_DATA, MODULE_PROGRESS);

	var sLastVisitedFrameset = document.location.href;

	var iQuery = sLastVisitedFrameset.indexOf("?");
	if (-1 != iQuery)
	{
		sLastVisitedFrameset = sLastVisitedFrameset.slice(0, iQuery);
		sLastVisitedFrameset = sLastVisitedFrameset.valueOf();
	}

	var sLastPage = oStorage.getItem(sCourseID, sModuleID, MODULE_LVL_DATA, MODULE_LVL_DATA, LAST_VISITED_PAGE);
	//var sPostRequest = this.BuildPostRequest(POST_CATCHER, sStudent, sCourseID, sScore, sStatus, sTimeSpent, sCourseVersion, sCourseProgString, sVersion, sProgString, sLastVisitedFrameset, sLastPage);
	//call scorm functions
	//window.frames["fra_server"].document.open();
	//window.frames["fra_server"].document.write(sPostRequest);
	//window.frames["fra_server"].document.close();
	kmisavescore(sScore);
	kmisavearray(g_array_COURSE_PROG_STRING,sCourseProgString);
	kmisavearray(g_array_PROG_STRING,sProgString);
	kmisavearray(g_array_RESTORE_FRAMESET,sLastVisitedFrameset);
	kmisavearray(g_array_RESTORE_PAGE,sLastPage);
	kmisavearray(g_array_VERSION,sVersion);
	kmisavearray(g_array_COURSE_VERSION,sCourseVersion);
		
	
	return true;
}
function ccWindow_sdwapi_GetDisplayConfiguration()
{
	return CFG_DISPLAY_PROPS;
}
function ccWindow_sdwapi_SetPopupProperties(obj)
{
	self.onblur = "javascript: self.close();";
	return true;
}
function ccWindow_sdwapi_VerifyLocalInstallation(sModId)
{
	return false;
}
function ccWindow_sdwapi_SetBrowserProperties(obj)
{
	self.close();
	return true;
}
function private_ccWindow_server_IsSectionEnd(oObj)
{
	if (null != oObj)
	{
		if ("undefined" != typeof(window.frames["fra_content"]))
		{
			var sPageKey = oObj.GetPageKey(window.frames["fra_content"].location.href);
			if (null != oObj.aSectionPages[sPageKey])
			{	return true;	}
			else
			{	return false;	}
		}
		else
		{	return false;	}
	}
	else
	{	return false;	}
}
function private_ccWindow_server_GetPageKey(sPageName)
{
	var sTempPK;
	var sRawPK = (sPageName.toString());
	var iInxBS = sRawPK.lastIndexOf("\\");
	var iInxFS = sRawPK.lastIndexOf( "/");
	var iInxDot = sRawPK.lastIndexOf(".");
	var iStart = 0;

	if (iInxBS > iInxFS)
	{	iStart = iInxBS;	}
	else
	{	iStart = iInxFS;	}

	if (iInxDot != -1)
	{	sTempPK = sRawPK.substr ((iStart + 1) , (iInxDot - (iStart + 1)));	}
	else
	{	sTempPK = sRawPK;	}
	return sTempPK;
}

//////SCORM Code

// Change these preset values to suit your taste and requirements.

var g_bShowApiErrors = true; 	// change to true to show error messages

var g_bInitializeOnLoad = true; // change to false to not initialize LMS when HTML page loads

// Translate these strings if g_bShowApiErrors is true
// and you need to localize the application
var g_strAPINotFound = "An error has occured, please close this course and try again.\n If this continues please report error 100 to technical support";
var g_strAPITooDeep = "An error has occured, please close this course and try again.\n If this continues please report error 101 to technical support";
var g_strAPIInitFailed = "An error has occured, please close this course and try again.\n If this continues please report error 102 to technical support";
var g_strAPISetError = "An error has occured, please close this course and try again.\n If this continues please report error 103 to technical support";
var g_strFSAPIError = 'An error has occured, please close this course and try again.\n If this continues please report error 104.%1.%2.%3 to technical support';
 //"%1"\nWhen FScommand called API.%2\nwith "%3"';
var g_strDisableErrorMsgs = "Select cancel to disable future warnings.";
var g_strSaveStatus = "An error has occured, please close this course and try again.\n If this continues please report error 105 to technical support";
// Change g_bSetCompletedAutomatically to true if you want the status to
// be set to completed automatically when calling LMSFinish. Normally,
// this flag remains false if the Flash movie itself sets status
// to completed by sending a FSCommand to set status to "completed",
// "passed" or "failed" (both of which imply "completed")
var g_bSetCompletedAutomatically = false;

// This value is normally given by the LMS, but in case it is not
// this is the default value to use to determine passed/failed.
// Set this null if the Flash actionscript uses its own method
// to determine passed/fail, otherwise set to a value from 0 to 1
// inclusive (may be a floating point value, e.g "0.75".
var g_SCO_MasteryScore = null; // allowable values: 0.0..1.0, or null

//==================================================================

// WARNING!!!
// Do not modify anything below this line unless you know exactly what
// you are doing!

// You should not have to change these two values as the Flash template
// presets are based on them.
var g_nSCO_ScoreMin = 0; 		// must be a number
var g_nSCO_ScoreMax = 100; 		// must be a number > nSCO_Score_Min

// Per SCORM specification, the LMS provided mastery score,
// if any, will override the SCO in interpreting whether the score
// should be interpreted when the pass/fail status is determined.
// The template tries to obtain the mastery score, and if it
// is available, to set the status to passed or failed accordingly
// when the SCO sends a score. The LMS may not actually make the
// determination until the SCO has been terminated.
// Default value for this flag is true. Set it to false if don't
// want to predict how the LMS will set pass/fail status based on
// the mastery score (the LMS will win in the end anyway).
var g_bInterpretMasteryScore = true;

// This script implements various aspects of
// common logic behavior of a SCO.

/////////// API INTERFACE INITIALIZATION AND CATCHER FUNCTIONS ////////
var g_nFindAPITries = 0;
var g_objAPI = null;
var g_bInitDone = false;
var g_bFinishDone = false;
var	g_bSCOBrowse = false;
var g_dtmInitialized = new Date(); // will be adjusted after initialize
var g_bMasteryScoreInitialized = false;
var g_suspend_data = ":;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;::;:;,%;";
var g_array_COURSE_PROG_STRING = 1;
var g_array_PROG_STRING = 2;
var g_array_RESTORE_FRAMESET = 3;
var g_array_RESTORE_PAGE = 4;
var g_array_VERSION = 5;
var g_array_COURSE_VERSION = 6;


function AlertUserOfAPIError(strText) {
	if (g_bShowApiErrors) {
		var s = strText + "\n\n" + g_strDisableErrorMsgs;
		if (!confirm(s)){
			g_bShowApiErrors = false;
		}
	}
}

function ExpandString(s){
	var re = new RegExp("%","g")
	for (i = arguments.length-1; i > 0; i--){
		s2 = "%" + i;
		if (s.indexOf(s2) > -1){
			re.compile(s2,"g")
			s = s.replace(re, arguments[i]);
		}
	}
	return s
}

function FindAPI(win) {
	while ((win.API == null) && (win.parent != null) && (win.parent != win)) {
		g_nFindAPITries ++;
		if (g_nFindAPITries > 500) {
			AlertUserOfAPIError(g_strAPITooDeep);
			return null;
		}
		win = win.parent;
	}
	return win.API;
}

function APIOK() {
	return ((typeof(g_objAPI)!= "undefined") && (g_objAPI != null));
}

function SCOInitialize() {
	var err = true;
	if (!g_bInitDone) {
		if ((window.parent) && (window.parent != window)){
			g_objAPI = FindAPI(window.parent);
		}
		if ((g_objAPI == null) && (window.opener != null))	{
			g_objAPI = FindAPI(window.opener);
		}
		if (!APIOK()) {
			AlertUserOfAPIError(g_strAPINotFound);
			err = false
		} else {
			err = g_objAPI.LMSInitialize("");
			if (err == "true") {
				g_bSCOBrowse = (g_objAPI.LMSGetValue("cmi.core.lesson_mode") == "browse");						
				if (!g_bSCOBrowse) {
					if (g_objAPI.LMSGetValue("cmi.core.lesson_status") == "not attempted") {
						err = g_objAPI.LMSSetValue("cmi.core.lesson_status","incomplete");
					}
				}
			} else {
				AlertUserOfAPIError(g_strAPIInitFailed);
			}
		}
		if (typeof(SCOInitData) != "undefined") {
			// The SCOInitData function can be defined in another script of the SCO
			SCOInitData();
		}
		g_dtmInitialized = new Date();
		//get cmi.suspend_data and compare to g_suspend_data
		//if cmi.suspend_data length is >= g_suspend_data then set g_suspend_data = cmi.suspend_data
		var temp = SCOGetValue("cmi.suspend_data")
		if (temp.length > g_suspend_data.length) {
			g_suspend_data = temp
		}
		
		
	}
	g_bInitDone = true;
	return (err + ""); // Force type to string
}

function frame_Initialize() {
	var err = true;
	if (!g_bInitDone) {
		if ((window.parent) && (window.parent != window)){
			g_objAPI = FindAPI(window.parent);
		}
		if ((g_objAPI == null) && (window.opener != null))	{
			g_objAPI = FindAPI(window.opener);
		}
		if (!APIOK()) {
			AlertUserOfAPIError(g_strAPINotFound);
			err = false
		} else {
			g_bSCOBrowse = (g_objAPI.LMSGetValue("cmi.core.lesson_mode") == "browse");						
			if (!g_bSCOBrowse) {
				if (g_objAPI.LMSGetValue("cmi.core.lesson_status") == "not attempted") {
					err = g_objAPI.LMSSetValue("cmi.core.lesson_status","incomplete");
				}
			}
			
			
		}
		if (typeof(SCOInitData) != "undefined") {
			// The SCOInitData function can be defined in another script of the SCO
			SCOInitData();
		}
		g_dtmInitialized = new Date();
		//get cmi.suspend_data and compare to g_suspend_data
		//if cmi.suspend_data length is >= g_suspend_data then set g_suspend_data = cmi.suspend_data
		var temp = SCOGetValue("cmi.suspend_data")
		if (temp.length > g_suspend_data.length) {
			g_suspend_data = temp
		}
		
		
	}
	g_bInitDone = true;
	return (err + ""); // Force type to string
}


function SCOFinish() {
	if ((APIOK()) && (g_bFinishDone == false)) {
		SCOReportSessionTime()
		if (g_bSetCompletedAutomatically){
			SCOSetStatusCompleted();
		}
		if (typeof(SCOSaveData) != "undefined"){
			// The SCOSaveData function can be defined in another script of the SCO
			SCOSaveData();
		}
		g_bFinishDone = (g_objAPI.LMSFinish("") == "true");
	}
	return (g_bFinishDone + "" ) // Force type to string
}

// Call these catcher functions rather than trying to call the API adapter directly
function SCOGetValue(nam)			{return ((APIOK())?g_objAPI.LMSGetValue(nam.toString()):"")}
function SCOCommit()					{return ((APIOK())?g_objAPI.LMSCommit(""):"false")}
function SCOGetLastError()		{return ((APIOK())?g_objAPI.LMSGetLastError():"-1")}
function SCOGetErrorString(n)	{return ((APIOK())?g_objAPI.LMSGetErrorString(n):"No API")}
function SCOGetDiagnostic(p)	{return ((APIOK())?g_objAPI.LMSGetDiagnostic(p):"No API")}

//LMSSetValue is implemented with more complex data
//management logic below

var g_bMinScoreAcquired = false;
var g_bMaxScoreAcquired = false;

// Special logic begins here
function SCOSetValue(nam,val){
	var err = "";
	if (!APIOK()){
			AlertUserOfAPIError(g_strAPISetError + "\n" + nam + "\n" + val);
			err = "false"
	} else if (nam == "cmi.core.score.raw") err = privReportRawScore(val)
	if (err == ""){
			err = g_objAPI.LMSSetValue(nam,val.toString() + "");
			if (err != "true") return err
	}
	if (nam == "cmi.core.score.min"){
		g_bMinScoreAcquired = true;
		g_nSCO_ScoreMin = val
	}
	else if (nam == "cmi.core.score.max"){
		g_bMaxScoreAcquired = true;
		g_nSCO_ScoreMax = val
	}
	return err
}

function privReportRawScore(nRaw) { // called only by SCOSetValue
	if (isNaN(nRaw)) return "false";
	if (!g_bMinScoreAcquired){
		if (g_objAPI.LMSSetValue("cmi.core.score.min",g_nSCO_ScoreMin+"")!= "true") return "false"
	}
	if (!g_bMaxScoreAcquired){
		if (g_objAPI.LMSSetValue("cmi.core.score.max",g_nSCO_ScoreMax+"")!= "true") return "false"
	}
	if (g_objAPI.LMSSetValue("cmi.core.score.raw", nRaw)!= "true") return "false";
	g_bMinScoreAcquired = false;
	g_bMaxScoreAcquired = false;
	//if (!g_bMasteryScoreInitialized){
	//	var nMasteryScore = parseInt(SCOGetValue("cmi.student_data.mastery_score"),10);
	//	if (!isNaN(nMasteryScore)) g_SCO_MasteryScore = nMasteryScore
	//}
  	//if ((g_bInterpretMasteryScore)&&(!isNaN(g_SCO_MasteryScore))){
    //	var stat = (nRaw >= g_SCO_MasteryScore? "passed" : "failed");
    //	if (SCOSetValue("cmi.core.lesson_status",stat) != "true") return "false";
  	//}
  	if (SCOSetValue("cmi.core.lesson_status","completed") != "true") return "false";
  	return "true"
}

function MillisecondsToCMIDuration(n) {
//Convert duration from milliseconds to 0000:00:00.00 format
	var hms = "";
	var dtm = new Date();	dtm.setTime(n);
	var h = "000" + Math.floor(n / 3600000);
	var m = "0" + dtm.getMinutes();
	var s = "0" + dtm.getSeconds();
	var cs = "0" + Math.round(dtm.getMilliseconds() / 10);
	hms = h.substr(h.length-4)+":"+m.substr(m.length-2)+":";
	hms += s.substr(s.length-2)+"."+cs.substr(cs.length-2);
	return hms
}

// SCOReportSessionTime is called automatically by this script,
// but you may call it at any time also from the SCO
function SCOReportSessionTime() {
	var dtm = new Date();
	var n = dtm.getTime() - g_dtmInitialized.getTime();
	return SCOSetValue("cmi.core.session_time",MillisecondsToCMIDuration(n))
}

// Since only the designer of a SCO knows what completed means, another
// script of the SCO may call this function to set completed status.
// The function checks that the SCO is not in browse mode, and
// avoids clobbering a "passed" or "failed" status since they imply "completed".
function SCOSetStatusCompleted(){
	var stat = SCOGetValue("cmi.core.lesson_status");
	if (SCOGetValue("cmi.core.lesson_mode") != "browse"){
		if ((stat!="completed") && (stat != "passed") && (stat != "failed")){
			return SCOSetValue("cmi.core.lesson_status","completed")
		}
	} else return "false"
}

// Objective management logic

function SCOSetObjectiveData(id, elem, v) {
	var result = "false";
	var i = SCOGetObjectiveIndex(id);
	if (isNaN(i)) {
		i = parseInt(SCOGetValue("cmi.objectives._count"));
		if (isNaN(i)) i = 0;
		if (SCOSetValue("cmi.objectives." + i + ".id", id) == "true"){
			result = SCOSetValue("cmi.objectives." + i + "." + elem, v)
		}
	} else {
		result = SCOSetValue("cmi.objectives." + i + "." + elem, v);
		if (result != "true") {
			// Maybe this LMS accepts only journaling entries
			i = parseInt(SCOGetValue("cmi.objectives._count"));
			if (!isNaN(i)) {
				if (SCOSetValue("cmi.objectives." + i + ".id", id) == "true"){
					result = SCOSetValue("cmi.objectives." + i + "." + elem, v)
				}
			}
		}
	}
	return result
}

function SCOGetObjectiveData(id, elem) {
	var i = SCOGetObjectiveIndex(id);
	if (!isNaN(i)) {
		return SCOGetValue("cmi.objectives." + i + "."+elem)
	}
	return ""
}

function SCOGetObjectiveIndex(id){
	var i = -1;
	var nCount = parseInt(SCOGetValue("cmi.objectives._count"));
	if (!isNaN(nCount)) {
		for (i = nCount-1; i >= 0; i--){ //walk backward in case LMS does journaling
			if (SCOGetValue("cmi.objectives." + i + ".id") == id) {
				return i
			}
		}
	}
	return NaN
}



// Detect Internet Explorer
var g_bIsInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;

// Handle fscommand messages from a Flash movie, remapping
// any AICC Flash template commands to SCORM if necessary

//saves current page
function kmisavepage(arg1) {
	err = SCOSetValue("cmi.core.lesson_location",arg1);
	if ((g_bShowApiErrors) && (err != "true")) {
		AlertUserOfAPIError(ExpandString(g_strFSAPIError, err, cmd, args));
	}
	return err;
}

//gets current page
function kmigetpage() {
	err = SCOGetValue("cmi.core.lesson_location");
	if ((g_bShowApiErrors) && (err == "false")) {
		AlertUserOfAPIError(ExpandString(g_strFSAPIError, err, cmd, args));
	}
	return err;
}

function kmigetcourseid() {
	return 1111111;
}


function kmigetlearnername(){
	err = SCOGetValue("cmi.core.student_name");
	if ((g_bShowApiErrors) && (err == "false")) {
		AlertUserOfAPIError(ExpandString(g_strFSAPIError, err, cmd, args));
	}
	return err;

}

function kmisavescore(arg1){
	if (arg1 == ""||arg1 == null) {
		return true;
	} else {
		err = SCOSetValue("cmi.core.score.raw",arg1.toString() + "");
		if ((g_bShowApiErrors) && (err == "false")) {
			AlertUserOfAPIError(ExpandString(g_strFSAPIError, err, cmd, args));
		}
	}
	return err;
}

function kmisavearray(arg1,arg2) {
		//Save array Value
		
		
	var suspend_data_items = g_suspend_data.split(';,%;');
	var arrayelements = suspend_data_items[0];
	var suspend_data_values = suspend_data_items[1];
	var elementItems = arrayelements.split(':;:');
	if ((arg1 - 1) == 0)	{
		arrayelements = arg2;
	} else {
		arrayelements = elementItems[0];
	}
	for ( i = 1; i < elementItems.length; i++)	{
		if ((arg1 - 1) == i){
			arrayelements = arrayelements + ":;:" + arg2;
		} else	{
			arrayelements = arrayelements + ":;:" + elementItems[i];
		}
	}
	g_suspend_data = arrayelements + ";,%;" + suspend_data_values;
	//Store cmi.suspend_data
	err = SCOSetValue("cmi.suspend_data",g_suspend_data);
	if ((g_bShowApiErrors) && (err == "false")) {
		AlertUserOfAPIError(ExpandString(g_strFSAPIError, err, cmd, args));
	}
	return err;

}



function kmigetarray(arg1) {
	//GetArray Value
	var suspend_data_items = g_suspend_data.split(';,%;');
	var arrayelements = suspend_data_items[0];
	var elementItems = arrayelements.split(':;:');
	var element_data = "";
	if ( (arg1 -1 )< elementItems.length) {
		element_data = elementItems[arg1 - 1];
	} else {
		//asked for one that does not exist
	}
	//alert("get array data: " + element_data);
	return element_data.toString();
		
}

function pause(numberMillis) { 
     var now = new Date(); 
     var exitTime = now.getTime() + numberMillis; 
     while (true) { 
          now = new Date(); 
          if (now.getTime() > exitTime) 
               return; 
     } 
}

function ParseQueryString(queryStringParam)
  {
   var nvString = "&" + location.search.substring(1, location.search.length) + "&";
   var paramBegin = nvString.indexOf("&" + queryStringParam + "=");
   if (paramBegin != -1)
   {
    valBegin = (paramBegin * -1 - queryStringParam.length - 2) * -1;
    qsVal = nvString.substring(valBegin, nvString.indexOf("&", valBegin));
    if (qsVal != "")
    {
     return unescape(qsVal);
    }
    else
    {
     return "";
    }
   }
   else
   {
    return "";
   }
}

