var currentTest=-1;
var score=null;
function startTest(){
	if(!document.getElementById("btnGroupTitle_" + arguments[0]).disabled){		
		if(currentTest!=-1){
			currentTest.cleanup()
		}
		var syllNum = arguments[0].toString();
		syllNum=syllNum.substr(syllNum.lastIndexOf("_")+1);
		//alert(syllNum);
		loadXMLDoc("dynamicpages/lms_course_test_load.asp", "syllID=" + syllNum);	
		syllID=syllNum;
	}
}
function tutorTest(){
		if(currentTest!=-1){
			currentTest.cleanup()
		}
		var syllNum = arguments[0]
		//syllNum=syllNum.substr(syllNum.lastIndexOf("_")+1);
		loadXMLDoc("dynamicpages/lms_course_test_load.asp", "syllID=" + syllNum);	
		syllID=syllNum;
}
function startQuiz(){
	if(!document.getElementById("btnGroupTitle_" + arguments[0]).disabled){	
		if(currentTest!=-1){
			currentTest.cleanup()
		}
		var syllNum = arguments[0].toString();
		syllNum=syllNum.substr(syllNum.lastIndexOf("_")+1);
		loadXMLDoc("dynamicpages/lms_course_test_load.asp", "syllID=" + syllNum);	
		syllID=syllNum;
	}
}

function startSurvey(){
	if(!document.getElementById("btnGroupTitle_" + arguments[0]).disabled){	
		if(currentTest!=-1){
			currentTest.cleanup()
		}
		var syllNum = arguments[0].toString();
		syllNum=syllNum.substr(syllNum.lastIndexOf("_")+1);
		loadXMLDoc("dynamicpages/lms_course_test_load.asp", "syllID=" + syllNum);	
		syllID=syllNum;
	}
}
function tutorTestQuiz(){
		if(currentTest!=-1){
			currentTest.cleanup()
		}
		var syllNum = arguments[0];
		var student = arguments[1];
		
		loadXMLDoc("dynamicpages/lms_course_test_tutor_load.asp", "syllID=" + syllNum,"studentID=" + student);	
		syllID=syllNum;
}
function test(testID,testInstructions,testType,testTitle,pointstopass,complete,noPassTxt,points){
	this.id = testID;
	this.title = testTitle;
	this.instruct = testInstructions;
	this.type = testType;
	this.pass = pointstopass;
	this.questions = new Array();
	this.complete = complete;
	this.currentQuestion = 0;
	this.noPassTxt=noPassTxt;
	this.totalPoints = points;
	this.graded=false;
	this.getEnglishType = function(){
		var typeArray= new Array("","Test","Quiz","Survey");
		return typeArray[this.type];
	}
	this.setCorrectAnswer=function(ansId,val,tutor,corrected){
		var elem=this.getAnswerIndex(ansId);
		if(elem[0]!=-1){
			this.questions[elem[0]].answers[elem[1]].correct=val;
			this.questions[elem[0]].answers[elem[1]].corrected=corrected;
			if(tutor=="-1"){
				layoutTest("tutor");
			}else{
				layoutEditTest();
			}
		}
	}
	this.getAnswerIndex=function(ansId){
		var itm=new Array;
		itm.push(-1);
		for(var i=0;i<this.questions.length;i++){
			if(this.questions[i].findAnswerIndex(ansId)!=-1){
				itm[0]=i;
				itm.push(this.questions[i].findAnswerIndex(ansId));
				break;
			}
		}
		return itm;
		itm=null;
	}
	this.getTestPointsAvail=function(){
		var tmpVal=0;
		if(this.questions.length>0){
			for(var i=0;i<this.questions.length;i++){
				tmpVal+=parseInt(this.questions[i].qvalue);
			}
		}
		return tmpVal;
	}
	this.swapQuestions=function(id1,id2){
		var tmpElem;
		var index1=this.getIndex(id1);
		var index2=this.getIndex(id2);
		tmpElem=this.questions[index1];
		this.questions[index1]=this.questions[index2];
		this.questions[index2]=tmpElem;
		tmpElem=null;
		return null;
	}
	this.swapAnswer=function(id1,id2){
		var tmpElem;
		var index1=this.getAnswerIndex(id1);
		var index2=this.getAnswerIndex(id2);
		tmpElem=this.questions[index1[0]].answers[index1[1]];
		this.questions[index1[0]].answers[index1[1]]=this.questions[index2[0]].answers[index2[1]];
		this.questions[index2[0]].answers[index2[1]]=tmpElem;
		tmpElem=null;
		return null;
	}
	this.getIndex=function(id){
		var index=-1;
		for(var i=0;i<this.questions.length;i++){
			if(this.questions[i].id==id){
				index=i;
			}
		}
		return index;
	}
	this.getQuestion=function(id){
		var index=-1;
		for(var i=0;i<this.questions.length;i++){
			if(this.questions[i].id==id){
				index=this.questions[i];
			}
		}
		return index;
	}
	this.deleteQuestion=function(id){
		for(var i=0;i<this.questions.length;i++){
			if(this.questions[i].id ==id){
				this.questions[i].cleanup();
				this.questions[i]=null;
				this.questions.splice(i,1);
			}			
		}
		layoutEditTest();
		return null;
	}
	this.getAnswer=function(ansId){
		var itm=new Array;
		itm.push(-1);
		for(var i=0;i<this.questions.length;i++){
			if(this.questions[i].getAnswer(ansId)!=-1){
				itm[0]=i;
				itm.push(this.questions[i].getAnswer(ansId));
				break;
			}
		}
		return itm;
		itm=null;
	}
	this.cleanup = function(){
		for(var i=0; i<this.questions.length; i++){
			this.questions[i].cleanup();
		}
		this.questions = null;
		this.id = null;
		this.instruct=null;
		this.type = null;
		this.title=null;
		this.pass=null;
		this.complete=null;
		this.currentQuestion=null;
		this.noPassTxt=null;
		this.totalPoints=null;
		this.deleteQuestion=null;
		this.getTestPointsAvail=null;
		this.getIndex=null;
		this.swapQuestions=null;
		this.getQuestion=null;
		this.getAnswer=null;
		currentTest = -1;
		this.cleanup=null;
	}
}
function question(questionID,questionText,questionType,questionValue,selAnswerID,corrected){
	this.id = questionID;
	this.text = questionText;
	this.type = questionType;
	this.qvalue = questionValue;
	this.answers = new Array();
	this.selectedAnswer = selAnswerID;
	this.corrected=corrected;
	this.findAnswerIndex = function(id){
		var index=-1;
		for(var i=0;i<this.answers.length;i++){
			if(this.answers[i].id==id){
				index=i;
			}
		}
		return index;
	}
	this.getAnswer = function(id){
		var index=-1;
		for(var i=0;i<this.answers.length;i++){
			if(this.answers[i].id==id){
				index=this.answers[i];
			}
		}
		return index;
	}
	this.cleanup=function(){
		for(var i=0; i<this.answers.length; i++){
			this.answers[i].cleanup();
		}
		this.answers=null;
		this.text = null;
		this.type = null;
		this.value = null;
		this.id = null;
		this.findAnswerIndex=null;
		this.corrected=null;
	}
}
function answer(answerID, answerText, correctAnswer,instructComment,corrected){
	this.id = answerID;
	this.text=answerText;
	this.correct=correctAnswer;
	this.comment=instructComment;
	this.corrected=corrected;
	this.cleanup = function(){
		this.id=null;
		this.text=null;
		this.correct=null;
		this.comment=null;
		this.corrected=null;
	}
}
function layoutEditTest(){	
	if(document.getElementById("container_questions_" + currentTest.id)){
		if(document.getElementById("container_questions_" + currentTest.id).childNodes.length>0){
			clearElements(document.getElementById("container_questions_" + currentTest.id),0);
		}
	}
	if(currentTest.questions.length>=1){
		for(var i=0;i<currentTest.questions.length;i++){
			if(currentTest.questions[i].answers.length>=1){
				for(var z=0;z<currentTest.questions[i].answers.length;z++){
					newQuestionItem(currentTest.id,currentTest.questions[i].id,currentTest.questions[i].type,currentTest.questions[i].text,currentTest.questions[i].qvalue,currentTest.questions[i].answers[z].id,currentTest.questions[i].answers[z].text,currentTest.questions[i].answers[z].correct,currentTest.totalPoints,currentTest.pass);
				}
			}else{
				newQuestionItem(currentTest.id,currentTest.questions[i].id,currentTest.questions[i].type,currentTest.questions[i].text,currentTest.questions[i].qvalue,'','','',currentTest.totalPoints,currentTest.pass);				
			}
		}
	}
	sumTestValue()
}
function newQuestionItem(TestID, QuestionID, questionType, questionText, questionValue, AnswerID, answerText, correctAnswer,totalPoints,pointsToPass){
	if(QuestionID!=''){
		var tst=document.getElementById("container_questions_" + TestID);
		var qstn = document.getElementById("container_question_" + QuestionID)
		var qstnTxt;
		var qstnVal;
		var qstnAns;
		var ans = document.getElementById("container_answer_" + AnswerID)
		var ansTxt;
		var ansCorrect;
		if(!qstn){
			qstn = document.createElement("div");
			qstnTxt = document.createElement("div");
			qstnVal = document.createElement("div");
			qstnAns= document.createElement("div");
			qstn.appendChild(qstnTxt);
			qstn.appendChild(qstnVal);
			qstn.appendChild(qstnAns);
			qstn.id =  "container_question_" + QuestionID
			qstnTxt.id = "container_questionText_" + QuestionID
			qstnAns.id = "container_questionAnswers_" + QuestionID			
			qstnVal.id = "container_questionValue_" + QuestionID			
			
			qstn.className =  "container_question"
			qstnTxt.className = "container_questionText"
			qstnAns.className = "container_questionAnswers"
			qstnVal.className = "container_questionValue"

			qstnTxt.onmousedown=fireContextMenu;
			
			qstnAns.style.display="none";
			qstnTxt.innerHTML = unescape(questionText);
			qstnTxt.onmousedown = fireContextMenu;
			qstnVal.innerHTML = unescape(questionValue);
			tst.appendChild(qstn);
		}		
		if(!ans && AnswerID!='' && AnswerID!='-1'){
			ans=document.createElement("div");
			ansTxt=document.createElement("div");
			ansCorrect = document.createElement("div");
			ans.appendChild(ansCorrect);
			ans.appendChild(ansTxt);
			ansTxt.innerHTML = answerText;	
			document.getElementById("container_questionAnswers_" + QuestionID).appendChild(ans);
			document.getElementById("container_questionAnswers_" + QuestionID).style.display="";
			ans.id = "container_answer_" + AnswerID;
			ansTxt.id = "container_answerTxt_" + AnswerID;
			ansCorrect.id = "container_answerCorrect_" + AnswerID;
			ansTxt.onmousedown=fireContextMenu;
			ansCorrect.onmousedown=fireContextMenu;
			ans.className = "container_answer";
			ansTxt.className = "container_answerTxt";
			ansCorrect.className = "container_answerCorrect_" + correctAnswer;
			//alert(ansCorrect.className);
		}
		tst = null;
		qstn = null;
		qstnTxt = null;
		qstnVal = null;
		qstnAns = null;
		ans = null;
		ansTxt = null;
		ansCorrect = null;
	}
}
function sumTestValue(){
	var newElem=document.getElementById("container_TestSummary_" + currentTest.id);
	if(!newElem){
		var elem=document.getElementById("container_questions_"+currentTest.id).parentNode;
		newElem=document.createElement("div");
		newElem.id="container_TestSummary_" + currentTest.id;
		newElem.className="container_testValue";
		elem.appendChild(newElem);
		elem=null;
	}
	newElem.innerHTML = "Test points assigned: " + currentTest.getTestPointsAvail() + " of " + currentTest.totalPoints;
	newElem=null;
}
function layoutTest(){
	/*var head = document.getElementsByTagName('head').item(0);
	url="CSS/default_course_editor.css"
	q = document.getElementById("style");
	if(q){
		head.removeChild(q)
	}
	var s=document.createElement('link');
	sid = 'style'
	void(s.id = sid );
	void(s.rel='stylesheet');
	void(s.href=url +"?" + Date());
	void(s.type="text/css");
	void(head.appendChild(s));
	s = null;
	q=null;
	head = null;*/
	loadCSS("default_course_editor.css");
	if(document.getElementById("window_test_"+ currentTest.id)){
		clearElements(document.getElementById("window_test_"+ currentTest.id));
	}												  
	createObject("test_" + currentTest.id, currentTest.title, "lesson", clientWidth-192,clientHeight-38,190,37,fireCloseEditWin);
	var contentWindow = document.createElement("div");
	document.getElementById("window_test_"+currentTest.id).appendChild(contentWindow);
	//alert("window_manage" + arguments[1] + "_"+arguments[0])
	//alert(document.getElementById("window_manage" + arguments[1] + "_"+arguments[0]).childNodes[1].childNodes[1].id)
	contentWindow.id= "window_test_" + currentTest.id + "_content";
	contentWindow.className= "window_Editor_content";
	contentWindow.style.height= stripPX(contentWindow.parentNode.style.height)-35 + "px";//"95%" //clientHeight-38-15;
	contentWindow.style.width= "100%"//clientWidth-192;
	var target = document.createElement("div");
	var	testContainer = document.createElement("div");
	var	testContainerDirections = document.createElement("div");
	
		testContainer.id =  "container_testquestions_" + currentTest.id;
		testContainer.className ="testTakeQuestions";
		

		contentWindow.appendChild(target);
		target.appendChild(testContainer);	
		
		testContainer.appendChild(testContainerDirections);
		testContainerDirections.innerHTML="<u>Directions</u><br>" + currentTest.instruct + "<br> You will have " + currentTest.questions.length + " questions to answer.<br>" ;
		testContainerDirections.className="TestDirections";
	if(currentTest.complete!=1 && currentTest.type<3){
			var testNav = document.createElement("a");
			var testNavPrev = document.createElement("a");	
			target.appendChild(testNavPrev);
			target.appendChild(testNav);
			testNav.id= "container_testNav_" + currentTest.id;
			testNavPrev.id= "container_testNavPrev_" + currentTest.id;
			testNav.innerHTML = "Next <BR> Question"
			testNav.href="#";
			testNav.className="navButtonRight";
			testNav.onclick=nextQuestion;
			testNavPrev.innerHTML = "Previous<br>Question"
			testNavPrev.href="#";
			testNavPrev.className="navButtonLeft";
			testNavPrev.onclick=prevQuestion;
			testNav = null;
			testNavPrev = null;
			
	}else{
			if(currentTest.complete!=1){
			var testNav = document.createElement("a");
			target.appendChild(testNav);
			testNav.id= "container_testNav_" + currentTest.id;
			testNav.innerHTML = "Submit <BR> Survey"
			testNav.href="#";
			testNav.className="navButtonRight";
			testNav.onclick=finishSurvey;
			testNav = null;
			}
	}
		//accessContainerTitle.innerHTML=arguments[1] + ": " + arguments[2] + " questions";
		testContainerDirections.onmousedown=fireContextMenu;	
	target.className="questionManage";
	document.getElementById('HandleTitle_test_' + currentTest.id).innerHTML=currentTest.title;
	target= null
	accessContainer = null;
	accessContainerTitle= null;
	if(currentTest.complete==0){
		takeTest();
	}else{
		//alert("here");
		if(!currentTest.graded){
			currentTest.graded=true;
			finishTest(true,arguments[0]);		
		}else{
			
			if(!arguments[0]){
				gradeTest();
			}else{
				if(arguments[0]=="tutor"){
					gradeTest(arguments[0]);
				}else{
					gradeTest();
				}
			}
		}
		//gradeTest();
	}
}
function gradeTest(){
	//alert("here");
	var target = document.getElementById("container_testquestions_" + currentTest.id);
	var questionContainer;
	var questionText;
	var answerText;
	var correct;
	var pointsAwarded;
	var pointSummary=0;
	var potentialPoints = 0;
	questionContainer = document.createElement("div");
	questionText = document.createElement("div");
	answerText = document.createElement("div");
	correct = document.createElement("div");
	pointsAwarded= document.createElement("div");
	
	questionContainer.className="answerSheet_Question";
	questionText.className="answerSheet_QuestionText";
	answerText.className="answerSheet_AnswerText";
	pointsAwarded.className="answerSheet_PointsAwarded";
	if(currentTest.type==3){
		pointsAwarded.style.display="none";
	}
	target.appendChild(questionContainer);

	questionContainer.appendChild(correct);
	questionContainer.appendChild(questionText);
	questionContainer.appendChild(answerText);		
	questionContainer.appendChild(pointsAwarded);
	
	questionText.innerHTML = "Question";
	answerText.innerHTML = "Your Answer";
	pointsAwarded.innerHTML = "Pts.";
	correct.className="container_answerCorrect_Holder";
	questionContainer = null;
	questionText = null;
	answerText = null;
	correct = null;
	pointsAwarded= null;
	for(var i=0;i<currentTest.questions.length;i++){
		questionContainer = document.createElement("div");
		questionText = document.createElement("div");
		answerText = document.createElement("div");
		correct = document.createElement("div");
		pointsAwarded= document.createElement("div");
		
		questionContainer.className="answerSheet_Question";
		questionText.className="answerSheet_QuestionText";
		answerText.className="answerSheet_AnswerText";
		pointsAwarded.className="answerSheet_PointsAwarded";
		
		if(currentTest.type==3){
			pointsAwarded.style.display="none";
		}
		target.appendChild(questionContainer);

		questionContainer.appendChild(correct);
		questionContainer.appendChild(questionText);
		questionContainer.appendChild(answerText);		
		questionContainer.appendChild(pointsAwarded);
		
		questionText.innerHTML = i+1 + ". " + currentTest.questions[i].text;
		
			for(var z=0; z<currentTest.questions[i].answers.length;z++){
				if(currentTest.questions[i].selectedAnswer==currentTest.questions[i].answers[z].id){
					answerText.innerHTML = currentTest.questions[i].answers[z].text;
					answerText.id="container_answer_" +currentTest.questions[i].answers[z].id;
					
					if(arguments[0]=='tutor'){
					questionContainer.id="container_tutorQuestion_" +currentTest.questions[i].answers[z].id;
					answerText.onmousedown=fireContextMenu;					
					}
					if(currentTest.questions[i].answers[z].comment && currentTest.questions[i].answers[z].comment!=""){
						var note = document.createElement("a");
						note.href="#"
						note.id="note_" + i + "_" + z;
						
						note.onmouseover=fireNote;
						
						note.className="note";
						answerText.appendChild(note);
					}					
					if(currentTest.questions[i].answers[z].corrected==1){
					    if(currentTest.questions[i].answers[z].correct=="True"){
						    if(currentTest.type==3){
							    correct.className="container_answerCorrect_Holder"
						    }else{
							    correct.className="container_answerCorrect_True"
						    }
						    pointSummary += parseInt(currentTest.questions[i].qvalue);
						    pointsAwarded.innerHTML = currentTest.questions[i].qvalue;							
						    potentialPoints+=parseInt(currentTest.questions[i].qvalue);
					    }else{
						    if(currentTest.type==3){
							    correct.className="container_answerCorrect_Holder"
						    }else{
							    correct.className="container_answerCorrect_False"
						    }
						    pointsAwarded.innerHTML=0;
						    potentialPoints+=parseInt(currentTest.questions[i].qvalue);					
					    }
					}else{
					        if(currentTest.type==3){
							    correct.className="container_answerCorrect_Holder";
						    }else{
						       correct.className="container_answerCorrect_Question";
						    }
						    //pointSummary += parseInt(currentTest.questions[i].qvalue);
						    pointsAwarded.innerHTML = "Not graded";							
						    //potentialPoints+=parseInt(currentTest.questions[i].qvalue);
					}
				}
			}
			if(answerText.innerHTML == ""){
				answerText.innerHTML = "No Answer Given"
				if(currentTest.type==3){
					correct.className="container_answerCorrect_Holder"
				}else{
					correct.className="container_answerCorrect_False"
					potentialPoints+=parseInt(currentTest.questions[i].qvalue);
				}
			}
		questionContainer = null;
		questionText = null;
		answerText = null;
		correct = null;
		pointsAwarded= null;
	}
	questionContainer = document.createElement("div");
	pointsAwarded = document.createElement("div");
	target.appendChild(questionContainer);
	questionContainer.appendChild(pointsAwarded);
	questionContainer.className="answerSheet_Question";
	pointsAwarded.className="answerSheet_PointsAwarded";
	if(currentTest.type==3){
		pointsAwarded.style.display="none";
	}
	pointsAwarded.innerHTML ="Your Score: " +  pointSummary + "/" + potentialPoints + " (" +  Math.round(pointSummary/potentialPoints*100)+ "%)" 
	score=Math.round(pointSummary);
	//alert(currentTest.pass);
	if(Math.round(pointSummary)>=currentTest.pass){
		if(arguments[0]!='tutor'){
		var moveOn=document.createElement("a")
		moveOn.id= "container_testNav_" + currentTest.id;
		moveOn.innerHTML = "Move On"
		moveOn.href="#";
		moveOn.className="navButtonRight";
		moveOn.onclick=endTest;
		target.appendChild(moveOn);		
		moveOn=null;
		}
	}else{
		var failMessage=document.createElement("div")
		target.appendChild(failMessage);
		failMessage.className="failMessage";
		if(currentTest.noPassTxt!=""){
			failMessage.innerHTML=currentTest.noPassTxt;
		}else{
			failMessage.innerHTML="Sorry, you have not scored the required points to move on. Please contact your instructor for directions.";
		}
		failMessage=null;
	}
	questionContainer=null;
	pointsAwarded=null;
	target=null;
}
function fireNote(){
	//alert(this.id);
}
function takeTest(){
	//alert(currentTest.id + ": " + currentTest.questions.length + ", " + currentTest.questions[0].answers.length);
	if(currentTest.type==3){
		currentTest.currentQuestion=0;
		for(var i=0;i<currentTest.questions.length;i++){
			loadContinuousQuestion();
			currentTest.currentQuestion++;
		}
	}else{
		loadQuestion();
	}
}
function nextQuestion(){
	if(currentTest.currentQuestion==-1){
		currentTest.currentQuestion=0;
	}else{
		currentTest.currentQuestion++;
	}
	if(currentTest.currentQuestion>=currentTest.questions.length){
			finishTest();
	}else{
		loadQuestion(currentTest.currentQuestion);
	}
}
function finishSurvey(){
    currentTest.currentQuestion=currentTest.questions.length;
    finishTest();
}
function prevQuestion(){
	if(!currentTest.currentQuestion){
		currentTest.currentQuestion=0;
	}else{
		currentTest.currentQuestion--;
	}
	if(currentTest.currentQuestion<0){
		currentTest.currentQuestion=0;		
	}
	loadQuestion(currentTest.currentQuestion);
}
function loadQuestion(){
	var target=document.getElementById("container_testquestions_" + currentTest.id);
	if(target.childNodes.length>1){
		clearElements(target.childNodes[1]);
	}
	var qstn = document.createElement("div");
	target.appendChild(qstn);
	qstn.innerHTML =currentTest.currentQuestion+1  +  ". " + currentTest.questions[currentTest.currentQuestion].text;
	qstn.id = "container_question_" + currentTest.questions[currentTest.currentQuestion].id;
	qstn.className="testTakeQuestion";
	qstn.onmousedown = fireContextMenu;
	
	switch(currentTest.questions[currentTest.currentQuestion].type){
		case 3:
			loadShortAnswer(0);
		break;
		default:
			for(var i=0;i<currentTest.questions[currentTest.currentQuestion].answers.length;i++){
				loadRadioAnswer(i);
			}
		break;
	}
	
	target =null;
}
function loadContinuousQuestion(){
	var target=document.getElementById("container_testquestions_" + currentTest.id);
	var qstn = document.createElement("div");
	target.appendChild(qstn);
	qstn.innerHTML =currentTest.currentQuestion+1  +  ". " + currentTest.questions[currentTest.currentQuestion].text;
	qstn.id = "container_question_" + currentTest.questions[currentTest.currentQuestion].id;
	qstn.className="testTakeQuestion";
	qstn.onmousedown = fireContextMenu;
	
	switch(currentTest.questions[currentTest.currentQuestion].type){
		case 3:
			loadShortAnswer(0);
		break;
		default:
			for(var i=0;i<currentTest.questions[currentTest.currentQuestion].answers.length;i++){
				loadRadioAnswer(i);
			}
		break;
	}
	
	target =null;
}
function loadShortAnswer(id){

	var target= document.getElementById("container_question_" + currentTest.questions[currentTest.currentQuestion].id);
/*if(target.childNodes.length>1){
		clearElements(target.childNodes[1]);
	}*/
	var ansForm 
	if(!document.getElementById("container_answerForm_" + currentTest.questions[currentTest.currentQuestion].id)){
		var containDiv = document.createElement("div");

		ansForm = document.createElement("form")
		containDiv.appendChild(ansForm);
		containDiv.className="answerGroup";
		ansForm.id="container_answerForm_" + currentTest.questions[currentTest.currentQuestion].id;
		target.appendChild(containDiv);
		containDiv=null;
	}else{
		ansForm = document.getElementById("container_answerForm_" + currentTest.questions[currentTest.currentQuestion].id);
	}
	//var ans = document.createElement("div");
	//ansForm.appendChild(ans);
	var oclick
	if(currentTest.questions[currentTest.currentQuestion].selectedAnswer==currentTest.questions[currentTest.currentQuestion].answers[id].id){
		oclick= "setActive"
	}else{
		oclick=null;
	}
	//alert(currentTest.questions[currentTest.currentQuestion].answers[id].text);
	createFormElem(ansForm.id,"txtAns_" + currentTest.questions[currentTest.currentQuestion].id,"newLineLeft",currentTest.questions[currentTest.currentQuestion].answers[id].text,"none",currentTest.questions[currentTest.currentQuestion].answers[id].text,oclick,"txt",null,markCorrectText,null,null,null,50,5000);

	target =null;
	ansForm = null;
}
function loadRadioAnswer(id){
	var target= document.getElementById("container_question_" + currentTest.questions[currentTest.currentQuestion].id);
	/*if(target.childNodes.length>1){
		clearElements(target.childNodes[1]);
	}*/
	var ansForm 
	if(!document.getElementById("container_answerForm_" + currentTest.questions[currentTest.currentQuestion].id)){
			var containDiv = document.createElement("div");

		ansForm = document.createElement("form")
		containDiv.appendChild(ansForm);
		containDiv.className="answerGroup";
		ansForm.id="container_answerForm_" + currentTest.questions[currentTest.currentQuestion].id;
		target.appendChild(containDiv);
		containDiv=null;
		/*ansForm = document.createElement("form")
		ansForm.id="container_answerForm_" + currentTest.questions[currentTest.currentQuestion].id;
		target.appendChild(ansForm);*/
	}else{
		ansForm = document.getElementById("container_answerForm_" + currentTest.questions[currentTest.currentQuestion].id);
	}
	//var ans = document.createElement("div");
	//ansForm.appendChild(ans);
	var oclick
	if(currentTest.questions[currentTest.currentQuestion].selectedAnswer==currentTest.questions[currentTest.currentQuestion].answers[id].id){
		oclick= "setActive"
	}else{
		oclick=null;
	}
		
	createFormElem(ansForm.id,"radAns_" + currentTest.questions[currentTest.currentQuestion].id,"newLineLeft",currentTest.questions[currentTest.currentQuestion].answers[id].text,"right",currentTest.questions[currentTest.currentQuestion].answers[id].id,oclick,"rad",markCorrect,null,null,null,null,5,100,"100%");

	target =null;
	ansForm = null;
}
function markCorrect(){
	var prntID = this.parentNode.parentNode.parentNode.id
	prntID=prntID.substr(prntID.lastIndexOf("_")+1);
	currentTest.questions[getQuestionIndexById(prntID)].selectedAnswer=this.value;
	loadXMLDoc("dynamicpages/lms_course_test_question_student_update.asp","tid=" + currentTest.id,"qid=" + prntID, "aid=" + escape(this.value), "answerText=");
}
function markCorrectText(){
    var prntID = this.parentNode.parentNode.parentNode.id
	prntID=prntID.substr(prntID.lastIndexOf("_")+1);
	if(parseInt(currentTest.currentQuestion)!=getQuestionIndexById(prntID)){
	    currentTest.currentQuestion=getQuestionIndexById(prntID);
	}
	currentTest.questions[currentTest.currentQuestion].answers[0].text = this.value;
	loadXMLDoc("dynamicpages/lms_course_test_question_student_update.asp","tid=" + currentTest.id,"qid=" + currentTest.questions[currentTest.currentQuestion].id, "aid=" + currentTest.questions[currentTest.currentQuestion].answers[0].id, "answerText=" + escape(this.value));
		
}
function getQuestionIndexById(id){
	var retval=0;
	for(var i=0;i<currentTest.questions.length;i++){
		if(currentTest.questions[i].id==parseInt(id)){
			retval=i;
			break;
		}
	}
	return retval;
}
function finishTest(){
	var moveOn = arguments[0]
	
	
	if(!arguments[0]){
		moveOn = confirm("Are you finished with this test? Click OK to see your score, click CANCEL to go back to the test")
	}
	if(moveOn){
		
		var pointSummary=0;
		var potentialPoints=0;
		var corrected=0
		for(var i=0;i<currentTest.questions.length;i++){
			for(var z=0;z<currentTest.questions[i].answers.length;z++){
				if(currentTest.questions[i].selectedAnswer==currentTest.questions[i].answers[z].id){					
					if(currentTest.questions[i].answers[z].correct=="True"){						
						pointSummary += parseInt(currentTest.questions[i].qvalue);
					}
					if(currentTest.questions[i].answers[z].corrected==1){
					    corrected=1;
					}
				}
			}
			if(corrected==1){
			    potentialPoints+=parseInt(currentTest.questions[i].qvalue);	
			    corrected=0;
			}			
		}
		//alert(syllID + ' ' + pointSummary + ' ' + currentTest.pass + ' ' + potentialPoints);
		loadXMLDoc("dynamicpages/lms_course_test_close.asp","syllID=" + syllID, "grade=" + pointSummary,"expected=" + currentTest.pass,"gradePossible=" + potentialPoints,"tutor=" + arguments[1]);
		
	}else{
		currentTest.currentQuestion--;
	}
}
function endTest(){
	mveOn();
}
function mveOn(){
	clearElements(document.getElementById("window_test_"+ currentTest.id));
	loadXMLDoc("dynamicpages/lms_course_test_moveOn.asp","syllID=" + syllID, "grade=" + score,"expected=" + currentTest.pass);
	currentTest.cleanup();
	
}