/* functions for inline and assessment multiple choice single answer and multiple choice multiple answer questions and the overall assessment */

/* set up the functionality of the clickable options */
var inputChkDone = false;
function setupClickableOptions () 
{	
	$(".qItem").mouseover(function(e) {
		/* ensure hover states do not appear on focus for question objects in mobile 2021 */
	  	if (isWeb){
			$(this).addClass("mcma_hl_hover");		
			$(this).parent().find(".mc_btn").addClass("mcma_hl_hover");
		}	
	});
	
	$(".mc_btn").mouseover(function(e) {
		/* ensure hover states do not appear on focus for question objects in mobile 2021 */
	  	if (isWeb){
			$(this).addClass("mcma_hl_hover");		
			$(this).parent().parent().find(".qItem").addClass("mcma_hl_hover");
		}	
	});
	
	$(".qItem").mouseout(function(e) {
	  	$(this).removeClass("mcma_hl_hover");		
		$(this).parent().find(".mc_btn").removeClass("mcma_hl_hover");
	});
	
	$(".mc_btn").mouseout(function(e) {
	  	$(this).removeClass("mcma_hl_hover");		
		$(this).parent().parent().find(".qItem").removeClass("mcma_hl_hover");
	});

	$(".qItems .qItem").each(function() {
		$(this).bind( "click", function() { 
			toggleOptionChoice($(this));
		});		
				
		$(this).bind("keypress", function(e){
			if (e.keyCode == 13 || e.keyCode == 32) {
				toggleOptionChoice($(this));
			}			
		});
		/* stop checkbox from bubbling up to parent action and calling twice */
		$(this).find(".squaredBox").bind( "click", function(event) { 
			event.stopPropagation();
		});		
		/*$(this).find(".squaredBox").bind("keypress", function(e){
			if (e.keyCode == 13 || e.keyCode == 32) {
				event.stopPropagation();
			}
		});*/		
  	});	
	/* ensures that the edge of the checkbox is clickable */
	$(".squaredBox").bind( "click", function() {
		toggleOptionChoice($(this).parent().parent());
	});	
	
	/*$(".squaredBox").bind("keypress", function(e){
		if (e.keyCode == 13 || e.keyCode == 32) {
			toggleOptionChoice($(this).parent().parent());
		}		
	});*/
	
	/* assign click action to change of checkbox only once */
	$('input[type=checkbox]').change( function(){
		toggleOptionChoice($(this).parent().parent().parent());		
		inputChkDone = true;
	});
	/* set submit button to disabled when page loads */
	$('.submit_btn').addClass('disabled');
	/* 2021 Accessibility Update */
	$('.submit_btn').attr('title', localiseString('submit_btn_locked'));
	$('.submit_btn').attr('alt', localiseString('submit_btn_locked'));

	/* set focus to feedback */
	$( ".submit_btn" ).keypress(function(e) {
		if (e.keyCode == 13 || e.keyCode == 32) {
	  		$('#sec_' + document.currentSection + ' .feedback_text').focus();
			$(this).parent().parent().parent().find(".qItem").unbind("mouseover");
			$(this).parent().parent().parent().find(".qItem").unbind("mouseout");
			$(this).parent().parent().parent().find(".mc_btn").unbind("mouseover");
			$(this).parent().parent().parent().find(".mc_btn").unbind("mouseout");
		}
	});	
	
	/* 20180501 Accessibility Added to set feedback focus when using a screen reader, JAWs doesn't use keypress */
	$( ".submit_btn" ).click(function(e) {
	  	$('#sec_' + document.currentSection + ' .feedback_text').focus();
		$(this).parent().parent().parent().find(".qItem").unbind("mouseover");
		$(this).parent().parent().parent().find(".qItem").unbind("mouseout");
		$(this).parent().parent().parent().find(".mc_btn").unbind("mouseover");
		$(this).parent().parent().parent().find(".mc_btn").unbind("mouseout");
	});
	/* 20180501 Accessibility Added to set feedback focus when using a screen reader, JAWs doesn't use keypress */
}

function reSetupClickableOptionsInlineQues(secId)
{
	$("#" + secId + " .qItem").each(function() {
		
		/* 2021 Accessibility Update */
		$(this).bind("mouseover", function(e) {
			/* ensure hover states do not appear on focus for question objects in mobile 2021 */
			if (isWeb)
			{
				$(this).addClass("mcma_hl_hover");		
				$(this).parent().find(".mc_btn").addClass("mcma_hl_hover");
			}	
		});
	
		$(this).bind("mouseout", function(e) {
			$(this).removeClass("mcma_hl_hover");		
			$(this).parent().find(".mc_btn").removeClass("mcma_hl_hover");
		});
		
		$(this).unbind("click");		
		$(this).bind( "click", function() { 
			toggleOptionChoice($(this));
		});
		
		// 20170830 Keyboard functionality
		$(this).bind("keypress", function(e){
			if (e.keyCode == 13 || e.keyCode == 32) {
				toggleOptionChoice($(this));
			}			
		});
		// 20170830 Keyboard functionality

		$(this).find(".squaredBox").unbind("click");
		/* ensures that the edge of the checkbox is clickable */
		/* stop checkbox from bubbling up to parent action and calling twice */
		$(this).find(".squaredBox").bind( "click", function(event) { 
			toggleOptionChoice($(this).parent().parent());
			event.stopPropagation();
		});
		/* assign click action to change of checkbox */
		$(this).find(".inputTest input[type=checkbox]").change( function(){
			toggleOptionChoice($(this).parent().parent().parent());
		});
  	});
	/* 2021 Accessibility Update */
	$("#" + secId + " .mc_btn").each(function() {
		
		$(this).bind("mouseover", function(e) {
			/* ensure hover states do not appear on focus for question objects in mobile 2021 */
			if (isWeb)
			{
				$(this).addClass("mcma_hl_hover");
				$(this).parent().parent().find(".qItem").addClass("mcma_hl_hover");
			}
		});
	
		$(this).bind("mouseout", function(e) {
			$(this).removeClass("mcma_hl_hover");		
			$(this).parent().parent().find(".qItem").removeClass("mcma_hl_hover");
		});
	});	
	setTabIndex(); // 20170830 Keyboard functionality
}

/* 2021 Accessibility Update */
function reSetupClickableOptionsTest (goToPlaceSec) 
{	
	$(".qItems .qItemTest").each(function() {		
		$(this).mouseover(function(e) {
			/* ensure hover states do not appear on focus for question objects in mobile 2021 */
			if (isWeb)
			{
				$(this).addClass("mcma_hl_hover");		
				$(this).parent().find(".mc_btn").addClass("mcma_hl_hover");
			}	
		});
		
		$(this).mouseout(function(e) {
			$(this).removeClass("mcma_hl_hover");		
			$(this).parent().find(".mc_btn").removeClass("mcma_hl_hover");
		});

		$(this).parent().find(".mc_btn").mouseover(function(e) {
			/* ensure hover states do not appear on focus for question objects in mobile 2021 */
			if (isWeb)
			{
				$(this).parent().parent().find(".qItem").addClass("mcma_hl_hover");
			}	
		});
		
		$(this).parent().find(".mc_btn").mouseout(function(e) {
			$(this).parent().parent().find(".qItem").removeClass("mcma_hl_hover");
		});		
	
		$(this).unbind("click");
		$(this).bind( "click", function() { 
			toggleOptionChoice($(this));
		});
		
		// 20170830 Keyboard functionality
		$(this).bind("keypress", function(e){
			if (e.keyCode == 13 || e.keyCode == 32) {
				toggleOptionChoice($(this));
			}			
		});
		// 20170830 Keyboard functionality

		$(this).find(".squaredBoxTest").unbind("click");
		/* ensures that the edge of the checkbox is clickable */
		/* stop checkbox from bubbling up to parent action and calling twice */
		$(this).find(".squaredBoxTest").bind( "click", function(event) {
			toggleOptionChoice($(this).parent().parent());		
			event.stopPropagation();
		});
  	});	
	
	/* assign click action to change of checkbox only once */
	if (!inputChkDone) {
		$('.inputTest input[type=checkbox]').change( function(){
			toggleOptionChoice($(this).parent().parent().parent());		
			inputChkDone = true;
		}); 
	}
	/* set submit button to disabled when page loads */
	$('.submit_btn').addClass('disabled');
	/* ensure hover states do not appear on focus for question objects in mobile 2021 */
	$('.submit_btn').removeClass("hovered");
	/* 2021 Accessibility Update */
	$('.submit_btn').attr('title', localiseString('submit_btn_locked'));
	$('.submit_btn').attr('alt', localiseString('submit_btn_locked'));

	setTabIndex(); // 20170830 Keyboard functionality
	
	/* 2021 Accessibility Update */		
	$(goToPlaceSec + ' .page_start').focus();
}

/* toggle the selected option on/off and update the user selected array */
function toggleOptionChoice (o) 
{		
	document.optionsArr = [];
	var optId = $(o).attr('id');	
	var secNum = optId.split("_")[1];
	var secId = "sec_" + secNum;
	var optNum1 = optId.split("_")[2];
	var optNum2 = optId.split("_")[3];
	var optTest = optId.split("_")[4];
	var optQType = optId.split("_")[5];	
	var numOfOptions = $("#" + secId + " .qItems .qItem").length / 2;
	var userAnsArray = "";
	if (optTest == "t") {
		userAnsArray = jQuery.makeArray(post_test_ques_dat[secId][0].user_ans.split(","));
	}
	else {
		userAnsArray = jQuery.makeArray(inline_ques_dat[secId][0].user_ans.split(","));
	}
	if (optQType == "mcsa") {
		for (var i = 0; i < numOfOptions; i++)
		{			
			userAnsArray[i] = 0;
			$('#rb_'+ secNum + "_" + (i + 1)).prop('checked', false);
			$("#opt_" + secNum + "_" + (i + 1) + "_0_" + optTest + "_mcsa").attr("aria-checked", false);
			
			document.optionsArr.push($.trim($("#opt_" + secNum + "_" + (i + 1) + "_0_" + optTest + "_mcsa .labelTxt").text())); //  option text for reporting of interactions
		}	
		userAnsArray[optNum1-1] = 1;
		$('#rb_'+ secNum + "_" + optNum1).prop('checked', true);
		$("#opt_" + secNum + "_" + optNum1 + "_0_" + optTest + "_mcsa").attr("aria-checked", true);
		
	}
	else if (optQType == "mcma") {
		if (userAnsArray[optNum1-1] != 1) {		
			userAnsArray[optNum1-1] = 1;
			$('#rb_'+ secNum + "_" + optNum1).prop('checked', true);
			$("#opt_" + secNum + "_" + optNum1 + "_0_" + optTest + "_mcma").attr("aria-checked", true);
		}
		else {			
			userAnsArray[optNum1-1] = 0;
			$('#rb_'+ secNum + "_" + optNum1).prop('checked', false);
			$("#opt_" + secNum + "_" + optNum1 + "_0_" + optTest + "_mcma").attr("aria-checked", false);
		}	
		
		for (var i = 0; i < numOfOptions; i++){
			document.optionsArr.push($.trim($("#opt_" + secNum + "_" + (i + 1) + "_0_" + optTest + "_mcma .labelTxt").text())); //  option text for reporting of interactions
			//alert($.trim($("#opt_" + secNum + "_" + (i + 1) + "_0_" + optTest + "_mcma .labelTxt").html()))
		}
	}
	/* change submit button state to enabled as long as at least one option selected */
	if (userAnsArray.toString().indexOf(1) >= 0) {
		$('#submit_btn_' + secNum).removeClass('disabled');
		/* 2021 Accessibility Update */
		$('#submit_btn_' + secNum).attr('title',localiseString('submit_btn'));
		$('#submit_btn_' + secNum).attr('alt',localiseString('submit_btn'));
		/* ensure hover states do not appear on focus for question objects in mobile 2021 */
		$("#submit_btn_" + secNum).mouseover(function(e) {			
			if ((isWeb) && (!$(this).hasClass("disabled")))
			{
				$(this).addClass("hovered");
			}
		});	
		$("#submit_btn_" + secNum).mouseout(function(e) {
			$(this).removeClass("hovered");
		});
	}
	else {
		$('#submit_btn_' + secNum).addClass('disabled');
		/* ensure hover states do not appear on focus for question objects in mobile 2021 */
		$('#submit_btn_' + secNum).removeClass('hovered');
		/* 2021 Accessibility Update */
		$('#submit_btn_' + secNum).attr('title', localiseString('submit_btn_locked'));
		$('#submit_btn_' + secNum).attr('alt', localiseString('submit_btn_locked'));
	}
	if (optTest == "t") {
		post_test_ques_dat[secId][0].user_ans = userAnsArray.join(",");		
	}
	else {
		inline_ques_dat[secId][0].user_ans = userAnsArray.join(",");
	}
}

/* process the submitted answer */
function calcAns(secNum, secTest, secQType, tNum, noFB) {	
	var secId = "sec_" + secNum;
	var numOfOptions = $("#" + secId + " .qItems .qItem").length / 2;	
	var inlineCorrect = true;
	var correctAnsArray = "";
	var userAnsArray = "";
	var runningTotal = 0;
	var score = 0;
	var partialScoring = false;
	var results_content = "";
	/* 20230804 tracking fixes: confidence and inline/kc questions only answered once, all questions have unique cmi.interactions IDs and resetting course after max assessment attempts */
	var resultsReached = false;
	var testScore = actionsLMSGetScore();
	testScore = testScore == "" ? 0 : Number(testScore);
	
	var noFB = noFB;
	
	if(noFB == undefined){
		noFB = false;
	}
	
	
	var sumbitIndex = 0; /* 20200730 Badges */
	
	document.answeredCorrect = false; // section topic test-out
	
	document.questStem = $.trim($("#"+secId + " .questionStem").text()); // section topic test-out question stem for reporting interactions
	
	if (!$("#submit_btn_" + secNum).hasClass("disabled"))
	{
	
		$("#submit_btn_" + secNum).blur();
		if ($("#submit_btn_" + secNum).html() == localiseString('tryagain_btn'))
		{
			document.inlineNumOfAttempts++; /* 20200730 Badges */
			resetInlineQues(secNum,tNum);		
			$("#submit_btn_" + secNum).addClass("disabled");
			/* ensure hover states do not appear on focus for question objects in mobile 2021 */
			$('#submit_btn_' + secNum).removeClass('hovered');
			/* 2021 Accessibility Update */
			$('#submit_btn_' + secNum).attr('title', localiseString('submit_btn_locked'));
			$('#submit_btn_' + secNum).attr('alt', localiseString('submit_btn_locked'));
			
		}
		else
		{
			if (secTest == "t") {
				document.test_score = Number(jQuery.makeArray(post_test_ques_dat['test_dat'][0].user_score));		
				correctAnsArray = jQuery.makeArray(post_test_ques_dat[secId][0].ans.split(","));		
				userAnsArray = jQuery.makeArray(post_test_ques_dat[secId][0].user_ans.split(","));		
				document.currentAssessQues++;
				secTest = "_t";		
			}
			else {

				/* 20200730 Badges */
				if(document.inlineQuesMaxAttempts > 0){
					if(document.inlineNumOfAttempts == document.inlineQuesMaxAttempts - 1){
						document.inlineQuesTryAgain = false;

					}
				}
				if(document.trackBadges){
					for(i in inline_ques_dat){
						sumbitIndex ++;
						if(i == secId){
							break
						}
					}
				}
				//console.log("sumbitIndex = " + sumbitIndex);
				/* 20200730 Badges */
				correctAnsArray = jQuery.makeArray(inline_ques_dat[secId][0].ans.split(","));
				userAnsArray = jQuery.makeArray(inline_ques_dat[secId][0].user_ans.split(","));
				secTest = "_i";		
				if(userAnsArray.toString() != correctAnsArray.toString()){		
					inlineCorrect = false;
				}
			}
			if((secQType == "mcma") && (((secTest == "_t") && document.partial_scoring_assess) || ((secTest == "_i") && document.partial_feedback_inline)))
			{
				partialScoring = true;
			}
			/* check to see if any options are selected, as long as one option is selected process question */
			if (eval(userAnsArray.join('+')) > 0) {
				for (var x=1; x < (numOfOptions + 1); x++) {			
					/* test out: if there is a pre-test in the course and it is being taken */
					if ((document.pretestPresent == 1) && document.takingPretest)
					{
						/* test out: apply background style to options for pre-test questions */
						$("#opt_"+ secNum + "_" + x + "_0" + secTest + "_" + secQType).addClass("mcma_hl_pretest");			
						$("#opt_"+ secNum + "_" + x + "_1" + secTest + "_" + secQType).addClass("mcma_hl_pretest");
					}
					else {
						/* if inline question try again is enabled and the question is not correct */
						if (document.inlineQuesTryAgain && !inlineCorrect)
						{
							/* do nothing */
						}
						else 
						{
							/* change the background of the item to the correctly not selected highlight */
							$("#opt_"+ secNum + "_" + x + "_0" + secTest + "_" + secQType).addClass("mcma_hl_corr_no_select");			
							$("#opt_"+ secNum + "_" + x + "_1" + secTest + "_" + secQType).addClass("mcma_hl_corr_no_select");
						}	
					}			
					if (userAnsArray[x - 1] == 1) {
						/* if inline question try again is enabled and the question is not correct */
						if (document.inlineQuesTryAgain && !inlineCorrect)
						{
							/* do nothing */
						}
						else 
						{
							$('#rb_'+ secNum + "_" + x).prop('checked', false);
						}
						/* test out: if there is a pre-test in the course and it is being taken */
						if ((document.pretestPresent == 1) && document.takingPretest)
						{						
							/* test out: apply background style to options for pre-test questions */
							$("#opt_"+ secNum + "_" + x + "_0" + secTest + "_" + secQType).find(".squaredBox label").addClass("mcma_hl_pretest");
						}					
						if (correctAnsArray[x - 1] == 1) {
							/* if inline question try again is enabled and the question is not correct */
							if (document.inlineQuesTryAgain && !inlineCorrect)
							{
								/* do nothing */
							}
							else {
								$('#rb_'+ secNum + "_" + x).prop('checked', false);
							}	
							/* test out: if there is a pre-test in the course and it is being taken */
							if ((document.pretestPresent == 1) && document.takingPretest)
							{
								/* test out: apply background style to options for pre-test questions */
								$("#opt_"+ secNum + "_" + x + "_0" + secTest + "_" + secQType).addClass("mcma_hl_pretest");
								$("#opt_"+ secNum + "_" + x + "_1" + secTest + "_" + secQType).addClass("mcma_hl_pretest");					
								$("#opt_"+ secNum + "_" + x + "_0" + secTest + "_" + secQType).find(".squaredBox label").addClass("mcma_hl_pretest");
							}
							else {
								/* if inline question try again is enabled and the question is not correct */
								if (document.inlineQuesTryAgain && !inlineCorrect)
								{
									/* do nothing */
								}
								else
								{
									/* if the user selected an option and it is correctly selected change the background and selected checkbox item to the correct highlight and tick */
									if(!noFB){
										$("#opt_"+ secNum + "_" + x + "_0" + secTest + "_" + secQType).addClass("mcma_hl_corr");
										$("#opt_"+ secNum + "_" + x + "_1" + secTest + "_" + secQType).addClass("mcma_hl_corr");					
										$("#opt_"+ secNum + "_" + x + "_0" + secTest + "_" + secQType).find(".squaredBox label").addClass("mcma_hl_corr");
										$("#opt_"+ secNum + "_" + x + "_1" + secTest + "_" + secQType).addClass("mcma_hl_corr_tick");
									}else{
										$("#opt_"+ secNum + "_" + x + "_0" + secTest + "_" + secQType).addClass("mcma_hl_pretest");
										$("#opt_"+ secNum + "_" + x + "_1" + secTest + "_" + secQType).addClass("mcma_hl_pretest");					
										$("#opt_"+ secNum + "_" + x + "_0" + secTest + "_" + secQType).find(".squaredBox label").addClass("mcma_hl_pretest");
									}
								}	
							}	
							if(partialScoring)
							{
								/* for each correct answer selected, give 1pt */
								runningTotal++;
							}
						}
						else
						{
							if (correctAnsArray[x - 1] == 0) 
							{
								/* test out: if there is a pre-test in the course and it is being taken */
								if ((document.pretestPresent == 1) && document.takingPretest)
								{
									/* do nothing */
								}
								else {
									/* if inline question try again is enabled and the question is not correct */
									if (document.inlineQuesTryAgain && !inlineCorrect)
									{
										/* do nothing */
									}
									else
									{
										/* if the user selected an option and it is incorrectly selected change the background and selected checkbox item to the incorrect highlight and cross */
										if(!noFB){
											$("#opt_"+ secNum + "_" + x + "_0" + secTest + "_" + secQType).addClass("mcma_hl_incorr");			
											$("#opt_"+ secNum + "_" + x + "_1" + secTest + "_" + secQType).addClass("mcma_hl_incorr");
											$("#opt_"+ secNum + "_" + x + "_0" + secTest + "_" + secQType).find(".squaredBox label").addClass("mcma_hl_incorr");
											$("#opt_"+ secNum + "_" + x + "_1" + secTest + "_" + secQType).addClass("mcma_hl_incorr_cross");
										}else{
											$("#opt_"+ secNum + "_" + x + "_0" + secTest + "_" + secQType).addClass("mcma_hl_pretest");			
											$("#opt_"+ secNum + "_" + x + "_1" + secTest + "_" + secQType).addClass("mcma_hl_pretest");
											$("#opt_"+ secNum + "_" + x + "_0" + secTest + "_" + secQType).find(".squaredBox label").addClass("mcma_hl_pretest");
										}
									}
								}						
								if(partialScoring)
								{
									/* for each incorrect answer selected, take 1pt */
									runningTotal--;
								}	
							}
						}
					}
					else
					{				
						if (correctAnsArray[x - 1] == 1) 
						{
							/* test out: if there is a pre-test in the course and it is being taken */
							if ((document.pretestPresent == 1) && document.takingPretest)
							{
								$("#opt_"+ secNum + "_" + x + "_0" + secTest + "_" + secQType).addClass("mcma_hl_pretest");
								$("#opt_"+ secNum + "_" + x + "_1" + secTest + "_" + secQType).addClass("mcma_hl_pretest");
							}	
							else {
								/* if inline question try again is enabled and the question is not correct */
								if (document.inlineQuesTryAgain && !inlineCorrect)
								{
									/* do nothing */
								}
								else
								{
									/* if the user did not select an option and it should have been selected change the background to the correct selected highlight and tick */if(!noFB){								
										$("#opt_"+ secNum + "_" + x + "_0" + secTest + "_" + secQType).removeClass("mcma_hl_corr_no_select");			
										$("#opt_"+ secNum + "_" + x + "_1" + secTest + "_" + secQType).removeClass("mcma_hl_corr_no_select");
										$("#opt_"+ secNum + "_" + x + "_0" + secTest + "_" + secQType).addClass("mcma_hl_corr_select");			
										$("#opt_"+ secNum + "_" + x + "_1" + secTest + "_" + secQType).addClass("mcma_hl_corr_select");								
										$("#opt_"+ secNum + "_" + x + "_1" + secTest + "_" + secQType).addClass("mcma_hl_corr_select_tick");
									}
								}	
							}	
							if(partialScoring)
							{
								/* for each correct answer not selected, take 1pt */
								runningTotal--;
							}	
						}
						else
						{
							if(partialScoring)
							{
								/* for each incorrect answer not selected, give 1pt */
								runningTotal++;
							}	
						}	
					}
					$("#opt_"+ secNum + "_" + x + "_0" + secTest + "_" + secQType).unbind("click");			
					$("#opt_"+ secNum + "_" + x + "_1" + secTest + "_" + secQType).unbind("click");
					
					$("#opt_"+ secNum + "_" + x + "_0" + secTest + "_" + secQType + " .mc_btn").removeClass("mcma_hl_hover"); //removed hover state when using keyboard			
					$("#opt_"+ secNum + "_" + x + "_1" + secTest + "_" + secQType + " .mc_btn").removeClass("mcma_hl_hover"); //removed hover state when using keyboard
					
					$("#opt_"+ secNum + "_" + x + "_0" + secTest + "_" + secQType).unbind("keypress");	// 20170830	keyboard functionality	
					$("#opt_"+ secNum + "_" + x + "_1" + secTest + "_" + secQType).unbind("keypress");  // 20170830 keyboard functionality
					$("#opt_"+ secNum + "_" + x + "_0" + secTest + "_" + secQType).css("cursor","default");
					$("#opt_"+ secNum + "_" + x + "_1" + secTest + "_" + secQType + " .button").css("cursor","default");
				}
				/* show feedback */
				if(partialScoring)
				{
					/* set score per calculation rules */
					if (runningTotal > 0) {
						score = 0.5;
					}
					else if (runningTotal <= 0) {
						score = 0;
					}
				}
				if(userAnsArray.toString() == correctAnsArray.toString()){
					document.answeredCorrect = true; 
					if (secTest == "_t")
					{
						/* if completely answered correctly, give full pt */
						document.test_score++;
						/* test out: if there is a pre-test in the course */
						if (document.pretestPresent == 1)
						{
							var topicNum = Number(post_test_ques_dat[secId][0].topic_num);
							/* test out: if the pre-test is being taken then add one to the number of questions answered correctly for this topic */
							if (document.takingPretest) {
								document.topicsPretestQuesCorArr[topicNum - 1] = document.topicsPretestQuesCorArr[topicNum - 1] + 1;
							}
						}				
					}
					/* test out: if there is a pre-test in the course */
					if (document.pretestPresent == 1)
					{
						/* test out: do not show feedback for pre-test questions */
						if ((secTest == "_i") || ((secTest == "_t") && (!document.takingPretest))) {
							/* if inline question try again is enabled and the question is not correct */
							if (document.inlineQuesTryAgain && !inlineCorrect)
							{
								/* do nothing */
							}
							else
							{
								if(document.useTransitions){
									/* transitions: fade in question feedback */
									$("#feedback_corr_" + secNum).fadeIn();
								}else{
									$("#feedback_corr_" + secNum).show();
								}
							}
						}	
					}
					else
					{
						/* if inline question try again is enabled and the question is not correct */
						if (document.inlineQuesTryAgain && !inlineCorrect)
						{
							/* do nothing */
						}
						else
						{
							if(document.useTransitions){
								/* transitions: fade in question feedback */
								$("#feedback_corr_" + secNum).fadeIn();
							}else{
								$("#feedback_corr_" + secNum).show();
							}	
						}	
					}	
				}
				else
				{		
					if (score > 0)
					{
						if (secTest == "_t")
						{
							document.test_score+=score;
							/* test out: if there is a pre-test in the course */
							if (document.pretestPresent == 1)
							{
								/* test out: do not show feedback for pre-test questions */
								if (!document.takingPretest) {
									if(document.useTransitions){
										/* transitions: fade in question feedback */
										$("#feedback_partial_" + secNum).fadeIn();
									}else{
										$("#feedback_partial_" + secNum).show();
									}
								}	
							}
							else
							{
								if(document.useTransitions){
									/* transitions: fade in question feedback */
									$("#feedback_partial_" + secNum).fadeIn();
								}else{
									$("#feedback_partial_" + secNum).show();
								}
							}					
						}
						else
						{
							/* if inline question try again is enabled and the question is not correct */
							if (document.inlineQuesTryAgain && !inlineCorrect)
							{			
								var numOfOptions = $("#" + secId + " .qItems .qItem").length / 2;
								for (var x=1; x < (numOfOptions + 1); x++) {
									$("#opt_"+ secNum + "_" + x + "_0" + secTest + "_" + secQType).addClass("mcma_hl_pretest");
									$("#opt_"+ secNum + "_" + x + "_1" + secTest + "_" + secQType).addClass("mcma_hl_pretest");
									if (secQType == "mcsa")
									{
										$("#opt_"+ secNum + "_" + x + "_0" + secTest + "_" + secQType).find(".squaredBox").removeClass().addClass("squaredBoxMCSA").addClass("squaredBox").addClass("alignCheckBox");
									}
									else if (secQType == "mcma")
									{
										$("#opt_"+ secNum + "_" + x + "_0" + secTest + "_" + secQType).find(".squaredBox").removeClass().addClass("squaredBox").addClass("alignCheckBox");
									}
									if (userAnsArray[x - 1] == 1)
									{							
										$("#opt_"+ secNum + "_" + x + "_0" + secTest + "_" + secQType).find(".squaredBox label").addClass("mcma_hl_pretest");
									}
								}
								/* two levels of try again feedback */
								var fb_level = 0;
								if (inline_ques_dat[secId][0].ans_once == '0')
								{
									fb_level = 1;
								}
								else 
								{
									fb_level = 2;
								}
								if (document.inlineQuesTryAgainTwoFB)
								{
									inline_ques_dat[secId][0].ans_once = '1';
								}
								if(document.useTransitions){								
									/* transitions: fade in question feedback */
									$("#feedback_tryagain_" + fb_level + "_" + secNum).fadeIn();
								}else{
									$("#feedback_tryagain_" + fb_level + "_" + secNum).show();
								}
							}
							else
							{
								if(document.partial_feedback_inline)
								{								
									if(document.useTransitions){
										/* transitions: fade in question feedback */
										$("#feedback_partial_" + secNum).fadeIn();
									}else{
										$("#feedback_partial_" + secNum).show();
									}								
								}
								else
								{								
									if(document.useTransitions){
										/* transitions: fade in question feedback */
										$("#feedback_incorr_" + secNum).fadeIn();
									}else{
										$("#feedback_incorr_" + secNum).show();
									}
								}	
							}	
						}
					}
					else {
						/* test out: if there is a pre-test in the course */
						if (document.pretestPresent == 1)
						{
							/* test out: do not show feedback for pre-test questions */
							if ((secTest == "_i") || ((secTest == "_t") && (!document.takingPretest))) {
								/* if inline question try again is enabled and the question is not correct */
								if ((secTest == "_i") && document.inlineQuesTryAgain && !inlineCorrect)
								{				
									var numOfOptions = $("#" + secId + " .qItems .qItem").length / 2;
									for (var x=1; x < (numOfOptions + 1); x++) {
										$("#opt_"+ secNum + "_" + x + "_1" + secTest + "_" + secQType).addClass("mcma_hl_pretest");
										$("#opt_"+ secNum + "_" + x + "_0" + secTest + "_" + secQType).addClass("mcma_hl_pretest");
										if (secQType == "mcsa")
										{
											$("#opt_"+ secNum + "_" + x + "_0" + secTest + "_" + secQType).find(".squaredBox").removeClass().addClass("squaredBoxMCSA").addClass("squaredBox").addClass("alignCheckBox");
										}
										else if (secQType == "mcma")
										{
											$("#opt_"+ secNum + "_" + x + "_0" + secTest + "_" + secQType).find(".squaredBox").removeClass().addClass("squaredBox").addClass("alignCheckBox");
										}
										if (userAnsArray[x - 1] == 1)
										{
											$("#opt_"+ secNum + "_" + x + "_0" + secTest + "_" + secQType).find(".squaredBox label").addClass("mcma_hl_pretest");
										}
									}
									/* two levels of try again feedback */
									var fb_level = 0;
									if (inline_ques_dat[secId][0].ans_once == '0')
									{
										fb_level = 1;
									}
									else 
									{
										fb_level = 2;
									}
									if (document.inlineQuesTryAgainTwoFB)
									{
										inline_ques_dat[secId][0].ans_once = '1';
									}
									if(document.useTransitions){								
										/* transitions: fade in question feedback */
										$("#feedback_tryagain_" + fb_level + "_" + secNum).fadeIn();
									}else{
										$("#feedback_tryagain_" + fb_level + "_" + secNum).show();
									}
								}
								else
								{
									if(document.useTransitions){
										/* transitions: fade in question feedback */
										$("#feedback_incorr_" + secNum).fadeIn();
									}else{
										$("#feedback_incorr_" + secNum).show();
									}
								}	
							}	
						}
						else 
						{
							/* if inline question try again is enabled and the question is not correct */
							if ((secTest == "_i") && document.inlineQuesTryAgain && !inlineCorrect)
							{					
								var numOfOptions = $("#" + secId + " .qItems .qItem").length / 2;
								for (var x=1; x < (numOfOptions + 1); x++) {
									$("#opt_"+ secNum + "_" + x + "_0" + secTest + "_" + secQType).addClass("mcma_hl_pretest");
									$("#opt_"+ secNum + "_" + x + "_1" + secTest + "_" + secQType).addClass("mcma_hl_pretest");
									if (secQType == "mcsa")
									{
										$("#opt_"+ secNum + "_" + x + "_0" + secTest + "_" + secQType).find(".squaredBox").removeClass().addClass("squaredBoxMCSA").addClass("squaredBox").addClass("alignCheckBox");
									}
									else if (secQType == "mcma")
									{
										$("#opt_"+ secNum + "_" + x + "_0" + secTest + "_" + secQType).find(".squaredBox").removeClass().addClass("squaredBox").addClass("alignCheckBox");
									}
									if (userAnsArray[x - 1] == 1)
									{							
										$("#opt_"+ secNum + "_" + x + "_0" + secTest + "_" + secQType).find(".squaredBox label").addClass("mcma_hl_pretest");
									}
								}
								/* two levels of try again feedback */
								var fb_level = 0;
								if (inline_ques_dat[secId][0].ans_once == '0')
								{
									fb_level = 1;
								}
								else 
								{
									fb_level = 2;
								}
								if (document.inlineQuesTryAgainTwoFB)
								{
									inline_ques_dat[secId][0].ans_once = '1';
								}
								if(document.useTransitions){
									/* transitions: fade in question feedback */
									$("#feedback_tryagain_" + fb_level + "_" + secNum).fadeIn();
								}else{
									$("#feedback_tryagain_" + fb_level + "_" + secNum).show();
								}
							}
							else
							{							
								if(document.useTransitions){
									/* transitions: fade in question feedback */
									$("#feedback_incorr_" + secNum).fadeIn();
								}else{
									$("#feedback_incorr_" + secNum).show();
								}
							}	
						}
					}	
				}	
				if (secTest == "_t")
				{
					post_test_ques_dat['test_dat'][0].user_score = document.test_score;
				}

				/* disable options */
				$("#" + secId + ' input[type=checkbox]').attr('disabled', true);
				$("#" + secId + " .squaredBox").unbind( "click" );
				$("#" + secId + " .squaredBox").unbind("keypress");  // 20170830 keyboard functionality
				$("#" + secId + " .squaredBox label").css("cursor","default");
				$("#" + secId + " .qItem").unbind( "click");
				$("#" + secId + " .qItem").unbind("keypress");  // 20170830 keyboard functionality
				$("#" + secId + " .qItem").css("cursor","default");
				if (document.inlineQuesTryAgain && !inlineCorrect)
				{
					$("#submit_btn_" + secNum).html(localiseString('tryagain_btn'));
					$("#submit_btn_" + secNum).attr('title',localiseString('tryagain_btn'));
					$("#submit_btn_" + secNum).attr('alt',localiseString('tryagain_btn'));
					/* 2021 Accessibility Update */
					$("#submit_btn_" + secNum).addClass('tryagain_btn');
				}
				else
				{
					/* hide submit */
					$("#submit_btn_" + secNum).hide();
				}	
				if (secTest == "_t")
				{	
					document.assessAttempted = true;
					if ((document.currentAssessQues + 1) == document.assessRandomQuesArr.length)
					{
						/* test out: if there is a pre-test in the course */
						if (document.pretestPresent == 1)
						{
							var percentage_score = 0;
							var totalQues = 0;
							for (var i = 0; i < document.topicsCount; i++)
							{
								totalQues += Number(document.assessSelectQuesArr[i]);	
							}
							/* test out: if taking the pre-test */
							if (document.takingPretest) {
								/* test out: obtain the status of what topics have been tested out of */
								/* stores 1s for topics with question banks that are tested out of only */
								var tempTPretestOutArr = document.topicsPretestedOut.split('');
								/* stores 1s for topics with question banks that are tested out of as well as 1s for topics without question banks that are not required to be viewed */
								var tempTPretestOutArr2 = document.topicsPretestedOut.split('');
								var totalTCanBePretestedOut = 0;
								var totalTPretestedOut = 0;
								for (var y = 0; y < document.topicsCount; y++)
								{
									/* test out: if the number of questions answered correctly for this topic matches those required and it is not the summary topic or the test topic */
									if ((document.topicsPretestQuesCorArr[y] == document.assessSelectQuesArr[y]) && ((y != (document.topicsCount - 2)) && (y != (document.topicsCount - 1))))								
									{							
										/* if there is no question bank for this topic and the topic is not required to be viewed then mark this topic as tested out only in the second array */ 
										if (document.assessTopicHasQBank[y] == "0")
										{
											tempTPretestOutArr2[y] = 1;
										}
										/* if there is a question bank for this topic then mark this topic as tested out in both arrays */
										else if (document.assessTopicHasQBank[y] == "1")
										{
											tempTPretestOutArr[y] = 1;
											tempTPretestOutArr2[y] = 1;
											/* increment the counter for possible tested out topics */
											totalTCanBePretestedOut++;
											/* increment the counter for tested out topics */
											totalTPretestedOut++;
										}
									}
									else
									{
										/* if there is a question bank for this topic */
										if (document.assessTopicHasQBank[y] == "1")
										{
											/* increment the counter for possible tested out topics */
											totalTCanBePretestedOut++;
										}
									}
								}
								/* if all topics with question banks have been tested out */
								if (totalTPretestedOut == totalTCanBePretestedOut)
								{							
									for (var yy = 0; yy < document.topicsCount; yy++)
									{
										/* if there is no question bank for this topic and the topic is required to be viewed but not if the learner has pre-tested out then mark this topic as tested out only in the second array */ 
										if (document.assessTopicHasQBank[yy] == "3")
										{
											tempTPretestOutArr2[yy] = 1;
										}
									}
								}
								/* test out: if all topics with question banks have been tested out of then mark the test topic as tested out of */
								if (totalTPretestedOut == (document.topicsCount - 1))
								{
									tempTPretestOutArr[document.topicsCount - 1] = 1;
									tempTPretestOutArr2[document.topicsCount - 1] = 1;
								}
								/* test out: assign the status of what topics have been tested out of */
								/* if there are no topics with question banks that are tested out of then use first array so that the full course must be taken */
								if (tempTPretestOutArr.toString().indexOf('1') == -1)
								{
									document.topicsPretestedOut = tempTPretestOutArr.join('');
								}
								/* if there is at least one topic with a question bank that is tested out of but not all then use second array so that only the topics with question banks not tested out of and the topics without question banks which are required to be viewed must be taken, or not taken if the learner has pre-tested out */
								else
								{
									document.topicsPretestedOut = tempTPretestOutArr2.join('');
								}					
								recordPercentComplete(1, document.subsectionCount, false);						
								percentage_score = Math.round((document.test_score / totalQues)*100);
							}				
							else {									
								/* test out: if there is a pre-test in the course and the test has not yet been passed in a previous session */
								if (testScore < document.assessPassmark)
								{								
									/* test out: obtain the status of what topics have been tested out of */
									var tempTPretestOutArr = document.topicsPretestedOut.split('');				
									for (var i = 0; i < document.topicsCount; i++)
									{
										if ((document.assessTopicHasQBank[i] == "1") && (tempTPretestOutArr[i] == "1"))
										{
											document.test_score = document.test_score + Number(document.assessSelectQuesArr[i]);
										}
									}						
									percentage_score = Math.round((document.test_score / totalQues)*100);
									if (percentage_score > 100)
									{
										percentage_score = 100;
									}
								}
								/* test out: if the test has been passed in a previous session */
								else if (testScore >= document.assessPassmark)
								{
									percentage_score = testScore;
								}
							}	
						}
						else
						{
							percentage_score = Math.round((document.test_score / Number(document.assessRandomQuesArr.length - 1))*100);
						}
						document.assessPercentageScore = percentage_score;				
						var assessResultsSec = document.assessRandomQuesArr[document.assessRandomQuesArr.length - 1];
						/* test out: if there is a pre-test in the course and it is being taken */
						if ((document.pretestPresent == 1) && document.takingPretest)
						{					
							/* if all topics that have a question bank have been tested out of and there are no topics (besides summary) that do not have a question bank and are required to be viewed */
							if((percentage_score==100) && (document.assessTopicHasQBank.toString().indexOf("2") == -1))
							{
								/* show the passing results and prepare to require the learner to only take the summary */
								results_content += '<p class="lgTitleSubText">' + test_results_dat['pre_test'][0].pass_msg + '</p>';
								/* test out: ensure the test results is marked as viewed */
								document.topicsPretestedOut = document.topicsPretestedOut.substring(0,document.topicsCount-2) + "01";
								$('#left_nav').hide();
								$('#right_nav').removeClass('locked');
								/* 2022 Accessibility Update */
								$('#right_nav').attr('title', localiseString('right_nav'));
								$('#right_nav').attr('alt', localiseString('right_nav'));
								$('#home_nav').addClass('pretest');
							}
							else {
								var topicsTestedOut = "";
								for (var j = 0; j < (tempTPretestOutArr.length - 1); j++)
								{
									if (j == 0)
									{
										topicsTestedOut += "<br>";
									}
									/* if a topic has a question bank and is not tested out of or a topic does not have a question bank but is required to be viewed or is the summary */
									if (((tempTPretestOutArr[j] == 0) && ((document.assessTopicHasQBank[j] != "0"))) || (j == (tempTPretestOutArr.length - 2)))
									{
										/* if all topics that have a question bank have been tested out of and this topic does not have a question bank but is required to be viewed */
										if((percentage_score==100) && (document.assessTopicHasQBank[j] == "3"))
										{
											/* include a tick beside the topic in the list in the results */
											/* 2021 Accessibility Update */
											topicsTestedOut += '<div class=\'screen_reader_instruction\'>' + test_results_dat['pre_test'][0].pass_msg_4 + '</div><div class=\'pretest_topic_passed\'>' + document.topicTitles['titles'][j].title + '</div><br>';
										}
										else {									
											/* do not include a tick beside the topic in list in the results */
											/* 2021 Accessibility Update */
											topicsTestedOut += '<div class=\'screen_reader_instruction\'>' + test_results_dat['pre_test'][0].pass_msg_5 + '</div><div class=\'pretest_topic_passed pretest_topic_blank\'>' + document.topicTitles['titles'][j].title + '</div><br>';
										}	
									}							
									/* if a topic has a question bank and is tested out of or a topic does not have a question bank and is not required to be viewed and is not the summary */
									else if ((tempTPretestOutArr[j] == 1) || ((document.assessTopicHasQBank[j] == "0") && (j != (tempTPretestOutArr.length - 2))))
									{
										/* include a tick beside the topic in the list in the results */
										/* 2021 Accessibility Update */
										topicsTestedOut += '<div class=\'screen_reader_instruction\'>' + test_results_dat['pre_test'][0].pass_msg_4 + '</div><div class=\'pretest_topic_passed\'>' + document.topicTitles['titles'][j].title + '</div><br>';
									}
								}
								/* if all topics that have a question bank have been tested out of and there are topics (besides summary) that do not have a question bank and are required to be viewed then the learner must complete those topics and the summary but not the post-test to complete the course */
								if ((percentage_score==100) && (document.assessTopicHasQBank.toString().indexOf("2") != -1))
								{
									/* test out: ensure the test results are not marked as viewed */
									document.topicsPretestedOut = document.topicsPretestedOut.substring(0,document.topicsCount-2) + "01";
									/* 2021 Accessibility Update */
									results_content += '<p class="lgTitleSubText">' + test_results_dat['pre_test'][0].pass_msg_2 + '</p><p class="screen_reader_instruction">' + test_results_dat['pre_test'][0].pass_msg_3a + '</p>' + topicsTestedOut + '<p class="lgTitleSubText">' + test_results_dat['pre_test'][0].pass_msg_3b + '</p>';
								}
								/* if there are no topics with question banks that are tested out of then the learner must take the full course to complete the course */
								else if (tempTPretestOutArr.toString().indexOf("1") == -1)
								{
									/* test out: ensure the test results are not marked as viewed */
									document.topicsPretestedOut = document.topicsPretestedOut.substring(0,document.topicsCount-2) + "00";								
									results_content += '<p class="lgTitleSubText">' + test_results_dat['pre_test'][0].fail_msg_3 + '</p>';
								}
								/* if there is at least one topic with a question bank that is tested out then the learner must take the topics not tested out of, topics that do not have a question bank and are required to be viewed, the summary and if not all topics are tested out of then the post-test to complete the course */
								else
								{
									/* test out: ensure the test results are not marked as viewed */
									document.topicsPretestedOut = document.topicsPretestedOut.substring(0,document.topicsCount-2) + "00";
									/* 2021 Accessibility Update */
									results_content += '<p class="lgTitleSubText">' + test_results_dat['pre_test'][0].fail_msg_1 + '</p><p class="screen_reader_instruction">' + test_results_dat['pre_test'][0].pass_msg_3a + '</p>' + topicsTestedOut + '<p class="lgTitleSubText">' + test_results_dat['pre_test'][0].fail_msg_2 + '</p>';
								}
								$('#left_nav').hide();
								$('#right_nav').hide();
								$('#home_nav').addClass('pretest');
							}	
							$('#retake_assess_btn_div_' + assessResultsSec).hide();
						}
						else {
							if(typeof(LMSAPI)!="undefined"){
								if(useAICCRules!=true && commitTimer!=true){
									actionsLMSCommit();
								}
								checkCourseCompletion();	
							}
							var percentSymbol = '%';
							/* space before percentage for specific languages fix 2019 */
							if ((document.selectedLang == 'fr') || (document.selectedLang == 'de'))
							{
								percentSymbol = '&nbsp;' + percentSymbol;
							}
							results_content = '<p class="lgTitleSubText">' + test_results_dat['post_test'][0].generic_msg + ' ' + percentage_score + percentSymbol + '</p>';
							if(percentage_score>=document.assessPassmark)
							{
								results_content += '<p class="lgTitleSubText">' + test_results_dat['post_test'][0].pass_msg + '</p>';
								$('#retake_assess_btn_div_' + assessResultsSec).hide();		
								$('#retake_course_btn_div_' + assessResultsSec).hide();
							}
							else
							{
								/*results_content += '<p class="lgTitleSubText">' + test_results_dat['post_test'][0].fail_msg + '</p>';
								$('#retake_assess_btn_div_' + assessResultsSec).show();*/
								
								/* 20220426 Increment post-test attempts */
								document.assessAttempts++
								if(document.assessAttempts != document.maxAssessAttempts){
									results_content += '<p class="lgTitleSubText">' + test_results_dat['post_test'][0].fail_msg + '</p>';
									$('#retake_assess_btn_div_' + assessResultsSec).show();
									$('#retake_course_btn_div_' + assessResultsSec).hide();
								}else{
									/* 20220426 Failed post-test the max number of times so show re-start button and text */
									results_content += '<p class="lgTitleSubText">' + test_results_dat['post_test'][0].fail_max_msg + '</p>';
									$('#retake_course_btn_div_' + assessResultsSec).show();
									$('#retake_assess_btn_div_' + assessResultsSec).hide();

									//resetCourse(); // 20190205 moved to lock.js

								}
								
							}
						}		
						$('#sec_' + assessResultsSec + ' .content_text .content_text_2').html(results_content);
						/* 20230804 tracking fixes: confidence and inline/kc questions only answered once, all questions have unique cmi.interactions IDs and resetting course after max assessment attempts */
						resultsReached = true;
					}
				}

				if (document.inlineQuesTryAgain && !inlineCorrect)
				{
					/* do nothing */
				}
				else
				{
					var secNum = secNum
					var questionDone = 0;
					var clicked = 0;
						if(Number($('#sec_'+secNum+' .submit_btn').attr('data')) == 0){ 
							$('#sec_'+secNum+' .submit_btn').attr('data',1);
						}
						var data = Number($('#sec_'+secNum+' .submit_btn').attr('data'));
						if(data === Number(1)){
							questionDone++;
							clicked = Number($('#sec_'+secNum).attr('data-clicked'));
							clicked +=1;
							$('#sec_'+secNum).attr('data-clicked',clicked);	
							$('#sec_'+secNum+' .submit_btn').attr('data','2');
						}

					/* mark question as complete */
					var totalClicked = Number($('#sec_'+secNum).attr('data-clicked'))// + Number($('#sec_'+secNum).attr('data-links')) + Number($('#sec_'+secNum).attr('data-hotwords'));
					var totalClicks = Number(document.clickArr[Number(secNum) - 1])// + Number(document.linkArr[Number(secNum) - 1]) + Number(document.hotArr[Number(secNum) - 1])
					if(totalClicked == totalClicks){			
						if(isAndroidTablet|| isAndroidPhone || isiPad){
							document.intComplete = true;
							clearInterval(document.lockinterval)
							document.lockinterval = setInterval(function(){
								che = '#sec_'+secNum;
								document.getnear(che);
								isPageComplete(document.currentSection);
								/* assign the next section based on if inline or test question */
								var nextSec = parseInt(secNum)+1;
								if (secTest == "_t")
								{
									var tCurrQues = $("#sec_" + secNum + " .testQuesLabel").html().split(" ")[1];
									nextSec = document.assessRandomQuesArr[tCurrQues];	
								}
								if(($('#sec_'+nextSec).is(':visible') || !$('#right_nav').hasClass('locked')) && document.courseLockedDown == true){
									clearInterval(document.lockinterval)
								} 
							},250)
						}else{
							document.intComplete = true;
							isPageComplete(document.currentSection);
						}

						/* 20200730 Badges */
						if(document.inlineQuesMaxAttempts > 0){
							document.inlineQuesTryAgain = true;
							document.inlineNumOfAttempts = 0;
						}

						if(document.trackBadges && inlineCorrect){

							var badgeArr = document.badgeData.split(",");

							if(badgeArr[sumbitIndex-1] == 0){
								badgeArr[sumbitIndex-1] = secNum;
							}
							document.badgeData = badgeArr.join(",")
						}
						/* 20200730 Badges */
						if(document.trackBadges){
							displayBadges()
						}

						if(secTest == "_i"){
							//if(secQType == "mcsa"){
							if($("#sec_"+secNum).hasClass("conf_quest")){
								//if(document.userConfidence == 0){
									
									for(var i = 0; i!=userAnsArray.length; i++){
										if(userAnsArray[i] == 1){
											document.userConfidence = Number(i+1);
											//markSectionComplete(secNum); /* 20230626 fix to mark quesiton as complete on submit */
											//pageCompleted = secNum;	/* 20230626 fix to mark quesiton as complete on submit */
										}
									}
									
								//}
							}
						}

						/* 20230607 track inline questions in suspend_data to be able to display question summary */
						/* 20230830 ensure to always display how learner answered confidence and tracked inline questions after first attempt */
						trackQuestion(secNum, userAnsArray, document.answeredCorrect);

						/* 20230607 populate question summary from tracked inline questions in suspend_data to be able to display question summary */
						populateSummary();

						/* 20230913 tracking fixes: ensure confidence has been chosen before trying to disable a confidence question, disable likert/survey questions when answered, remove first likert/survey question when return to topic after answered, do not send cmi.interactions if inline/kc question does not have track_quest class */
						var confQuest = $("#sec_"+secNum).hasClass("conf_quest");
						var trackQuest = $("#sec_"+secNum).hasClass("track_quest");
						var testQuest = $("#sec_"+secNum).hasClass("testQues");						
						if((confQuest) || (trackQuest) || (testQuest)){
							prepareInteractions(secNum, userAnsArray, document.answeredCorrect,noFB); //  collate the question data for reporting of interactions	
						}

						/* 20230804 tracking fixes: confidence and inline/kc questions only answered once, all questions have unique cmi.interactions IDs and resetting course after max assessment attempts */
						if (resultsReached) {document.allTimeAssessAttempts++;}
					}
				}
				/* hotspot banner fix */
				if(isiPad){				
					setTimeout(function(){hotSpotAdjustBanner();},100);
				}
				/* hotspot banner fix */
				if(isAndroidTablet || isAndroidPhone || isMacChrome){
					$('html,body').scrollTop(windowTop -1)
				}
			}
		}	
	}
}


function displayBadges(){
	
	var badgeArr = document.badgeData.split(",");
	
	for(var i = 0; i!= badgeArr.length; i++){
		
		if(badgeArr[i] != Number(0)){
			
			$("#badge_"+badgeArr[i]).css("display","block");	
		}	
	}
	
	$('.sec_rest_wrapper').find('.section').each(function(index, element) {
		
		if($(this).hasClass("inlineRes")){
			
			var secID = $(this).attr("id")
			
			var resNum = Number(secID.split("_")[1])
			doInlineRes(resNum);
		}
		
	});
}

function doInlineRes(n){
	$("#pass_txt_"+n).css("display","none");
	$("#fail_txt_"+n).css("display","none");
	var totalNumOfBadges = $("#sec_" + n + " .res_badge_holder .result_badge").length;
	var numofBadges = 0;
	$("#sec_" + n + " .res_badge_holder").find(".result_badge").each(function(index, element) {
		
		if($(this).css("display") == "block"){
			numofBadges ++;
		}
		
	});	
	console.log("numofBadges = " + numofBadges + "   totalNumOfBadges = " + totalNumOfBadges)
	if(numofBadges > 0){
		
		$("#pass_txt_"+n).css("display","block");
	}else{
		$("#fail_txt_"+n).css("display","block");
	}
	
	
}

/* reset an inline question */
function resetInlineQues(secNum,tNum) {
	var secId = "sec_" + secNum;
	var numOfOptions = $("#" + secId + " .qItems .qItem").length / 2;
	var secTest = "_i";
	var secQType1 = "_mcsa";
	var secQType2 = "_mcma";	
	for (var x=1; x < (numOfOptions + 1); x++) {
		/* change the background of all items to have no highlight */		
		$("#opt_"+ secNum + "_" + x + "_0" + secTest + secQType1).find(".squaredBox").removeClass().addClass("squaredBox").addClass("squaredBoxMCSA").addClass("squaredBox_bg_" + tNum).addClass("alignCheckBox");
		$("#opt_"+ secNum + "_" + x + "_0" + secTest + secQType1).removeClass("mcma_hl_pretest");			
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType1).removeClass("mcma_hl_pretest");
		$("#opt_"+ secNum + "_" + x + "_0" + secTest + secQType1).find(".squaredBox label").removeClass("mcma_hl_pretest");			
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType1).find(".squaredBox label").removeClass("mcma_hl_pretest");
		$("#opt_"+ secNum + "_" + x + "_0" + secTest + secQType2).find(".squaredBox").removeClass().addClass("squaredBox").addClass("squaredBox_bg_" + tNum).addClass("alignCheckBox");
		$("#opt_"+ secNum + "_" + x + "_0" + secTest + secQType2).removeClass("mcma_hl_pretest");			
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType2).removeClass("mcma_hl_pretest");
		$("#opt_"+ secNum + "_" + x + "_0" + secTest + secQType2).find(".squaredBox label").removeClass("mcma_hl_pretest");			
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType2).find(".squaredBox label").removeClass("mcma_hl_pretest");
		/* enable options */
		$('#rb_'+ secNum + "_" + x).prop('checked', false);
		$("#opt_"+ secNum + "_" + x + "_0" + secTest + secQType1).css("cursor","pointer");
		$("#opt_"+ secNum + "_" + x + "_0" + secTest + secQType2).css("cursor","pointer");
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType1 + " .button").css("cursor","pointer");
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType2 + " .button").css("cursor","pointer");
		/* two levels of try again feedback */
		$("#feedback_tryagain_1_" + secNum).hide();
		$("#feedback_tryagain_2_" + secNum).hide();
		/* allow for two levels of partially correct feedback for mcma 012722 */
		$("#feedback_tryagain_3_" + secNum).hide();
		$("#feedback_tryagain_4_" + secNum).hide();
		$("#" + secId + ' input[type=checkbox]').attr('disabled', false);
		$("#" + secId + " .squaredBox label").css("cursor","pointer");
		$("#" + secId + " .qItem").css("cursor","pointer");
		/* show submit */
		$("#submit_btn_" + secNum).html(localiseString('submit_btn'));
		$("#submit_btn_" + secNum).attr('title',localiseString('submit_btn'));
		$("#submit_btn_" + secNum).attr('alt',localiseString('submit_btn'));
		/* clear user answer */
		var userAns = inline_ques_dat[secId][0].user_ans;
		userAns = userAns.replace('1','0');
		inline_ques_dat[secId][0].user_ans = userAns;
	}
	reSetupClickableOptionsInlineQues(secId);
	/* hotspot banner fix */
	if(isiPad || isiPhone){				
		setTimeout(function(){hotSpotAdjustBanner();},100);
		window.scrollTo(window.scrollX, window.scrollY - 1); // iOS13 Fix to issue with radio buttons not being active when trying question again
		window.scrollTo(window.scrollX, window.scrollY + 1); // iOS13 Fix to issue with radio buttons not being active when trying question again
	}
	if(!iOSApp){ // iOS13 Fix to issue with radio buttons not being active when trying question again
		
		if(navigator.platform == "MacIntel"){
			window.scrollTo(window.scrollX, window.scrollY - 1);
			window.scrollTo(window.scrollX, window.scrollY + 1);
		}
	}
	/* hotspot banner fix */
	if(isAndroidTablet || isAndroidPhone || isMacChrome){
		$('html,body').scrollTop(windowTop -1)
	}
}

/* reset a test question */
function resetTestQues(secNum) {
	var secId = "sec_" + secNum;
	var numOfOptions = $("#" + secId + " .qItems .qItem").length / 2;
	var secTest = "_t";
	var secQType1 = "_mcsa";
	var secQType2 = "_mcma";
	for (var x=1; x < (numOfOptions + 1); x++) {
		/* change the background of all items to have no highlight */		
		$("#opt_"+ secNum + "_" + x + "_0" + secTest + secQType1).removeClass("mcma_hl_incorr");
		$("#opt_"+ secNum + "_" + x + "_0" + secTest + secQType1).removeClass("mcma_hl_corr");
		$("#opt_"+ secNum + "_" + x + "_0" + secTest + secQType1).removeClass("mcma_hl_corr_select");
		$("#opt_"+ secNum + "_" + x + "_0" + secTest + secQType1).removeClass("mcma_hl_corr_no_select");
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType1).removeClass("mcma_hl_incorr");
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType1).removeClass("mcma_hl_corr");		
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType1).removeClass("mcma_hl_corr_select");
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType1).removeClass("mcma_hl_corr_no_select");
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType1).removeClass("mcma_hl_corr_tick");
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType1).removeClass("mcma_hl_corr_select_tick");
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType1).removeClass("mcma_hl_incorr_cross");
		$("#opt_"+ secNum + "_" + x + "_0" + secTest + secQType1).find(".squaredBox label").removeClass("mcma_hl_incorr");
		$("#opt_"+ secNum + "_" + x + "_0" + secTest + secQType1).find(".squaredBox label").removeClass("mcma_hl_corr");		
		$("#opt_"+ secNum + "_" + x + "_0" + secTest + secQType1).find(".squaredBox label").removeClass("mcma_hl_corr_select");
		$("#opt_"+ secNum + "_" + x + "_0" + secTest + secQType1).find(".squaredBox label").removeClass("mcma_hl_corr_no_select");
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType1).find(".squaredBox label").removeClass("mcma_hl_incorr");
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType1).find(".squaredBox label").removeClass("mcma_hl_corr");		
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType1).find(".squaredBox label").removeClass("mcma_hl_corr_select");
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType1).find(".squaredBox label").removeClass("mcma_hl_corr_no_select");
		$("#opt_"+ secNum + "_" + x + "_0" + secTest + secQType2).removeClass("mcma_hl_incorr");
		$("#opt_"+ secNum + "_" + x + "_0" + secTest + secQType2).removeClass("mcma_hl_corr");
		$("#opt_"+ secNum + "_" + x + "_0" + secTest + secQType2).removeClass("mcma_hl_corr_select");
		$("#opt_"+ secNum + "_" + x + "_0" + secTest + secQType2).removeClass("mcma_hl_corr_no_select");
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType2).removeClass("mcma_hl_incorr");
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType2).removeClass("mcma_hl_corr");
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType2).removeClass("mcma_hl_corr_select");
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType2).removeClass("mcma_hl_corr_no_select");		
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType2).removeClass("mcma_hl_corr_tick");
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType2).removeClass("mcma_hl_corr_select_tick");
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType2).removeClass("mcma_hl_incorr_cross");
		$("#opt_"+ secNum + "_" + x + "_0" + secTest + secQType2).find(".squaredBox label").removeClass("mcma_hl_incorr");
		$("#opt_"+ secNum + "_" + x + "_0" + secTest + secQType2).find(".squaredBox label").removeClass("mcma_hl_corr");
		$("#opt_"+ secNum + "_" + x + "_0" + secTest + secQType2).find(".squaredBox label").removeClass("mcma_hl_corr_select");
		$("#opt_"+ secNum + "_" + x + "_0" + secTest + secQType2).find(".squaredBox label").removeClass("mcma_hl_corr_no_select");
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType2).find(".squaredBox label").removeClass("mcma_hl_incorr");
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType2).find(".squaredBox label").removeClass("mcma_hl_corr");
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType2).find(".squaredBox label").removeClass("mcma_hl_corr_select");
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType2).find(".squaredBox label").removeClass("mcma_hl_corr_no_select");
		/* test out: if there is a pre-test in the course */
		if (document.pretestPresent == 1)
		{
			$("#opt_"+ secNum + "_" + x + "_0" + secTest + secQType1).removeClass("mcma_hl_pretest");			
			$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType1).removeClass("mcma_hl_pretest");
			$("#opt_"+ secNum + "_" + x + "_0" + secTest + secQType1).find(".squaredBox label").removeClass("mcma_hl_pretest");			
			$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType1).find(".squaredBox label").removeClass("mcma_hl_pretest");
			$("#opt_"+ secNum + "_" + x + "_0" + secTest + secQType2).removeClass("mcma_hl_pretest");			
			$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType2).removeClass("mcma_hl_pretest");
			$("#opt_"+ secNum + "_" + x + "_0" + secTest + secQType2).find(".squaredBox label").removeClass("mcma_hl_pretest");			
			$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType2).find(".squaredBox label").removeClass("mcma_hl_pretest");
		}	
		/* enable options */
		$('#rb_'+ secNum + "_" + x).prop('checked', false);
		$("#opt_"+ secNum + "_" + x + "_0" + secTest + secQType1).css("cursor","pointer");
		$("#opt_"+ secNum + "_" + x + "_0" + secTest + secQType2).css("cursor","pointer");
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType1 + " .button").css("cursor","pointer");
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType2 + " .button").css("cursor","pointer");
		$("#feedback_corr_" + secNum).hide();
		$("#feedback_incorr_" + secNum).hide();
		$("#feedback_partial_" + secNum).hide();
		$("#" + secId + ' input[type=checkbox]').attr('disabled', false);
		$("#" + secId + " .squaredBox label").css("cursor","pointer");
		$("#" + secId + " .qItem").css("cursor","pointer");		
		/* show submit */
		$("#submit_btn_" + secNum).show();
		/* 2021 Accessibility Update */
		$("#submit_btn_" + secNum).attr('title',localiseString('submit_btn_locked'));
		$("#submit_btn_" + secNum).attr('alt',localiseString('submit_btn_locked'));
		/* clear user answer */
		var userAns = post_test_ques_dat[secId][0].user_ans;
		userAns = userAns.replace('1','0');
		post_test_ques_dat[secId][0].user_ans = userAns;
	}
}

function getCheckHeights(){
	if($('#checkHeight').length < 1){
	var clone = $('.mc_btn').eq(0).closest('.row').clone().attr('id', 'checkHeight');
	$('body').append(clone);
	
	$('#checkHeight .mc_btn').html('The');
	
	$('#checkHeight .mc_btn').addClass('centreQtext');

	/* ensure that the cloned question option used for checking heights has different ids than actual question cloned kgs 100523 */
	$('#checkHeight .qItems .qItem').each(function(index, element) {
		$(this).attr('id',('opt_ch_' + index));
		$(this).find('input').attr('id','rb_ch_1');
		$(this).find('label').attr('for','rb_ch_1');
  	});

	}
	checkboxText = $('#checkHeight .mc_btn').height();
	$('#checkHeight').css('opacity','0');
	$('#checkHeight').css('visibility','hidden'); /* 20230613 Hide question options */
	checkBoxHeight = $('#checkHeight').height();
	
}
var parentHeight;
var breakheight;
function windowWidth(){
	var windowWidth = $(window).width();
		parentHeight = checkBoxHeight;
		breakheight = checkboxText * 2;
	if(windowWidth < 480){
		var newCheck = checkBoxHeight;
		parentHeight = newCheck;
		breakheight = checkboxText * 2;
	}
	resizeCheckBox();
}



function alignCheckBox(){
	$('.mc_btn').each(function() {
	$(this).closest('.section').show();
	if($(this).height() > checkboxText){
		$(this).parent().parent().find('.squaredBox').addClass('alignCheckBox');
	}else{
		$(this).parent().parent().find('.squaredBox').addClass('alignCheckBox');
		$(this).parent().parent().find('.mc_btn').addClass('centreQtext')
	}
	$(this).closest('.section').hide();
	});
}

function checkBoxInView(next){
	$('#sec_'+next+' .mc_btn').each(function(index) {
	var parent = $('#sec_'+next+' .mc_btn').eq(index).parent().parent();
			if(parent.height() > parentHeight){
				if(parent.find('.mc_btn').hasClass('centreQtext')){	
					parent.find('.mc_btn').removeClass('centreQtext');
				}
			}else if($('#sec_'+next+' .mc_btn').eq(index) < breakheight){
				if(!parent.find('.mc_btn').hasClass('centreQtext')){
					parent.find('.mc_btn').addClass('centreQtext');
				}
			}
	});
}

$(window).resize(function(){
	getCheckHeights()
	windowWidth()
	
})		
	
function resizeCheckBox(){
	
	if($('.screen_loader').css('display') == 'none'){
		$('.mc_btn').each(function(index) {
			var parent = $('.mc_btn').eq(index).parent().parent()
			if(parent.height() > parentHeight){
				if($('.mc_btn').eq(index).hasClass('centreQtext')){	
					$('.mc_btn').eq(index).removeClass('centreQtext');
				}
			}else if($('.mc_btn').eq(index).height() < breakheight){
			
					$('.mc_btn').eq(index).addClass('centreQtext');
				
			}
		})
	}
}
getCheckHeights()
windowWidth()
alignCheckBox()


/* retake assessment */
function retakeAssessment() {
	$('.testStart .content_text').html(test_intro_dat['post_test'][0].generic_msg);
	/* clear assessment score */
	document.assessAttempted = false;
	document.test_score = 0;
	post_test_ques_dat['test_dat'][0].user_score = 0;
	/* clear current assessment question index */
	document.currentAssessQues = 0;
	/* go to the assessment intro */
	gotoPlace = '#sec_' + document.testIntroSubsection;
	/* test out: if there is a pre-test in the course */
	if (document.pretestPresent == 1)
	{	
		/* test out: if currently taking the pre-test mark the pre-test as no longer being taken else show the post-test */
		if (document.takingPretest) {
			document.takingPretest = false;
		}
		else {
			/* added condition for iPad iPhone scroll issue when in frameset */
			/* remove isiPad to fix blank window appearing in iPad iOS13 on Saba Cloud */
			if(isiPhone){ 
				if(window.top !== window.self) {
					$(parent.parent.document).scrollTop($(gotoPlace).offset().top);
					$('.bar_robot').css('top',($(parent.parent.document).scrollTop())-1+'px');
				}else{
					$('html, body').scrollTop($(gotoPlace).offset().top);
				}
			}else{
				$('html, body').scrollTop($(gotoPlace).offset().top);
			}
		}
	}
	else {
		/* added condition for iPad iPhone scroll issue when in frameset */
		/* remove isiPad to fix blank window appearing in iPad iOS13 on Saba Cloud */
		if(isiPhone){
			if(window.top !== window.self) {
				$(parent.parent.document).scrollTop($(gotoPlace).offset().top);
				$('.bar_robot').css('top',($(parent.parent.document).scrollTop())-1+'px');
			}else{
				$('html, body').scrollTop($(gotoPlace).offset().top);
			}
		}else{
			$('html, body').scrollTop($(gotoPlace).offset().top);
		}
	}
	/* hide and reset the questions */
	$('.testQues').not('.testQues:eq(0)').hide();
	$('.testResults').hide();	
	for (var i = document.testIntroSubsection; i < document.testResultsSubsection; i++) {
		resetTestQues(i);		
		document.trackingArr[i-1] = 0; /* reset question tracking so it doesn't unlock on retake */
	}	
	$('.topic_nav_bar').hide();
	$('.testStart').nextAll().find('.complete_arrow').removeClass('unlocked').show();
	/* trickle button functionality 2018 */
	$('.complete_arrow').removeClass('visited');
	var tempTestQuesDivs = "";
	for (var m = 1; m < (document.assessRandomQuesArr.length + 1); m++)
	{
		tempTestQuesDivs = tempTestQuesDivs + "<div id='testQues" + m + "'></div>";
	}	
	$("#sec_" + document.assessRandomQuesArr[0]).before(tempTestQuesDivs);
	document.randomizeAssessment();	
	var color1 = "bgColor1";
	var color2 = "bgColor2"
	if($('.testStart .background_stretch .background_stretch_bg').hasClass('bgColor1')){
		color1 = "bgColor2";
		color2 = "bgColor2"
	}else{
		color1 = "bgColor2";
		color2 = "bgColor2"
	}
	for (var j = 0; j < document.assessRandomQuesArr.length; j++) 
	{
		/* trickle button functionality 2020 */
		/* clear that the trickle button was clicked on questions in this session */
		document.assessQuesDownArrowClicked[j] = 0;
		var secNum = document.assessRandomQuesArr[j];
		$("#testQues" + (j + 1)).replaceWith($("#sec_" + secNum));
		$("#sec_" + secNum + " .background_stretch .background_stretch_bg").removeClass("bgColor1");
		$("#sec_" + secNum + " .background_stretch .background_stretch_bg").removeClass("bgColor2");
		if ((j + 1)%2 == 0)
		{
			$("#sec_" + secNum + " .background_stretch .background_stretch_bg").addClass(color1);
		}
		else
		{
			$("#sec_" + secNum + " .background_stretch .background_stretch_bg").addClass(color2);
		}			
		$("#sec_" + secNum + " .testQuesLabel").html(localiseString('test_question') + " " + (j + 1) + " " + localiseString('test_of') + " " + document.assessTotalQues);
	}
	var assessRandQuesStr = document.assessRandomQuesArr.join(",");
	/* randomise assessment question options */
	if(document.assessOptRandomize){		
		$(".testQues .grid .container .optionHolder").not('.optionsNoRand').shuffleOptions('.qOption');
	}
	for (var k = (document.testIntroSubsection + 1); k < document.testResultsSubsection; k++) 
	{
		$("#sec_"+k).css("display","none");		
	}	
	reSetupClickableOptionsTest(gotoPlace);
}
$('.submit_btn').attr('data',0);

/* randomise assessment question options */
function randomizeOpts(){
	
	$('.sec_rest_wrapper').find('.testQues').each(function(index, element) {
		
		$(this).find('.grid').find('.container').find('.row').each(function(index, element) {
			
			$(this).find('.qItem').each(function(index, element) {
				$(this).parent().parent().parent().attr('class','row qOption');
            });			
        });
	});
	
	$(".testQues .grid .container .optionHolder").not('.optionsNoRand').shuffleOptions('.qOption');
}

$.fn.shuffleOptions = function(childElem) {
	function shuffle(o) {
		for(var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
		return o;
	};
	return this.each(function() {
		var $this = $(this);
		var elems = $this.children(childElem);

		shuffle(elems);

		$this.detach(childElem);  

		for(var i=0; i < elems.length; i++) {
			$this.append(elems[i]);      
		}
	});    
}

if(document.assessOptRandomize){	
	randomizeOpts();
}

/* submit attestation */
function submitAttestation() {
	$('.attestation_btn_div .retake_assess_btn').hide();
	$('.attestation .content_text .content_text_2').html('<p class="">' + attestation_dat['attestation'][0].attested_msg + '</p>');
	$('.attestation .content_text').focus(); /* 112222 ensure to focus on the updated attestation text when submitted */
	document.attestationAttempted = true;
	markSectionComplete(document.subsectionCount);
	pageCompleted = document.subsectionCount;
	checkCourseCompletion();
}



/*

	prepareInteractions
	Function to prepare and collate all data from the test-out question
	and send to LMS if document.sendInteractions = true;

*/
function prepareInteractions(secNum, userAnsArray, result, isSurvey){
	
	var isAssessTest = $("#sec_"+secNum).hasClass("testQues");
	
	var isInline;
	
	if(!isAssessTest){
		isInline = true;
	}
		
	if(document.sendInteractions){
		
		var userAnsArr = [];
		userAnsArr = userAnsArray;
		var questionNum;
		var questionType;
		var qType;
		var topicNum;
		var isResult = result;
		
		var isSurvey = isSurvey;
	
		if(isSurvey == undefined){
			isSurvey = false;
		}
		
		if(isAssessTest){
			questionNum = post_test_ques_dat["sec_" + secNum][0].question;
			questionType = post_test_ques_dat["sec_" + secNum][0].type;
			topicNum = post_test_ques_dat["sec_" + secNum][0].topic_num;
		}
		
		if(isInline){
			questionNum = inline_ques_dat["sec_" + secNum][0].question;
			questionType = inline_ques_dat["sec_" + secNum][0].type;
			topicNum = inline_ques_dat["sec_" + secNum][0].topic_num;
		}
		qType = questionType;
		if(questionType == "mcsa" || questionType == "mcma"){
			questionType = "choice";
		}

		/* 20230804 tracking fixes: confidence and inline/kc questions only answered once, all questions have unique cmi.interactions IDs and resetting course after max assessment attempts */
		var questionID = "T_" + topicNum + "_Q_" + questionNum + "_" + document.allTimeAssessAttempts;
		var optionsArr = [];
		var questStem = ""
		var correctAnsArray = [];
		
		
		if(isAssessTest){
			correctAnsArray = jQuery.makeArray(post_test_ques_dat["sec_" + secNum][0].ans.split(","));
		}
		
		if(isInline){
			correctAnsArray = jQuery.makeArray(inline_ques_dat["sec_" + secNum][0].ans.split(","));
		}

		optionsArr = document.optionsArr;
		questStem = document.questStem;

		var correctResponse = "";
		var userResponse = "";

		var courseTitle = document.courseTitle.replace(/ /g, '_');
		
		var intWeighting = 1;
		
		var temp1Arr = [];
		var temp2Arr = []
		for(var i = 0; i != correctAnsArray.length; i++){

			if(Number(correctAnsArray[i]) == 1){
				if(lms_type == "scorm_2004"){
			
					temp1Arr.push(optionsArr[i].replace(/[^a-zA-Z0-9 ]/g, "").replace(/ /g, '_'))
				}else if (lms_type == "scorm_1_2"){
					//correctResponse = Number(i) + 1;
					temp1Arr.push(Number(i) + 1)
				}
			}

			if(Number(userAnsArr[i]) == 1){
				if(lms_type == "scorm_2004"){
	
					
					temp2Arr.push(optionsArr[i].replace(/[^a-zA-Z0-9 ]/g, "").replace(/ /g, '_'))
					
				}else if (lms_type == "scorm_1_2"){
					//userResponse = Number(i) + 1;
					temp2Arr.push(Number(i) + 1)
				}
				
			}
		}
		
		
		for(var i = 0; i!= temp1Arr.length; i++){
			if(temp1Arr.length == 1){
				//correctResponse = temp1Arr[0].replace(/[,’.]/g, "").replace(/[“”‘’]/g,"");
				//correctResponse = temp1Arr[0].replace(/[^a-zA-Z0-9 ]/g, "");
				correctResponse = temp1Arr[0];
			}else{
				if(i == (temp1Arr.length-1)){
					//correctResponse += temp1Arr[i].replace(/[,’.]/g, "").replace(/[“”‘’]/g,"");
					//correctResponse += temp1Arr[i].replace(/[^a-zA-Z0-9 ]/g, "");
					correctResponse += temp1Arr[i];
				}else{
					//correctResponse += temp1Arr[i].replace(/[,’.]/g, "").replace(/[“”‘’]/g,"")+"[,]";
					//correctResponse += temp1Arr[i].replace(/[^a-zA-Z0-9 ]/g, "")+"[,]";
					correctResponse += temp1Arr[i]+"[,]";
				}
				
			}
		}
		
		for(var i = 0; i!= temp2Arr.length; i++){
			if(temp2Arr.length == 1){
				//userResponse = temp2Arr[0].replace(/[,’.]/g, "").replace(/[“”‘’]/g,"");
				//userResponse = temp2Arr[0].replace(/[^a-zA-Z0-9 ]/g, "");
				userResponse = temp2Arr[0];
			}else{
				if(i == (temp2Arr.length-1)){
					//userResponse += temp2Arr[i].replace(/[,’.]/g, "").replace(/[“”‘’]/g,"");
					//userResponse += temp2Arr[i].replace(/[^a-zA-Z0-9 ]/g, "");
					userResponse += temp2Arr[i];
				}else{
					//userResponse += temp2Arr[i].replace(/[,’.]/g, "").replace(/[“”‘’]/g,"")+"[,]";
					//userResponse += temp2Arr[i].replace(/[^a-zA-Z0-9 ]/g, "")+"[,]";
					userResponse += temp2Arr[i]+"[,]";
				}
				
			}
		}
		
		if(isSurvey){
			isResult = "neutral"
		}
		
		var dateobj = new Date(); 
		var dateStr = dateobj.toISOString();
		
		var intTimeStamp = "";
		var tempDatStr1 = dateStr.split(":")[0];
		var tempDatStr2 = dateStr.split(":")[1];
		var tempDatStr3 = dateStr.split(":")[2];
		
		if(lms_type == "scorm_2004"){
			intTimeStamp = tempDatStr1 + ":" + tempDatStr2 + ":" + tempDatStr3.split(".")[0];
			
		}else if(lms_type == "scorm_1_2"){
			intTimeStamp = tempDatStr1.split("T")[1] + ":" + tempDatStr2 + ":" + tempDatStr3.split(".")[0];
		}
		
		//console.log(questionID + " " + userResponse + " " + result + " " + correctResponse + " " + questStem + " " + questionType + " " + intWeighting + " " + intTimeStamp + " " +  courseTitle);
					
		recordInteractions(questionID, userResponse, isResult, correctResponse, questStem, questionType, intWeighting, intTimeStamp, courseTitle);
		
	}
}


// reset inline questions after failing assessment 3 times
function resetInQues(secNum,tNum) {
	var secId = "sec_" + secNum;
	var numOfOptions = $("#" + secId + " .qItems .qItem").length / 2;
	var secTest = "_i";
	var secQType1 = "_mcsa";
	var secQType2 = "_mcma";	
	for (var x=1; x < (numOfOptions + 1); x++) {
		/* change the background of all items to have no highlight */		
		$("#opt_"+ secNum + "_" + x + "_0" + secTest + secQType1).find(".squaredBox").removeClass().addClass("squaredBox").addClass("squaredBoxMCSA").addClass("squaredBox_bg_" + tNum).addClass("alignCheckBox");
		$("#opt_"+ secNum + "_" + x + "_0" + secTest + secQType1).removeClass("mcma_hl_pretest");			
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType1).removeClass("mcma_hl_pretest");
		$("#opt_"+ secNum + "_" + x + "_0" + secTest + secQType1).find(".squaredBox label").removeClass("mcma_hl_pretest");			
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType1).find(".squaredBox label").removeClass("mcma_hl_pretest");
		$("#opt_"+ secNum + "_" + x + "_0" + secTest + secQType1).removeClass("mcma_hl_corr");			
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType1).removeClass("mcma_hl_corr");
		$("#opt_"+ secNum + "_" + x + "_0" + secTest + secQType1).find(".squaredBox label").removeClass("mcma_hl_corr");			
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType1).find(".squaredBox label").removeClass("mcma_hl_corr");
		$("#opt_"+ secNum + "_" + x + "_0" + secTest + secQType1).removeClass("mcma_hl_incorr");			
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType1).removeClass("mcma_hl_incorr");
		$("#opt_"+ secNum + "_" + x + "_0" + secTest + secQType1).find(".squaredBox label").removeClass("mcma_hl_incorr");			
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType1).find(".squaredBox label").removeClass("mcma_hl_incorr");
		$("#opt_"+ secNum + "_" + x + "_0" + secTest + secQType2).find(".squaredBox").removeClass().addClass("squaredBox").addClass("squaredBox_bg_" + tNum).addClass("alignCheckBox");
		$("#opt_"+ secNum + "_" + x + "_0" + secTest + secQType2).removeClass("mcma_hl_pretest");			
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType2).removeClass("mcma_hl_pretest");
		$("#opt_"+ secNum + "_" + x + "_0" + secTest + secQType2).find(".squaredBox label").removeClass("mcma_hl_pretest");			
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType2).find(".squaredBox label").removeClass("mcma_hl_pretest");
		$("#opt_"+ secNum + "_" + x + "_0" + secTest + secQType2).removeClass("mcma_hl_corr");			
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType2).removeClass("mcma_hl_corr");
		$("#opt_"+ secNum + "_" + x + "_0" + secTest + secQType2).find(".squaredBox label").removeClass("mcma_hl_corr");			
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType2).find(".squaredBox label").removeClass("mcma_hl_corr");
		$("#opt_"+ secNum + "_" + x + "_0" + secTest + secQType2).removeClass("mcma_hl_incorr");			
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType2).removeClass("mcma_hl_incorr");
		$("#opt_"+ secNum + "_" + x + "_0" + secTest + secQType2).find(".squaredBox label").removeClass("mcma_hl_incorr");			
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType2).find(".squaredBox label").removeClass("mcma_hl_incorr");
		/* ensure activities are reset after reaching limit of post-test attempts 060822 */
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType1).removeClass("mcma_hl_corr_tick");
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType1).removeClass("mcma_hl_corr_select_tick");
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType2).removeClass("mcma_hl_corr_tick");
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType2).removeClass("mcma_hl_corr_select_tick");		
		/* enable options */
		$('#rb_'+ secNum + "_" + x).prop('checked', false);
		$("#opt_"+ secNum + "_" + x + "_0" + secTest + secQType1).css("cursor","pointer");
		$("#opt_"+ secNum + "_" + x + "_0" + secTest + secQType2).css("cursor","pointer");
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType1 + " .button").css("cursor","pointer");
		$("#opt_"+ secNum + "_" + x + "_1" + secTest + secQType2 + " .button").css("cursor","pointer");
		$("#feedback_tryagain_" + secNum).hide();
		$("#" + secId + ' input[type=checkbox]').attr('disabled', false);
		$("#" + secId + " .squaredBox label").css("cursor","pointer");
		$("#" + secId + " .qItem").css("cursor","pointer");
		/* show submit */
		$("#submit_btn_" + secNum).html(localiseString('submit_btn'));
		/* ensure activities are reset after reaching limit of post-test attempts 060822 */
		$("#submit_btn_" + secNum).attr('title',localiseString('submit_btn_locked'));
		$("#submit_btn_" + secNum).attr('alt',localiseString('submit_btn_locked'));
		$("#submit_btn_" + secNum).show();
		$("#submit_btn_" + secNum).addClass('disabled');
		$("#feedback_corr_" + secNum).hide();
		$("#feedback_partial_" + secNum).hide();
		$("#feedback_incorr_" + secNum).hide();
		
		/* clear user answer */
		var userAns = inline_ques_dat[secId][0].user_ans;
		userAns = userAns.replace('1','0');
		inline_ques_dat[secId][0].user_ans = userAns;
        
        //LJ Tick Cross Funcitonality
        //$("#opt_"+ secNum + "_" + x + "_1_" + secTest + "_" + secQType1).find(".mc_btn").removeClass("mc_btn_incorrect");			
        //$("#opt_"+ secNum + "_" + x + "_1_" + secTest + "_" + secQType2).find(".mc_btn").removeClass("mc_btn_correct");
        /*$(".mc_btn").removeClass("mc_btn_correct");
        $(".mc_btn").removeClass("mc_btn_incorrect");*/
        //LJ Tick Cross Funcitonality
        
	}
	reSetupClickableOptionsInlineQues(secId);
}

/* 20230607 track inline questions in suspend_data to be able to display question summary */
/* 20230830 ensure to always display how learner answered confidence and tracked inline questions after first attempt */
function trackQuestion(n, uArray, boo){

	var trackQuest = $("#sec_"+n).hasClass("track_quest");
	if(trackQuest){

		var questIndex;
		
		/* 20230830 ensure to always display how learner answered confidence and tracked inline questions after first attempt */
		var userAnsChosen = uArray.join("");
		
		var ansCorr = boo;

		/* 20230830 ensure to always display how learner answered confidence and tracked inline questions after first attempt */
		var qTrackArr = document.trackQuests.split("|");

		$('.track_quest').each(function(index, element) {

			var qID = $(this).attr("id");
			if(qID == ("sec_"+n)){
				questIndex = index;
			}

		});

		if(ansCorr){
			/* 20230830 ensure to always display how learner answered confidence and tracked inline questions after first attempt */
			qTrackArr[questIndex] = "1_" + userAnsChosen;
		}else{
			/* 20230830 ensure to always display how learner answered confidence and tracked inline questions after first attempt */
			qTrackArr[questIndex] = "2_" + userAnsChosen;
		}

		/* 20230830 ensure to always display how learner answered confidence and tracked inline questions after first attempt */
		document.trackQuests =  qTrackArr.join("|");
		/* 20230607 populate question summary from tracked inline questions in suspend_data to be able to display question summary */
		populateSummary()
	}
}

/* 20230607 disable inline questions that have already been answered when returning to course */
function disableQuests(){
	
	/* 20230830 ensure to always display how learner answered confidence and tracked inline questions after first attempt */
	/* there are multiple changes throughout this function for the comment above */

	var confNum = $(".conf_quest").index(".section");
	var	confSec = $(".conf_quest").attr("id");
	var confUser = document.userConfidence - 1;
	
	/* 20230913 tracking fixes: ensure confidence has been chosen before trying to disable a confidence question, disable likert/survey questions when answered, remove first likert/survey question when return to topic after answered, do not send cmi.interactions if inline/kc question does not have track_quest class */
	if (confUser > 0)
	{
		/* 20230804 tracking fixes: confidence and inline/kc questions only answered once, all questions have unique cmi.interactions IDs and resetting course after max assessment attempts */
		if (document.allTimeAssessAttempts > document.maxAssessAttempts)
		{
			document.lockedArr[confNum] = 0;
		}
		if((document.trackingArr[confNum] == 1) || (document.lockedArr[confNum] == 0)){
			$("#" + confSec + ' input[type=checkbox]').attr('disabled', true);
			$("#" + confSec  + " .squaredBox").unbind("click");
			$("#" + confSec + " .squaredBox").unbind("keypress");  // 20170830 keyboard functionality
			$("#" + confSec + " .squaredBox label").css("cursor","default");
			$("#" + confSec + " .qItem").unbind("click");
			$("#" + confSec + " .qItem").unbind("keypress");  // 20170830 keyboard functionality
			$("#" + confSec + " .qItem").css("cursor","default");
			$("#" + confSec + " .qItem .mc_btn").css("cursor","default");
			$("#" + confSec + " .qItem").unbind("mouseover");
			$("#" + confSec + " .qItem").unbind("mouseout");
			$("#" + confSec + " .mc_btn").unbind("mouseover");
			$("#" + confSec + " .mc_btn").unbind("mouseout");
			$("#" + confSec + " .qItem").addClass("mcma_hl_corr_no_select");
			$("#" + confSec).find(".qItem").each(function(index, element) {
				if ((index == (confUser*2)) || (index == ((confUser*2) + 1)))
				{
					$(this).addClass("mcma_hl_pretest");
					$(this).addClass("mcma_hl_corr_no_select");
					$(this).find(".squaredBox label").addClass("mcma_hl_pretest");
					$(this).find("input[type=checkbox]").attr('checked', true);
				}
			});
			$("#" + confSec).find(".submit_btn").css("display","none");
			$("#feedback_corr_" + confSec.split("_")[1]).show();
		}
	}
	
	if (document.trackQuests.toString().indexOf("_") != -1)	
	{
		var trackQuestsArr = document.trackQuests.split("|");
		$('.track_quest').each(function(index, element) {
			
			var indexNum = $(this).index(".section");

			/* 20230804 tracking fixes: confidence and inline/kc questions only answered once, all questions have unique cmi.interactions IDs and resetting course after max assessment attempts */
			if (document.allTimeAssessAttempts > document.maxAssessAttempts)
			{
				document.lockedArr[indexNum] = 0;
			}
			if((document.trackingArr[indexNum] == 1) || (document.lockedArr[indexNum] == 0)){
				var	trackQuestSec = $(this).attr("id");
				var correctAnsArray = jQuery.makeArray(inline_ques_dat[trackQuestSec][0].ans.split(","));
				var trackQuesAnsCorr = trackQuestsArr[index].split("_")[0];
				var trackQuesAns = trackQuestsArr[index].split("_")[1];
				trackQuesAns = trackQuesAns.split("");
							
				$("#" + trackQuestSec + ' input[type=checkbox]').attr('disabled', true);
				$("#" + trackQuestSec  + " .squaredBox").unbind("click");
				$("#" + trackQuestSec + " .squaredBox").unbind("keypress");  // 20170830 keyboard functionality
				$("#" + trackQuestSec + " .squaredBox label").css("cursor","default");
				$("#" + trackQuestSec + " .qItem").unbind("click");
				$("#" + trackQuestSec + " .qItem").unbind("keypress");  // 20170830 keyboard functionality
				$("#" + trackQuestSec + " .qItem").css("cursor","default");
				$("#" + trackQuestSec + " .qItem .mc_btn").css("cursor","default");
				$("#" + trackQuestSec + " .qItem").unbind("mouseover");
				$("#" + trackQuestSec + " .qItem").unbind("mouseout");
				$("#" + trackQuestSec + " .mc_btn").unbind("mouseover");
				$("#" + trackQuestSec + " .mc_btn").unbind("mouseout");
				$("#" + trackQuestSec + " .qItem").addClass("mcma_hl_corr_no_select");

				for (var i = 0; i < trackQuesAns.length; i++)
				{
					if (trackQuesAns[i] == 1)
					{
						$("#" + trackQuestSec).find(".qItem").each(function(index, element) {
							if ((index == (i*2)) || (index == ((i*2) + 1)))
							{
								$(this).addClass("mcma_hl_corr_no_select");
								$(this).find("input[type=checkbox]").attr('checked', true);
								if (correctAnsArray[i] == 1)
								{
									$(this).addClass("mcma_hl_corr");
									$(this).find(".squaredBox").removeClass("squaredBox_bg_2");
									$(this).find(".squaredBox label").addClass("mcma_hl_corr");
									$(this).addClass("mcma_hl_corr_tick");
								}
								if (correctAnsArray[i] == 0)
								{
									$(this).addClass("mcma_hl_incorr");
									$(this).find(".squaredBox").removeClass("squaredBox_bg_2");
									$(this).find(".squaredBox label").addClass("mcma_hl_incorr");
									$(this).addClass("mcma_hl_incorr_cross");
								}
							}
						});
					}
					else if (trackQuesAns[i] == 0)
					{
						$("#" + trackQuestSec).find(".qItem").each(function(index, element) {
							if ((index == (i*2)) || (index == ((i*2) + 1)))
							{
								if (correctAnsArray[i] == 1)
								{
									$(this).removeClass("mcma_hl_corr_no_select");
									$(this).addClass("mcma_hl_corr_select");
									$(this).addClass("mcma_hl_corr_select_tick");
								}
							}
						});
					}
				}
				$("#" + trackQuestSec).find(".submit_btn").css("display","none");
				if (trackQuesAnsCorr == 1)
				{
					$("#feedback_corr_" + trackQuestSec.split("_")[1]).show();
				}
				else
				{
					$("#feedback_incorr_" + trackQuestSec.split("_")[1]).show();
				}
				$(this).find(".submit_btn").css("display","none");
			}
		});
	}
	
	/* 20230913 tracking fixes: ensure confidence has been chosen before trying to disable a confidence question, disable likert/survey questions when answered, remove first likert/survey question when return to topic after answered, do not send cmi.interactions if inline/kc question does not have track_quest class */
	$('.likert_scale_first').each(function(index, element) {
		var indexNum = $(this).index(".section");
		if (document.allTimeAssessAttempts > document.maxAssessAttempts)
		{
			document.lockedArr[indexNum] = 0;
		}
		if((document.trackingArr[indexNum] == 1) || (document.lockedArr[indexNum] == 0))		
		{
			$('#sec_'+ (indexNum + 1)).css('background-image','none');
			$('#sec_'+ (indexNum + 2)).css('background-image','url("images/gs049_201008_bg.jpg');
			$('#sec_'+ (indexNum + 1)).css('height','1px');
			$('#sec_'+ (indexNum + 1)).find('.container').html('');
			$('#sec_'+ (indexNum + 1)).find('.container').css('height','1px');
		}
	});

	/* 20230607 populate question summary from tracked inline questions in suspend_data to be able to display question summary */
	populateSummary();
}
/* 20230607 populate question summary from tracked inline questions in suspend_data to be able to display question summary */
function populateSummary(){

	//if(document.userConfidence != 0){

	$(".user_conf_sel").removeClass("user_selected");

	$(".quest_ans_corr").removeClass("user_ans_selected");

	$("#user_conf_sel_"+document.userConfidence).addClass("user_selected");

	$("#user_conf_sel_"+document.userConfidence).css("display","block");


	var tempStr = document.trackQuests;
	/* 20230830 ensure to always display how learner answered confidence and tracked inline questions after first attempt */
	var qTrackArr = tempStr.split("|");
	var corrCnt = 0;
	for(var i = 0; i!= qTrackArr.length; i++){

		/* 20230830 ensure to always display how learner answered confidence and tracked inline questions after first attempt */
		if(Number(qTrackArr[i].split("_")[0]) == 1){
			corrCnt++;
		}

	}

	$("#quest_ans_corr_1").addClass("user_ans_selected");
	$(".kc_num").html(corrCnt);
	//}
}

/* 20230608 Likert functionality */
$(".likert_rb").on("change", function() {
	checkLikert();
});

/* 20230608 Likert functionality check all are selected before enabling submit */
function checkLikert(){

	$('.sec_rest_wrapper').find('.likert_scale').each(function(index, element) {

		var secID = $(this).attr("id");

		var secNum = Number(secID.split("_")[1]);
		var likertNum = 0;
		var likertChecked = 0;

		$(this).find(".likert").each(function(index, element) {

			likertNum++;

			$(this).find(".likert_rb").each(function(index, element) {

				if($(this).is(":checked")){
					likertChecked++;
				}
				
			});

		});

		if(likertChecked == likertNum){
			/* 082223 likert submit button accessibility */
			$('#submit_btn_' + secNum).removeClass("disabled");
			$('#submit_btn_' + secNum).attr('title',localiseString('submit_btn'));
			$('#submit_btn_' + secNum).attr('alt',localiseString('submit_btn'));
		}
	});

}
/* 20230608 Likert functionality calculet the likert question */
function calcLikert(secNum){

	if (!$("#submit_btn_" + secNum).hasClass("disabled")){

		$("#submit_btn_" + secNum).blur();
		$("#submit_btn_" + secNum).hide();

		$("#sec_"+secNum).find(".likert").each(function(index, element) {

			var questStem = "";
			var optSel = "";

			var likertNum;

			var userArr = [];

			questStem = $.trim($("#statement_"+secNum+"_"+(index + 1)).html());

			likertNum = Number(index + 1);

			$(this).find(".likert_rb").each(function(index, element) {

				if($(this).is(":checked")){
					optSel = $.trim($("#like_t_"+secNum+"_"+likertNum+"_"+(index+1)).html());
				}
				/* 20230913 tracking fixes: ensure confidence has been chosen before trying to disable a confidence question, disable likert/survey questions when answered, remove first likert/survey question when return to topic after answered, do not send cmi.interactions if inline/kc question does not have track_quest class */
				$(this).attr('disabled',true);
				$(this).css('cursor','default');
				$(this).parent().find("label").css('cursor','default');
			});

			prepareLikertInteractions(secNum,questStem,optSel,likertNum);

		});
		document.audioComplete = true;
		document.intComplete = true;
		isPageComplete(document.currentSection);
	}
}

/* 20230608 Likert functionality prepare the likert questions for cmi.interaction tracking */
function prepareLikertInteractions(secNum, questStem, optSel, questNum){
		
	if(document.sendInteractions){

		var questionNum = questNum;
		var questionType = "likert";
		var topicNum = Number(currentSec + 1);
		var isResult = "neutral";		
	
		/* 20230804 tracking fixes: confidence and inline/kc questions only answered once, all questions have unique cmi.interactions IDs and resetting course after max assessment attempts */
		var questionID = "L_" + topicNum + "_Q_" + questionNum + "_" + (document.allTimeAssessAttempts - 1);
		var optionsArr = [];
		var questStem = questStem;
	

		var correctResponse = optSel;
		var userResponse = optSel;

		var courseTitle = document.courseTitle.replace(/ /g, '_');
		
		var intWeighting = 1;
		
		correctResponse = correctResponse.replace(/ /g, '_');
		userResponse = userResponse.replace(/ /g, '_');

		var dateobj = new Date(); 
		var dateStr = dateobj.toISOString();
		
		var intTimeStamp = "";
		var tempDatStr1 = dateStr.split(":")[0];
		var tempDatStr2 = dateStr.split(":")[1];
		var tempDatStr3 = dateStr.split(":")[2];
		
		if(lms_type == "scorm_2004"){
			intTimeStamp = tempDatStr1 + ":" + tempDatStr2 + ":" + tempDatStr3.split(".")[0];
			
		}else if(lms_type == "scorm_1_2"){
			intTimeStamp = tempDatStr1.split("T")[1] + ":" + tempDatStr2 + ":" + tempDatStr3.split(".")[0];
		}
		
		recordInteractions(questionID, userResponse, isResult, correctResponse, questStem, questionType, intWeighting, intTimeStamp, courseTitle);
		
	}
}