// Define exception/error codes
var _NoError = 0;
var _GeneralException = 101; 
var _InvalidArgumentError = 201;
var _NotInitialized = 301;
var _NotImplementedError = 401;

var rootPath = "http://www.apluslearn.com/"

var apiHandle = null;
var _Debug = false;
var soundFlag = true;
var formSubmitted = false;
var soundico = "/als/images/pb/toolbartextnew_02.gif";
var nosoundico = "/als/images/pb/toolbartextnewOff_02.gif";
var pbsoundico = "/als/images/pb/snd_on.gif";
var pbnosoundico = "/als/images/pb/snd_off.gif";
var ver4 = true;
var NS4 = null;
var contextrelpath = "/als"
var feedBackText = "Please enter your feedback. If you wish to be contacted about your feedback, enter your e-mail address and we will respond as soon as possible."
var feedBackFailed = "You must enter your feedback before you can continue."
var feedBackSuccess = "Thank you for your feedback."
var developmentSite = false;


var detect;
var OS = null;
var browser = null;
var version = null;
var total = null;
var thestring = null;
var mouseClicked = false;
var mouseClickedTime = 0;

window.onerror = errorHandler;


function catchScrollButton(event)
{
    if(event == null) 
    	event = window.parent.ContentFrame.event;
    if(event.button == 4)
	alert("The mouse wheel button functionality is disabled.");     
}

function getStyle(el,styleProp)
{
	try
	{
		var x = window.parent.ContentFrame.document.getElementById(el);
		if (window.parent.ContentFrame.document.defaultView)
			var y = window.parent.ContentFrame.document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
		else if (x.currentStyle)
			var y = eval('x.currentStyle.' + styleProp);
		return y;
        }catch (e)
        {
	 	errorHandler(e.message, "" ,"" , e.name, "alsutils.getStyle()");
        }
}

function enableLogin()
{
	try
	{
		setAppletLoaded(true) ;
		window.parent.ContentFrame.beginBrowserTesting() ;
	}
	catch (e)
	{
		//errorHandler(e.message, "" ,"" , e.name, "alsutils.enableLogin()");
		window.setTimeout( "enableLogin()", 500 ) ;
	}
}

function setAppletLoaded(bool)
{
	try
	{
		if(window.parent.LMSFrame.appletLoaded != null)
			window.parent.LMSFrame.appletLoaded = bool
        }catch (e)
        {
	 	errorHandler(e.message, "" ,"" , e.name, "alsutils.setAppletLoaded()");
        }
}

function launchStudyGuide()
{
	try
	{
		if(checkMouseClicked())
			return;				
		var done = false;
		if(window.parent.ContentFrame.document.ebForm.navbar != null)
		{
			window.parent.ContentFrame.document.ebForm.navbar.value = "showStudyGuide"
			window.parent.ContentFrame.document.ebForm.soundFlag.value = soundFlag
		}else
		{
			done = true;
			goNavbar('CommServlet?navbar=showStudyGuide&soundFlag=' + soundFlag + "&customerName=" + getCustomer())
		}

		if(window.parent.ContentFrame.document.ebForm.ebAnswer != null)
		{
			if(window.parent.ContentFrame.document.ebForm.ebAnswer.value == "" || window.parent.ContentFrame.document.ebForm.ebAnswer.disabled)
				window.parent.ContentFrame.document.ebForm.navbar2.value = ""
			var ebAnswers = window.parent.ContentFrame.document.getElementsByName("ebAnswer")
			for(var x=0; x<ebAnswers.length; x++)
			{
				if(ebAnswers[x].disabled)
				{
					window.parent.ContentFrame.document.ebForm.navbar2.value = ""
					break;
				}
			}				
		}
		if(window.ContentFrame.looptype == "study")
		{
			window.macapiframe.innerFrame = null;
			window.macapiframe.innerFrameParams = null;
			window.macapiframe.hasInnerFrame = false;
		}
		if(!done)
		{
			saveInnerFrameState(); 
			initMouseClicked()
			window.parent.ContentFrame.document.ebForm.submit();
		}
        }catch (e)
        {
	 	errorHandler(e.message, "" ,"" , e.name, "alsutils.launchStudyGuide()");
        }
}

function NavPrevious(navbar2)
{
	try
	{
		if(checkMouseClicked())
			return;		
		var done = false;
		if(window.parent.ContentFrame.document.ebForm.navbar != null)
		{
			window.parent.ContentFrame.document.ebForm.navbar.value = "previousPage"
			window.parent.ContentFrame.document.ebForm.soundFlag.value = soundFlag
		}else
		{
			done = true;
			goNavbar('CommServlet?navbar=previousPage&soundFlag=' + soundFlag + "&customerName=" + getCustomer())
		}

		if(window.parent.ContentFrame.document.ebForm.ebAnswer != null)
		{
			if(window.parent.ContentFrame.document.ebForm.ebAnswer.value == "" || window.parent.ContentFrame.document.ebForm.ebAnswer.disabled)
				window.parent.ContentFrame.document.ebForm.navbar2.value = ""
			var ebAnswers = window.parent.ContentFrame.document.getElementsByName("ebAnswer")
			for(var x=0; x<ebAnswers.length; x++)
			{
				if(ebAnswers[x].disabled)
				{
					window.parent.ContentFrame.document.ebForm.navbar2.value = ""
					break;
				}
			}	
		}
		
		if(navbar2 != null)
		{
			window.parent.ContentFrame.document.ebForm.navbar2.value = navbar2;
			if(window.ContentFrame.dndpanel != null)
			{
				var dndstate = window.ContentFrame.dndpanel.getAnswersString();
				window.ContentFrame.document.ebForm.selectedAnswer.value = dndstate;
			}			
		}
		if(!done)
		{
			initMouseClicked()
			window.parent.ContentFrame.document.ebForm.submit();
		}
        }catch (e)
        {
	 	errorHandler(e.message, "" ,"" , e.name, "alsutils.NavPrevious()");
        }
}

function NavNext(navbar2)
{
	try
	{
		if(checkMouseClicked())
			return;		
		var done = false;
		if(window.parent.ContentFrame.document.ebForm.navbar != null)
		{
			window.parent.ContentFrame.document.ebForm.navbar.value = "nextPage"
			window.parent.ContentFrame.document.ebForm.soundFlag.value = soundFlag
		}else
		{
			done = true;
			goNavbar('CommServlet?navbar=nextPage&soundFlag=' + soundFlag + "&customerName=" + getCustomer())
		}

		if(window.parent.ContentFrame.document.ebForm.ebAnswer != null)
		{
			if(window.parent.ContentFrame.document.ebForm.ebAnswer.value == "" || window.parent.ContentFrame.document.ebForm.ebAnswer.disabled)
				window.parent.ContentFrame.document.ebForm.navbar2.value = ""
			var ebAnswers = window.parent.ContentFrame.document.getElementsByName("ebAnswer")
			for(var x=0; x<ebAnswers.length; x++)
			{
				if(ebAnswers[x].disabled)
				{
					window.parent.ContentFrame.document.ebForm.navbar2.value = ""
					break;
				}
			}
				
		}
		if(navbar2 != null)
		{
			window.parent.ContentFrame.document.ebForm.navbar2.value = navbar2;	
		}
		if(window.ContentFrame.dndpanel != null)
		{
			var dndstate = window.ContentFrame.dndpanel.getAnswersString();
			window.ContentFrame.document.ebForm.selectedAnswer.value = dndstate;
		}		
		if(!done)
		{
			initMouseClicked()		
			window.parent.ContentFrame.document.ebForm.submit();
		}
        }catch (e)
        {
	 	errorHandler(e.message, "" ,"" , e.name, "alsutils.NavNext()");
        }
}

function NavNextSkill()
{
	try
	{
		if(checkMouseClicked())
			return;				
		var done = false;
		if(window.parent.ContentFrame.document.ebForm.navbar != null)
		{
			window.parent.ContentFrame.document.ebForm.navbar.value = "nextPage"
			window.parent.ContentFrame.document.ebForm.soundFlag.value = soundFlag
			window.parent.ContentFrame.document.ebForm.gotonextskill.value = "true"
		}else
		{
			done = true;
			goNavbar('CommServlet?navbar=nextPage&soundFlag=' + soundFlag + "&customerName=" + getCustomer() + "&gotonextskill=true")
		}

		if(window.parent.ContentFrame.document.ebForm.ebAnswer != null)
		{
			if(window.parent.ContentFrame.document.ebForm.ebAnswer.value == "" || window.parent.ContentFrame.document.ebForm.ebAnswer.disabled)
				window.parent.ContentFrame.document.ebForm.navbar2.value = ""
			var ebAnswers = window.parent.ContentFrame.document.getElementsByName("ebAnswer")
			for(var x=0; x<ebAnswers.length; x++)
			{
				if(ebAnswers[x].disabled)
				{
					window.parent.ContentFrame.document.ebForm.navbar2.value = ""
					break;
				}
			}				
		}
		if(!done)
		{
			initMouseClicked()		
			window.parent.ContentFrame.document.ebForm.submit();	
		}
        }catch (e)
        {
	 	errorHandler(e.message, "" ,"" , e.name, "alsutils.NavNextSkill()");
        }
}

function NavStop()
{
	try
	{
		if(checkMouseClicked())
			return;		
		var done = false;
		if(window.parent.ContentFrame.document.ebForm.navbar != null)
		{
			if(window.parent.ContentFrame.adminessay)
				window.parent.ContentFrame.document.ebForm.navbar.value = "stopAdminEssay"
			else
				window.parent.ContentFrame.document.ebForm.navbar.value = "stop"
			window.parent.ContentFrame.document.ebForm.soundFlag.value = soundFlag
		}else
		{
			done = true;
			goNavbar('CommServlet?navbar=stop&soundFlag=' + soundFlag + "&customerName=" + getCustomer())
		}

		if(window.parent.ContentFrame.document.ebForm.ebAnswer != null)
		{
			if(window.parent.ContentFrame.document.ebForm.ebAnswer.value == "" || window.parent.ContentFrame.document.ebForm.ebAnswer.disabled)
				window.parent.ContentFrame.document.ebForm.navbar2.value = ""
			var ebAnswers = window.parent.ContentFrame.document.getElementsByName("ebAnswer")
			for(var x=0; x<ebAnswers.length; x++)
			{
				if(ebAnswers[x].disabled)
				{
					window.parent.ContentFrame.document.ebForm.navbar2.value = ""
					break;
				}
			}				
		}
		if(!done)
		{
			initMouseClicked()
			window.parent.ContentFrame.document.ebForm.submit();	
		}
        }catch (e)
        {
	 	errorHandler(e.message, "" ,"" , e.name, "alsutils.NavStop()");
        }
}

function NavFirstPage()
{
	try
	{
		if(checkMouseClicked())
			return;		
		if(window.parent.ContentFrame.document.ebForm.navbar != null)
		{
			window.parent.ContentFrame.document.ebForm.navbar.value = "firstPage"
			window.parent.ContentFrame.document.ebForm.soundFlag.value = soundFlag
		}
		if(window.parent.ContentFrame.document.ebForm.ebAnswer != null)
		{
			if(window.parent.ContentFrame.document.ebForm.ebAnswer.value == "" || window.parent.ContentFrame.document.ebForm.ebAnswer.disabled)
				window.parent.ContentFrame.document.ebForm.navbar2.value = ""
			var ebAnswers = window.parent.ContentFrame.document.getElementsByName("ebAnswer")
			for(var x=0; x<ebAnswers.length; x++)
			{
				if(ebAnswers[x].disabled)
				{
					window.parent.ContentFrame.document.ebForm.navbar2.value = ""
					break;
				}
			}				
		}
		initMouseClicked();
		saveInnerFrameState();
		window.parent.ContentFrame.document.ebForm.submit();
        }catch (e)
        {
	 	errorHandler(e.message, "" ,"" , e.name, "alsutils.NavFirstPage()");
        }
}

function NavLastPage()
{
	try
	{
		if(checkMouseClicked())
			return;
		if(window.parent.ContentFrame.document.ebForm.navbar != null)
		{
			window.parent.ContentFrame.document.ebForm.navbar.value = "lastPage"
			window.parent.ContentFrame.document.ebForm.soundFlag.value = soundFlag
		}
		if(window.parent.ContentFrame.document.ebForm.ebAnswer != null)
		{
			if(window.parent.ContentFrame.document.ebForm.ebAnswer.value == "" || window.parent.ContentFrame.document.ebForm.ebAnswer.disabled)
				window.parent.ContentFrame.document.ebForm.navbar2.value = ""
			var ebAnswers = window.parent.ContentFrame.document.getElementsByName("ebAnswer")
			for(var x=0; x<ebAnswers.length; x++)
			{
				if(ebAnswers[x].disabled)
				{
					window.parent.ContentFrame.document.ebForm.navbar2.value = ""
					break;
				}
			}				
		}
		initMouseClicked();
		saveInnerFrameState();
		window.parent.ContentFrame.document.ebForm.submit();
        }catch (e)
        {
	 	errorHandler(e.message, "" ,"" , e.name, "alsutils.NavLastPage()");
        }
}

function NavGotoPage()
{
	try
	{
		var userReply = prompt("Enter page number.", "")
		if(userReply != null)
		{
			if(checkMouseClicked())
				return;		
			if(window.parent.ContentFrame.document.ebForm.navbar != null)
			{
				window.parent.ContentFrame.document.ebForm.navbar.value = "gotoPage"
				window.parent.ContentFrame.document.ebForm.soundFlag.value = soundFlag
				window.parent.ContentFrame.document.ebForm.gotonextskill.value = userReply
			}
			if(window.parent.ContentFrame.document.ebForm.ebAnswer != null)
			{
				if(window.parent.ContentFrame.document.ebForm.ebAnswer.value == "" || window.parent.ContentFrame.document.ebForm.ebAnswer.disabled)
					window.parent.ContentFrame.document.ebForm.navbar2.value = ""
				var ebAnswers = window.parent.ContentFrame.document.getElementsByName("ebAnswer")
				for(var x=0; x<ebAnswers.length; x++)
				{
					if(ebAnswers[x].disabled)
					{
						window.parent.ContentFrame.document.ebForm.navbar2.value = ""
						break;
					}
				}					
			}
			initMouseClicked();
			saveInnerFrameState();
			window.parent.ContentFrame.document.ebForm.submit();
		}
        }catch (e)
        {
	 	errorHandler(e.message, "" ,"" , e.name, "alsutils.NavGotoPage()");
        }
}

function NavQuitModule(nUid)
{
	try
	{
		if(checkMouseClicked())
			return;
		var done = false;
		if(window.parent.ContentFrame.document.ebForm != null && window.parent.ContentFrame.document.ebForm.navbar != null)
		{
			window.parent.ContentFrame.document.ebForm.navbar.value = "quitModule"
			window.parent.ContentFrame.document.ebForm.soundFlag.value = soundFlag
		}else
		{
			done = true;
			goNavbar('CommServlet?navbar=quitModule&uid=' + nUid + '&soundFlag=' + soundFlag + "&customerName=" + getCustomer())
		}

		if(window.parent.ContentFrame.document.ebForm != null && window.parent.ContentFrame.document.ebForm.ebAnswer != null)
		{
			if(window.parent.ContentFrame.document.ebForm.ebAnswer.value == "" || window.parent.ContentFrame.document.ebForm.ebAnswer.disabled)
				window.parent.ContentFrame.document.ebForm.navbar2.value = ""
			var ebAnswers = window.parent.ContentFrame.document.getElementsByName("ebAnswer")
			for(var x=0; x<ebAnswers.length; x++)
			{
				if(ebAnswers[x].disabled)
				{
					window.parent.ContentFrame.document.ebForm.navbar2.value = ""
					break;
				}
			}				
		}
		if(window.parent.ContentFrame.document.ebForm != null && !done)
		{
			initMouseClicked()
			window.parent.ContentFrame.document.ebForm.submit();
		}
	}catch(e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alsutils.NavQuitModule()");
	}
}

function gradeQuestion()
{
	try
	{
		if(checkMouseClicked())
			return;		
		var done = false;
		if(window.parent.ContentFrame.document.ebForm.navbar != null)
		{
			window.parent.ContentFrame.document.ebForm.navbar.value = "gradeQuestion"
			window.parent.ContentFrame.document.ebForm.soundFlag.value = soundFlag
			if(window.ContentFrame.dndpanel != null)
			{
				var dndstate = window.ContentFrame.dndpanel.getAnswersString();
				window.ContentFrame.document.ebForm.selectedAnswer.value = dndstate;
			}
		}else
		{
			done = true;
			goNavbar('CommServlet?navbar=gradeQuestion&soundFlag=' + soundFlag + "&customerName=" + getCustomer())
		}
		if(!done)
		{
			initMouseClicked()
			window.parent.ContentFrame.document.ebForm.submit();
		}
        }catch (e)
        {
	 	errorHandler(e.message, "" ,"" , e.name, "alsutils.gradeQuestion()");
        }
}

function performActionEvent(src_id)
{
	try
	{
		if(checkMouseClicked())
			return;		
		var done = false;
		if(window.parent.ContentFrame.document.ebForm.navbar != null)
		{
			window.parent.ContentFrame.document.ebForm.navbar.value = "performActionEvent"
			window.parent.ContentFrame.document.ebForm.soundFlag.value = soundFlag
			//I'm dynamically adding a src_id input needed for this method so that we 
			//don't have to change the template requiring a regen of the content.
			var frmele = window.parent.ContentFrame.document.ebForm;
			var tmpfrm = frmele.innerHTML
			frmele.innerHTML = "<INPUT type=hidden name=src_id value=" + src_id + ">" + tmpfrm;
			
			//if the page has a gradeQuestion event  set navbar2 to setText
			//so that the text can be set before the performActionEvent 
			//this is so that anything entered by the user will not be lost
			if(window.ContentFrame.setDynamicLayers.toString().indexOf("gradeQuestion()") > -1)
				window.parent.ContentFrame.document.ebForm.navbar2.value = "setText"
			if(window.ContentFrame.dndpanel != null)
			{
				var dndstate = window.ContentFrame.dndpanel.getAnswersString();
				window.ContentFrame.document.ebForm.selectedAnswer.value = dndstate;
			}	
		}else
		{
			done = true;
			goNavbar('CommServlet?navbar=performActionEvent&soundFlag=' + soundFlag + "&customerName=" + getCustomer() + "&src_id=" + src_id)
		}
		if(!done)
		{
			initMouseClicked()
			window.parent.ContentFrame.document.ebForm.submit();
		}
        }catch (e)
        {
	 	errorHandler(e.message, "" ,"" , e.name, "alsutils.performActionEvent()");
        }
}

function getBrowserNameVersion()   
{   
        try
	{
		retVal = navigator.appName + " " + navigator.appVersion;     
		return retVal;
        }catch (e)
        {
	 	errorHandler(e.message, "" ,"" , e.name, "alsutils.getBrowserNameVersion()");
        }
}

function getUserAgent()
{

	try
	{
		detect = navigator.userAgent.toLowerCase();

		if (checkIt('konqueror', detect))
		{
			browser = "Konqueror";
			OS = "Linux";
		}
		else if (checkIt('opera', detect)) browser = "Opera"
		else if (checkIt('webtv', detect)) browser = "WebTV";
		else if (checkIt('icab', detect)) browser = "iCab"
		else if (checkIt('msie', detect)) browser = "Internet Explorer"
		else if (!checkIt('compatible', detect))
		{
			browser = "Netscape Navigator"
			version = detect.charAt(8);
		}
		else browser = "An unknown browser";

		if (!version) version = detect.charAt(place + thestring.length);

		if (!OS)
		{
			if (checkIt('linux', detect) != 0)
			{
				OS = "Linux";
			}
			else if (checkIt('x11', detect) != 0)
			{
				OS = "Unix";
			}
			else if (checkIt('mac', detect) != 0)
			{
				OS = "Mac";
			}
			else if (checkIt('win', detect) != 0)
			{
				//alert("found windows");
				OS = "Windows";
			}
			else 
			{
				OS = "an unknown operating system";
			}
			return OS;
		}
		return OS;
        }catch (e)
        {
	 	errorHandler(e.message, "" ,"" , e.name, "alsutils.getUserAgent()");
        }

}

function checkIt(string, detect)
{
	try
	{
		place = detect.indexOf(string) + 1;
		// ("place = " + place + "\nstring = " + string);
		thestring = string;
		return place;
        }catch (e)
        {
	 	errorHandler(e.message, "" ,"" , e.name, "alsutils.checkIt()");
        }
}

function getSpecificBrowserName()
{
	result = " ";
	if( navigator.userAgent.indexOf( "Galeon" ) != -1 ) result = "Galeon";
	else if( navigator.appName.indexOf( "Mozilla" ) != -1 ) result = "Mozilla";
	else if( navigator.appName.indexOf( "Microsoft" ) != -1 ) result = "Internet Explorer";
	else if( navigator.userAgent.indexOf( "Gecko" ) != -1 ) result = "Mozilla";
	else if( navigator.userAgent.indexOf( "Konqueror" ) != -1 ) result = "Konqueror";
	else if( navigator.userAgent.indexOf( "Opera" ) != -1 ) result = "Opera";
	else result = "Unknown";
	return result;
}

function getBrowserName()
{
	try
	{
		return navigator.appName
        }catch (e)
        {
	 	errorHandler(e.message, "" ,"" , e.name, "alsutils.getBrowserName()");
        }
}

function getBrowserVersion()
{
	try
	{
		return parseInt(navigator.appVersion)
        }catch (e)
        {
	 	errorHandler(e.message, "" ,"" , e.name, "alsutils.getBrowserVersion()");
        }
}

function launchHelp(sHref)
{
	try
	{
		windowprops = "top=50,left=100,scrollbars=yes,status=0,resizable=yes,menubar=0,width=" + (screen.width * .8) + ",height=" + (screen.height * .8);
		helpWin = window.open(sHref, "helpPage", windowprops);
        }catch (e)
        {
	 	errorHandler(e.message, "" ,"" , e.name, "alsutils.launchHelp()");
        }
}

function checkFonts()
{
	try
	{
		var hasFonts = true;	

		ALSFonts = ["AEC Calculus","AEC Chemistry","AEC Language","AEC Math Regular","AEC Math Regular2","AEC Math Regular3","AEC Math30","AEC Regular"];
		for(i=0;i<ALSFonts.length;i++) 
		{
		if(!checkIfInstalled(ALSFonts[i],1))
		 hasFonts = false;

		}

		if(!hasFonts)
		{
		answer = confirm("You are missing some fonts. Do you want to install these fonts?")
		if (answer)
		  messageWin=window.open("/als/download.html", "downloadwin","toolbar=0,location=0,status=0,menubar=0,scrollbars=0 resizable=0,width=400,height=400");
		else
		  return;

		}
        }catch (e)
        {
	 	errorHandler(e.message, "" ,"" , e.name, "alsutils.checkFonts()");
        }
}

function logoff()
{
	try
	{
		var sConfirm = true;
		custName = getCustomer();
		if(logoff.arguments.length > 0)
			sConfirm = logoff.arguments[0];
		if(sConfirm)
		{
			if(confirm("Click 'OK' to log off, or 'Cancel' returns you to the program."))
				logout(custName, false)
		}else
			logout(custName, false)

        }catch (e)
        {
	 	errorHandler(e.message, "" ,"" , e.name, "alsutils.logoff()");
        }
}	


function checkIfInstalled(fname,loaded)
{
   	try
	{
		   IE4 = document.all;
		   NS4 = document.layers;
		   ver4 = (IE4 || NS4);
		   if(!ver4) return false;

		   isMac = (navigator.appVersion.indexOf("Mac") != -1);
		   isWin = (navigator.appVersion.indexOf("Win") != -1);

		   arNotNavWin = ["Webdings","Marlett"];

		   if(NS4 && isWin)
		   {
		      for(k=0;k<arNotNavWin.length;k++) 
		      {
			 if (fname == arNotNavWin[k]) return false;
		      }
		   }

		   teststr = "font&nbsp;existence&nbsp;test"
		   if(IE4) 
		   {
		      if(!window.fntLyr0) 
		      {
			 lyrstr0 = "<SPAN ID=fntLyr0 STYLE='position:absolute;visibility:hidden;width:30;font:12pt Courier'>"+ teststr +"</SPAN>";
			 lyrstr1 = "<SPAN ID=fntLyr1 STYLE='position:absolute;visibility:hidden;width:30;font-size:12pt'>"+ teststr +"</SPAN>";
			 if (loaded)
			 {
			    window.parent.ContentFrame.document.body.insertAdjacentHTML("BeforeEnd",lyrstr0);
			    window.parent.ContentFrame.document.body.insertAdjacentHTML("BeforeEnd",lyrstr1);
			 }
			 else
			 {
			    document.write(lyrstr0);
			    document.write(lyrstr1);
			 }
		      }
		      fntLyr1.style.fontFamily = fname +",Courier";
		      width0 = (isMac) ? fntLyr0.offsetWidth : fntLyr0.scrollWidth;
		      width1 = (isMac) ? fntLyr1.offsetWidth : fntLyr1.scrollWidth;
		   }
		   if(NS4)
		   {
		      lyrstr1 = "<FONT FACE='"+ fname +",Courier' POINT-SIZE=12>"+ teststr +"</FONT>";
		      if(!window.fntLyr0) 
		      {
			 lyrstr0 = "<FONT FACE='Courier' POINT-SIZE=12>"+ teststr +"</FONT>";
			 if (loaded) 
			 {
			    fntLyr0 = new Layer(400);
			    fntLyr0.document.write(lyrstr0);
			    fntLyr0.document.close();
			    fntLyr1 = new Layer(400);
			    fntLyr1.document.write(lyrstr1);
			    fntLyr1.document.close();
			 }
			 else 
			 {
			    document.write("<LAYER VISIBILITY=HIDE>"+ lyrstr0 +"</LAYER>");
			    fntLyr0 = document.layers[document.layers.length-1];
			    document.write("<LAYER VISIBILITY=HIDE>"+ lyrstr1 +"</LAYER>");
			    fntLyr1 = document.layers[document.layers.length-1];
			 }
		      }
		      else 
		      {
			 if (loaded) 
			 {
			    fntLyr1.document.write(lyrstr1);
			    fntLyr1.document.close();
			 }
			 else 
			 {
			    document.write("<LAYER VISIBILITY=HIDE>"+ lyrstr1 +"</LAYER>");
			    fntLyr1 = document.layers[document.layers.length-1];
			 }
		      }
		      width0 = fntLyr0.clip.width;
		      width1 = fntLyr1.clip.width;
		   }
		   return (width0 != width1);
        }catch (e)
        {
	 	errorHandler(e.message, "" ,"" , e.name, "alsutils.checkIfInstalled()");
        }
}

function getCustomer()
{
	try
	{
		var indexstart;
		var indexend;
		var query;
		var customerValue = "_default";

		query = parent.window.location.search;

		if(query.indexOf("customer") != -1)
		{
			indexstart = query.indexOf("customer")
			indexstart = query.indexOf("=", indexstart);
			indexend = query.indexOf("&", indexstart)
			if(indexend == -1)
			   customerValue  = query.substring(indexstart + 1);
			else
			   customerValue  = query.substring(indexstart + 1, indexend);
		}
		//alert("returning customerValue: " + customerValue);
		return customerValue;
        }catch (e)
        {
	 	errorHandler(e.message, "" ,"" , e.name, "alsutils.getCustomer()");
        }
}

function getSoundFlag()
{
	return soundFlag;
}

function getParamCurrentWindow(paramName)
{
      	try
	{
		var indexstart;
		var indexend;
		var query;
		var paramValue = "_default";
		try
		{
			query = window.parent.ContentFrame.location.search;
		}catch(e)
		{
			query = window.location.search;
		}
		if(query.indexOf(paramName) != -1)
		{
			indexstart = query.indexOf("&" + paramName)
			indexstart = query.indexOf("=", indexstart)
			indexend   = query.indexOf("&", indexstart)
			if(indexend != -1)
				paramValue = query.substring(indexstart + 1, indexend)
			else
				paramValue = query.substring(indexstart + 1);

			//alert("returning paramValue: " + paramValue);
		}
		return paramValue;
        }catch (e)
        {
	 	errorHandler(e.message, "" ,"" , e.name, "alsutils.getParam()");
        }
}

function getParam(paramName)
{
      	try
	{
		var indexstart;
		var indexend;
		var query;
		var paramValue = "_default";
		query = parent.window.location.search;
		if(query.indexOf(paramName) != -1)
		{
			indexstart = query.indexOf(paramName)
			indexstart = query.indexOf("=", indexstart)
			indexend   = query.indexOf("&", indexstart)
			if(indexend != -1)
				paramValue = query.substring(indexstart + 1, indexend)
			else
				paramValue = query.substring(indexstart + 1);

			//alert("returning paramValue: " + paramValue);
		}
		return paramValue;
        }catch (e)
        {
	 	errorHandler(e.message, "" ,"" , e.name, "alsutils.getParam()");
        }
}

/******************************************************************************************
**
** Section 	HunkyFunky
** Inputs:	Many
** Return:	Many
**
** Description:
** This stuff is used by the content engine for reasons unknown
** 
**
** Side Effects: Usually makes the content work
**
******************************************************************************************/
var retVal = true;
var tid;
var ep;
var fn1;
var timeoutVal = 200;



function goNavbar(path)
{
	try
	{
	//	alert(path);
		window.parent.ContentFrame.document.location.href=path;
        }catch (e)
        {
	 	errorHandler(e.message, "" ,"" , e.name, "alsutils.goNavbar()");
        }
}




function enlargePicture(fn, wd, ht)
{
	try
	{
		  if(wd > screen.width)
		    wd = screen.width - 40;

		  if(ht > screen.height)
		    ht = screen.height - 40

		  options = "menubar=no, toolbar=no, dependent=yes, alwaysRaised=yes, resizable=yes, scrollbars=yes,width=" + wd + ",height=" + ht;

		  fn1 = fn;
		  ep = window.open("/als/hf/ep.html", "Picture", options);
		  tid = setTimeout("setImageName()", timeoutVal);
        }catch (e)
        {
	 	errorHandler(e.message, "" ,"" , e.name, "alsutils.enlargePicture()");
        }
}

function showCalc(theURL)
{
	try
	{
		var height = "330";
		if(theURL.indexOf("graphingcalc") > -1)
			height = "600"; 
		windowprops = "\"top=0,left=0,resizable=no, dependent=yes, alwaysRaised=yes, width=425, height=" + height + "\"";
		window.open(theURL, "calculator", windowprops);
        }catch (e)
        {
	 	errorHandler(e.message, "" ,"" , e.name, "alsutils.showCalc()");
        }

}

function launchRuler(x, y)
{
   	try
	{
   		alert("The ruler hasn't been implemented yet.");
        }catch (e)
        {
	 	errorHandler(e.message, "" ,"" , e.name, "alsutils.launchRuler()");
        }
}

function setImageName()
{
       try
       {
	   clearTimeout(tid);
	   if(ep != null && ep.document.images != null && ep.document.images.length > 0)
	   {
	      fn1 = fn1.replace("&#39;", "'");
	      ep.document.images[0].src = fn1;
	   }else
	      tid = setTimeout("setImageName()", timeoutVal);
       }catch (e)
       {
	 	errorHandler(e.message, "" ,"" , e.name, "alsutils.setImageName()");
       }
}

function enterKeySubmit(evt)
{
      try
      {
      	  startTimer();
	  var keyCode;  	
	  var safari = navigator.userAgent.indexOf('Safari')>0;
	  retVal = true;
	  if(document.all)
	    keyCode = window.ContentFrame.event.keyCode;
	  else if(document.layers)
	    keyCode = evt.which;
	  else
	    keyCode = evt.keyCode;
	  if(keyCode == 10 || keyCode == 13 || (safari && keyCode == 3))
	  {
		    retVal = false;
		if(formSubmitted == false)
		{
		    formSubmitted = true;
		    window.parent.ContentFrame.document.ebForm.navbar.value = window.parent.ContentFrame.document.ebForm.navbar2.value;
		    window.parent.ContentFrame.document.ebForm.navbar2.value = ""
		    window.parent.ContentFrame.document.ebForm.soundFlag.value = soundFlag
		    if(window.parent.ContentFrame.document.ebForm.navbar.value != "")
		    {
			disableSound();
			if(window.ContentFrame.dndpanel != null)
			{
				var dndstate = window.ContentFrame.dndpanel.getAnswersString();
				window.ContentFrame.document.ebForm.selectedAnswer.value = dndstate;
			}			
			//I'm removing this delay from Safari because it causes white screen with the word null when hitting the enter key 
			//during practice tests. You can duplcate the problem in the absolute values practice test on Mac Safari. 
			//I can't remember why the delay was added so this might break something else.
			//if(safari)
			//	tid = setTimeout("alsutils_SubmitForm()", 100);
			//else
			if(window.ContentFrame.setDynamicLayers.toString().indexOf("gradeQuestion()") == -1)	
				alsutils_SubmitForm()		
		    }
		}
		    return retVal;
	 }
	 return retVal;
       }catch (e)
       {
	 	errorHandler(e.message, "" ,"" , e.name, "alsutils.enterKeySubmit()");
       }
  
}

function alsutils_SubmitForm()
{
	window.parent.ContentFrame.document.ebForm.submit();
}

function catchKeyDown(evt)
{
	try
	{
		  var keyCode;  	
		  retVal = true;
		  if(document.all)
		  {
		    if(window.ContentFrame.event.ctrlKey && window.ContentFrame.event.shiftKey && window.ContentFrame.event.keyCode == 70)
			NavFirstPage();
		    else if(window.ContentFrame.event.ctrlKey && window.ContentFrame.event.shiftKey && window.ContentFrame.event.keyCode == 76)
			NavLastPage();
		    else if(window.ContentFrame.allowContentReview && window.ContentFrame.event.keyCode == 118)
		    	openContentReviewWindow();
		    else if(window.ContentFrame.event.ctrlKey && window.ContentFrame.event.shiftKey && window.ContentFrame.event.keyCode == 71)	
		    	NavGotoPage();
		  }else if(document.layers)
		  {
		    if(window.ContentFrame.evt.modifiers & Event.CONTROL_MASK && window.ContentFrame.evt.modifiers & window.ContentFrame.Event.SHIFT_MASK && window.ContentFrame.evt.which == 70)
			NavFirstPage();
		    else if(window.ContentFrame.evt.modifiers & window.ContentFrame.Event.CONTROL_MASK && window.ContentFrame.evt.modifiers & window.ContentFrame.Event.SHIFT_MASK && window.ContentFrame.evt.which == 76)
			NavLastPage();
		    else if(window.ContentFrame.allowContentReview && window.ContentFrame.evt.which == 118)
		    	openContentReviewWindow();
		    else if(window.ContentFrame.evt.modifiers & window.ContentFrame.Event.CONTROL_MASK && window.ContentFrame.evt.modifiers & window.ContentFrame.Event.SHIFT_MASK && window.ContentFrame.evt.which == 71)	
		    	NavGotoPage();	
		  }else
		  {
		    var safari = navigator.userAgent.indexOf('Safari')>0;
		    if(OS == null)
		    	OS = getUserAgent();
		    if(!safari && !(OS == "Mac" && getBrowserName() == "Netscape"))
		    {
			if(evt.ctrlKey && evt.shiftKey && evt.keyCode == 70)
				NavFirstPage();
		    	else if(evt.ctrlKey && evt.shiftKey && evt.keyCode == 76)
				NavLastPage();
		    	else if(window.ContentFrame.allowContentReview && evt.keyCode == 118)
				openContentReviewWindow();
			else if(evt.ctrlKey && evt.shiftKey && evt.keyCode == 71)
				NavGotoPage();	
		    }	
		  }
		  return retVal;
       }catch (e)
       {
	 	errorHandler(e.message, "" ,"" , e.name, "alsutils.catchKeyDown()");
       }
    
}

function saveData()
{
       try
       {
		//disableRight();
		LMSFinish();
       }catch (e)
       {
	 	errorHandler(e.message, "" ,"" , e.name, "alsutils.saveData()");
       }
}

function exitCurric()
{
       try
       {
		//disableRight();
		window.parent.document.title = "A+LS";
		LMSFinish();
       }catch (e)
       {
	 	errorHandler(e.message, "" ,"" , e.name, "alsutils.exitCurric()");
       }
}

function initialize()
{
       try
       {
		initMouseClicked()
		formSubmitted = false;
		//disableRight();
		LMSInitialize();
       }catch (e)
       {
	 	errorHandler(e.message, "" ,"" , e.name, "alsutils.initialize()");
       }
}


/******************************************************************************************
**
** Function disableRight()
** Inputs:	None
** Return:	None
**
** Description:
** Determines disables the right click. If the user is using IE it displays an alert
** 
**
** Side Effects: Displays an alert window with the appropriate information
**
******************************************************************************************/
function disableRight()
{
	try
	{
		window.parent.ContentFrame.document.onmousedown=right;
		window.parent.ContentFrame.document.onmouseup=right;
		if (document.layers)
			window.captureEvents(Event.MOUSEDOWN);
		if (document.layers)
			window.captureEvents(Event.MOUSEUP);
		window.onmousedown=right;
		window.onmouseup=right;
       }catch (e)
       {
	 	errorHandler(e.message, "" ,"" , e.name, "alsutils.disableRight()");
       }
}


function right(e)
{
    try
    {
	    if (navigator.appName == 'Netscape' && (e.which == 3 || e.which == 2))
		return false;
	    else if (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2 || event.button == 3))
	    {
		alert("Right click is unavailable.");
		return false;
	    }
	    return true;
     }catch (e)
     {
	errorHandler(e.message, "" ,"" , e.name, "alsutils.right()");
     }
}

function setInputValue(inputField, newValue)
{
  	try
	{
        	inputField.value = newValue;
     	}catch (e)
     	{
		errorHandler(e.message, "" ,"" , e.name, "alsutils.setInputValue()");
     	}
}

function swapImage(imageName, newPic)
{
  	try
	{
  		imageName.src = newPic;
     	}catch (e)
     	{
		errorHandler(e.message, "" ,"" , e.name, "alsutils.swapImage()");
     	}
}

function initSound(flag)
{
	try
	{
	//	alert('initSound');
		soundFlag = flag;
		if(document.layers != null)
		{
			if(window.parent.ContentFrame.document.images['soundimg'] != null)
				initSoundImg(window.parent.ContentFrame.document.images['soundimg'])
		}else
		{
			if(window.parent.ContentFrame.document.soundimg != null)
				initSoundImg(window.parent.ContentFrame.document.soundimg)
		}
     	}catch (e)
     	{
		errorHandler(e.message, "" ,"" , e.name, "alsutils.initSound()");
     	}
}	

function initSound2(flag)
{
	try
	{
	//	alert('initSound');
		soundFlag = flag;
		soundico = "/als/images/pb/toolbartextnew_02.gif";
		if(document.layers != null)
				initSoundImg2(window.parent.ContentFrame.document.images['soundimg'])
		else
				initSoundImg2(window.parent.ContentFrame.document.soundimg)
     	}catch (e)
     	{
		errorHandler(e.message, "" ,"" , e.name, "alsutils.initSound2()");
     	}
}	

function initSoundImg(imageName)
{
  	try
	{
		if(imageName != null)
		{
			if(!soundFlag)
				swapImage(imageName, pbnosoundico);
			else
				swapImage(imageName, pbsoundico);
		}
     	}catch (e)
     	{
		errorHandler(e.message, "" ,"" , e.name, "alsutils.initSoundImg()");
     	}
}

function initSoundImg2(imageName)
{
	try
	{
		if(imageName != null)
		{
			if(!soundFlag)
				swapImage(imageName, nosoundico);
			else
				swapImage(imageName, soundico);
		}
     	}catch (e)
     	{
		errorHandler(e.message, "" ,"" , e.name, "alsutils.initSoundImg2()");
     	}
}

function toggleSound2(imageName)
{
	try
	{
		  if(soundFlag)
		  {
		    swapImage(imageName, nosoundico);
		    soundFlag = false
		  }
		  else
		  {
		    swapImage(imageName, soundico);
		    soundFlag = true
		  }
     	}catch (e)
     	{
		errorHandler(e.message, "" ,"" , e.name, "alsutils.toggleSound2()");
     	}
}

function toggleSound(inputField, imageName)
{
       try
       {
		  if(soundFlag)
		  {
		    swapImage(imageName, nosoundico);
		    soundFlag = false
		  }
		  else
		  {
		    swapImage(imageName, soundico);
		    soundFlag = true
		  }

		  setInputValue(inputField, soundFlag);
     	}catch (e)
     	{
		errorHandler(e.message, "" ,"" , e.name, "alsutils.toggleSound()");
     	}

}

function toggleSound3(inputField, imageName)
{
	try
	{
	  if(soundFlag)
	  {
	    swapImage(imageName,pbsoundico);
	    soundFlag = false
	  }
	  else
	  {
	    swapImage(imageName, pbnosoundico);
	    soundFlag = true
	  }

	  setInputValue(inputField, soundFlag);
     	}catch (e)
     	{
		errorHandler(e.message, "" ,"" , e.name, "alsutils.toggleSound3()");
     	}

}



function getFullPath(path)
{
	try
	{
  		return rootPath + path;
     	}catch (e)
     	{
		errorHandler(e.message, "" ,"" , e.name, "alsutils.getFullPath()");
     	}
}

/******************************************************************************************
**
** Function ErrorHandler()
** Inputs:	None
** Return:	The current value of the LMS Error Code
**
** Description:
** Determines if an error was encountered by the previous API call
** and if so, displays a message to the user.  If the error code
** has associated text it is displayed.  
**
** Side Effects: Displays an alert window with the appropriate error information
**
******************************************************************************************/
function ErrorHandler() 
{
	try
	{
		   var api;
		   var osVersion = getUserAgent();

		   if(osVersion == "Mac" || !(document.all))
		   {
			api = window.parent.macapiframe;
		   }

		   else if(osVersion == "Windows")
		   {
			api = getAPIHandle(); //parent.LMSFrame.document.APIApplet;
			//alert("the REAL api = " + api);
		   }

		   else
			api = getAPIHandle();
			//api = window.parent.macapiframe;

		   if (api == null)
		   {
		      alert("Unable to locate the LMS's API Implementation.\nCannot determine LMS error code.");
		      return;
		   }

		   // check for errors caused by or from the LMS
		   var errCode = api.LMSGetLastError().toString();
		   if (errCode != _NoError)
		   {
		      // an error was encountered so display the error description
		      var errDescription = api.LMSGetErrorString(errCode);

		      if (_Debug == true)
		      {
			 errDescription += "\n";
			 errDescription += api.LMSGetDiagnostic(null);
			 // by passing null to LMSGetDiagnostic, we get any available diagnostics
			 // on the previous error.
		      }

		      alert(errDescription);
		   }

		   return errCode;
     	}catch (e)
     	{
		errorHandler(e.message, "" ,"" , e.name, "alsutils.ErrorHandler()");
     	}
}

function destroyAPI()
{
	try
	{
		   //get API handle
		   var api;
		   var osVersion = getUserAgent();

		   if(osVersion == "Mac" || !(document.all))
		   {
			api = window.parent.macapiframe;
		   }

		   else if(osVersion == "Windows")
		   {
			api = getAPIHandle(); //parent.LMSFrame.document.APIApplet;
			//alert("the REAL api = " + api);
		   }

		   else
			api = getAPIHandle();
			//api = window.parent.macapiframe;

		   if (api == null)
		   {
		      alert("Unable to locate the LMS's API Implementation.\nCannot determine LMS error code.");
		      return;
		   }

		 //destroy api
		   api.destroy();
     	}catch (e)
     	{
		errorHandler(e.message, "" ,"" , e.name, "alsutils.destroyAPI()");
     	}

}

/******************************************************************************************
**
** Function: LMSInitialize()
** Inputs:	None
** Return:	CMIBoolean true if the initialization was successful, or
**			CMIBoolean false if the initialization failed.
**
** Description:
** Initialize communication with LMS by calling the LMSInitialize 
** function which will be implemented by the LMS, if the LMS is 
** compliant with the SCORM.
**
******************************************************************************************/
function LMSInitialize() 
{   
	try
	{
	     if(LMSIsInitialized())
	      	return true;

	     var api;
	     var osVersion = getUserAgent();

	     if(osVersion == "Mac" || !(document.all))
	     {
		 api = window.parent.macapiframe;
	     }
	     else if(osVersion == "Windows")
	     {
		 api = getAPIHandle(); //parent.LMSFrame.document.APIApplet;
	     }
	     else
	     {
		 //uncomment this line for strict SCORM compliance
		 api = getAPIHandle();
	     }

	     if (api == null && (osVersion == "Mac" || !(document.all)))
	     	return true;	      	
	     else if(api == null)
	     {
	     	//alert("Unable to locate the LMS's API Implementation.\nLMSInitialize was not successful.");
	      	return false;
	     }

	     // call the LMSInitialize function that should be implemented by the API
	     var emptyString = new String("");
	     var initResult = api.LMSInitialize(emptyString);

	     if (initResult.toString() != "1")
	     {
	     	 // LMSInitialize did not complete successfully.

	      	// Note: An assumption is made that if LMSInitialize returns a non-true
	      	//		 value, then and only then, an error was raised.

	      	// Note: Each function could define its own error handler, but we'll 
	      	// just implement a generic one in this example.
	      	//var err = ErrorHandler();
	     }

	     return initResult;
     	}catch (e)
     	{
		errorHandler(e.message, "" ,"" , e.name, "alsutils.LMSInitialize()");
     	}
   
} 

/******************************************************************************************
**
** Function LMSFinish()
** Inputs:	None
** Return:	None
**
** Description:
** Close communication with LMS by calling the LMSFinish 
** function which will be implemented by the LMS, if the LMS is 
** compliant with the SCORM.
**
******************************************************************************************/
function LMSFinish()
{
	try
	{
	   //maximizeFrame();
	   var api;
	   var osVersion = getUserAgent();

	  if(osVersion == "Mac" || !(document.all))
	      api = window.parent.macapiframe;
	  else if(osVersion == "Windows")
	      api = getAPIHandle(); //parent.LMSFrame.document.APIApplet;
	  else
	      api = getAPIHandle();
	      //api = window.parent.macapiframe;
	   if (api == null)
	   {
	      alert("Unable to locate the LMS's API Implementation.\nLMSFinish was not successful.");
	   }
	   else
	   {
	      // call the LMSInitialize function that should be implemented by the API
	      var emptyString = new String("");
	      api.LMSFinish(emptyString);
	      var err = ErrorHandler();
	   }   

	   return;
     	}catch (e)
     	{
		errorHandler(e.message, "" ,"" , e.name, "alsutils.LMSFinish()");
     	}
   
} 

function LMSIsInitialized()
{
	try
	{
		var osVersion = getUserAgent();
		if(osVersion == "Mac" || !(document.all))
		{
			if(window.parent.macapiframe != null && window.parent.macapiframe.LMSInitialized == "1")
			   return true;
			else
			   return false;
		}

		if(osVersion == "Mac" || !(document.all))
		{
		    api = window.parent.macapiframe;
		    //alert("Using mac api: " + api);
		}
		else if(osVersion == "Windows")
		{
		    api = getAPIHandle(); //parent.LMSFrame.document.APIApplet;
		    //alert("Using API Applet: " + api);
		}
		else
		 api = getAPIHandle();
		 //api = window.parent.macapiframe;

		if (api == null)
		{
		      //alert("Unable to locate the LMS's API Implementation.\nLMSIsInitialized was not successful.");
		      return false;
		}
		// Determines if the API (LMS) is in an initialized state.
		// There is no direct method for determining if the LMS API is initialized
		// for example an LMSIsInitialized function defined on the API so we'll try
		// a simple LMSGetValue and trap for the LMS Not Initialized Error
		var value = api.LMSGetValue("cmi.core.student_name");
		var errCode = api.LMSGetLastError().toString();
		if (errCode == 301)
		{
			return false;
		}
		else
		{
			return true;
		}
     	}catch (e)
     	{
		errorHandler(e.message, "" ,"" , e.name, "alsutils.LMSIsInitialized()");
     	}
}

function LMSGetUrlParams(Object)
{
	try
	{
		var fragString = window.parent.ContentFrame.document.location.search;
		//alert("URL Params: " + fragString);
		//We had problems returning the fragString back to the api so we just call the api
		//and pass in the fragstring.
		API.LMSSetUrlParams(fragString);
     	}catch (e)
     	{
		errorHandler(e.message, "" ,"" , e.name, "alsutils.LMSGetUrlParams()");
     	}
}


function setBackParams(params)
{

     try
     {
	     var api;
	     var osVersion = getUserAgent();

	     if(osVersion == "Mac" || !(document.all))
	     {
		 api = window.parent.macapiframe;
		 //alert("Using MAC api: " + api);
	     }
	     else if(osVersion == "Windows")
	     {
		 api = getAPIHandle(); //parent.LMSFrame.document.APIApplet;
		 //alert("Using API Applet: " + api);
	     }
	     else
		api = getAPIHandle();
		//api = window.parent.macapiframe;

	    api.setSelectAsgParams(params);
     }catch (e)
     {
		errorHandler(e.message, "" ,"" , e.name, "alsutils.setBackParams()");
     }
}

function getBackParams()
{
	
     try
     {
	     window.parent.document.title = "A+LS";
	     var api;
	     var osVersion = getUserAgent();

	     if(osVersion == "Mac" || !(document.all))
	     {
		 api = window.parent.macapiframe;
		 //alert("Using mac api: " + api);
	     }
	     else if(osVersion == "Windows")
	     {
		 api = getAPIHandle(); //parent.LMSFrame.document.APIApplet;
		 //alert("Using API Applet: " + api);
	     }
	     else
		api = getAPIHandle();
		//api = window.parent.macapiframe;

	     var temp = api.getBackParams();
	     return temp;
     }catch (e)
     {
		errorHandler(e.message, "" ,"" , e.name, "alsutils.getBackParams()");
     }
}

function changeAUContent()
{
	try
	{
		  var urlClip = window.parent.ContentFrame.document.location.search;
		  // This is the launch line for all AUs...
		  // The LMSCMI servlet figures out which AU (in sequence) to launch and
		  // serves it up into the LMS's content frame or child window - depending
		  // on the method that was used to launch the content in the first place.

		  var auWinType = typeof(window.parent.ContentFrame.auWindow);

		  if (auWinType != "undefined" && auWinType != "unknown")
		  {
			if (window.parent.ContentFrame.auWindow != null)
			{
				// there is a child content window so display the au there.
				window.parent.ContentFrame.auWindow.document.location.href = contextrelpath + "/servlet/lmslesson" + urlClip;
			}
			else
			{
				window.parent.ContentFrame.document.location.href = contextrelpath + "/servlet/lmslesson" + urlClip;
			}
		  }
		  else
		  {
			window.parent.ContentFrame.document.location.href = contextrelpath + "/servlet/lmslesson" + urlClip;
			//  auWindow is undefined which means that the content frame
			//  does not contain the lesson menu at this time.
		  }
    	}catch (e)
    	{
		errorHandler(e.message, "" ,"" , e.name, "alsutils.changeAUContent()");
    	}
}

function closeAUContent()
{
       try
       {
	       if(OS == "Mac" || !(document.all))
	       {
		   api = window.parent.macapiframe;
		   //alert("Using mac api: " + api);
	       }
	       else if(OS == "Windows")
	       {
		   api = getAPIHandle(); //parent.LMSFrame.document.APIApplet;
		   //alert("Using API Applet: " + api);
	       }
	       else
		 api = getAPIHandle();
		 //api = window.parent.macapiframe;

		  api.launchSelectAsg();
		  var urlClip = window.parent.ContentFrame.document.location.search;
		 //window.parent.ContentFrame.document.location.href = contextrelpath + "/servlet/lmscourse" + urlClip;

		  var auWinType = typeof(window.parent.ContentFrame.auWindow);

		  if (auWinType != "undefined" && auWinType != "unknown")
		  {
		    if (window.parent.ContentFrame.auWindow != null)
			{
				// there is a child content window so close it.
				window.parent.ContentFrame.auWindow.close();
				window.parent.ContentFrame.auWindow = null;
			}
		  }
		  else
		  {
			//  auWindow is undefined which means that the content frame
			//  does not contain the lesson menu so do nothing...
		  }
    	}catch (e)
    	{
		errorHandler(e.message, "" ,"" , e.name, "alsutils.closeAUContent()");
    	}
  
}

function init()
{
   try
   {
	   OS = getUserAgent();
	   //alert("OS = " + OS);
	   if(OS == "Mac" || !(document.all))
	   {
		API = window.parent.macapiframe;
	   }
	   else
	   {
		window.parent.LMSFrame.CreateApplet();
		API = getAPIHandle(); //this.document.APIApplet;
	   }
	   //disableRight();

	   //var xyz = "The handle was created successfully.";
    }catch (e)
    {
	errorHandler(e.message, "" ,"" , e.name, "alsutils.init()");
    }
}

var API = null;

function initAPI()
{
    try
    {
	    OS = getUserAgent();
	    if(OS == "Mac" || !(document.all))
	    {
		API = window.parent.macapiframe;
	    }
	    else
	    {
		API = getAPIHandle(); //LMSFrame.document.APIApplet;
	    }
	    //disableRight();
	    //API = window.APIFrame;
    }catch (e)
    {
	errorHandler(e.message, "" ,"" , e.name, "alsutils.initAPI()");
    }
}

function logout(customer, close)
{
	try
	{
		if(close == true)
		    window.close();
		try
		{
			window.parent.macapiframe.clearInterval(window.parent.macapiframe.renewLic);
			window.parent.commframe.document.location.href = window.parent.AuthServerAddress + "?msg=logoff&sessionid=" + window.parent.sessionGUID;
		}catch(e)
		{}
		window.parent.ContentFrame.document.location.href = "/als/servlet/logout?respond=true&customer=" + customer
   	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alsutils.logout()");
	}
}

function minimizeFrame()
{
	//alert("minimizeFrame() has been deprecated.");
}
function maximizeFrame()
{	
	//alert("maximizeFrame() has been deprecated.");
}

function setStatusBarText(mesg)
{
	try
	{
		window.status = mesg;
   	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alsutils.setStatusBarText()");
	}
}

function setStatusBarALS()
{
	setStatusBarText("A+nyWhere Learning System");
}

function setStatusBarHelp()
{
	setStatusBarText("Help");
}

function setStatusBarNext()
{
	setStatusBarText("Next");
}

function setStatusBarPrevious()
{
	setStatusBarText("Previous");
}

function setStatusBarFeedBack()
{
	setStatusBarText("Leave Feedback");
}

function setStatusBarStop()
{
	setStatusBarText("Stop");
}

function setStatusBarLogout()
{
	setStatusBarText("Log Out");
}

function setStatusBarSoundOn()
{
	setStatusBarText("Sound ON");
}

function setStatusBarSoundOff()
{
	setStatusBarText("Sound OFF");
}

function setTextOver(ele, msg)
{
	try
	{
		if(ele != null)
			ele.innerHTML = msg
   	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alsutils.setTextOver()");
	}
}

function setSPTTextOverStudy(ele)
{
	var msg = "To complete the Study Guide, you must meet the minimum time or number of accesses requirement. " + 
		  "\"Your Performance\" shows the progress you have made toward fulfilling this requirement.";
	setTextOver(ele, msg)
}

function setSPTTextOverPractice(ele)
{
	var msg = "You must achieve the minimum score requirement to complete the Practice Test. \"Your Performance\" shows your highest Practice Test score on this lesson so far."
	setTextOver(ele, msg)
}

function setSPTTextOverMastery(ele)
{
	var msg = "You must achieve the minimum score requirement to complete the Mastery Test. \"Your Performance\" shows your highest Mastery Test score on this lesson so far."
	setTextOver(ele, msg)
}

function setSPTTextOverBlank(ele)
{
	var msg = "";
	setTextOver(ele, msg)
}

function getTextForMinimumRequired(val)
{
	return "Minimum Required:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + val + "%";
}

function getTextForPrestest()
{
	return "You will now take a Pretest on this lesson. You will pass the Pretest if you achieve the \"Minimum Required\" score shown below."; 
}

function getTextForPrestestMaster()
{
	return "You will now take a Pretest on this lesson. If you achieve the \"Minimum Required\" score shown below, " +
	       "you will be given credit for mastering this lesson."; 
}

function getTextForReview()
{
	return "You are now going to take a Review Test on some of the material you have already learned. " +
	       "Please relax and do the best you can!";
}

function getTextForAssessment()
{
	return "You will now take an <b>Assessment</b> Test. In order to receive your lessons, you <b>MUST</b> complete the entire test. " +
	       "Please take your time and do your best. The number of required assignments you must complete for this course will be " + 
	       "based on the results of your assessment test. You do not have to study for this test.";
}

function getTextForAdvancerAssessment()
{
	return "You will now take an <b>Assessment</b> Test. In order to receive your lessons, you <b>MUST</b> complete the entire test. " +
	       "Please take your time and do your best. The number of required assignments you must complete for this course will be " + 
	       "based on the results of your assessment test. You do not have to study for this test.";
}

function getTextForCourseAssessment()
{
	return "You will now take an <b>Assessment</b> Test. In order to receive your lessons, you <b>MUST</b> complete the entire test. " +
	       "Please take your time and do your best. The number of required assignments you must complete for this course will be " + 
	       "based on the results of your assessment test. You do not have to study for this test.";
}

/******************************************************************************************
**
** Function getAPIHandle()
** Inputs:	None
** Return:	value contained by APIHandle
**
** Description:
** Returns the handle to API object if it was previously set, 
** otherwise it returns null
**
******************************************************************************************/
function getAPIHandle() 
{
   try
   {
	   if (apiHandle == null)
	   {
	      apiHandle = window.parent.macapiframe; //getAPI();
	   } 

	   return apiHandle;
   }catch (e)
   {
	errorHandler(e.message, "" ,"" , e.name, "alsutils.getAPIHandle()");
   }
}


/******************************************************************************************
**
** Function findAPI(win)
** Inputs:	win - a Window Object
** Return:	If an API object is found, it is returned, otherwise null is returned.
**
** Description:
** This function looks for an object named API in the supported window hierarchy, 
** 
******************************************************************************************/
function findAPI(win) 
{

   try
   {
	   // Search the window hierarchy for an object named "API"  
	   // Look in the current window (win) and recursively look in any child frames


	   if (_Debug)
	   {
	      alert("win is: "+win.location.href);
	   }


	   if (win.API != null)
	   {
	      if (_Debug)
	      {
		 alert("found api in this window");
	      }
	      return win.API;
	   }

	   if (win.length > 0)  // does the window have frames?
	   {
	      if (_Debug)
	      {
		 alert("looking for api in windows frames");
	      }

	      for (var i=0;i<win.length;i++)
	      {

		 if (_Debug)
		 {
		    alert("looking for api in frames["+i+"]");
		 }
		 var theAPI = findAPI(win.frames[i]);
		 if (theAPI != null)
		 {
		    return theAPI;
		 }
	      }
	   }

	   if (_Debug)
	   {
	      alert("didn't find api in this window (or its children)");
	   }
	   return null;
   }catch (e)
   {
	errorHandler(e.message, "" ,"" , e.name, "alsutils.findAPI()");
   }

}


/******************************************************************************************
**
** Function getAPI()
** Inputs:	none
** Return:	If an API object is found, it is returned, otherwise null is returned.
**
** Description:
** This function looks for an object named API, first in the current window's hierarchy, 
**  and then, if necessary, in the current window's opener window hierarchy (if there is
**  an opener window).
******************************************************************************************/

function getAPI()
{

   try
   {
	   // start at the topmost window - findAPI will recurse down through
	   // all of the child frames
	   var theAPI = findAPI(this.top);
	   //var theAPI = findAPI(this);

	   if (theAPI == null)
	   {
	      // the API wasn't found in the current window's hierarchy.  If the
	      // current window has an opener (was launched by another window),
	      // check the opener's window hierarchy. 
	      if (_Debug)
	      {
		 alert("checking to see if this window has an opener");
		 alert("window.opener typeof is> "+typeof(window.opener));
	      }

	      if (typeof(this.opener) != "undefined")
	      {
		 if (_Debug)
		 {
		    alert("checking this windows opener");
		 }
		 if (this.opener != null)
		 {
		    if (_Debug)
		    {
		       alert("this windows opener is NOT null - looking there");
		    }
		    theAPI = findAPI(this.opener.top);
		 }
		 else
		 {
		    if (_Debug)
		    {
		       alert("this windows opener is null");
		    }
		 }
	      }
	   }

	   return theAPI;
   }catch (e)
   {
	errorHandler(e.message, "" ,"" , e.name, "alsutils.getAPI()");
   }
}

function errorHandler(msg, url, lno, errorname, failedfunction)
{
	var inContent = true;
	try
	{
        	window.parent.ContentFrame.setValues();
	}catch (e)
	{
		inContent = false;
	}
	var alertmsg =	"There has been an internal javascript error on this page.\nThis could have been caused by many things including, a slow connection.\n" +
			"You can go back to the previous page by right clicking your mouse and selecting 'back' from the context menu or by pressing the 'backspace' key on your keyboard.\n" +
			"Once you've gone back to the previous page you can try to access this page again.\n" +
			"There could be a problem with your browser settings, on the login screen there is a 'Check Browser Settings' link on the top of the page." + 
			"Click the link and run the tests provided.\n" + 
			"If you still cannot access this page shut down your browser and try again.\nIf you are still having problems accessing this page contact your technical support.\n" +
			"\nError: " + msg + "\nURL: " + url + "\nLine: " + lno + "\n" +
			"Error Name: " + errorname + "\nFailed in: " + failedfunction + "\n";
	if(inContent)
	{
		alertmsg = alertmsg + "\nSubject: " + window.parent.ContentFrame.subname + "\nActivity: " + window.parent.ContentFrame.actname + "\nPage: " + window.parent.ContentFrame.page +
			   "\nAssess Subject: " + window.parent.ContentFrame.assesssub + "\nAssess Activity: " + window.parent.ContentFrame.assessact;
			   
	}
	alertmsg = alertmsg + "\nResolution: " + screen.width + "x" + screen.height +
		   "\nBrowser: " + getBrowserNameVersion();
	alert(alertmsg);
	return (true);
}

function getCookie( name )
{
	var cname = name + "=";
	var dc = document.cookie;
	if ( dc.length > 0 )
	{
		begin = dc.indexOf( cname );

		if ( begin != -1 )
		{
			begin += cname.length;
			end = dc.indexOf( ";", begin );

			if ( ( end == -1 ) && ( dc.indexOf( "path=;" ) == -1 ) )
			{
				end = dc.length;
			}
			return unescape( dc.substring( begin, end ) );
		}
	}
	return null;
}

function setCookie(name, value, expires, path, domain, secure)
{
  document.cookie = name + "=" + escape(value) +
  ((expires == null) ? "" : "; expires=" + expires.toUTCString()) +
  ((path == null) ? "" : "; path=" + path) +
  ((domain == null) ? "" : "; domain=" + domain) +
  ((secure == null) ? "" : "; secure");
}

function delCookie (name,path,domain)
{
	if ( getCookie( name ) )
	{
		document.cookie = name + "=" +
		( ( path == null ) ? "" : "; path=" + path ) +
		( ( domain == null ) ? "" : "; domain=" + domain ) +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

function checkMouseClicked()
{
	if((mouseClicked && browser=="Internet Explorer") || (mouseClicked && ((mouseClickedTime + 3000) > new Date().getTime())))
		return true;
	else
	{
		mouseClicked = true;
		mouseClickedTime = new Date().getTime();
                return false;
	}
}

function setLLSSoundImages()
{
	soundico = "/als/images/pb/lls/frog.gif";	
}

function setERSoundImages()
{
	soundico = "/als/images/pb/emergentreader/repeatButton.jpg";	
}

function isDebug()
{
	return _Debug;
}

function isDevelopmentSite()
{
	return developmentSite;
}

function initMouseClicked()
{
	mouseClicked = false;
	mouseClickedTime = 0;
}

// send message to Flash movie's ALSTrace - handy for debugging

function flashALSTrace(msgStr, traceCategory) {
    if (window.parent.frames["ContentFrame"] != null) {
        var flashPlayer = window.ContentFrame.document.getElementById("ALSViewer");        
        if (flashPlayer != null) {
            msgStr = "[JS] " + msgStr;
            flashPlayer.ALSTrace(msgStr, traceCategory);
        }
    }
}

function handleBrowserEvent(eventName, eventParam) {
    if (window.parent.frames["ContentFrame"] != null) {
 		var flashPlayer = window.ContentFrame.document.getElementById("ALSViewer");
 		if (flashPlayer != null) { 			
 			flashPlayer.ALSEventDispatcher(eventName, eventParam); 			
 		}
    }
}

function getRequestObject()
{
	var requestObj = null;
	if (window.XMLHttpRequest)
	{
		requestObj = new XMLHttpRequest();
		if (requestObj.overrideMimeType)
			requestObj.overrideMimeType('text/xml');
	}
	else if (window.ActiveXObject)
	{
		try
		{
			requestObj = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e)
		{
			try
			{
				requestObj = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	return requestObj;
}

function alsutilsIsLoaded() 
{
	window.parent.ContentFrame.document.onmousedown = catchScrollButton;
	return true;
}

