//alscontent.js
//this file contains functions used by the content templates

var pageIsLoaded = false;
var nextPagePrompt = null;
var previousObj = null;
var firsttime = true;
var mediaArr = new Array(0);
var playingSound = false;
var isDynamic = false;
var showingResults = false;
var JSVersion = "4.0009"
var userName;

function MM_preloadImages() { //v3.0
    try
    {
	    var d=window.ContentFrame.document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
    }catch (e)
    {
  	 errorHandler(e.message, "" ,"" , e.name, "alscontent.MM_preloadImages()");
    }
}

function MM_swapImgRestore() { //v3.0
  try
  {
  	var i,x,a=window.ContentFrame.document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
  }catch (e)
  {
  	 errorHandler(e.message, "" ,"" , e.name, "alscontent.MM_swapImgRestore()");
  }
}

function MM_findObj(n, d) { //v4.0
  try
  {
	  var p,i,x;  if(!d) d=window.ContentFrame.document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	  if(!x && window.ContentFrame.document.getElementById) x=window.ContentFrame.document.getElementById(n); return x;
  }catch (e)
  {
  	 errorHandler(e.message, "" ,"" , e.name, "alscontent.MM_findObj()");
  }
}

function MM_swapImage() { //v3.0
  try
  {
	   var i,j=0,x,a=MM_swapImage.arguments; window.ContentFrame.document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	   if ((x=MM_findObj(a[i]))!=null){window.ContentFrame.document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
  }catch (e)
  {
  	 errorHandler(e.message, "" ,"" , e.name, "alscontent.MM_swapImage()");
  }
}

function MM_goToURL() { //v3.0
  try
  {
	  var i, args=MM_goToURL.arguments; window.ContentFrame.document.MM_returnValue = false;
	  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
  }catch (e)
  {
  	 errorHandler(e.message, "" ,"" , e.name, "alscontent.MM_goToURL()");
  }
}

document.onmousedown = executeMouseClick;

function doSoundMouseOver()
{
	try
	{
		if(soundFlag)
		{
			window.ContentFrame.document.soundimg.scr = MM_swapImage('soundimg','','/adv/images/pb/rolloversnd_on.gif',1);
			setStatusBarSoundOn();
		}
		else
		{
			window.ContentFrame.document.soundimg.scr = MM_swapImage('soundimg','','/adv/images/pb/rolloversnd_off.gif',1);
			setStatusBarSoundOff();
		}
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.doSoundMouseOver()");
	}

}

function doSoundMouseOut()
{
	try
	{
		if(soundFlag)
			window.ContentFrame.document.soundimg.scr = MM_swapImage('soundimg','','/adv/images/pb/snd_on.gif',1);
		else
			window.ContentFrame.document.soundimg.scr = MM_swapImage('soundimg','','/adv/images/pb/snd_off.gif',1);
		displayPageNo();
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.doSoundMouseOut()");
	}
}

function displayPageNo()
{
	try
	{
		window.status=window.ContentFrame.message;
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.displayPageNo()");
	}
}

function manageGlobalVars()
{
	try
	{
		initVariables();
		setAnswers();
		try
		{
			atu = window.ContentFrame.allTriesUsed	
		}catch(e)
		{}
		if(window.ContentFrame.mode == "practice" && atu)
			disableInputs();
		if(window.ContentFrame.randomize)
			randomizeanswers(window.ContentFrame.answerIds, window.ContentFrame.selectableObjects)
		showAnswers();
		if(window.ContentFrame.document.ebForm != null)
		{
			if(window.ContentFrame.document.ebForm.customerName != null)
				window.ContentFrame.document.ebForm.customerName.value = getCustomer();
			if(window.ContentFrame.document.ebForm.uid != null)
				window.ContentFrame.document.ebForm.uid.value = window.ContentFrame.uid
			if(window.ContentFrame.document.ebForm.adminEssay != null)
				window.ContentFrame.document.ebForm.adminEssay.value = window.ContentFrame.adminessay
		}

		if(window.ContentFrame.promptmessage)
		{
			if(window.ContentFrame.mode == "study" || window.ContentFrame.mode == "essay")
				promptUser();
			else if(!window.ContentFrame.bookMark && (window.ContentFrame.mode == "practice" || window.ContentFrame.mode == "mastery" ||  window.ContentFrame.mode == "review" || window.ContentFrame.mode == "pretest" || window.ContentFrame.mode == "snapshot assessment"))
				promptUserTest(false);
			else if(!window.ContentFrame.bookMark && window.ContentFrame.mode == "assess")
				promptUserSkill();
			else if(window.ContentFrame.mode == "course assessment" || (window.ContentFrame.mode == "practice" || window.ContentFrame.mode == "mastery" ||  window.ContentFrame.mode == "review" || window.ContentFrame.mode == "pretest" || window.ContentFrame.mode == "assess" && window.ContentFrame.bookMark))
				promptQuestionsUnanswered();
		}
		setInputFocus(window.ContentFrame.document.ebForm)
		if(window.ContentFrame.document.body.style.background == "" && window.ContentFrame.background != "")
			setBgImage();
		
		if(getBrowserName() == "Netscape")
		{
			loadMedia();
			if(window.ContentFrame.document.getElementsByTagName("body").item(0).style.backgroundImage == "" && window.ContentFrame.background != "")
				setBgImage();
		}
		if(window.ContentFrame.document.ebForm.ebAnswer != null)
		{
			var ebA = window.ContentFrame.document.ebForm.ebAnswer.value
			if(ebA != null && ebA.length > 1 && !window.ContentFrame.document.ebForm.ebAnswer.disabled)
				startTimer();
		}

		//fix for setText bug
		var nb2 = window.ContentFrame.document.getElementById("navbar2");
		if(nb2 == null)
		{
			var safari = navigator.userAgent.indexOf('Safari')>0;
			var formObj = window.ContentFrame.document.forms["ebForm"];
			if(formObj != null)
			{
				var elmts_array = formObj.elements;
				for(var i = 0; i < elmts_array.length; i++)
				{		
					if(elmts_array[i].name == "navbar2")
					{
						nb2 = elmts_array[i]; 
						if(!safari)
							break;
					}
					if(safari && elmts_array[i].type == "text")
					{
						elmts_array[i].style.color="black";
					}	
				}
			}
		}
		if(nb2 != null)
		{
			var val = nb2.value;
			if((!window.ContentFrame.adminview && window.ContentFrame.mode == "essay") || window.ContentFrame.adminessay)
				nb2.value = "essayAnswer"
			else if(window.ContentFrame.answerIds.length > 0)
				nb2.value = "answer"
		}
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.manageGlobalVars()");
	}
}

function initVariables()
{
	previousObj = null;
	firsttime = true;
	showingResults = false;
	mediaArr = new Array(0);
	isDynamic = false;
			
	var nameJSP = "/adv/getAdvancerUserName.jsp"
	var params = "customer=" + getCustomer();
	var req = getRequestObject();
	req.onreadystatechange = function()
	{
		if(req.readyState == 4)
		{
			if(req.status == 200)
			{
				var response = req.responseText;
				userName = trim(response);
			}
		}
	}
	req.open("POST", nameJSP, true);
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	req.send(params);

}

function promptUser()
{
	try
	{
		var userReply = confirm("Click 'OK' to exit, or 'Cancel' returns you to the activity.")
		if(userReply)
		{
			finalInit();
			stop();
		}
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.promptUser()");
	}
}

function promptUserTest(promptBeforeServerHit)
{
	try
	{
		var userReply
		//if(bookMark && (mode == "mastery" || mode == "course assessment") && !allQuestionsAnswered)
		//{
		//	userReply = confirm("Would you like to save a bookmark so you can finish this test later? Click 'OK' for yes or 'Cancel' for no.")
		//	if(userReply)
		//	{
		//		exitWithoutTestResults();
		//		return;
		//	}
		//}

		//In the case that the user has right clicked and hit back calling stop will
		//not take them to the StudyPracticeTest(STP) Screen, but will take them to this function
		//that would have prompted them "are the finished with the test". Since stopStudentNav
		//is true we know that they have already finished the test and that any "stop" call after
		//that needs to take them to the STP Screen so that's where we are taking them now.
		if(window.parent.stopStudentNav && !window.ContentFrame.bookMark)
		{
			gotoStudyPracticeTest();
			return;
		}
		if(window.ContentFrame.mode == "assess" || window.ContentFrame.mode == "snapshot assessment")
			userReply = confirm("Click 'OK' to exit the test, or 'Cancel' to return to it.")
		else
			userReply = confirm("Click 'OK' to score the test, or 'Cancel' to return to it.")
		if(userReply)
		{
			if(window.ContentFrame.mode == "snapshot assessment")
			{
				userReply = confirm("You can not continue with your regular\n leassons until this test is completed.\n\n Would you like to finish it now?\n Click 'OK' for yes or 'Cancel' for no.")
				if(!userReply)
				{
					if(window.ContentFrame.document.ebForm.navbar2 != null)
						window.ContentFrame.document.ebForm.navbar2.value = ""
					finalInit();
					//This Hack was because Pat wanted the prompt to the user to happen
					//before the submit to the server. This only happens if bookMark is false
					if(promptBeforeServerHit)
						NavQuitModule()
					else
						stop();
				}
			}else
			{
				window.ContentFrame.preventNav = true;
				//This Hack was because Pat wanted the prompt to the user to happen
				//before the submit to the server. This only happens if bookMark is false
				if(promptBeforeServerHit && window.ContentFrame.mode == "assess")
					NavQuitModule()
				else
				{
					showingResults = true;
					eval("document.onconte"+"xtmenu = cancelRightClick");
					showResults()
				}
			}
		}
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.promptUserTest()");
	}
	
}

function promptUserSkill()
{
	try
	{
		var userReply = confirm("That was the last question for this ALS skill. Do you want to go on? Click 'OK' for yes or 'Cancel' for no.")
		if(userReply)
		{
			doubleCheckUID()
			NavNextSkill();
		}
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.promptUserSkill()");
	}
}

function promptQuestionsUnanswered()
{
	
	try
	{
		if(window.ContentFrame.flatLastChance)
		{
			userReply = confirm("Are you finished answering these questions? Click 'OK' for yes or 'Cancel' for no.")
			if(userReply)
			{
				if(window.ContentFrame.allPagesShown && window.ContentFrame.mode != "assess")
				{
					eval("document.onconte"+"xtmenu = cancelRightClick");
					showResults()
				}else
					gotoStudyPracticeTest();
			}
		}else if(window.ContentFrame.allQuestionsAnswered && window.ContentFrame.mode != "assess")
			promptUserTest()
		else
		{
			if(window.ContentFrame.visitedQuestionsUnanswered == -1)
			{
				var userReply = confirm("You have not completed this test.\n Are you sure you would like to exit and finish it later? Click 'OK' for yes or 'Cancel' for no.");
				if(userReply)
					getVisitedQuestionsUnanswered();
			}else
			{
				if(window.ContentFrame.visitedQuestionsUnanswered > 0 && !window.ContentFrame.flatLastChance)
				{
					if(window.ContentFrame.autoSound && window.ContentFrame.soundEvent != "" && window.ContentFrame.soundEvent != "<SOUNDEVENT></SOUNDEVENT>")
					{
						disableSound();
						player = null;
					}				
					userReply = confirm("You have viewed " + window.ContentFrame.visitedQuestionsUnanswered  + " question(s) and not answered them.\n If you do not answer them now you will not be allowed to\n answer them next time and they will be marked incorrect.\n\n Would you like to answer these questions now? Click 'OK' for yes or 'Cancel' for no.")
					if(userReply)
						gotoFirstUnansweredQuestion()
					else
					{
						if(window.ContentFrame.allPagesShown && window.ContentFrame.mode != "assess")
						{
							eval("document.onconte"+"xtmenu = cancelRightClick");
							showResults()
						}else
							gotoStudyPracticeTest();
					}
				}else
					gotoStudyPracticeTest();
			}
		}
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.promptQuestionsUnanswered()");
	}
		
}

function promptSaveEssay()
{
	try
	{	var userReply = confirm("Click 'OK' to exit, or 'Cancel' returns you to the Essay.")
		if(userReply)
		{
		
			userReply = confirm("Click 'OK' to save your Essay, or 'Cancel' exits without saving.")
			if(userReply)
			{
				save(true)
				return true;
			}else
				return false;
		}else
			return "continue"
			
		}catch (e)
		{
			errorHandler(e.message, "" ,"" , e.name, "alscontent.promptSaveEssay()");
	}
}

function setInputFocus(formObj)
{
      try
      {
	      var setFocus = false;
	      var foundFirstObj = false;
	      var obj = null;
	      if(!showingResults)
	      {
		      if(formObj != null)
		      {
			      for(i=0; i<formObj.elements.length; i++)
			      {
					if(formObj.elements[i].type == 'text' || formObj.elements[i].type == 'textarea')
					{
						if(formObj.elements[i].style.tabindex == 1 && !formObj.elements[i].disabled)
						{
							setFocus = true;
							formObj.elements[i].focus();
							break;
						}else if(!formObj.elements[i].disabled && !foundFirstObj)
						{
							//save the first text object to set focus to if we can't find one with a tab order
							obj = formObj.elements[i];
							foundFirstObj = true;
						}
					}
			      }
			      if(!setFocus && foundFirstObj && obj != null && !obj.disabled)
			      {
					try
					{
						obj.focus();
					}catch(e)
					{
						//added this because I can't check for visiblity and if it is invisible 
						//we'll get an exception but we still want to continue. There's no 
						//reason to throw an error alert for not being able to set the focus.			      		
			      		}
			      	}	
		     }
	      }
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.setInputFocus()");
	}
}

function randomizeanswers(answerIds, selectableObjects)
{
	try
	{
		objs = new Array(answerIds.length)
		brdobjs = new Array(selectableObjects.length)
		otherobjs = new Array(selectableObjects.length);
		otherobjsjoin = new Array(selectableObjects.length);
		raid = null;

		//fill the arrays with objects
		if(answerIds.length > 1)
		{
			for(i=0; i<answerIds.length; i++)
			{
				objs[i] = window.ContentFrame.document.getElementById("x" + answerIds[i]);
				brdobjs[i] = window.ContentFrame.document.getElementById("x" + selectableObjects[i]);
				var elems = window.ContentFrame.document.getElementsByTagName("div");
				var numberobjs = 0;
				for(x = 0; x < elems.length; x++)
				{
					var tmpobj = elems[x];
					if(tmpobj.id != "")
					{	
						var left = Number(brdobjs[i].style.left.substring(0, brdobjs[i].style.left.length - 2));
						var top = Number(brdobjs[i].style.top.substring(0, brdobjs[i].style.top.length - 2));
						var height = Number(brdobjs[i].style.height.substring(0, brdobjs[i].style.height.length - 2));
						var width = Number(brdobjs[i].style.width.substring(0, brdobjs[i].style.width.length - 2));

						var left2 = Number(tmpobj.style.left.substring(0, tmpobj.style.left.length - 2));
						var top2 = Number(tmpobj.style.top.substring(0, tmpobj.style.top.length - 2));
						var height2 = Number(tmpobj.style.height.substring(0, tmpobj.style.height.length - 2));
						var width2 = Number(tmpobj.style.width.substring(0, tmpobj.style.width.length - 2));
						if(top2 >= (top - 25) && (top2 + height2) <= (top + height + 25))
						{
							if(left2 >= (left - 25) && (left2 + width2) <= (left + width + 25))
							{
								var needadded = true;
								if(objs[i].id == tmpobj.id)
									needadded = false;
								if(brdobjs[i].id == tmpobj.id)
									needadded = false;
								if(needadded == true)
								{
									numberobjs = numberobjs + 1;
								}
							}
						}
					}
				}
				if(numberobjs > 0)
				{
					var tmparr = new Array(numberobjs);
					var index = 0
					for(x = 0; x < elems.length; x++)
					{
						var tmpobj = elems[x];
						if(tmpobj.id != "")
						{	
							var left = Number(brdobjs[i].style.left.substring(0, brdobjs[i].style.left.length - 2));
							var top = Number(brdobjs[i].style.top.substring(0, brdobjs[i].style.top.length - 2));
							var height = Number(brdobjs[i].style.height.substring(0, brdobjs[i].style.height.length - 2));
							var width = Number(brdobjs[i].style.width.substring(0, brdobjs[i].style.width.length - 2));

							var left2 = Number(tmpobj.style.left.substring(0, tmpobj.style.left.length - 2));
							var top2 = Number(tmpobj.style.top.substring(0, tmpobj.style.top.length - 2));
							var height2 = Number(tmpobj.style.height.substring(0, tmpobj.style.height.length - 2));
							var width2 = Number(tmpobj.style.width.substring(0, tmpobj.style.width.length - 2));

							if(top2 >= (top - 25) && (top2 + height2) <= (top + height + 25))
							{	
								if(left2 >= (left - 25) && (left2 + width2) <= (left + width + 25))
								{
									var needadded = true;
									if(objs[i].id == tmpobj.id)
										needadded = false;
									if(brdobjs[i].id == tmpobj.id)
										needadded = false;
									if(needadded == true)
									{
										tmparr[index] = tmpobj;
										otherobjsjoin[i] = new JoinOtherObjects(tmpobj.id, brdobjs[i].id)										
										index = index + 1;
									}
								}
							}
						}
					}
					otherobjs[i] = tmparr;
				}
			}

			//create arrays that will store our objects in random order
			objsrandom = new Array(objs.length);
			brdobjsrandom = new Array(brdobjs.length)
			placearray = new Array(objs.length);

			//create a random order for the answer items and objects
			if(window.ContentFrame.itemOrder.length == 0)
			{
				i = 0;
				raid = new Array(answerIds.length);
				while (i<objs.length)
				{
					random=Math.floor(Math.random()*objs.length)
					if(placearray[random]!="selected")
					{
						//place the random objects top and left properties in the random array
						objsrandom[i] = new DivObjProps(objs[random].id, objs[random].style.top, objs[random].style.left);
						brdobjsrandom[i] = new DivObjProps(brdobjs[random].id, brdobjs[random].style.top, brdobjs[random].style.left);
						placearray[random]="selected"
						raid[i] = otherobjs[random];
						i++
					}
				}
			}else //use existing random order
			{
				raid = new Array(answerIds.length);
				for(k=0; k<window.ContentFrame.itemOrder.length; k++)
				 {
					ranobj = window.ContentFrame.document.getElementById(window.ContentFrame.itemOrder[k]);
					ranbrd = window.ContentFrame.document.getElementById(window.ContentFrame.objectOrder[k])
					objsrandom[k] = new DivObjProps(ranobj.id, ranobj.style.top, ranobj.style.left);
					brdobjsrandom[k] = new DivObjProps(ranbrd.id, ranbrd.style.top, ranbrd.style.left);
					for(z=0; z<otherobjsjoin.length; z++)
					{
						if(otherobjsjoin[z] != null)
						{
							var OtherObjectAnswerObjId = otherobjsjoin[z].answerObjid;
							if(OtherObjectAnswerObjId == ranbrd.id) 
								raid[k] = otherobjs[z];
						}
					}
				}
			}


			//loop through are arrays of objects and set their top and left properties to the
			//top and left properties of the random arrays objects
			for(i=0; i<objs.length; i++)
			{
				brdobjs[i].style.top = brdobjsrandom[i].top
				brdobjs[i].style.left = brdobjsrandom[i].left
				objs[i].style.top = objsrandom[i].top
				objs[i].style.left = objsrandom[i].left

				if(raid != null)
				{
					if(raid[i] != null)
					{
						for(z=0;z<raid[i].length;z++)
						{		
							if(raid[i] != null)
							{
							//	alert("otherArr size is: " + raid[i].length);
							//	var idone = Number(raid[i][z].id.substring(1, tmpobj.style.width.length));	
							//	alert("other id is: " + idone);
								var nonrandomobject = raid[i][z];

								if(nonrandomobject != null)
								{
									var dl1 = new DynLayer(raid[i][z].id, "", "ContentFrame");
									if (is.ns) dl1.elm.captureEvents(Event.MOUSEDOWN);
									if(window.ContentFrame.mode == "study" || window.ContentFrame.mode == "practice")
									{
											dl1.elm.onmousedown = new Function ("javascript:answerQuestion(" + nonrandomobject + ")");
									}else
									{
									     if(i == 0)
										dl1.elm.onmousedown = new Function ("javascript:changeBorder(" + selectableObjects[0] + ", window.ContentFrame.selectedAnswers)");
									     else if(i == 1)
										dl1.elm.onmousedown = new Function ("javascript:changeBorder(" + selectableObjects[1] + ", window.ContentFrame.selectedAnswers)");
									     else if(i == 2)
										dl1.elm.onmousedown = new Function ("javascript:changeBorder(" + selectableObjects[2] + ", window.ContentFrame.selectedAnswers)");
									     else if(i == 3)
										dl1.elm.onmousedown = new Function ("javascript:changeBorder(" + selectableObjects[3] + ", window.ContentFrame.selectedAnswers)");
									     else if(i == 4)
										dl1.elm.onmousedown = new Function ("javascript:changeBorder(" + selectableObjects[4] + ", window.ContentFrame.selectedAnswers)");
									     else if(i == 5)
										dl1.elm.onmousedown = new Function ("javascript:changeBorder(" + selectableObjects[5] + ", window.ContentFrame.selectedAnswers)");
									     else if(i == 6)
										dl1.elm.onmousedown = new Function ("javascript:changeBorder(" + selectableObjects[6] + ", window.ContentFrame.selectedAnswers)");
									     else if(i == 7)	
										dl1.elm.onmousedown = new Function ("javascript:changeBorder(" + selectableObjects[7] + ", window.ContentFrame.selectedAnswers)");
									     else if(i == 8)	
										dl1.elm.onmousedown = new Function ("javascript:changeBorder(" + selectableObjects[8] + ", window.ContentFrame.selectedAnswers)");
									     else if(i == 9)	
										dl1.elm.onmousedown = new Function ("javascript:changeBorder(" + selectableObjects[9] + ", window.ContentFrame.selectedAnswers)");
									     else if(i == 10)	
										dl1.elm.onmousedown = new Function ("javascript:changeBorder(" + selectableObjects[10] + ", window.ContentFrame.selectedAnswers)");
									     else if(i == 11)	
										dl1.elm.onmousedown = new Function ("javascript:changeBorder(" + selectableObjects[11] + ", window.ContentFrame.selectedAnswers)");
									}
								}
							}
						}
					}
				}

			}

			var ansitemorder = "";
			var ansobjorder = "";
			//create a comma delimited string that contains the random order
			//of the answer items and answer objects
			for(j=0; j<objsrandom.length; j++)
			{
				if(j == 0)
				{
					ansitemorder += objsrandom[j].id
					ansobjorder += brdobjsrandom[j].id
				}else
				{
					ansitemorder += "," + objsrandom[j].id
					ansobjorder += "," + brdobjsrandom[j].id
				}
			}

			window.ContentFrame.document.ebForm.answeritemorder.value=ansitemorder
			window.ContentFrame.document.ebForm.answerobjorder.value=ansobjorder
		}
	}catch (e)
	{
		//there will be errors if the user has right clicked and gone back
		//don't show these errors
		if(!window.parent.stopStudentNav)
			errorHandler(e.message, "" ,"" , e.name, "alscontent.randomizeanswers()");
	}


}

function JoinOtherObjects(otherObjID, answerObjID)
{
	try
	{
		//creates a new object with the ID of the otherObj and the ID othe the corresponding answerObject
		this.id = otherObjID;
		this.answerObjid = answerObjID;
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.JoinOtherObjects()");
	}
}

function DivObjProps(objId, top, left)
{
	try
	{
		//creates a new object with the id, top and left properties on the object passed in
		this.id = objId;
		this.top = top;
		this.left = left;
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.DivObjProps()");
	}
}

function showAnswers()
{
	try
	{
		for(i=0; i<window.ContentFrame.answerIds.length; i++)
		{

			ansobj = window.ContentFrame.document.getElementById("x" + window.ContentFrame.answerIds[i]);
			if(ansobj != null)
				ansobj.style.visibility = "visible";
		}
		for(j=0; j<window.ContentFrame.selectableObjects.length; j++)
		{
			brdobj = window.ContentFrame.document.getElementById("x" + window.ContentFrame.selectableObjects[j]);
			if(brdobj != null)
				brdobj.style.visibility = "visible";
		}
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.showAnswers()");
	}
}

function setAnswers()
{
	try
	{
		var localIsLLS = false; 
		try
		{
			localIsLLS = window.ContentFrame.isLLS			
		}catch(e)
		{}
		if(window.ContentFrame.answers != "")
		{
			answerEles = window.ContentFrame.document.getElementsByName("ebAnswer");
			objectIds = window.ContentFrame.document.getElementsByName("objectid")
			if(objectIds.length > 0)
			{
				//must be input items
				for(i=0; i<objectIds.length; i++)
				{
					for(j=0; j<window.ContentFrame.selectableObjects.length; j++)
					{
						if(objectIds[i].value == window.ContentFrame.answerIds[j])
						{
							answerEles[i].value = window.ContentFrame.answers[j];
							if(window.ContentFrame.answers[j] != null && window.ContentFrame.answers[j].length > 0)
							{
								obj = window.ContentFrame.document.getElementById("x" + window.ContentFrame.selectableObjects[j]);
								if(obj != null && !localIsLLS)
									obj.style.border= "thin solid black";
							}
							break;
						}

					}
				}
			}else
			{
				//mustbe multiple choice
				if(window.ContentFrame.selectedAnswers != "" && window.ContentFrame.selectedAnswers.length > 0)
				{
					for(i=0; i<window.ContentFrame.selectedAnswers.length; i++)
					{
						obj = window.ContentFrame.document.getElementById("x" + window.ContentFrame.selectedAnswers[i]);
						if(obj != null && !localIsLLS)
							obj.style.border= "thin solid black";
					}
				}
			}
		}
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.setAnswers()");
	}
}

function answerQuestion(answer)
{
	try
	{
		if(checkMouseClicked())
			return;		
		if(getPageIsLoaded())
		{
			if(!window.parent.stopStudentNav)
			{
				if(!window.ContentFrame.preventNav)
				{
					if(window.ContentFrame.document.ebForm.navbar != null)
					{
							doubleCheckUID()
							window.ContentFrame.document.ebForm.navbar.value = "answer"
							window.ContentFrame.document.ebForm.navbar2.value = ""
							window.ContentFrame.document.ebForm.soundFlag.value = soundFlag
							window.ContentFrame.document.ebForm.selectedAnswer.value = answer
							window.ContentFrame.document.ebForm.customerName.value = getCustomer();
							window.ContentFrame.document.ebForm.submit();
					}
				}
			}else
			{
				alert("You have attempted to access the test outside of the normal navigation.\n All navigation has been be cancelled."); 
				gotoStudyPracticeTest();
			}
			mouseClicked = false;
			mouseClickedTime = 0;
		}
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.answerQuestion()");
	}
}

function previous()
{
	try
	{
		if(getPageIsLoaded())
		{
			if(!window.parent.stopStudentNav)
			{
				if(!window.ContentFrame.preventNav)
				{
					if(nextPagePrompt != null)
						clearTimeout(nextPagePrompt);
					doubleCheckUID()
					NavPrevious();
				}
			}else
			{
				alert("You have attempted to access the test outside of the normal navigation.\n All navigation has been be cancelled."); 
				gotoStudyPracticeTest();
			}
		}
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.previous()");
	}
}

function next()
{
	try
	{
		if(getPageIsLoaded())
		{
			if(!window.parent.stopStudentNav)
			{
				if(!window.ContentFrame.preventNav)
				{
					if(nextPagePrompt != null)
						clearTimeout(nextPagePrompt);
					doubleCheckUID()
					NavNext();
				}
			}else
			{
				alert("You have attempted to access the test outside of the normal navigation.\n All navigation has been be cancelled."); 
				gotoStudyPracticeTest();
			}

		}
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.next()");
	}	
}


function doRepeatMouseOver()
{
	try
	{
		if(soundFlag)
		{
			if(window.ContentFrame.soundEvent != "" && window.ContentFrame.soundEvent != "<SOUNDEVENT></SOUNDEVENT>")
			{
				window.ContentFrame.document.repeat.src='/adv/images/pb/repeatsoundroll.gif'
				setStatusBarText('Play Sound');
			}else
				window.ContentFrame.document.repeat.src='/adv/images/pb/repeatsoundblank.gif'

		}
		else
			return true;
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.doRepeatMouseOver()");
	}	
}

function doLLSRepeatMouseOver()
{
	try
	{
		if(soundFlag)
			window.ContentFrame.document.repeat.src='/adv/images/pb/lls/frogb.gif'
		else
			return true;
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.doLLSRepeatMouseOver()");
	}	
}

function doERRepeatMouseOver()
{
	try
	{
		if(soundFlag)
		{
			if(window.ContentFrame.soundEvent != "" && window.ContentFrame.soundEvent != "<SOUNDEVENT></SOUNDEVENT>")
				window.ContentFrame.document.repeatER.src='/adv/images/pb/emergentreader/repeatover.jpg'
			else
				window.ContentFrame.document.repeatER.src='/adv/images/pb/emergentreader/repeatDisabled.jpg'
		}else
			return true;
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.doERRepeatMouseOver()");
	}	
}

function doRepeatMouseOut()
{
	try
	{
		if(soundFlag)
		{

		   	if(window.ContentFrame.soundEvent != "" && window.ContentFrame.soundEvent != "<SOUNDEVENT></SOUNDEVENT>")
		   	{
				window.ContentFrame.document.repeat.src='/adv/images/pb/repeatsound.gif';
				displayPageNo();
		   	}else
				window.ContentFrame.document.repeat.src='/adv/images/pb/repeatsoundblank.gif'
		}
		else
			return true;
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.doRepeatMouseOut()");
	}	

}

function doLLSRepeatMouseOut()
{
	try
	{
		if(soundFlag)
	   		window.ContentFrame.document.repeat.src='/adv/images/pb/lls/frog.gif';
		else
			return true;
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.doLLSRepeatMouseOut()");
	}	

}

function doERRepeatMouseOut()
{
	try
	{
		if(soundFlag)
		{
	   		if(window.ContentFrame.soundEvent != "" && window.ContentFrame.soundEvent != "<SOUNDEVENT></SOUNDEVENT>")
	   			window.ContentFrame.document.repeatER.src='/adv/images/pb/emergentreader/repeatButton.jpg';
			else
				window.ContentFrame.document.repeatER.src='/adv/images/pb/emergentreader/repeatDisabled.jpg'
		}else
			return true;
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.doERRepeatMouseOut()");
	}	

}

function toggleSoundRollover()
{
	try
	{
		if(!soundFlag)
			window.ContentFrame.document.soundimg.src='/adv/images/pb/rolloversnd_on.gif';
		else
			window.ContentFrame.document.soundimg.src='/adv/images/pb/rolloversnd_off.gif';
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.toggleSoundRollover()");
	}		
}


function toggle()
{
	try
	{
		if(soundFlag)
		{
			if(window.ContentFrame.soundEvent != "" && window.ContentFrame.soundEvent != "<SOUNDEVENT></SOUNDEVENT>")
			{
				window.ContentFrame.document.repeat.src="/adv/images/pb/repeatsoundblank.gif";
				disableSound();
			}

		}
		else
		{
			if(window.ContentFrame.soundEvent != "" && window.ContentFrame.soundEvent != "<SOUNDEVENT></SOUNDEVENT>")
				window.ContentFrame.document.repeat.src="/adv/images/pb/repeatsound.gif";
		}

		if(document.layers != null)
			toggleSound3(window.ContentFrame.document.images['soundimg'], "")
		else
			toggleSound3(window.ContentFrame.document.soundimg, "")
		doSoundMouseOver();
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.toggle()");
	}	
}


function stop()
{
	try
	{
		var localIsLLS = false; 
		try
		{
			localIsLLS = window.ContentFrame.isLLS			
		}catch(e)
		{}

		if(getPageIsLoaded())
		{
			if(nextPagePrompt != null)
				clearTimeout(nextPagePrompt);
			
			if(window.ContentFrame.mode == 'essay' && !window.ContentFrame.adminview)
			{
				var save = promptSaveEssay()
				if(save == "continue")
					return;
				if(save)
					return true;
				else if(!save && window.ContentFrame.document.ebForm.navbar2 != null)
					window.ContentFrame.document.ebForm.navbar2.value = ""

				if(window.ContentFrame.adminessay)
				{
					window.close()
					return;
				}

			}

			if(!window.parent.stopStudentNav)
			{
				if(!window.ContentFrame.preventNav && !(window.ContentFrame.mode == 'essay' && window.ContentFrame.adminview))
				{
					
					if(nextPagePrompt != null)
						clearTimeout(nextPagePrompt);					
					doubleCheckUID()
					//This Hack was because Pat wanted the prompt to the user to happen
					//before the submit to the server. This only happens if bookMark is false
					if(!localIsLLS && !window.ContentFrame.bookMark && !mouseClicked && (window.ContentFrame.mode == "practice" || window.ContentFrame.mode == "mastery" ||  window.ContentFrame.mode == "review" || window.ContentFrame.mode == "pretest" || window.ContentFrame.mode == "snapshot assessment" || window.ContentFrame.mode == "assess"))
						promptUserTest(true);
					else
						NavStop();
				}else
					gotoStudyPracticeTest();
				
			}else
			{
				alert("You have attempted to access the test outside of the normal navigation.\n All navigation has been be cancelled. "); 
				gotoStudyPracticeTest();
			}
		}
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.stop()");
	}	

}

function showResults()
{
	try
	{
		window.ContentFrame.preventNav = true;
		customer = getCustomer()
		//To stop students from cheating by right clicking and hitting back we
		//set the stopStudentNav variable to true when we show the test results
		if(window.parent.stopStudentNav != null)
			window.parent.stopStudentNav = true;
		tp = (screen.height - 500) / 2
		lft = (screen.width - 500) / 2
		windowprops = "top=" + tp + ",left=" + lft + ",scrollbars=yes,status=0,resizable=yes,menubar=0,width=500,height=500";
		var url = ""
		//This Hack was because Pat wanted the prompt to the user to happen
		//before the submit to the server. This only happens if bookMark is false
		//This part of the Hack is needed to send the answer of the current page before
		//showing the results. This wouldn't be necessary except we are prompting before
		//we hit the server.
		//***********************************************************************
		var ebAnswer = ""
		var navbar2 = ""
		var selectedAnswer = ""
		var objectid = ""
		if(window.ContentFrame.document.ebForm.ebAnswer != null)
			ebAnswer = window.ContentFrame.document.ebForm.ebAnswer.value
		if(window.ContentFrame.document.ebForm.selectedAnswer != null)
			selectedAnswer = window.ContentFrame.document.ebForm.selectedAnswer.value; 
		if(window.ContentFrame.document.ebForm.objectid != null)
			objectid = window.ContentFrame.document.ebForm.objectid.value; 
		if((ebAnswer != null && ebAnswer != "" && selectedAnswer != null && selectedAnswer != "" && objectid != null && objectid != "") || selectedAnswer != null && selectedAnswer != "")
				navbar2 = "answer";
		//************************************************************************
		if(!window.ContentFrame.bookMark && (window.ContentFrame.mode == "practice" || window.ContentFrame.mode == "mastery" ||  window.ContentFrame.mode == "review" || window.ContentFrame.mode == "pretest" || window.ContentFrame.mode == "snapshot assessment" || window.ContentFrame.mode == "assess"))
		{
			url = "/adv/servlet/CommServlet?navbar=getTestResults&uid="+window.ContentFrame.uid+"&soundFlag=" + soundFlag + "&customerName=" + customer + "&navbar2=" + navbar2 + "&selectedAnswer=" + selectedAnswer + "&ebAnswer=" + ebAnswer + "&objectid=" + objectid
			
			//For some reason the document.location.href doesn't work here on the Mac IE
			//I added the work around to submit the form 
			if(getSpecificBrowserName() == "Internet Explorer" && getUserAgent() == "Mac")
			{
				window.ContentFrame.document.ebForm.navbar.value = "getTestResults";
				window.ContentFrame.document.ebForm.uid.value = window.ContentFrame.uid
				window.ContentFrame.document.ebForm.soundFlag.value = soundFlag
				window.ContentFrame.document.ebForm.customerName.value = getCustomer();
				if((ebAnswer != null && ebAnswer != "" && selectedAnswer != null && selectedAnswer != "" && objectid != null && objectid != "") || selectedAnswer != null && selectedAnswer != "")
					window.ContentFrame.document.ebForm.navbar2.value = "answer";
				window.ContentFrame.document.ebForm.submit();
				return;
			}
		}else
		{
			url = "/adv/servlet/CommServlet?navbar=getTestResults&uid="+window.ContentFrame.uid+"&soundFlag=" + soundFlag + "&customerName=" + customer
			
			//For some reason the document.location.href doesn't work here on the Mac IE
			//I added the work around to submit the form 
			if(getSpecificBrowserName() == "Internet Explorer" && getUserAgent() == "Mac")
			{
				window.ContentFrame.document.ebForm.navbar.value = "getTestResults";
				window.ContentFrame.document.ebForm.uid.value = window.ContentFrame.uid
				window.ContentFrame.document.ebForm.soundFlag.value = soundFlag
				window.ContentFrame.document.ebForm.customerName.value = getCustomer();
				window.ContentFrame.document.ebForm.submit();
				return;
			}
		}
		window.ContentFrame.document.location.href = url;
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.showResults()");
	}	
}

function mouseDownHandler(divMsg)
{
	try
	{
		if(isPlayingSound())
			return;
		//redirect to the passed-in location.
		//a href="javascript:history.go(0)
		if(divMsg.indexOf("CommServlet") == 0)
			divMsg += "&soundFlag=" + soundFlag

		//added by Scott H.
		//this was added to support saving the essay answer when the user click the notes button in
		//the writing titles
		if(divMsg.indexOf("javascript") == -1 && divMsg.indexOf("previous") == -1 && divMsg.indexOf("next") == -1 && divMsg.indexOf("enlargePicture") == -1 && divMsg.indexOf("playSound") == -1 && !window.ContentFrame.adminview && window.ContentFrame.document.ebForm.navbar2 != null && window.ContentFrame.document.ebForm.navbar2.value == "essayAnswer" )
		{
			for (x=0; x<window.ContentFrame.document.ebForm.elements.length; x++)
			{
				if(window.ContentFrame.document.ebForm.elements[x].name == "soundFlag")
					divMsg += "&" + window.ContentFrame.document.ebForm.elements[x].name + "=" + soundFlag;
				else if(window.ContentFrame.document.ebForm.elements[x].name != "navbar")
					divMsg += "&" + window.ContentFrame.document.ebForm.elements[x].name + "=" + window.ContentFrame.document.ebForm.elements[x].value;
			}
		}
		
		firstTick = divMsg.indexOf("'");
		lastTick = divMsg.lastIndexOf("'")
		if(divMsg.indexOf("enlargePicture") != -1 && firstTick != -1 && lastTick != -1 && firstTick != lastTick)
		{
			firstPart = divMsg.slice(0, firstTick + 1);
			middlePart = divMsg.slice(firstTick + 1, lastTick)
			lastPart = divMsg.slice(lastTick, divMsg.length)
			middlePart = middlePart.replace("'", "\\'")
			divMsg =  firstPart + middlePart + lastPart
		}
		if(divMsg.indexOf("CommServlet") == 0)
			window.ContentFrame.document.location.href = divMsg;
		else
			eval(divMsg)
		return false;
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.mouseDownHandler()");
	}	
}

function save(stopAfterSave)
{
	try
	{
		if(getPageIsLoaded())
		{
			if(window.ContentFrame.document.ebForm.objectid != null)
			{
				doubleCheckUID();
				if(stopAfterSave != null && stopAfterSave)
				{
					window.ContentFrame.document.ebForm.navbar2.value = "essayAnswer"
					if(window.ContentFrame.adminessay)
						window.ContentFrame.document.ebForm.navbar.value = "stopAdminEssay"
					else
						window.ContentFrame.document.ebForm.navbar.value = "stop"
				}else
				{
					window.ContentFrame.document.ebForm.navbar.value = "essayAnswer"
					window.ContentFrame.document.ebForm.navbar2.value = ""
				}
				window.ContentFrame.document.ebForm.soundFlag.value = soundFlag
				window.ContentFrame.document.ebForm.submit();
			}else if(stopAfterSave)
			{
				if(window.ContentFrame.adminessay)
					window.ContentFrame.document.ebForm.navbar.value = "stopAdminEssay"
				else
					window.ContentFrame.document.ebForm.navbar.value = "stop"
				window.ContentFrame.document.ebForm.navbar2.value = ""	
				window.ContentFrame.document.ebForm.soundFlag.value = soundFlag
				window.ContentFrame.document.ebForm.submit();
			}
			if(window.ContentFrame.adminessay && stopAfterSave)
				window.close();
		}
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "save()");
	}	
}

function gotoStudyPracticeTest(passedUid)
{
	try
	{
		var nUid;		
		try
		{
			if(passedUid != null && passedUid.length > 0)
				nUid = passedUid
			else
				nUid = window.ContentFrame.uid
		}catch(e)
		{
			//this uid is passed from the TestResults Screen in the case that the user has
			//right clicked and hit back and now the content screen contains the Test Results
			//since it doesn't have the uid anymore the TestResults Screen passes it to this function
			nUid = passedUid
		}

		customer = getCustomer();
		window.parent.ContentFrame.document.location.href = "/adv/servlet/CommServlet?navbar=stop&uid="+nUid+"&customerName=" + customer
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.gotoStudyPracticeTest()");
	}	
}

function loadChooseActType(passedUid, lBookMark, lMode)
{
	try
	{
		var nUid;		
		try
		{
			if(passedUid != null && passedUid.length > 0)
				nUid = passedUid
			else
				nUid = window.ContentFrame.uid
		}catch(e)
		{
		
		}

		customer = getCustomer();
//		if((!lBookMark) || (lMode == "review" || lMode == "course assessment" || lMode == "assess" || lMode == "snapshot assessment"))
			NavQuitModule(nUid);
//		else
//		{
//			
//			window.parent.ContentFrame.document.location.href = "/adv/servlet/CommServlet?navbar=loadChooseActType&uid="+nUid+"&customerName=" + customer
//		}
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.loadChooseActType()");
	}	
}

function gotoFirstUnansweredQuestion()
{
	try
	{
		customer = getCustomer();
		window.parent.ContentFrame.document.location.href = "/adv/servlet/CommServlet?navbar=getFirstUnansweredQuestion&uid="+window.ContentFrame.uid+"&customerName=" + customer
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.gotoFirstUnansweredQuestion()");
	}	
}

function getVisitedQuestionsUnanswered()
{
	try
	{
		customer = getCustomer();
		window.parent.ContentFrame.document.location.href = "/adv/servlet/CommServlet?navbar=getVisitedQuestionsUnanswered&uid="+window.ContentFrame.uid+"&customerName=" + customer
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.getVisitedQuestionsUnanswered()");
	}	
}

function exitWithoutTestResults()
{
	try
	{
		customer = getCustomer();
		window.parent.ContentFrame.document.location.href = "/adv/servlet/CommServlet?navbar=stop&uid="+window.ContentFrame.uid+"&customerName=" + customer	+ "&savebookmark=true";
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.exitWithoutTestResults()");
	}	
}

function doubleCheckUID()
{
	try
	{
		//there are timing issues when the user clicks next, previous or stop the uid
		//may not have been set in the form yet. This function checks to see it is set
		//and if not set it
		if(window.ContentFrame.document.ebForm != null)
		{
			if(window.ContentFrame.document.ebForm.uid != null)
			{
				if(window.ContentFrame.document.ebForm.uid.value == "")
					window.ContentFrame.document.ebForm.uid.value = window.ContentFrame.uid
			}
		}
		disableSound();
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.doubleCheckUID()");
	}	
}

function changeBorder(obj, previous)
{
	try
	{
		var localIsLLS = false; 
		try
		{
			localIsLLS = window.ContentFrame.isLLS			
		}catch(e)
		{}		
		
		if(getPageIsLoaded())
		{
			for(x = 0; x < window.ContentFrame.answerIds.length; x++)
			{
				if(obj == window.ContentFrame.answerIds[x])
				{
					obj = Number(obj) - 1;
					break;
				}
			}
			
			if(localIsLLS)
			{
				window.ContentFrame.document.ebForm.selectedAnswer.value = obj;
				return;
			}
			//check to see if a object has been selected before and this is the first time this function
			//is called set the previousObj equal to the previous selected obj
			if(firsttime && previous != "")
			{
				for(i=0; i<previous.length; i++)
					previousObj = previous[i];  
			}

			firsttime = false;

			//get the newly selected object
			newObj = window.ContentFrame.document.getElementById("x" + obj);
			if(newObj != null)
			{
				//if this object is the same as the previous object
				if(obj != previousObj)
				{
					//a different object has been selected change its border to solid
					newObj.style.border= "thin solid black";
					window.ContentFrame.document.ebForm.selectedAnswer.value = obj;

					//if the previous object is not null, meaning that another object has its borders turned on
					if(previousObj != null)
					{
						//get the previous object
						oldObj = window.ContentFrame.document.getElementById("x" + previousObj);
						//and turn off its borders
						oldObj.style.border= "thin none black";
					}

					//now set the previous object equal to the current object
					previousObj = obj;
					startTimer();
				}

			}
		}
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.changeBorder()");
	}
}

function startTimer()
{
	try
	{
		if(nextPagePrompt != null)
			clearTimeout(nextPagePrompt);
		if(!window.ContentFrame.adminessay)
			nextPagePrompt = setTimeout("promptNextPage()", 15000); 	
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.startTimer()");
	}
}

function promptNextPage()
{
	try
	{
		alert("Reminder: To continue, you must click on the 'next' arrow located on the A+dvancer toolbar above.");
	}catch(e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.promptNextPage()");
	}
}

function executeMouseClick(e)
{
	  try
	  {
		var localIsLLS = false; 
		try
		{
			localIsLLS = window.ContentFrame.isLLS			
		}catch(e)
		{}
		
		if(getPageIsLoaded() && !localIsLLS)
		{	
		  //current mouse x and y location	
		  var x;
		  var y;
		  if(getBrowserName() == "Netscape" || getBrowserName() == "Netscape Navigator")
		  {	
			x = e.pageX + document.body.scrollLeft;
			y = e.pageY + document.body.scrollTop;
		  }else
		  {
			x = event.clientX + document.body.scrollLeft;
			y = event.clientY + document.body.scrollTop;
		  }

		  if(window.ContentFrame.selectableObjects != null && window.ContentFrame.selectableObjects.length > 1)
		  {
			  answerObjects = new Array(window.ContentFrame.selectableObjects.length)
			  for(i=0; i<window.ContentFrame.selectableObjects.length; i++)
			  {     
				answerObjects[i] = window.ContentFrame.document.getElementById("x" + window.ContentFrame.selectableObjects[i]);
				if(answerObjects[i] != null)
				{

					dLeft = Number(answerObjects[i].style.left.substring(0, answerObjects[i].style.left.length - 2));
					dTop = Number(answerObjects[i].style.top.substring(0, answerObjects[i].style.top.length - 2));
					dWidth = Number(answerObjects[i].style.width.substring(0, answerObjects[i].style.width.length - 2));
					dHeight = Number(answerObjects[i].style.height.substring(0, answerObjects[i].style.height.length - 2));
					if((x > dLeft && x < dLeft + dWidth) && (y > dTop && y < dTop + dHeight))
					{
						if(window.ContentFrame.mode == "study" || window.ContentFrame.mode == "practice")
							answerQuestion(window.ContentFrame.selectableObjects[i]);
						else
							changeBorder(window.ContentFrame.selectableObjects[i], window.ContentFrame.selectedAnswers)
						break;
					}
				}
			  }
		  }
		  return true;
		}
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.executeMouseClick()");
	}
}

function buildURL(imgName, mediaPath, usePgImageUrl)
{
	try
	{
		if(getBrowserName() == "Netscape")
		{
			//Netscape parses it's HTML differently than IE, because of that we have to handle
			//setting the images sources diffently. In Netscape the browser doesn't actually 
			//know anything about an object until it is completely parsed. With this being the
			//case we can't set the image source on the passed in object because Netscape can't
			//find it yet, so we take the properties of the image that we want to set and store
			//them in another object and put that object in an array for later use

			//object that contains the image properties
			var mediaObj = new mediaObjProps(imgName, mediaPath, usePgImageUrl)
			if(mediaObj != null)
			{
				//add the object to the array
				mediaArr[mediaArr.length] = mediaObj;
			}
		}else
			//IE will be able to find the object because it continues to parse the page even
			//as it executes javascript to we go ahead and set the image source on the
			//passed in imgName.
			setImageSource(imgName, mediaPath, usePgImageUrl)
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.buildURL()");
	}
	
}

function loadMedia()
{
	try
	{
		//This function gets called after the page is completely loaded. One completely loaded we
		//loop through the arry of properties and set the image source of each one.
		if(getBrowserName() == "Netscape")
		{	
			for(x=0; x<mediaArr.length; x++)
				setImageSource(mediaArr[x].imgName, mediaArr[x].mediaPath, mediaArr[x].usePgImageUrl)
		}
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.loadMedia()");
	}
}

function mediaObjProps(imgName, mediaPath, usePgImageUrl)
{
	try
	{
		//creates a new object with the id, media path and pgImage boolean properties on the media passed in
		this.imgName = imgName;
		this.mediaPath = mediaPath;
		this.usePgImageUrl = usePgImageUrl;
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.mediaObjProps()");
	}	
}

function setImageSource(imgName, mediaPath, usePgImageUrl)
{
	try
	{
		var basePath = null;
		if(usePgImageUrl)
			basePath = window.ContentFrame.pgImageUrl
		else
			basePath = window.ContentFrame.base4xUrl
		if(basePath != null)
		{
			var imgObj = window.ContentFrame.document.getElementById(imgName);
			if(imgObj != null)
			{
				if(encoding == "url")
					imgObj.src = basePath + escape(mediaPath)
				else if(encoding == "utf8")
					imgObj.src = basePath + encodeURIComponent(mediaPath)
				else
					imgObj.src = basePath + mediaPath
			}
		}
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.setImageSource()");
	}	
}

function setBgImage(obj, bg)
{
	try
	{
		if(obj == null)
		{
			if(getUserAgent() == "Mac")
			{
				if(window.ContentFrame.document.body && window.ContentFrame.base4xUrl != null && window.ContentFrame.background != null)
				{
					window.ContentFrame.document.body.style.backgroundImage = "url(" + window.ContentFrame.base4xUrl + window.ContentFrame.background + ")";
					window.ContentFrame.document.body.style.layerBackgroundImage = "url(" + window.ContentFrame.base4xUrl + window.ContentFrame.background + ")";
				}
			}else
			{
				if(window.ContentFrame.document.body && window.ContentFrame.base4xUrl != null && window.ContentFrame.background != null)
				{
					window.ContentFrame.document.body.style.background = "url('" + window.ContentFrame.base4xUrl + window.ContentFrame.background + "')";
					window.ContentFrame.document.body.style.layerBackground = "url('" + window.ContentFrame.base4xUrl + window.ContentFrame.background + "')";
				}
			}
		}else
		{
			var div = window.ContentFrame.document.getElementById(obj)
			if(div != null)
			{
				if(getUserAgent() == "Mac")
				{
					div.style.backgroundImage = "url(" + window.ContentFrame.base4xUrl + bg + ")";
					div.style.layerBackgroundImage = "url(" + window.ContentFrame.base4xUrl + bg + ")";
				}else
				{
					div.style.background = "url('" + window.ContentFrame.base4xUrl + bg + "')";
					div.style.layerBackground = "url('" + window.ContentFrame.base4xUrl + bg + "')";
				}
			}
		}
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.setBgImage()");
	}
}

function alscontentIsLoaded()
{
	return true;
}

function getPageIsLoaded()
{
     return pageIsLoaded; 
}

function setPageIsLoaded(bool)
{
     pageIsLoaded = bool;
}

function finalInit()
{
     setPageIsLoaded(true)
}

function launchContentHelp(currMode)
{
	try
	{
		if(nextPagePrompt != null)
			clearTimeout(nextPagePrompt);		
		if(currMode == "study")
			launchHelp("/adv/help/users/study/study.html");
		else if(currMode == "practice")
			launchHelp("/adv/help/users/practice/practice.html");
		else if(currMode == "mastery")
			launchHelp("/adv/help/users/mastery/mastery.html");
		else if(currMode == "essay")
			launchHelp("/adv/help/users/essay/essay.html");
		else
			launchHelp("/adv/help/users/menus/selectanactivityassignment.html");
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.launchContentHelp()");
	}
}

function cancelRightClick()
{
	return false;
}

function clearWinResults()
{
	window.parent.resultsWindow = null;
}

function setVisible(arr, bool)
{
	for(var x=0; x<arr.length; x++)
	{
		var tmp = window.ContentFrame.document.getElementById(arr[x]);
		if(tmp != null)
		{
			if(bool)
				tmp.style.visibility = "visible";
			else
				tmp.style.visibility = "hidden";
		}
	}
}

function loadUrl(objID, htmlRel)
{
	var obj = window.ContentFrame.document.getElementById(objID);
	if(obj != null)
		obj.src = window.ContentFrame.base4xUrl + htmlRel;
}

function loadScript(srcObjID, destObjID)
{
	var srcObj = window.ContentFrame.document.getElementById(srcObjID);
	var destObj = window.ContentFrame.document.getElementById(destObjID);
	if(srcObj != null && destObj != null)
	{
		destObj.style.overflow = "auto";
		destObj.innerHTML = srcObj.innerHTML;
	}
}

function disableInputs()
{
	var tmpArr = window.ContentFrame.document.getElementsByName("ebAnswer");
	for(var x=0; x<tmpArr.length; x++)
		tmpArr[x].disabled = true
}

function launchVideo(relPath)
{
	var mediaLoc = "http://64.95.53.25/amered/progressive/content"

	window.open(mediaLoc + "/" + relPath)
}

function setCorrects(numCorrects, numIncorrects)
{
	var corr = window.ContentFrame.document.getElementById("llscorrect");
	var incorr = window.ContentFrame.document.getElementById("llsincorrect");
	if(corr != null && numCorrects != "<NUMCORRECT></NUMCORRECT>")
		corr.innerHTML = numCorrects; 
	if(incorr != null && numIncorrects != "<NUMINCORRECT></NUMINCORRECT>")
		incorr.innerHTML = numIncorrects
}

function setPlayingSound(bool)
{
	playingSound = bool;
}

function isPlayingSound()
{
	return playingSound;
}

function trim(stringToTrim) 
{ 
	return stringToTrim.replace(/^\s+|\s+$/g,""); 
} 
