//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.0010"

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; 
	   //added this check to prevent the swapping of images when the button is disabled
	   if(window.ContentFrame.disableForwardButtons)
	   {
	   	if(a[0] == "Image1")
	   		return 
	   	else
	   	{
	   		for(var x=0; x<window.ContentFrame.forwardButtons.length; x++)
	   		{
	   			if(a[0] == "img" + window.ContentFrame.forwardButtons[x])
	   				return;
	   		}
	   	}
	   }
	   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','','/als/images/pb/rolloversnd_on.gif',1);
			setStatusBarSoundOn();
		}
		else
		{
			window.ContentFrame.document.soundimg.scr = MM_swapImage('soundimg','','/als/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','','/als/images/pb/snd_on.gif',1);
		else
			window.ContentFrame.document.soundimg.scr = MM_swapImage('soundimg','','/als/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
	{
		createInputDiv();
		setupTitle();
		initVariables();
		setAnswers();
		try
		{
			atu = window.ContentFrame.allTriesUsed	
		}catch(e)
		{}
		if((window.ContentFrame.mode == "practice" || window.ContentFrame.mode == "study") && 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
			var selObj = window.ContentFrame.selectableObjects[0];
			if(ebA != null && ebA.length > 0 && selObj != null && selObj.length > 1)
			{
				var newObj = window.ContentFrame.document.getElementById("x" + selObj);
				if(newObj != null)
				{
					var showBorder = true;
					var sbwa = null;
					try
					{
						sbwa = window.ContentFrame.showBordersWhenAnswered	
					}catch(e)
					{}
					if(sbwa != null)
						showBorder = sbwa[j];
					if(showBorder)
						newObj.style.border= "thin solid black";
				}
			}
		}

		//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 && window.ContentFrame.answerIds.length == numberOfEbAnswerObjects() )
				nb2.value = "answer"
		}
		
		if(document.all)
		{
			//added to prevent Control + left mouse from opening a new window or tab. 
			//This causes a problem because the response contains html and javascript 
			//that expects a frameset.
			//This will only work on IE because the obejcts in the template only have names and not ids
			var toolbarObj = window.parent.ContentFrame.document.getElementById('Image1');
			if(toolbarObj != null)
				toolbarObj.onclick = isCtrlClick;
			toolbarObj = window.parent.ContentFrame.document.getElementById('Image2');
			if(toolbarObj != null)
				toolbarObj.onclick = isCtrlClick;	
			toolbarObj = window.parent.ContentFrame.document.getElementById('soundimg');
			if(toolbarObj != null)
				toolbarObj.onclick = isCtrlClick;
			toolbarObj = window.parent.ContentFrame.document.getElementById('cambridgeImage');
			if(toolbarObj != null)
				toolbarObj.onclick = isCtrlClick;
			toolbarObj = window.parent.ContentFrame.document.getElementById('ebImage');
			if(toolbarObj != null)
				toolbarObj.onclick = isCtrlClick;
			toolbarObj = window.parent.ContentFrame.document.getElementById('save');
			if(toolbarObj != null)
				toolbarObj.onclick = isCtrlClick;
			toolbarObj = window.parent.ContentFrame.document.getElementById('guide');
			if(toolbarObj != null)
				toolbarObj.onclick = isCtrlClick;
			toolbarObj = window.parent.ContentFrame.document.getElementById('practice');
			if(toolbarObj != null)
				toolbarObj.onclick = isCtrlClick;
			toolbarObj = window.parent.ContentFrame.document.getElementById('Image6');
			if(toolbarObj != null)
				toolbarObj.onclick = isCtrlClick;
			toolbarObj = window.parent.ContentFrame.document.getElementById('Image7');
			if(toolbarObj != null)
				toolbarObj.onclick = isCtrlClick;				
		}
		
		if(window.parent.macapiframe.hasInnerFrame && window.parent.macapiframe.innerFrameParams != null && !window.parent.macapiframe.innerFrameAutoClose)
			window.parent.macapiframe.createInnerFrame();
		if(window.ContentFrame.disableForwardButtons)
			disableFwdButtons(window.ContentFrame.disableForwardButtons);
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.manageGlobalVars()"); 
	}
}

function numberOfEbAnswerObjects()
{
	var num = 0;
	var elements = window.ContentFrame.document.forms["ebForm"].elements;
	for (i=0; i<elements.length; i++)
	{
		if (elements[i].type=="text")
		{
			if (elements[i].name=="ebAnswer")
				num ++	
		}
	}
	return num;
}

function isCtrlClick(evt)
{
	if(window.ContentFrame.event != null && window.ContentFrame.event.ctrlKey)
		return false;
}

function initVariables()
{
	previousObj = null;
	firsttime = true;
	showingResults = false;
	mediaArr = new Array(0);
	isDynamic = false;

}

var userName = "";
function setupTitle()
{
	if(userName.length == 0)
	{
		var nameJSP = "/als/getUserName.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);
					setTitle(userName);
				}
			}
		}
		req.open("POST", nameJSP, true);
		req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
		req.send(params);
	}else if(window.parent.document.title == "A+LS")
		setTitle(userName);
}


function setTitle(username)
{
	var actName = "";
	window.parent.ContentFrame.setValues();
	actName = window.parent.ContentFrame.actname;
	if(actName.length > 0)
		window.parent.document.title = "A+LS" + " - " + actName + ", "+ username;
}

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)
		      {
		      	      var myarray = [];
		      	      for(i=0; i<formObj.elements.length; i++)
		      	      {
		      	      		if(formObj.elements[i].type == 'text' || formObj.elements[i].type == 'textarea')
		      	      			myarray[myarray.length] = formObj.elements[i]
		      	      }
		      	      myarray.sort();
			      for(i=0; i<myarray.length; i++)
			      {
					if(!myarray[i].disabled && myarray[i].value == " ")
					{
						visible = true
						setFocus = true;
						try
						{
							myarray[i].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.
							visible = false;
						}
						if(visible)
							break;
					}else if(!myarray[i].disabled && !foundFirstObj)
					{
						//save the first text object to set focus to if we can't find one with a tab order
						obj = myarray[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
				objs[i].style.zIndex = 100;
									
				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]);
			var visibleProp = window.ContentFrame.answerVisibility[i];
			if(ansobj != null && (visibleProp == null || visibleProp == true))
				ansobj.style.visibility = "visible";
		}
		for(j=0; j<window.ContentFrame.selectableObjects.length; j++)
		{
			brdobj = window.ContentFrame.document.getElementById("x" + window.ContentFrame.selectableObjects[j]);
			var visibleProp = window.ContentFrame.answerVisibility[i];
			if(brdobj != null && (visibleProp == null || visibleProp == true))
				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 != "" && !pageHasDNDPanel())
		{
			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]);
								var showBorder = true;
								var sbwa = null;
								try
								{
									sbwa = window.ContentFrame.showBordersWhenAnswered	
								}catch(e)
								{}
								if(sbwa != null)
									showBorder = sbwa[j];
								if(obj != null && !localIsLLS && showBorder)
									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]);
						var showBorder = true;
						var sbwa = null;
						try
						{
							sbwa = window.ContentFrame.showBordersWhenAnswered	
						}catch(e)
						{}
						if(sbwa != null)
							showBorder = sbwa[i];
						if(obj != null && !localIsLLS && showBorder)
							obj.style.border= "thin solid black";
					}
				}
			}
		}
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.setAnswers()");
	}
}

function answerQuestion(answer, type)
{
	try
	{
		if(checkMouseClicked())
			return;		
		if(getPageIsLoaded())
		{
			if(!window.parent.stopStudentNav)
			{
				if(!window.ContentFrame.preventNav)
				{
					if(window.ContentFrame.document.ebForm.navbar != null)
					{
							doubleCheckUID()
							if(type == null)
							{
								window.ContentFrame.document.ebForm.navbar.value = "answer"
								window.ContentFrame.document.ebForm.navbar2.value = ""
								window.ContentFrame.document.ebForm.selectedAnswer.value = answer
							}else
							{
								window.ContentFrame.document.ebForm.navbar.value = "dndanswer"
								window.ContentFrame.document.ebForm.navbar2.value = ""
								if(window.ContentFrame.dndpanel != null)
									answer = window.ContentFrame.dndpanel.getAnswersString();
								window.ContentFrame.document.ebForm.selectedAnswer.value = answer
							}
							window.ContentFrame.document.ebForm.soundFlag.value = soundFlag
							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(navbar2)
{
	try
	{
		if(getPageIsLoaded())
		{
			if(!window.parent.stopStudentNav)
			{
				if(!window.ContentFrame.preventNav)
				{
					if(nextPagePrompt != null)
						clearTimeout(nextPagePrompt);
					doubleCheckUID()
					var nlvmApplet = pageHasApplet();
					if(nlvmApplet != null && !window.ContentFrame.alwaysUseAppletOrigState)
						getStateAndSaveIt(nlvmApplet);
					saveInnerFrameState();
					NavPrevious(navbar2);
				}
			}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(navbar2)
{
	try
	{
		if(window.ContentFrame.disableForwardButtons)
			return;
		if(getPageIsLoaded())
		{
			if(!window.parent.stopStudentNav)
			{
				if(!window.ContentFrame.preventNav)
				{
					if(nextPagePrompt != null)
						clearTimeout(nextPagePrompt);
					doubleCheckUID()
					var nlvmApplet = pageHasApplet();
					if(nlvmApplet != null && !window.ContentFrame.alwaysUseAppletOrigState)
						getStateAndSaveIt(nlvmApplet);
					saveInnerFrameState();
					NavNext(navbar2);
				}
			}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 pageHasApplet()
{
	var hasApplet = null;
	if(window.ContentFrame.document.getElementById("mathlet") != null)
		hasApplet = window.ContentFrame.document.getElementById("mathlet");
	return hasApplet;
}

function getStateAndSaveIt(app)
{
	try
	{	
		if(app != null)
		{
			if(navigator.userAgent.indexOf('Safari')>0)
				return;

			var strState = app.getSavedState();
			if(window.parent.ContentFrame.document.ebForm.nlvmstate != null && window.ContentFrame.document.ebForm.navbar2 != null && strState != null && strState.length > 0)
			{
				window.parent.ContentFrame.document.ebForm.nlvmstate.value = strState;
				window.ContentFrame.document.ebForm.navbar2.value = "setNLVMStateForUser";
			}
		}
		
	}catch(e)
	{
		alert("there was an exception : " + e);
	}
}


function doRepeatMouseOver()
{
	try
	{
		if(soundFlag)
		{
			if(window.ContentFrame.soundEvent != "" && window.ContentFrame.soundEvent != "<SOUNDEVENT></SOUNDEVENT>")
			{
				window.ContentFrame.document.repeat.src='/als/images/pb/repeatsoundroll.gif'
				setStatusBarText('Play Sound');
			}else
				window.ContentFrame.document.repeat.src='/als/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='/als/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='/als/images/pb/emergentreader/repeatover.jpg'
			else
				window.ContentFrame.document.repeatER.src='/als/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='/als/images/pb/repeatsound.gif';
				displayPageNo();
		   	}else
				window.ContentFrame.document.repeat.src='/als/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='/als/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='/als/images/pb/emergentreader/repeatButton.jpg';
			else
				window.ContentFrame.document.repeatER.src='/als/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='/als/images/pb/rolloversnd_on.gif';
		else
			window.ContentFrame.document.soundimg.src='/als/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="/als/images/pb/repeatsoundblank.gif";
				disableSound();
			}

		}
		else
		{
			if(window.ContentFrame.soundEvent != "" && window.ContentFrame.soundEvent != "<SOUNDEVENT></SOUNDEVENT>")
				window.ContentFrame.document.repeat.src="/als/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;
				}

			}
			clearInnerFrame();
			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((window.ContentFrame.document.ebForm.ebAnswer != null && !window.ContentFrame.document.ebForm.ebAnswer.disabled) && ((ebAnswer != null && ebAnswer != "" && selectedAnswer != null && selectedAnswer != "" && objectid != null && objectid != "") || (selectedAnswer != null && selectedAnswer != "")))
				navbar2 = "answer";
		//************************************************************************
		var safari = navigator.userAgent.indexOf('Safari')>0;
		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 = "/als/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" || safari) && 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 == "" || window.parent.ContentFrame.document.ebForm.ebAnswer.disabled)
					window.parent.ContentFrame.document.ebForm.navbar2.value = ""	
				else 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 = "/als/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" || safari) && 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
	{
		//This prevents sounds playing multiple times caused by embedded div tage 
		//we check to see if the mouse is leaving the inner Div and if it is 
		//don't executed the event because it is still inside the outer Div
		var evt = window.ContentFrame.event
		if (evt != null && evt.type=="mouseover")
		{
			var fromElement=evt.fromElement || evt.relatedTarget
		        if(fromElement != null && fromElement.id == "innerText")
		        	return;
		}

		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("'")
		//July 31 added window.open because there was a pdf file authored with an "'" in the file name
		if((divMsg.indexOf("enlargePicture") != -1 || divMsg.indexOf("window.open") != -1) && firstTick != -1 && lastTick != -1 && firstTick != lastTick)
		{
			if(divMsg.indexOf("window.open") != -1)
			{			
				firstTick = divMsg.indexOf("window.open('") + 13;
				lastTick = divMsg.indexOf("')", firstTick)
			}
			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
		{
			if(divMsg.indexOf("window.ContentFrame.document.location.href") > 0)
			{
				//added by Scott H. 09/03/08
				//Took the location.href out of the eval function because it didn't work on the Mac server
				//Made the location.href a seperate call after the eval.
				var index = divMsg.indexOf("window.ContentFrame.document.location.href");
				var newdivMsg = divMsg.substring(0, index);
				eval(newdivMsg)
				var loc = divMsg.substring(index, divMsg.length);
				firstTick = loc.indexOf("'");
				lastTick = loc.lastIndexOf("'")
				loc = loc.substring(firstTick + 1, lastTick)
				window.ContentFrame.document.location.href = loc;
			}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
	{
		clearInnerFrame();
		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 = "/als/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 = "/als/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 = "/als/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 = "/als/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 = "/als/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
					//uncomment to revert to old way see below
					//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
						//uncomment to revert to old way see below
						//oldObj.style.border= "thin none black";
					}

					//now set the previous object equal to the current object
					previousObj = obj;
					startTimer();
					//A change was made to V3 to automatically go to the next page when an answer is clicked.
					//This is the V4 Implementation
					next();
				}

			}
		}
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.changeBorder()");
	}
}

function startTimer()
{
	try
	{
		if(nextPagePrompt != null)
			clearTimeout(nextPagePrompt);
		if(!window.ContentFrame.adminessay)
			nextPagePrompt = setTimeout("promptNextPage()", 45000); 	
	}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+LS 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 so 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);
     try
     {
     	if(window.parent.ContentFrame.UBF != null)
     		window.parent.ContentFrame.UBF.setValues();
     	window.parent.ContentFrame.createDNDPanel();
     }catch(e)
     {}
}

function launchContentHelp(currMode)
{
	try
	{
		if(nextPagePrompt != null)
			clearTimeout(nextPagePrompt);
		if(currMode == "study")
			launchHelp("/als/help/users/study/study.html");
		else if(currMode == "practice")
			launchHelp("/als/help/users/practice/practice.html");
		else if(currMode == "mastery")
			launchHelp("/als/help/users/mastery/mastery.html");
		else if(currMode == "essay")
			launchHelp("/als/help/users/essay/essay.html");
		else
			launchHelp("/als/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, registerevent)
{
	var zindex = 101
	var visiblitychanged = false;
	for(var x=0; x<arr.length; x++)
	{
		var tmp = window.ContentFrame.document.getElementById(arr[x]);
		if(tmp != null)
		{
			var currentvisiblity = tmp.style.visibility;
			if(currentvisiblity.length == 0) 
				visiblitychanged = true;
			else if(currentvisiblity == "visible" && bool == false) 
				visiblitychanged = true;
			else if(currentvisiblity == "hidden" && bool == true)
				visiblitychanged = true;

			if(bool)
				tmp.style.visibility = "visible";
			else
				tmp.style.visibility = "hidden";
			if(window.ContentFrame.randomize)
				tmp.style.zIndex = zindex++;
				
			if(pageHasDNDPanel())
			{
				var dndtop = window.ContentFrame.dndpanel.getTop();
				var dndbottom = window.ContentFrame.dndpanel.getTop() + window.ContentFrame.dndpanel.getHeight();
				var dndleft = window.ContentFrame.dndpanel.getLeft();
				var dndright = window.ContentFrame.dndpanel.getLeft() + window.ContentFrame.dndpanel.getWidth();

				var pos = findPos(tmp)
				var tmptop = pos[1]
				var tmpleft = pos[0]
				var tmpbottom = tmptop + tmp.offsetHeight;
				var tmpright = tmpleft + tmp.offsetWidth;
							
				if((dndtop >= tmptop && tmpbottom >= dndbottom) || (dndleft >= tmpleft && dndright >= tmpright))
				{
					var srcs = window.ContentFrame.dndpanel.sources;
					for(var y=0; y<srcs.length; y++)
					{
						var idAndDirection = srcs[y];
						var id = idAndDirection.substring(0, idAndDirection.length - 1);
						var tmpsrc = window.ContentFrame.document.getElementById(id);
						if(bool)
							tmpsrc.style.zIndex = 0;
						else
							tmpsrc.style.zIndex = 1001;
					}
					var btns = window.ContentFrame.dndpanel.buttons;
					for(var z=0; z<btns.length; z++)
					{
						var btnObj = btns[z];
						var tmpbtn = window.ContentFrame.document.getElementById(btnObj[0]);
						if(bool)
							tmpbtn.style.zIndex = 0;
						else
							tmpbtn.style.zIndex = 1001;
					}				
				}
			}				
		}
		
	
	}

	if(visiblitychanged && typeof registerevent=="undefined" || registerevent)
		registerEvents(arr, "setVisible", bool);
}

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
}

var handler = null;
function launchVideo(relPath)
{
	var mediaLoc = "http://progressive.playstream.com/amered/progressive/content"

	handler = window.open(mediaLoc + "/" + relPath)
	var safari = navigator.userAgent.indexOf('Safari')>0;
	if(OS == null)
    		OS = getUserAgent();
	if(!safari && !(OS == "Mac" && getBrowserName() == "Netscape"))		
		setTimeout("closeVideoWindow()", 2000)
}

function closeVideoWindow()
{
	if(handler != null)
		handler.close();
}

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 launchEB()
{
	try
	{
		if(checkMouseClicked())
			return;		
		if(getPageIsLoaded())
		{
			if(!window.ContentFrame.preventNav)
			{
				if(window.ContentFrame.document.ebForm.navbar != null)
				{
						doubleCheckUID()
						window.ContentFrame.document.ebForm.navbar.value = "launchEB"
						window.ContentFrame.document.ebForm.navbar2.value = ""
						window.ContentFrame.document.ebForm.soundFlag.value = soundFlag
						window.ContentFrame.document.ebForm.customerName.value = getCustomer();
						window.ContentFrame.document.ebForm.submit();
				}
			}
			mouseClicked = false;
			mouseClickedTime = 0;
		}
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.launchEB()");
	}
}

function openEB(launchString, errorMessage)
{
	if(errorMessage.length > 0)
		alert(errorMessage);
	else if(launchString.length > 0)
		window.open(launchString);
}

function openContentReviewWindow()
{
	try
	{
		if(window.ContentFrame.contentReviewURL == "<CONTENTREVIEWURL></CONTENTREVIEWURL>")
			alert("The content review url is not setup correctly.");
		else
		{
			var lft = (screen.width - 500) / 2
			var now = new Date()
			var elapsedTime = now.getTime() - window.ContentFrame.pageVisitTime.getTime();
			window.ContentFrame.pageVisitTime = new Date(); //reset the time
			var theURL = window.ContentFrame.contentReviewURL +"?userkey=" + window.ContentFrame.userkey + "&guid=" + window.ContentFrame.guid + "&elapsed=" + elapsedTime
			windowprops = "\"top=0,left=" + lft + ",resizable=no, dependent=yes, alwaysRaised=yes, width=500, height=300\"";
			window.open(theURL, "contentReview", windowprops);
		}
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alsutils.openContentReviewWindow()");
	}
}

function callAddPageVisit()
{
	try
	{
		if(window.ContentFrame.pageVisitURL != "<CONTENTREVIEWURL></CONTENTREVIEWURL>" && window.ContentFrame.pageVisitURL.length > 0)                                                
		{
			var now = new Date()
			var elapsedTime = now.getTime() - window.ContentFrame.pageVisitTime.getTime();
			window.parent.LMSFrame.document.location.href = window.ContentFrame.pageVisitURL +"?userkey=" + window.ContentFrame.userkey + "&guid=" + window.ContentFrame.guid + "&elapsed=" + elapsedTime
		}
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alsutils.callAddPageVisit()");
	}	
}

function findPos(obj)  
{
	var curleft = 0;
	var curtop = 0;
	if (obj != null && obj.offsetParent) 
	{
		do 
		{
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}

function showCambridgeMenu()
{
	try
	{	
		var cambridgeimg = window.ContentFrame.document.getElementById("cambridgeImage");
		if(cambridgeimg != null)
		{
			var pos = findPos(cambridgeimg)
			var cbimgtop = pos[1]
			var cbimgleft = pos[0]
			var cbimgheight = cambridgeimg.height
						
			var camdiv = window.ContentFrame.document.getElementById("cambridgemenu")
			removeChildNodes(camdiv);
			camdiv.style.position = "absolute";
			camdiv.style.top = cbimgtop + cbimgheight - 10;
			camdiv.style.left = cbimgleft;
			camdiv.style.border = "outset";
			camdiv.style.background = "#EEEEEE"
			camdiv.style.cursor = "pointer"
			var len = window.ContentFrame.cambridgeNames.length
			var divWidth = 0
			if(len > 1)
			{
				for(x=0; x<len; x++)
				{
					ele = window.ContentFrame.document.createElement("DIV");
					if(getSpecificBrowserName() == "Internet Explorer")
						ele.setAttribute("className", "CambrideMenuItem");
					else
						ele.setAttribute("class", "CambrideMenuItem");
					var name = window.ContentFrame.cambridgeNames[x]
					if(name.length > divWidth)
						divWidth = name.length
					ele.setAttribute("link", window.ContentFrame.cambridgeLinks[x])
					ele.appendChild(window.ContentFrame.document.createTextNode(name));
					camdiv.appendChild(ele);
				}
				camdiv.style.width = divWidth * 8
				camdiv.style.display = "";
				if(getSpecificBrowserName() == "Internet Explorer")
					camdiv.setCapture();
				else
					window.ContentFrame.document.addEventListener("mousedown",catchMozCambridgeMouseClick,false);			
			}else if(len > 0)
			{
				launchCambridge(window.ContentFrame.cambridgeLinks[0])
			}
		}
	}catch (e)
	{
		errorHandler(e.message, "" ,"" , e.name, "alscontent.showCambridgeMenu()");
	}
}

function clickCambridgeMenu(evt)
{
	var menuDiv = window.ContentFrame.document.getElementById("cambridgemenu")
	if(menuDiv != null)
	{
		menuDiv.style.display = "none";
		var el;
		if(getSpecificBrowserName() == "Internet Explorer")
			el = evt.srcElement;
		else		      
			el = evt.target;
		var link = null;	
		if(os == "Mac")
		{
			//I can't get the .attributes property or the getAttribute() method to work in Safari 1.0.3
			//or Netscape 7 on the Mac, so I'm writing this hack to find the text in the name array and 
			//find the corresponding link in the link array
			var txt = el.nodeValue
			for(var i=0; i<window.ContentFrame.cambridgeNames.length; i++)
			{
				if(txt ==  window.ContentFrame.cambridgeNames[i])
					link = window.ContentFrame.cambridgeLinks[i]
			}
		}else
		{
			try
			{
				var elattributes = el.attributes
				link = elattributes.getNamedItem("link").value
			}catch(e){}
		}
		if(link == null)
			link = el.getAttribute("link");
		if(link != null && link.length > 0)
			launchCambridge(link)
		if(getSpecificBrowserName() == "Internet Explorer")
			menuDiv.releaseCapture();
		else
			window.ContentFrame.document.removeEventListener("mousedown",catchMozCambridgeMouseClick, false);
	}
}


function highlightCambridgeMenu(evt)
{
	var el;
	if(getSpecificBrowserName() == "Internet Explorer")
		el = evt.srcElement;
	else
		el = evt.target;
	if(os == "Mac")
	{	
		//TODO 
		//I'm unable to figure out a way to highlight the cambridge menu.
		//None of the DOM methods or properties seem to be supported on 
		//on the Mac using Safari 1.0.3 or Netscape 7
	}else
	{
		if (el.className == "CambrideMenuItem")
			el.className = "CambridgeHightlightItem";
		else if (el.className == "CambridgeHightlightItem")
			el.className = "CambrideMenuItem";	
	}
}

function catchMozCambridgeMouseClick(evt)
{
	clickCambridgeMenu(evt);
	return;
}

function launchCambridge(link)
{
	if(window.ContentFrame.cambridgeBaseUrl != null && window.ContentFrame.cambridgeBaseUrl.length > 0)

	{
		var screenWidth = screen.width - 10;
		var screenHeight = screen.height - 50;
		var windowprops = "top=0,left=0,scrollbars=yes,status=yes,resizable=yes,menubar=0,width=" + screenWidth + ",height=" + screenHeight;
		window.open(window.ContentFrame.cambridgeBaseUrl + link, "Cambridge", windowprops);
	}
}

function trim(stringToTrim) 
{ 
	return stringToTrim.replace(/^\s+|\s+$/g,""); 
} 

function pageHasDNDPanel()
{
	var retVal = false;
	try
	{
		if(window.ContentFrame.dndpanel != null)
			retVal = true;
	}catch(e)
	{}
	return retVal;
}

function saveInnerFrameState()
{
	if(window.parent.macapiframe.innerFrame != null)
		window.parent.macapiframe.innerFrame.saveState();	
}

function clearInnerFrame()
{
	window.parent.macapiframe.hasInnerFrame = false;
	window.parent.macapiframe.innerFrameAutoClose = false;
	window.parent.macapiframe.innerFrame = null;
	window.parent.macapiframe.innerFrameParams = null;
}

function openSpanishGuide()
{
	window.open(window.ContentFrame.base4xUrl + "tools/currictools/spanish_user_guide.pdf");	
}

function registerEvents(arr, method, bool)
{
	var servlet = "/als/servlet/CommServlet"
	var params = "navbar=registerEvent" + "&uid=" + window.ContentFrame.uid + "&customerName=" + getCustomer();
	if(arr.length > 0)
	{
		params += "&eventobjs="
		for(var x=0; x<arr.length; x++)
		{
			if(arr[x] != null)
			{
				if(x == 0)
					params += arr[x].substring(1, arr[x].length)
				else
					params += ";" + arr[x].substring(1, arr[x].length);
			}
		}
		params += "&method=" + method + "&param=" + bool
		var req = getRequestObject();
		req.open("POST", servlet, false);
		req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
		req.send(params);
	}
}

function preventBubble(e)
{
	//This function prevents the bubbling of events in Divs that contain other Divs
	if (e && e.stopPropagation)
		e.stopPropagation()
	else
		window.ContentFrame.event.cancelBubble=true
}
	 
function disableFwdButtons(bool)
{
	if(bool)
	{
		window.ContentFrame.disableForwardButtons = true;
		var ele = window.ContentFrame.document.getElementById("Image1");
		if(ele != null)
			ele.src = "/als/images/pb/stu_arrownext_d.gif"
		for(var x=0; x< window.ContentFrame.forwardButtons.length; x++)
		{
			var fwd = window.ContentFrame.document.getElementById("img" + window.ContentFrame.forwardButtons[x]);
			if(fwd != null && fwd.disabledImg != null && fwd.disabledImg.length > 0)
				fwd.src = fwd.disabledImg
		}
	}else
	{
		registerEvents("null", "setDisableFwdButton", false);
		window.ContentFrame.disableForwardButtons = false;
		var ele = window.ContentFrame.document.getElementById("Image1");
		if(ele != null)
			ele.src = "/als/images/pb/stu_arrownext_u.gif"	
		for(var x=0; x< window.ContentFrame.forwardButtons.length; x++)
		{
			var fwd = window.ContentFrame.document.getElementById("img" + window.ContentFrame.forwardButtons[x]);
			if(fwd != null && fwd.origImg != null && fwd.origImg.length > 0)
				fwd.src = fwd.origImg
		}
	
	}
}
