/*******************************************************************************
**
** FileName: HTMLwrapper_fscommand.js
**
*******************************************************************************/

// ! Start code that’s necessary for Flash to communicate to JavaScript through fscommands !
var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
// Handle all the FSCommand messages in a Flash movie.
function movie_DoFSCommand(command, args) {
	var movieObj = isInternetExplorer ? document.all.movie : document.movie;
	
	if (command == "alert") {
		window.alert(args);
	} else if (command == "closeWindow") {
		window.close();
	} else if (command == "loadPDF") {
		window.open(args, "_new");
	} else if (command == "deleteOldCookie") {
		deleteOldCookie();
	} else if (command == "setNewCookie") {
		setNewCookie(args);
	} else if (command == "loadCookie") {
		loadCookie();
	}
	
}
// Hook for Internet Explorer.
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	document.write('<script language=\"VBScript\"\>\n');
	document.write('On Error Resume Next\n');
	document.write('Sub movie_FSCommand(ByVal command, ByVal args)\n');
	document.write('	Call movie_DoFSCommand(command, args)\n');
	document.write('End Sub\n');
	document.write('</script\>\n');
}
// ! End code that’s necessary for Flash to communicate to JavaScript through fscommands !

function init()
{
	// DO NOTHING
	// function stub to allow easier transition between LMS/Cookie modes
}

function deleteOldCookie()
{
	var cookie = document.cookie;
	var the_date = new Date("Jan 8, 1980");
	var cookie_date = the_date.toGMTString();
    cookie = cookie + ";expires=" + cookie_date;
	/*cookie = cookie +";path=/;";*/
    document.cookie = cookie;
}

function setNewCookie(cookieDataFromFlash)
{
	var cookieData = cookieDataFromFlash;
	var cookie = "cookieData=" + cookieData;
	var the_date = new Date("December 31, 2070");
    var cookie_date = the_date.toGMTString();
    cookie = cookie + ";expires=" + cookie_date;
	/*cookie = cookie +";path=/;";*/
    document.cookie = cookie;
	document.movie.SetVariable("closeWindowToggle_str", "true");
}

function loadCookie()
{
	var cookieCheck = document.cookie;

	if ((cookieCheck == null) || (cookieCheck.indexOf("cookieData") < 0)) 
	{
		document.movie.SetVariable("lstopThis", "false");
	}
	else
	{ 
		var courseCookie = document.cookie;
		courseCookie = courseCookie.substring(courseCookie.indexOf("cookieData="), courseCookie.length);

		// If only one cookie value is present, don't check for seperating ;
		if(courseCookie.indexOf(";") >= 0)
		{
			courseCookie = courseCookie.substring(0, courseCookie.indexOf(";") + 1);
		}
		
		document.movie.SetVariable("whatToProcess", courseCookie);
		document.movie.SetVariable("lstopThis", "true");
	}
}

function Minimize() 
{
	window.blur();
	window.alwaysLowered = true;
}

