/********************************************************/
/* Copyright (c) 2003-2004 Element K LLC. All rights reserved.
   This javaScript file is used for all splash content. */
/********************************************************/




/********************************************************/
/* initializes scorm variable*/

var strScorm = "";
/********************************************************/




/********************************************************/
/* This function makes several calls to the LMS to retrieve data and sets the
   lesson_status if this is the first time the student has launche the sco.
   The LMS return values are added to the scorm variable. */

function runCrawler()
{
	if (LMSInitialize(""))
	{
		var status = LMSGetValue( "cmi.core.lesson_status" );
		strScorm += "cmi.core.lesson_status"+ "=" + status + "&";
		if ( status == "not attempted" || status == "" )
		{
			LMSSetValue( "cmi.core.lesson_status", "incomplete" );
		}
		crawler(["cmi.core.lesson_location", "cmi.student_preference.audio", "cmi.comments" , "cmi.suspend_data"]);
		var elementkData = LMSGetValue( "elementk._children" );
		var elementkPresent = LMSGetValue( "elementk.navigation.is_next_sco" );
		if (elementkData != null && elementkData != "" || elementkPresent != null )
		{
			crawlChildren(["elementk.brand_element.brand_name","elementk.navigation","elementk.resources","elementk.system"]);
		}
		if (parent.elementk_left || parent.Left || parent.theLeftFrame) 
		{
			strScorm += "elementk.navigation.has_course_nav=true";
		}
		strScorm = escape(strScorm);
	}
	
}
/********************************************************/


		

/********************************************************/
/* This function calls the LMSGetvalue function for each item in the arrTree array.
   The data element names and values that are returned by the LMS are
   added on to the strScorm var */

function crawler(arrTree)
{
	for (var i=0; i<arrTree.length;i++)
	{
		var strNode = arrTree[i];
		var strVal = LMSGetValue(strNode);
		if (strVal != null)
		{
			strScorm += strNode + "=" + strVal + "&";
		}

	}
}
/********************************************************/




/********************************************************/
/* This function calls the LMSGetvalue function for each item in the arrTree array
   and any children the items may have. The data element names and values that
   are returned by the LMS are added on to the strScorm var. */

function crawlChildren(arrTree)
{
	for (var i=0; i<arrTree.length;i++)
	{
		var strNode = arrTree[i];
		var strArr = LMSGetValue(strNode + "._children");
		if (strArr != null)
		{
			var arrSubTree = strArr.split(",");
			var arrSubTreeFix = new Array();
			for (var j=0;j<arrSubTree.length;j++)
			{
				if (arrSubTree[j] != "")
				{
					arrSubTreeFix[arrSubTreeFix.length] = (strNode + "." + arrSubTree[j]);
				}
			}
			crawlChildren(arrSubTreeFix);
		}
		var strVal = LMSGetValue(strNode);
		if (strVal != null)
		{
			strScorm += strNode + "=" + strVal + "&";
		}

	}
}
/********************************************************/
