
// course functions; only found on top of window

// course functions August 2007

// SHORTHAND VARS
// FRAMESETS
// DATA
// DATA SCORM
// DATA AICC
// DATA COOKIE
// LAUNCH
// MAIN MENU
// SCREEN
// SCREEN NAV
// SCREEN LOCATION MENU
// SCREEN AUDIO
// SCREEN POPUP
// TEST
// TEST NAV
// DATA EXPORTLIVE
// GENERAL
// STORAGE EXTRA CODE

// ********************************************* SHORTHAND VARS

icon_clear = "<img src='../interface/spacer_clear.gif' width='16' height='16' alt='' border='0'>";
icon_folderopen = "<img src='../interface/folderopen.gif' width='16' height='16' alt='' border='0'>";
icon_folderclosed = "<img src='../interface/folderclosed.gif' width='16' height='16' alt='' border='0'>";

// ********************************************* FRAMESETS

function BuildMainFrameset(doc)
{
	doc.writeln("<FRAMESET border=0 frameBorder=NO frameSpacing=0 rows=\"28,*\" onload=\"focus();LaunchFirst();\" onunload=\"if(LMS==2){SaveSCORMData()};if(LMS==4){SaveCookieData()};\" >");
	doc.writeln("<frame src=\"course_head.htm\" name=\"course_head\" frameBorder=NO marginHeight=0 marginWidth=0 scrolling=no>");
  doc.writeln("<frame src=\"../screens/screen_blank.htm\" name=\"course_body\" frameBorder=NO marginHeight=0 marginWidth=0>");
	doc.writeln("</FRAMESET><noframes>This Course Needs Frames to Run.</noframes>");
}

function BuildLessonFrameset(doc)
{
	doc.writeln("<FRAMESET border=0 frameBorder=NO frameSpacing=0 rows='*,28' onload='ttlms_connect.ShowScreen();focus();'>");
	doc.writeln("<FRAME frameBorder='NO' marginHeight=0 marginWidth=0 name='lesson_content' src='../screens/screen_blank.htm'>");
	doc.writeln("<FRAME frameBorder='NO' marginHeight=0 marginWidth=0 name='lesson_foot' scrolling='no' src='lesson_foot.htm'>");
	doc.writeln("</FRAMESET><noframes></noframes>");
}

function BuildTestFrameset(doc)
{
	doc.writeln("<FRAMESET border=0 frameBorder=NO frameSpacing=0 rows='*,28' onload='ttlms_connect.ShowScreen();focus();'>");
	doc.writeln("<FRAME frameBorder='NO' marginHeight=0 marginWidth=0 name='test_content' src='test_question.htm'>");
	doc.writeln("<FRAME frameBorder='NO' marginHeight=0 marginWidth=0 name='test_foot' scrolling='no' src='test_foot.htm'>");
	doc.writeln("</FRAMESET><noframes></noframes>");
}

// ********************************************* DATA

function ResetData()
{
	location_order=0;
	location_screen=0;
	test_question = 0;
	test_answers = 0;
	test_done = 0;
	course_progress= new Array(0);
	course_testscores= new Array(0);
}

// ********************************************* DATA SCORM


function LoadSCORMData()
{
	loadPage();
	LMS_data["cmi.core.lesson_location"]=doLMSGetValue("cmi.core.lesson_location");
	d = LMS_data["cmi.core.lesson_location"];
	d = d.split(";");
	if(d.length==2)
	{// use data
		course_progress = d[0].split(",");
		course_testscores = d[1].split(",");
	}
}

function SaveSCORMData()
{
	lesson_location = ttlms_connect.course_progress + ";" + ttlms_connect.course_testscores;
	value = doLMSSetValue("cmi.core.lesson_location",lesson_location);
	if(!isUndefined(course_testscores[0]))
	{
		value = doLMSSetValue("cmi.core.score.raw",course_testscores[0]);
		value = doLMSSetValue("cmi.core.score.min",0);
		value = doLMSSetValue("cmi.core.score.max",100);
	}
	
	stat=GetCourseComplete();
	if(stat==0)
		doContinue("incomplete");
	else
		doContinue("passed");
	window.close();
}


// ********************************************* DATA AICC


function LoadAICCData()
{
	var myQueryStuff = new QueryString();

	d = myQueryStuff["aicc_sid"];
	if(d==undefined)
	{
		d = myQueryStuff["AICC_SID"];
		if(d==undefined)
		{
			d="";
		}
	}
	d = unescape(d);
	LMS_data["aicc_sid"] = d;

	d = myQueryStuff["aicc_url"];
	if(d==undefined)
	{
		d = myQueryStuff["AICC_URL"];
		if(d==undefined)
		{
			d="";
		}
	}
	d = unescape(d);
	LMS_data["aicc_url"] = unescape(d);
		
	// Test For real aicc path
	if(isUndefined(LMS_data["aicc_url"]) || LMS_data["aicc_url"]=="")
	{
		LMS=0;
		AICC_read=0;
	}
}

function LoadAICCUserData()
{
	self.frames["course_body"].document.location="../menu/aicc_read_frame.htm";
}
function BuildAICCUserDataRequest(doc)
{
	doc.writeln("<form method='post' action='" + LMS_data["aicc_url"] + "' name='getParamForm' target='aicc_read_return'>");
	doc.writeln("<input type='hidden' name='command' value='getParam'>");
	doc.writeln("<input type='hidden' name='version' value='2.0'>");
	doc.writeln("<input type='hidden' name='session_id' value='" + LMS_data["aicc_sid"] + "'>");
	doc.write("<input type='hidden' name='aicc_data' value='");
	doc.writeln("'>");
	doc.writeln("</form>");
	doc.writeln("<script>document.getParamForm.submit();</script>");
}

function TestAICCWaiting(doc)
{
	//var vTempString = doc.frames["aicc_read_return"].document.body.innerText;
 	var vTempString = self.frames["course_body"].frames["aicc_read_return"].document.body.innerText;
 	if(!(trim(vTempString)=="Return AICC Here..."))
	{
		// debug
		//alert(vTempString);
	 	var lines = vTempString.split('\r');
		var j2 = 0;
		// build associative array
		if(lines.length>0)
			for(c=0;c<lines.length;c=c+1)
			{
				l = trim(lines[c]);

				l = l.split('=');
				if(l.length == 2)
					{
						if(Left(l[0],5)=="j_id.")
						{
							j2 = Right(l[1],l[1].length-1);
							//alert(j2);
						}
						if(Left(l[0],9)=="j_status.")
						{
							if(l[1]=="C")
								course_progress[j2]=100;
						}
						if(Left(l[0],8)=="j_score.")
						{
							if((l[1]*1)>0)
								course_testscores[j2]=l[1];
						}
						LMS_data[trim(l[0])]=trim(l[1]);
					}
			}
		// pull current information
		if(!isUndefined(LMS_data["score"]))
			course_testscores[0] = LMS_data["score"];

		// return to Bookmark location
		var lines = LMS_data["Lesson_Location"];
		if( (SaveBookmark==1) && (lines) && (lines != ""))
		{
			lines = lines.split(',');
			l1=lines[1]*1;
			l2=lines[2]*1;
			if(l1>0 && l2>0)
				if(confirm("Do you want to return to where you left off?"))
				{
				launch_first=3;
				location_order=l1;
				location_screen=l2;
				}
		}
			
		LaunchFirstStart();
	}
}


function SaveAICCData()
{
	document.body.rows="0,*";
	self.frames["course_head"].document.location="../menu/close_head.htm";
	self.frames["course_body"].document.location="../menu/close1.htm";
}

// IE version
function BuildAICCSave(doc)
{
	doc.writeln("<form method='post' action='" + LMS_data["aicc_url"] + "'  name='AICC_DATA'>");
	doc.writeln("<input type='Hidden' name='command' value='putParam'>");
	doc.writeln("<input type='Hidden' name='version' value='2.0'>");
	doc.writeln("<input type='Hidden' name='session_id' value='" + LMS_data["aicc_sid"] + "'>");
	doc.write("<input type='Hidden' name='aicc_data' value='");
	doc.writeln("[CORE]");
	stat=GetCourseComplete();
	if(stat==0)
		doc.writeln("Lesson_Status=I");
	else
		doc.writeln("Lesson_Status=P");
	doc.writeln("Lesson_Location=");
	if( (SaveBookmark==1) && (location_order > 0) && (location_screen > 0) )
		doc.writeln(location_order + "," + location_screen);
	if(course_testscores[0]!=undefined)
		doc.writeln("score=" + course_testscores[0]);
	else
		doc.writeln("score=0");
	doc.writeln("time=");
	doc.writeln("[Core_Lesson]");
	doc.writeln("[Core_Vendor]");
	doc.writeln("[Objectives_status]");
	for(c=1;c<=course_units;c=c+1)
	{
		doc.writeln("j_id."+c+"=J" + c);
		if(course_progress[c]!=100)
			doc.writeln("j_status."+c+"=N");
		else
			doc.writeln("j_status."+c+"=C");
		if(course_testscores[c]!=undefined)
			doc.writeln("j_score."+c+"=" + course_testscores[c]);
		else
			doc.writeln("j_score."+c+"=0");
	}
	doc.write("'></form>");

}

// ********************************************* DATA COOKIE

function SaveCookieData()
{
	//alert("SaveCookieData");
	//alert(course_progress);
	//alert(course_testscores);
	WM_setCookie ("lesson_status_"+C_ID, course_progress, 365*24, "/");
	WM_setCookie ("lesson_location_"+C_ID, course_testscores, 365*24, "/");
}	

function LoadCookieData()
{
	//alert("LoadCookieData");
	var c="";
	c=WM_readCookie("lesson_status_"+C_ID);
	if(c)
		course_progress = c.split(',');
	//alert(course_progress);
	c = WM_readCookie("lesson_location_"+C_ID);
	if(c)
		course_testscores = c.split(',');
	//alert(course_testscores);
}

// ********************************************* LAUNCH

function LaunchFirst()
{ // ExportLive
	//alert(LMS + " LF()");
	if(window_maximize)
		maximizeWin();
	ResetData();
	switch(LMS)
	{
		case	1:
			{
				LoadAICCData();
				break;
			}
		case	2:
			{
				LoadSCORMData();
				break;
			}
		case	3:
			{
				LoadExportLiveData();
				break;
			}
		case	4:
			{
				LoadCookieData();
				break;
			}
	}
	if(AICC_read==1)
		LoadAICCUserData();
	else
		LaunchFirstStart();
}

function LaunchFirstStart()
{
	switch(launch_first)
	{
		case 1: // content
		{
			LaunchLesson(1,1);
			break;
		}
		case 2: // test
		{
			LaunchTest(0);
			break;
		}
		case 3: // Last screen
		{
			LaunchLesson(location_order,location_screen);
			break;
		}
		case 4: // S_ID passed from Preview
		{
			ShowEdit = 0;
			if(S_ID > 0)
				ExportLivePreview(S_ID);
			else
				LaunchMenu();
			break;
		}
		default: // menu
		{
			LaunchMenu();
			break;
		}
	}
}

function LaunchMenu()
{
	location_order=0;
	location_screen=0;
	if(menu_custom==0)
		self.frames["course_body"].document.location="../menu/menu_list.htm";
	else
		self.frames["course_body"].document.location="../menu/menu_list_custom.htm";
}

function LaunchLesson(order,screen)
{
	if(order>0)
		location_order=order*1;
	location_screen=screen*1;
	// load lesson frame
	self.frames["course_body"].document.location = document.location.pathname + "/../../menu/lesson_frame.htm";
	//self.frames["course_body"].document.location = "../menu/lesson_frame.htm";
}

function ExportLivePreview(S_ID)
{
	for(lo=1; lo < screens_array.length;lo=lo+1)
	{
		if(!isUndefined(screens_array[lo]))
		for(ls=0; ls < screens_array[lo].length;ls=ls+1)
			if(S_ID == screens_array[lo][ls])
			{
				location_order=lo;
				location_screen=ls+1;
			}
	}
	if ( (location_order > 0) && (location_screen > 0) )
		LaunchLesson(location_order,location_screen);
}

function LaunchTest(order)
{
	location_order=order;
	test_question=0;
	test_done=0;
	test_answers=new Array();
	questions_sub=new Array();
	if(questions_all.length>0)
	{
		if(test_all==1)
		{
			for(c=0;c<questions_all.length;c=c+1)
			{
				if(questions_all[c][12]==location_order | location_order==0)
				{
					questions_sub[questions_sub.length]=c;
				}
			}
		}
		else
		{
			// break up questions into objectives
			obj=new Array();
			num=0;
			
			for(c=0;c<questions_all.length;c=c+1)
			{
				if(location_order==0)
				{
					if(num==questions_all[c][12])
					{
						obj[obj.length-1][obj[obj.length-1].length]=c;
					}
					else
					{
						obj[obj.length]=new Array();
						obj[obj.length-1][obj[obj.length-1].length]=c;
					}
					num=questions_all[c][12];
				}
			}
			// randomize each objective/question list
			for(c=0;c<obj.length;c=c+1)
			{
				rndArray(obj[c]);
				questions_sub[questions_sub.length]=obj[c][0];
			}
			
			//alert(questions_sub);
		}
		if(test_rnd)
			{
				rndArray(questions_sub);
			}
	}

	// trim questions if needed
	if( (MaxQuestions > 0) && (questions_sub.length > MaxQuestions) )
	{
		var l = questions_sub.length - MaxQuestions;
		var t1=questions_sub.splice(0,l);
	}
	
	if(questions_sub.length==0)
		alert("There are no questions for this unit.");
	else
		if( (order > 0) || (allContentFirst==0) || ( (allContentFirst==1) && (GetContentComplete()) ) )
			self.frames["course_body"].document.location="../menu/test_frame.htm";
		else
			alert("You must review all content in this course before taking the mastery test.");

}
	
function DoTopicOutside()
{
	MM_openBrWindow(course_discussion_url ,'Discussion','scrollbars=yes,resizable=yes,width=550,height=400');
}

function 		LoadTestQuestion()
{
	self.frames["course_body"].frames["test_content"].location="../menu/test_question.htm";
}

function 		LoadTestReviewQuestion()
{
	test_done = 2;
	self.frames["course_body"].frames["test_content"].location="../menu/test_review.htm";
}

function 		LoadTestResults()
{
	self.frames["course_body"].frames["test_content"].location="../menu/test_results.htm";
}

function 		UniversalExit()
{
		switch(LMS)
	{
		case	1:
			{
				SaveAICCData();
				break;
			}
		case	3:
			{
				SaveExportLiveData();
				break;
			}
			default:
			{
				window.close();
				break;
			}
	}
}

// ********************************************* MAIN MENU

function GetCourseComplete()
{
	stat=1;
	if(completionIs==0 || completionIs==3)
	{
		for(c=1;c<=course_units;c=c+1)
		{
			// debug
			//alert(c + " : " + course_progress[c]);
			if(isUndefined(course_progress[c]) || (course_progress[c]<100))
				stat=0;
		}
	}
	if(course_tests[0]>0 && (isUndefined(course_testscores[0]) || course_testscores[0]==0))
		stat=0;
	return(stat)
}

function GetContentComplete()
{
	stat=1;
	if(completionIs==0 || completionIs==3)
		for(c=1;c<=course_units;c=c+1)
		{
			if(isUndefined(course_progress[c]) || (course_progress[c]<100))
				stat=0;
		}
	return(stat);
}

function BuildMenuTop(doc)
{
	;
}

function BuildMenuBottom(doc)
{
	;
}

function BuildMenu(doc)
{
	BuildMenuTop(doc);
	
	doc.write("<p align='right'><form><input type='Button' class='ibutton' value='Reset' onclick='if(confirm(\"Are you sure you want to reset your status?\")){ttlms_connect.ResetData();self.location.reload();};'></form></p>");	
	var modc = ttlms_connect.course_array.length-1;
	var t = "";

	doc.write("<table cols='5' class='menu' align='center'>");
	doc.write("<tr>");
	doc.write("<th width='100%' class='menu'>Training Units</th>");
	doc.write("<th class='menu'>Complete</th>");
	doc.write("<th class='menu'>Test</th><th class='menu'>Score</th>");
	doc.write("</tr>");

	if(modc>0)
	for(c1=1;c1<=modc;c1=c1+1)
	{
		doc.write("<tr><td class='menu'>");
		doc.write(icon_clear);
		if(isString(ttlms_connect.course_array[c1]))
		{
			t = ttlms_connect.course_array[c1];
			t = t.split(";");
			lesc = 0;
			doc.write(icon_folderclosed);
			doc.write("&nbsp;<a href='javascript:ttlms_connect.LaunchLesson(" + t[0] + ",1);' class='hilite'>" + t[1]  + "</a>");
			doc.write("</td><td align='right' class='menu'>");
			doc.write(GetProgress(t[0]));
			doc.write("</td><td align='center' class='menu'>");
			doc.write(GetTestLink(t[0]));
			doc.write("</td><td align='right' class='menu'>");
			doc.write(GetScore(t[0]));
			doc.write("</td></tr>");
		}
		else
		{
			t = ttlms_connect.course_array[c1][0];
			t = t.split(";");
			lesc = ttlms_connect.course_array[c1].length-1;
			doc.write(icon_folderopen);
			doc.write("&nbsp;" + t[1]);
			doc.write("</td><td class='menu'>&nbsp;</td><td class='menu'>&nbsp;</td><td class='menu'>&nbsp;</td></tr>");
		}
		if(lesc>0)
		{
			for(c2=1;c2<=lesc;c2=c2+1)
			{
				doc.write("<tr><td class='menu'>");
				doc.write(icon_clear);
				doc.write(icon_clear);
				if(isString(ttlms_connect.course_array[c1][c2]))
				{
					t = ttlms_connect.course_array[c1][c2];
					t = t.split(";");
					chc = 0;
					doc.write(icon_folderclosed);
					doc.write("&nbsp;<a href='javascript:ttlms_connect.LaunchLesson(" + t[0] + ",1);' class='hilite'>" + t[1] + "</a>");
					doc.write("</td><td align='right' class='menu'>");
					doc.write(GetProgress(t[0]));
					doc.write("</td><td align='center' class='menu'>");
					doc.write(GetTestLink(t[0]));
					doc.write("</td><td align='right' class='menu'>");
					doc.write(GetScore(t[0]));
					doc.write("</td></tr>");
				}
				else
				{
					t = ttlms_connect.course_array[c1][c2][0];
					t = t.split(";");
					chc = ttlms_connect.course_array[c1][c2].length-1;
					doc.write(icon_folderopen);
					doc.write("&nbsp;" + t[1]);
					doc.write("</td><td class='menu'>&nbsp;</td><td class='menu'>&nbsp;</td><td class='menu'>&nbsp;</td></tr>");
				}
				if(chc>0)
				{
					for(c3=1;c3<=chc;c3=c3+1)
					{
						doc.write("<tr><td class='menu'>");
						doc.write(icon_clear);
						doc.write(icon_clear);
						doc.write(icon_clear);
						doc.write(icon_folderclosed);
						t = ttlms_connect.course_array[c1][c2][c3];
						t = t.split(";");
						doc.write("&nbsp;<a href='javascript:ttlms_connect.LaunchLesson(" + t[0] + ",1);' class='hilite'>" + t[1] + "</a>");
						doc.write("</td><td align='right' class='menu'>");
						doc.write(GetProgress(t[0]));
						doc.write("</td><td align='center' class='menu'>");
						doc.write(GetTestLink(t[0]));
						doc.write("</td><td align='right' class='menu'>");
						doc.write(GetScore(t[0]));
						doc.write("</td></tr>");
					}
				}
			}
		}
	}
	if(ttlms_connect.course_tests[0]>0)
	{
		doc.write("<tr><td class='menu'>");
		doc.write("<b>Mastery Test</b>");
		doc.write("</td>");
		doc.write("<td class='menu'>&nbsp;</td>");
		doc.write("<td align='center' class='menu'>");
		doc.write("<a href='javascript:ttlms_connect.LaunchTest(0);' class='hilite'>Take</a>");
		doc.write("</td>");
		doc.write("<td class='menu'>");
		doc.write(GetScore(0));
		doc.write("</td>");
		doc.write("</tr>");
	}
	doc.write("</table>");	
	
	if(course_discussion==1)
	{
	 doc.write("<p><b>Discussions:</b><a href=\"JavaScript:ttlms_connect.DoTopicOutside();\">Check for Topics</a></p>");
	}

	BuildMenuBottom(doc);
}

function GetProgress(l)
{
	if(ttlms_connect.course_progress[l]==undefined)
		ttlms_connect.course_progress[l]=0;
	return(ttlms_connect.course_progress[l] + "%");
}

function GetScore(l)
{
	if( (!isUndefined(ttlms_connect.course_testscores[l])) && (!isUndefined(ttlms_connect.course_tests[l])) && (ttlms_connect.course_tests[l]>0)  && (ttlms_connect.course_testscores[l]>0) )
		return(ttlms_connect.course_testscores[l] + "%");
	else
		return("&nbsp;");
}

function GetTestLink(l)
{
	if(ttlms_connect.course_tests[l]>0)
		return("<a href='javascript:ttlms_connect.LaunchTest(" + l + ");' class='hilite'>Take</a>");
	else
		return("&nbsp;");
}


// ********************************************* SCREEN

function ShowScreen()
{ // ExportLive
	if(location_order>0 && location_screen>0 && isArray(screens_array[location_order]))
	{
	// mark progress
	p = course_progress[location_order];
	if(p==undefined)
		p=0;
	pnow = Math.round(location_screen*100/screens_array[location_order].length);
	if(completionIs==3)
		pnow=100;
	if(pnow > p)
		course_progress[location_order] = pnow;
	// load screen
	// self.frames["course_body"].document.frames["lesson_content"].document.location = "../screens/" + screens_array[location_order][location_screen-1] + ".htm";
	S_ID = screens_array[location_order][location_screen-1];
	FN = screens_filename[S_ID];
	if(ExportLive == 0)
		self.frames["course_body"].frames["lesson_content"].location = "../screens/" + FN + ".htm";
	else
		//ExportLive
		self.frames["course_body"].frames["lesson_content"].location = "../screens/exportlive_screen.cfm?S_ID=" + S_ID;
	}
}

function BuildScreenTop(doc)
{
	ttlms_connect.BuildScreenLocation(doc);
	doc.write("<table border=0 width='100%' height='100%' cellpadding='8' cellspacing='0' class='full'><tr><td valign='top'>");
	if(headerShow)
		doc.write("<h2>"+ ttlms_connect.screens_titles[ttlms_connect.S_ID] +"</h2>");
}

function BuildScreenBottom(doc)
{
	doc.write("</td></tr></table></body></form>");
}

// ********************************************* SCREEN NAV

function BuildAICCButton(doc)
{
//	if(ttlms_connect.LMS==1)
//	{
		doc.write("<A href=\"javascript:ttlms_connect.UniversalExit();\" onmouseout=\"MM_swapImgRestore();\" onmouseover=\"MM_swapImage('previous','','../interface/n_exit1.gif',1);\">");
		doc.write("<IMG border=0 height=28 name=previous src=\"../interface/n_exit.gif\" width=78>");
		doc.write("</A>");
//	}

//	if(ttlms_connect.LMS==3)
//	{
//		doc.write("<A href=\"javascript:ttlms_connect.SaveExportLiveData();\" onmouseout=\"MM_swapImgRestore();\" onmouseover=\"MM_swapImage('previous','','../interface/n_exit1.gif',1);\">");
//		doc.write("<IMG border=0 height=28 name=previous src=\"../interface/n_exit.gif\" width=78>");
//		doc.write("</A>");
//	}

}

function ScreenBack()
{
	location_screen = location_screen - 1;
	if(location_screen==0 || !isArray(screens_array[location_order]))
	{
		location_order = location_order - 1;
		if(location_order==0)
			LaunchMenu();
		else
		{
			if(!isArray(screens_array[location_order]))
				location_screen = 1;
			else
				location_screen = screens_array[location_order].length;
			ShowScreen();
		}
	}
	else
		ShowScreen();
}

function ScreenNext()
{
	location_screen = location_screen + 1;
	if(!isArray(screens_array[location_order]) || location_screen>screens_array[location_order].length)
	{
		location_order = location_order + 1;
		if(location_order>=screens_array.length)
		{
			if(course_tests[0] > 0)
			{
				if(confirm("This is the last page of course content. Do you want to take the mastery test?"))
					LaunchTest(0);
				else
					LaunchMenu();
			}
			else
				LaunchMenu();
		}
		else
		{
			location_screen = 1;
			ShowScreen();
		}
	}
	else
		ShowScreen();
}

// ********************************************* SCREEN LOCATION MENU

function BuildScreenLocation(doc)
{

	if(location_order>0 && location_screen>0)
	{
		// Find location in course
		var f1=0;
		var f2=0;
		var f3=0;
		var f1_name="";
		var f2_name="";
		var f3_name="";
		var u = ttlms_connect.course_array.length-1;
	
		if(u>0)
		{
			for(c1=1;c1<=u;c1=c1+1)
			{
				if(!isArray(ttlms_connect.course_array[c1]))
					t = ttlms_connect.course_array[c1];
				else
					t = ttlms_connect.course_array[c1][0];
				t = t.split(";");
				if(t[0]<=location_order)
				{
					f1=c1;
					f1_name=t[1];
				}
			}
			if(isArray(ttlms_connect.course_array[f1]))
			{
				u = ttlms_connect.course_array[f1].length-1;
				for(c2=1;c2<=u;c2=c2+1)
				{
					if(!isArray(ttlms_connect.course_array[f1][c2]))
						t = ttlms_connect.course_array[f1][c2];
					else
						t = ttlms_connect.course_array[f1][c2][0];
					t = t.split(";");
					if(t[0]<=location_order)
					{
						f2=c2;
						f2_name=t[1];
					}
				}
				if(isArray(ttlms_connect.course_array[f1][f2]))
				{
					u = ttlms_connect.course_array[f1][f2].length-1;
					for(c3=1;c3<=u;c3=c3+1)
					{
						t = ttlms_connect.course_array[f1][f2][c3];
						t = t.split(";");
						if(t[0]==location_order)
						{
							f3=c3;
							f3_name=t[1];
						}
					}
				}
			}

		
			switch(jumpmenu_type)
			{
				case 0:
				{	// NO location
					break;
				}
				case 1:
				{	// old location menu
					doc.write("<TABLE class='loc' cellPadding=3 cellSpacing=0 height=40 width='100%'>");
					doc.write("<tr><!-- Show Module -->");
					doc.write("<th class='loc' width='*' align='left' nowrap>");
					doc.write("<img src='../interface/module.gif' width='44' height='10' alt='' border='0'>");
					doc.write("</th>");
					if(f2>0)
					{
						doc.write("<th class='loc' width='*' align='left' nowrap><!-- Show Lesson -->");
						doc.write("<img src='../interface/lesson.gif' width='44' height='10' alt='' border='0'>");
						doc.write("</th>");
					}
					if(f3>0)
					{
						doc.write("<th class='loc' width='*' align='left' nowrap><!-- Show Chapter -->");
						doc.write("<img src='../interface/chapter.gif' width='52' height='10' alt='' border='0'>");
						doc.write("</th>");
					}
					doc.write("<th class='loc' width='*' align='right' nowrap>");
					doc.write("<img src='../interface/screen.gif' width='44' height='10' alt='' border='0'>");
					doc.write(grx_nums(location_screen,'../interface'));
					doc.write("<img src='../interface/of.gif' width='19' height='10' alt='' border='0'>");
					doc.write(grx_nums(screens_array[location_order].length,'../interface'));
					doc.write("</th>");
					doc.write("</tr>");
				
					doc.write("<tr><!-- Show Module -->");
					doc.write("<th class='loc' width='*' align='left' nowrap>");
				
					doc.write("<FORM target='_top' action='#' method='get' name='parent2_jump'>");
					doc.write("<SELECT name='L_ID' onchange='ttlms_connect.LaunchLesson(options[selectedIndex].value,1);' class='iloc'>");
					var u = ttlms_connect.course_array.length-1;
					if(u>0)
					{
						for(c1=1;c1<=u;c1=c1+1)
						{
							if(!isArray(ttlms_connect.course_array[c1]))
								t = ttlms_connect.course_array[c1];
							else
								t = ttlms_connect.course_array[c1][0];
							t = t.split(";");
							doc.write("<OPTION value='" + t[0] + "' " + ((f1==c1)?"selected":"") + ">" + t[1] + "</OPTION>");
						}
					}
					doc.write("</SELECT>");
					doc.write("</th>");
					if(f2>0)
					{
						doc.write("<th class='loc' width='*' align='left' nowrap><!-- Show Lesson -->");
						doc.write("<SELECT name='L_ID' onchange='ttlms_connect.LaunchLesson(options[selectedIndex].value,1);' class='iloc'>");
						var u = ttlms_connect.course_array[f1].length-1;
						if(u>0)
						{
							for(c2=1;c2<=u;c2=c2+1)
							{
								if(!isArray(ttlms_connect.course_array[f1][c2]))
									t = ttlms_connect.course_array[f1][c2];
								else
									t = ttlms_connect.course_array[f1][c2][0];
								t = t.split(";");
								doc.write("<OPTION value='" + t[0] + "' " + ((f2==c2)?"selected":"") + ">" + t[1] + "</OPTION>");
							}
						}
						doc.write("</SELECT>");
						doc.write("</th>");
					}
					if(f3>0)
					{
						doc.write("<th class='loc' width='*' align='left' nowrap><!-- Show Chapter -->");
						doc.write("<SELECT name='L_ID' onchange='ttlms_connect.LaunchLesson(options[selectedIndex].value,1);' class='iloc'>");
						var u = ttlms_connect.course_array[f1][f2].length-1;
						if(u>0)
						{
							for(c3=1;c3<=u;c3=c3+1)
							{
								t = ttlms_connect.course_array[f1][f2][c3];
								t = t.split(";");
								doc.write("<OPTION value='" + t[0] + "' " + ((f3==c3)?"selected":"") + ">" + t[1] + "</OPTION>");
							}
						}
						doc.write("</SELECT>");
						doc.write("</th>");
					}
					doc.write("<th class='loc' width='*' align='right' nowrap>");
					doc.write("<SELECT name='L_ID' onchange='ttlms_connect.LaunchLesson(0,options[selectedIndex].value);' class='iloc'>");
					var s = ttlms_connect.screens_array[location_order].length;
					if(s>0)
					{
						for(c=0;c<s;c=c+1)
						{
							tn = ttlms_connect.screens_array[location_order][c];
							t = ttlms_connect.screens_titles[tn];
							doc.write("<OPTION value='" + (c+1) + "' " + ((location_screen==(c+1))?"selected":"") + ">" + t + "</OPTION>");
						}
					}
					doc.write("</SELECT>");
					doc.write("</th>");
					doc.write("</tr>");
					doc.write("</table>");
					break;
				}
				case 3:
				{	// New location pulldowns
					doc.write("<TABLE class='loc' cellPadding=3 cellSpacing=0 height=40 width='100%'>");
				
					doc.write("<tr><!-- Show Module -->");
					doc.write("<th class='loc' width='*' align='left' nowrap>");
					
					doc.write("<p align=\"left\">");
					doc.write(f1_name);
					if(f2_name!="")
					{
						doc.write(": ");
						doc.write(f2_name);
					}
					if(f3_name!="")
					{
						doc.write(": ");
						doc.write(f3_name);
					}
					doc.write("</p>");

					doc.write("</th>");

					doc.write("<th class='loc' width='*' align='right' nowrap>");
					//doc.write("<img src='../interface/screen.gif' width='44' height='10' alt='' border='0'>");

					//doc.write(grx_nums(location_screen,'../interface'));
					//doc.write("<img src='../interface/of.gif' width='19' height='10' alt='' border='0'>");
					//doc.write(grx_nums(screens_array[location_order].length,'../interface'));

					doc.write("<SELECT name='L_ID' onchange='if(options[selectedIndex].value!=0){ttlms_connect.LaunchLesson(options[selectedIndex].value,1);}' class='iloc'>");
					doc.write("<option value='0' selected>Menu Jump...</option>");
					var u = ttlms_connect.course_array.length-1;
					if(u>0)
					{
						for(c1=1;c1<=u;c1=c1+1)
						{
							var hasChild=1;
							if(!isArray(ttlms_connect.course_array[c1]))
							{
								t = ttlms_connect.course_array[c1];
								hasChild=0;
							}
							else
							{
								t = ttlms_connect.course_array[c1][0];
								hasChild=1;
							}
							t = t.split(";");
							
							doc.write("<option value=\"");
							doc.write(t[0]);
							doc.write("\" ");
							doc.write("class=\"");
							if(hasChild==1)
									doc.write("parent");
							else
								if(t[0]==location_order)
										doc.write("current");
								else
									if(course_progress[t[0]]==100)
										doc.write("complete");
									else
										doc.write("incomplete");
							doc.write("\">");
							doc.write(t[1]);
							doc.write("</option>");
							
							if(hasChild==1)
							{
								doc.write("<ul style='z-index: 2;'>");
								var u2 = ttlms_connect.course_array[c1].length-1;
								if(u2>0)
								{
									for(c2=1;c2<=u2;c2=c2+1)
									{
										var hasChild2=1;
										if(!isArray(ttlms_connect.course_array[c1][c2]))
										{
											t = ttlms_connect.course_array[c1][c2];
											hasChild2=0;
										}
										else
										{
											t = ttlms_connect.course_array[c1][c2][0];
											hasChild2=1;
										}
										t = t.split(";");

										doc.write("<option value=\"");
										doc.write(t[0]);
										doc.write("\" ");
										doc.write("class=\"");
										if(hasChild2==1)
												doc.write("parent");
										else
											if(t[0]==location_order)
													doc.write("current");
											else
												if(course_progress[t[0]]==100)
													doc.write("complete");
												else
													doc.write("incomplete");
										doc.write("\">-&gt;");
										doc.write(t[1]);
										doc.write("</option>");

										
										if(hasChild2==1)
										{
											doc.write("<ul style='z-index: 3;'>");
											var u3 = ttlms_connect.course_array[c1][c2].length-1;
											if(u3>0)
											{
												for(c3=1;c3<=u3;c3=c3+1)
												{
													t = ttlms_connect.course_array[f1][f2][c3];
													t = t.split(";");
													doc.write("<option value=\"");
													doc.write(t[0]);
													doc.write("\" ");
													doc.write("class=\"");
													if(t[0]==location_order)
															doc.write("current");
													else
													{
														if(course_progress[t[0]]==100)
															doc.write("complete");
														else
															doc.write("incomplete");
													}
													doc.write("\">-=&gt;");
													doc.write(t[1]);
													doc.write("</option>");

												}
											}
										}
									}
								}
							}
						}
					}
					doc.write("</SELECT>");
					doc.write("</th>");
					doc.write("</tr>");
					doc.write("</table>");
					break;
				}
			}
		}
	}
}


// ********************************************* SCREEN AUDIO

function BuildScreenAudio(doc)
{
	doc.write("<h4>");
	doc.write("Audio Script");
	doc.write("</h4>");
	doc.write("<p>");
	doc.write(screens_audio_script[S_ID]);
	doc.write("</p>");
}

function BuildAudioButton(doc)
{
	if(ttlms_connect.audio_script == 1)
	{
		doc.write("<a href=\"javascript:ttlms_connect.DoAudioScript();\">");
		doc.write("<font color=\"#ffffff\">Audio Script</font>");
		doc.write("</A>");
	}
}

function DoAudioScript()
{
	var w = window;
	var pos = screens_popup_size[S_ID];
	pos = pos.split(",");
	var	w = window.open('../screens/screen_audio.htm','Audio_Script','scrollbars=yes,resizable=yes,width=' + pos[2] + ',height=' + pos[3]);
}


// ********************************************* SCREEN POPUP

function BuildScreenPopupTop(doc)
{
	doc.write("");
}

function BuildScreenPopupBottom(doc)
{
	doc.write("<p align=\"center\"><a href=\"#\" OnClick=\"window.close();\"><b>Close</b></a></p>");
}

function DoMore(theM,theS,MoreInfoMediaOnly,MoreInfoSizes)
{ // ExportLive
	var w = window;
	var pos = screens_popup_size[S_ID];
	var FN = screens_filename[S_ID];
	var m;
	var s;
	var x;
	var y;
	var f;

	z = pos.split(",");
	if(theM!=undefined)
		m=theM;
	else
		m=1;
	if(theS!=undefined)
		s=theS;
	else
		s=MoreInfoSizes[m];
	x=z[(s*2)];
	y=z[(s*2)+1];
	if(ExportLive == 0)
	{
		f= FN + '_' + theM + '.htm';
		if(MoreInfoMediaOnly[m]!="")
			f="../media/" + C_ID + "/" + MoreInfoMediaOnly[m];
		w = window.open(f,'MoreInfo','scrollbars=yes,resizable=yes,width=' + x + ',height=' + y);
	}
	else
	{
		//ExportLive
		f= 'exportlive_popup.cfm?S_ID=' + S_ID + '&more=' + m;
		if(MoreInfoMediaOnly[m]!="")
			f="../media/" + C_ID + "/" + MoreInfoMediaOnly[m];
		w = window.open(f,'MoreInfo','scrollbars=yes,resizable=yes,width=' + x + ',height=' + y);
	}
	if(isObject(w))
		w.focus();
} 

function DoLink(theLink,theS)
{
	var w = window;
	var pos=screens_popup_size[S_ID];
	pos = pos.split(",");
	if(theS==1)
		w = window.open(theLink,'Link','scrollbars=yes,menubar=yes,resizable=yes,width=' + pos[0] + ',height=' + pos[1]);
	if(theS==2)
		w = window.open(theLink,'Link','scrollbars=yes,menubar=yes,resizable=yes,width=' + pos[2] + ',height=' + pos[3]);
	if(theS==3)
		w = window.open(theLink,'Link','scrollbars=yes,menubar=yes,resizable=yes,width=' + pos[4] + ',height=' + pos[5]);
	if(theS==4)
		w = window.open(theLink,'Link','scrollbars=yes,menubar=yes,resizable=yes,width=' + pos[6] + ',height=' + pos[7]);
	if(theS==5)
		w = window.open(theLink,'Link','scrollbars=yes,menubar=yes,resizable=yes,width=' + pos[8] + ',height=' + pos[9]);
	w.focus();
}


// ********************************************* TEST

function 		ShowTestQuestion(doc)
{
	var tcol=0;
	
	if(test_question==0)
	{
			doc.write("<table cellpadding='4'><tr><td>");
			doc.write("<p>&nbsp;</p>");
			doc.write("<p>The following screens contain questions that will test your knowledge of the subject matter. ");
			doc.write("For each question, click the button next to the correct answer and then click the 'Next' button. You can navigate the questions using either the 'Next' button, the 'Previous' button, or by clicking on a question number above. Your current question will appear in bold.</p>");
			doc.write("<p>When you have completed the test, click the 'Done' button to score your test.</p>");
			doc.write("<p>Scores less than " + test_passing + "% are not considered passing and will not be recorded in your record.</p>");
			doc.write("<p>Click 'Next' to begin the test.</p>");
			doc.write("</td></tr></table>");
	}
	else
	{
		// quick-jump
		doc.write("<p align='center'><br><b>Question:</b>");
		for(c=0;c < (questions_sub.length);c=c+1)
		{
			if(test_question==(c+1))
				doc.write("&nbsp;<b>" + (c+1) + "</b>&nbsp;");
			else
				doc.write("&nbsp;<a href='javascript:ttlms_connect.TestJump(" + (c+1) + ");'>" + (c+1) + "</a>&nbsp;");
		}
		doc.write("&nbsp;&nbsp;<a href='javascript:ttlms_connect.LoadTestResults();'><b>Done</b></a>");
		doc.write("</p>");

	 	doc.write("<table cellpadding='4'><tr><td><p>&nbsp;</p>");
		
		refQText = questions_all[questions_sub[test_question-1]];
		theMedia = refQText[14];
		theMediaTag = refQText[15];
		theCAns = refQText[11];
		theFeedback = refQText[13];
		abc = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
			if(theMedia!="")
		{
			theMediaType=theMedia.substring(theMedia.length-3).toUpperCase();
			if(theMediaType == "JPG" || theMediaType == "GIF" || theMediaType == "PNG")
				doc.write("<img src='../media/"+C_ID+"/"+theMedia+"' "+ theMediaTag +" border='0'>");
			else
				doc.write("<embed src='../media/"+C_ID+"/"+theMedia+"' "+ theMediaTag +" border='0'></embed>");
			doc.write("</td><td>");
		}

		doc.write("<p><b>" + refQText[0] +"</b></p>");
		doc.write("<table border='0' width='100%'>");
		
		for(c=1;c<11;c=c+1)
		if(refQText[c]!="")
			{
			doc.write("<tr><td align='center' valign='top'>");
			doc.write("<input type='radio' name='A' value='"+ c +"' id='A_"+ c +"'");
			if(test_answers[test_question-1]==c)
				doc.write(" checked ");
			if(test_done==2)
			{
				doc.write(" disabled ");
			}
			doc.write(" onclick='ttlms_connect.TestAnswer("+ c +");'>");
			doc.write("<td align='left' valign='top'>");
			doc.write("<label for='A_"+ c +"'>");
			doc.write("<b>");
			doc.write(abc.substring(c-1,c))
			doc.write(".</b></label></td><td width='100%'>");
			doc.write("<label for='A_"+ c +"'>");
			tcol = 0; // 0=plain, 1=wrong, 2=right
			if(test_done==2)
			{
				if(test_answers[test_question-1]==c)
					tcol=1;
				if( (theCAns==c) && (always_show_correct==1) ) 
					tcol=1;
				if( (theCAns==test_answers[test_question-1]) && (theCAns==c) )
					tcol=2;

				if(tcol==1)
					doc.write("<font color=red>");
				if(tcol==2)
					doc.write("");
			}
			doc.write(refQText[c]);
			if(test_done==2 && ( (test_answers[test_question-1]==c) || (theCAns==c) ))
				doc.write("</font> ");
			doc.write("</label>");
			if(theCAns==c && test_done==2 && ( always_show_correct || (test_answers[test_question-1]==c) ) )
				doc.write(" <font color=green>(Correct Answer)</font> ");
			doc.write("<br>");
			doc.write("</td></tr>");
			}
		doc.write("</table>");
		doc.write("</td></tr></table>");
		
		if( (test_done==2) && (theFeedback!="") )
			// 0= no feedback, 1 = always show feedback, 2 = Only if correct, 3 = Only if Incorrect
			if( (posttest_showfeedback == 1) || (posttest_showfeedback == 2 && theCAns==test_answers[test_question-1]) || (posttest_showfeedback == 2 && theCAns!=test_answers[test_question-1]) );
			{
				doc.write("<p>&nbsp;</p>");
				doc.write("<p>" + theFeedback + "</p>");
			}
	}
}

function 		ShowTestResults(doc)
{

	if(test_done==0)
	{
		qgood=0;
		for(c=0;c < (questions_sub.length);c=c+1)
		{
			if(test_answers[c]==questions_all[questions_sub[c]][11])
				qgood=qgood+1;
		}
		finalscore=Math.round(qgood/questions_sub.length*100);
		
		pt=course_testscores[location_order];
		if(pt==undefined)
			pt=0;
	
		if(pt<finalscore && finalscore>=test_passing)
			course_testscores[location_order]=finalscore;
		
	}
	test_done = 1;
	test_question = 1;
	var ptq=posttest_questions;
	var ptc=posttest_content;
	var ptt=posttest_retake;
	doc.write("<p>&nbsp;</p>");
	doc.write("<p align='center'><br>Final Score: " + finalscore + "% (" + qgood + " out of " + questions_sub.length + ")<br><br></p>");
	if(finalscore>=test_passing)
	{
		doc.write("<p align='center'>You have passed the test.</p>");
		doc.write("<p align='center'>");
		if(finalscore>=test_passing && LMS==1)
			doc.write("Please click the 'Post Status to Training Server' button below in order for your score to be recorded. Click the 'Review Test' button to review the questions and your answers. ");
		if(ptq > 0)
			doc.write("Click the 'Review Test' button to review the questions and your answers. ");
		doc.write("</p>");
		if(posttest_questions==2)
			ptq=1;
		if(posttest_content==2)
			ptc=0;
		if(posttest_retake==2)
			ptt=0;
	}
	else
	{
		doc.write("<p align='center'>You have not completed the requirement for this course.<br>Please review the material and try again.<br>&nbsp;<br>Click the 'Close Test' button to return to the menu.</p>");
		if(posttest_questions==2)
			ptq=0;
		if(posttest_content==2)
			ptc=1;
		if(posttest_retake==2)
			ptt=1;
	}
	doc.write("<form><p align='center'>");
	if(ptq)
		doc.write("<input type='Button' class='ibutton' value='Review Test' onclick='ttlms_connect.LoadTestReviewQuestion();'>");
	if(ptc)
		doc.write("<input type='Button' class='ibutton' value='Review Content' onclick='ttlms_connect.LaunchLesson(1,1);'>");
	if(ptt)
		doc.write("<input type='Button' class='ibutton' value='Retake Test' onclick='ttlms_connect.LaunchTest(" + location_order + ");'>");
	if(finalscore>=test_passing && LMS==1)
		doc.write("<input type='button' value='Post Status to Training Server' class='ibutton' onclick='ttlms_connect.SaveAICCData();'>");
	else
		doc.write("<input type='Button' class='ibutton' value='Close Test' onclick='ttlms_connect.LaunchMenu();'>");
	// Save ExportLive
	if(finalscore>=test_passing && LMS==3)
		doc.write("<input type='button' value='Save Completion' class='ibutton' onclick='ttlms_connect.SaveExportLiveData();'>");

	doc.write("</p></form>");
}

function TestAnswer(c)
{
	test_answers[test_question-1]=c;
}

function	DoLinkQ(n)
{
	refQText = questions_all[questions_sub[test_question-1]];
	theL1 = refQText[17];
	theL2 = refQText[18];
	if(n==1)
		w=MM_openBrWindow(theL1,"Link","width=600,height=500,scrollbars=yes,resizable=yes,menubar=yes");
	if(n==2)
		w=MM_openBrWindow(theL2,"Link","width=600,height=500,scrollbars=yes,resizable=yes,menubar=yes");
}

function	DoMoreQ(n)
{
	refQText = questions_all[questions_sub[test_question-1]];
	theQID = refQText[19];
		w=MM_openBrWindow("../screens/Q_" + theQID + "_" + n + ".htm","Link","width=600,height=500,scrollbars=yes,resizable=yes");
}

// ********************************************* TEST NAV

function TestJump(q)
{
	test_question = q;
	if(test_done==0)
	{
		LoadTestQuestion();
	}
	if(test_done==2)
	{
		LoadTestReviewQuestion();
	}
}

function TestBack()
{
	if(test_done==0)
	{
		test_question = test_question - 1;
		if(test_question<0)
			LaunchMenu();
		else
			LoadTestQuestion();
	}
	if(test_done==2)
	{
		test_question = test_question - 1;
		if(test_question==0)
			LoadTestResults();
		else
			LoadTestReviewQuestion();
	}

}

function TestNext()
{
	if(test_done==0)
	{
		test_question = test_question + 1;
		if(test_question>questions_sub.length)
			LoadTestResults();
		else
			LoadTestQuestion();
	}
	if(test_done==2)
	{
		test_question = test_question + 1;
		if(test_question>questions_sub.length)
			LoadTestResults();
		else
			LoadTestReviewQuestion();
	}
}

// ********************************************* DATA EXPORTLIVE

function LoadExportLiveData()
{ // ExportLive
	alert("LoadExportLiveData()");
}

function SaveExportLiveData()
{ // ExportLive
	//document.body.rows="100,*";
	self.frames["course_head"].document.location="../screens/screen_blank.htm";
	self.frames["course_body"].document.location="../menu/exportlive_save.cfm?course_progress="+escape(course_progress)+"&course_testscores="+escape(course_testscores);
}

function EditScreen()
{ // ExportLive
	var w;
	var h;
	h = document.location.host;
	w=window.open("http://" + h + "/courseedit/s_edit.cfm?S_ID=" + S_ID + "&CloseMe=1","EditScreen","scrollbars=yes,resizable=yes,top=0,left=0,width=" + (screen.availWidth-10) + ",height=" + (screen.availHeight-25));
	w.focus();
}

function EditMedia()
{ // ExportLive
	var w;
	var h;
	h = document.location.host;
	w=window.open("http://" + h + "/courseedit/media.cfm?C_ID=" + C_ID,"DoMM","scrollbars=yes,resizable=yes,top=0,left=0,width=" + (screen.availWidth-10) + ",height=" + (screen.availHeight-25));
	w.focus();
}


function ShowEditBtns(doc)
{ // ExportLive
	if(ttlms_connect.ShowEdit)
	{
		doc.writeln("<br clear=\"all\">");
		doc.writeln("<input type=\"Button\" onclick=\"ttlms_connect.EditScreen();\" value=\"Edit Screen\">");
		doc.writeln("<input type=\"Button\" onclick=\"ttlms_connect.EditMedia();\" value=\"Media Manager\">");
		doc.writeln("<input type=\"Button\" onclick=\"ttlms_connect.ReloadScreen();\" value=\"Refresh\">");
		var s = ttlms_connect.screens_array[location_order].length;
		for(c=1;c<=s;c=c+1)
			doc.writeln("<a href=\"javascript:ttlms_connect.LaunchLesson(0," + c + ");\">" + c + "</a>");
	}
}

function ReloadScreen()
{ // ExportLive
	self.frames["course_body"].frames["lesson_content"].location.reload(); 
}

// ********************************************* GENERAL

function QueryString() {
  var oQuery = new Object();
  var sSearch = self.location.search.substring(1);
  if (sSearch.length > 0) {
    var asKeyValues = sSearch.split('&');
    var asKeyValue = '';
    for (var i = 0; i < asKeyValues.length; i++) {
      asKeyValue = asKeyValues[i].split('=');
      oQuery[asKeyValue[0]] = asKeyValue[1];
    }
 } return oQuery;
}

function maximizeWin() {
  if (top.window.screen) {
    var aw = top.window.screen.availWidth;
    var ah = top.window.screen.availHeight;
		var at = 0;
		var al = 0;
		if(aw>1024)
		{
			al = ((aw-1024)/2);
			aw = 1024;
		}
		if(ah>800)
		{
			at = ((ah-800)/2);
			ah = 800;
		}
    top.window.moveTo(al, at);
    top.window.resizeTo(aw, ah);
  }
}

function	grx_nums(theN,theInterface)
{
	var theOut="";
	var N2=theN.toString();
	if(theN > 0)
	{
		for(c=0;c < N2.length;c=c+1)
		{
			NT=N2.charAt(c);
			theOut = theOut + "<img src='" + theInterface + "/" + NT + ".gif' border='0' width='7' height='10'>";
		}
	}
	else
	{
		theOut = "<img src='" + theInterface + "/" + "0" + ".gif' border='0' width='7' height='10'>";
	}
	return(theOut);
}

function isArray(a) {
    return isObject(a) && a.constructor == Array;
}

function isBoolean(a) {
    return typeof a == 'boolean';
}

function isEmpty(o) {
    var i, v;
    if (isObject(o)) {
        for (i in o) {
            v = o[i];
            if (isUndefined(v) && isFunction(v)) {
                return false;
            }
        }
    }
    return true;
}

function isFunction(a) {
    return typeof a == 'function';
}

function isNull(a) {
    return typeof a == 'object' && !a;
}

function isNumber(a) {
    return typeof a == 'number' && isFinite(a);
}

function isObject(a) {
    return (a && typeof a == 'object') || isFunction(a);
}

function isString(a) {
    return typeof a == 'string';
}

function isUndefined(a) {
    return typeof a == 'undefined';
} 

function trim(t)
{
	var rt = t.replace(/(^\s*)|(\s*$)/g,'');
	return rt;
};
function replaceNewLineChars(replacement)
{
	return this.replace(/\n/g,replacement);
};

// LEFT RIGHT FUNCTIONS ADDED

function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

// Randomize a given array

function rndArray(myArray)
{
  var i = myArray.length;
  if ( i == 0 ) return false;
  while ( --i )
	{
     var j = Math.floor( Math.random() * ( i + 1 ) );
     var tempi = myArray[i];
     var tempj = myArray[j];
     myArray[i] = tempj;
     myArray[j] = tempi;
   }
}

/*
WM_setCookie(), WM_readCookie(), WM_killCookie()
A set of functions that eases the pain of using cookies.
Source: Webmonkey Code Library
(http://www.hotwired.com/webmonkey/javascript/code_library/)
Author: Nadav Savio
Author Email: nadav@wired.com
*/
// This next little bit of code tests whether the user accepts cookies.
var WM_acceptsCookies = false;
if(document.cookie == '') {
    document.cookie = 'WM_acceptsCookies=yes'; // Try to set a cookie.
    if(document.cookie.indexOf('WM_acceptsCookies=yes') != -1) {
	WM_acceptsCookies = true; 
    }// If it succeeds, set variable
} else { // there was already a cookie
  WM_acceptsCookies = true;
}
function WM_setCookie (name, value, hours, path, domain, secure) {
    if (WM_acceptsCookies) { // Don't waste your time if the browser doesn't accept cookies.
	var not_NN2 = (navigator && navigator.appName 
		       && (navigator.appName == 'Netscape') 
		       && navigator.appVersion 
		       && (parseInt(navigator.appVersion) == 2))?false:true;

	if(hours && not_NN2) { // NN2 cannot handle Dates, so skip this part
	    if ( (typeof(hours) == 'string') && Date.parse(hours) ) { // already a Date string
		var numHours = hours;
	    } else if (typeof(hours) == 'number') { // calculate Date from number of hours
		var numHours = (new Date((new Date()).getTime() + hours*3600000)).toGMTString();
	    }
	}
	document.cookie = name + '=' + escape(value) + ((numHours)?(';expires=' + numHours):'') + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:'') + ((secure && (secure == true))?'; secure':''); // Set the cookie, adding any parameters that were specified.
    }
} // WM_setCookie
function WM_readCookie(name) {
    if(document.cookie == '') { // there's no cookie, so go no further
	return false; 
    } else { // there is a cookie
	var firstChar, lastChar;
	var theBigCookie = document.cookie;
	firstChar = theBigCookie.indexOf(name);	// find the start of 'name'
	var NN2Hack = firstChar + name.length;
	if((firstChar != -1) && (theBigCookie.charAt(NN2Hack) == '=')) { // if you found the cookie
	    firstChar += name.length + 1; // skip 'name' and '='
	    lastChar = theBigCookie.indexOf(';', firstChar); // Find the end of the value string (i.e. the next ';').
	    if(lastChar == -1) lastChar = theBigCookie.length;
	    return unescape(theBigCookie.substring(firstChar, lastChar));
	} else { // If there was no cookie of that name, return false.
	    return false;
	}
    }	
} // WM_readCookie
function WM_killCookie(name, path, domain) {
  var theValue = WM_readCookie(name); // We need the value to kill the cookie
  if(theValue) {
      document.cookie = name + '=' + theValue + '; expires=Fri, 13-Apr-1970 00:00:00 GMT' + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:''); // set an already-expired cookie
  }
} // WM_killCookie



/**************** STORAGE EXTRA CODE ****************/

/*************** FIREFOX ONLY. REPLACED WITH IE VERSION


function BuildAICCSave()
{

//	doc.writeln("<form method='post' action='" + LMS_data["aicc_url"] + "'  name='AICC_DATA'>");
//	doc.writeln("<input type='Hidden' name='command' value='putParam'>");
//	doc.writeln("<input type='Hidden' name='version' value='2.0'>");
//	doc.writeln("<input type='Hidden' name='session_id' value='" + LMS_data["aicc_url"] + "'>");
//	doc.write("<input type='Hidden' name='aicc_data' value='");

	r = "";
	cr = "\r";
	r = r + "[CORE]" + cr;

	stat=GetCourseComplete();
	if(stat==0)
		r = r + "Lesson_Status=I" + cr;
	else
		r = r + "Lesson_Status=F" + cr;

	r = r + "Lesson_Location=" + cr;
	r = r + "score=" + course_testscores[0] + cr;
	r = r + "time=" + cr;
	r = r + "[Core_Lesson]" + cr;
	r = r + "[Core_Vendor]" + cr;
	r = r + "[Objectives_status]" + cr;
	
	for(c=1;c<=course_units;c=c+1)
	{
		r = r + "j_id."+c+"=J"+c + cr;
		if(course_progress[c]==100)
			r = r + "j_status."+c+"=N" + cr;
		else
			r = r + "j_status."+c+"=C" + cr;
		if(course_testscores[c]!=undefined)
			r = r + "j_score."+c+"=" + course_testscores[c] + cr;
		else
			r = r + "j_score.1=0" + cr;
	}	
	return(r);
}


function AICC_CallBack(data, obj)
{
	//alert("AICC data: \n" + data);
	switch(AICC_call)
	{
	case "SaveData":
		{
			alert("SaveData Callback:\r\r" + data);
			break;
		}
	}
}

function SaveAICCData()
{
	alert("SaveAICCData");
	AICC_call="SaveData";
	AJAXRequestor = new DataRequestor();
	// point callback to custom function
	AJAXRequestor.onload = AICC_CallBack;
	// add in data
	AJAXRequestor.addArg(_POST, "command", "putParam");
//	AJAXRequestor.addArg(_POST, "version", "2.0");
//	AJAXRequestor.addArg(_POST, "session_id", LMS_data["aicc_sid"]);
//	AJAXRequestor.addArg(_POST, "aicc_data", BuildAICCSave());
	AJAXRequestor.addArg(_GET, "jktest", 12345);
	// send away
	AJAXRequestor.getURL(LMS_data["aicc_url"]);
}
***************/

/************* Menu Locator, SuckerFish ***********/
/****
				case 2:
				{	// DHTML locator menu
					doc.write("<div id=\"module\">");
					doc.write("<ul id=\"sfnav\">");
					doc.write("<li>");
					doc.write("<a href=\"javascript:ttlms_connect.LaunchMenu();\" onmouseout=\"MM_swapImgRestore()\" onmouseover=\"MM_swapImage('b_main','','../interface/b_main1.gif',1)\"><img src=\"../interface/b_main.gif\" alt=\"Main Menu\" name=\"b_main\" width=\"72\" height=\"24\" border=\"0\" id=\"b_main\" /></a>");
					doc.write("</li>");
					doc.write("<ul style='z-index: 1;'>");
					var u = ttlms_connect.course_array.length-1;
					if(u>0)
					{
						for(c1=1;c1<=u;c1=c1+1)
						{
							var hasChild=1;
							if(!isArray(ttlms_connect.course_array[c1]))
							{
								t = ttlms_connect.course_array[c1];
								hasChild=0;
							}
							else
							{
								t = ttlms_connect.course_array[c1][0];
								hasChild=1;
							}
							t = t.split(";");
							
							doc.write("<li><a href=\"javascript:ttlms_connect.LaunchLesson(" + t[0] + ",1)\"");
							if(hasChild==1)
								doc.write(" class=\"subarrow\"");
							else
								if(course_progress[t[0]]==100)
									doc.write(" class=\"complete\"");
								else
									doc.write(" class=\"incomplete\"");
							doc.write(">");
							doc.write(t[1]);
							doc.write("</a></li>");
							
							if(hasChild==1)
							{
								doc.write("<ul style='z-index: 2;'>");
								var u2 = ttlms_connect.course_array[c1].length-1;
								if(u2>0)
								{
									for(c2=1;c2<=u2;c2=c2+1)
									{
										var hasChild2=1;
										if(!isArray(ttlms_connect.course_array[c1][c2]))
										{
											t = ttlms_connect.course_array[c1][c2];
											hasChild2=0;
										}
										else
										{
											t = ttlms_connect.course_array[c1][c2][0];
											hasChild2=1;
										}
										t = t.split(";");
										doc.write("<li><a href=\"javascript:ttlms_connect.LaunchLesson(" + t[0] + ",1)\"");
										if(hasChild2==1)
											doc.write(" class=\"subarrow\"");
										else
											if(course_progress[t[0]]==100)
												doc.write(" class=\"complete\"");
											else
												doc.write(" class=\"incomplete\"");
										doc.write(">");
										doc.write(t[1]);
										doc.write("</a></li>");
										if(hasChild2==1)
										{
											doc.write("<ul style='z-index: 3;'>");
											var u3 = ttlms_connect.course_array[c1][c2].length-1;
											if(u3>0)
											{
												for(c3=1;c3<=u3;c3=c3+1)
												{
													t = ttlms_connect.course_array[f1][f2][c3];
													t = t.split(";");
													doc.write("<li><a href=\"javascript:ttlms_connect.LaunchLesson(" + t[0] + ",1)\"");
													if(course_progress[t[0]]==100)
														doc.write(" class=\"complete\"");
													else
														doc.write(" class=\"incomplete\"");
													doc.write(">");
													doc.write(t[1]);
													doc.write("</a></li>");
												}
											}
											doc.write("</ul>");
										}
									}
								}
								doc.write("</ul>");
							}
						}
					}
					doc.write("</ul>");
					doc.write("</ul>");
				
					doc.write("<h1 align=\"right\">");
					doc.write(f1_name);
					if(f2_name!="")
					{
						doc.write(": ");
						doc.write(f2_name);
					}
					if(f3_name!="")
					{
						doc.write(": ");
						doc.write(f3_name);
					}
					doc.write("</h1>");
					doc.write("</div>");
					break;
				}		
******/


