//Called by processActivity() , used to display Activity Popup window
function showActPopup(theActivityQuestion, widthVal, heightVal)
{
closePopup();
var labelText = (theActivityQuestion.answeredCorrectly) ? "Correct": "Incorrect";
var htmlHeader = "
\n
";
window.popupWindowContents = htmlHeader + labelText + htmlTween + actDef + htmlFooter;
window.setTimeout("openPopup(" + widthVal + ", " + heightVal + ")", 500);
return true;
}
//OBJECT: Activity Object created by USER in inc_Activities
function objActQuestion(uniqueID, txtQuestionType)
{
this.type = 'ActivityQuestion';
this.uniqueID = uniqueID;
this.name = "q"+uniqueID;
this.actQuestion = '';
this.actQuestionType = txtQuestionType.toLowerCase();
this.actRationale = '';
this.actDistractors = new Array();
this.addDistractor = setDistractor;
this.shuffleDistractors = randomizeDistractors;
this.answeredCorrectly = false;
var instrVerb = (this.actQuestionType == "text") ? "Enter": "Select";
this.answerVerb = instrVerb.toLowerCase();
var instrNum = (this.actQuestionType == "checkbox") ? "s": "";
this.txtInstructions = "" + instrVerb + " the correct answer" + instrNum + " and click the 'Submit' button.\n";
return(this);
}
//OBJECT: Question Distractor Object created by setDistractor()
function buildDistractor(blnCorrect)
{
this.isCorrect = blnCorrect;
this.txtValue = '';
this.txtDisplay = '';
this.isSelected = false;
this.txtInput = '';
return(this);
}
//Called by objActQuestion(): addDistractor() method to create a Distractor (potential answer)
function setDistractor(blnCorrect)
{
this.actDistractors[this.actDistractors.length] = new buildDistractor(blnCorrect);
}
//Called by objActQuestion(): shuffleDistractors() used to shuffle the order of the Distractors
function randomizeDistractors()
{
shuffle(this.actDistractors);
}
//Called by randomizeDistractors() and inc_Activities, used to shuffle the order of Distractors
function shuffle(arrToShuffle)
{
var j, tempHolder;
for(var i = 0; i < arrToShuffle.length; i++)
{
j = Math.floor(Math.random() * arrToShuffle.length);
tempHolder = arrToShuffle[i];
arrToShuffle[i] = arrToShuffle[j];
arrToShuffle[j] = tempHolder;
}
return(arrToShuffle);
}
//Called by writeActivityHTML() and processActivity(), used to return a reference to an Activity Question Object by UniqueID
function rtnActQuestion(uniqueID)
{
var actQuestion;
var theID = uniqueID.toString();
for(actQuestion = 0; actQuestion < arrActObjects.length; actQuestion++)
if(arrActObjects[actQuestion].uniqueID.toString() == theID)
return(arrActObjects[actQuestion]);
return false;
}
//Called by processActivity(), used to return the answer provided
function setSelected(theActFormField, objQuestion)
{
var arrSelectedAnswers = new Array();
if(theActFormField.length)
{
var thisElement;
for(thisElement = 0; thisElement < theActFormField.length; thisElement++)
if(((theActFormField[thisElement].checked) || (theActFormField[thisElement].selected)))
arrSelectedAnswers[arrSelectedAnswers.length] = theActFormField[thisElement].value;
}else{
arrSelectedAnswers[arrSelectedAnswers.length] = theActFormField.value;
}
if(arrSelectedAnswers.length > 0)
{
var arrQuestionAnswers = objQuestion.actDistractors;
var questionType = objQuestion.actQuestionType;
var thisDistractor, thisSelValue, thisTestValue, theSetValue;
for(thisDistractor = 0; thisDistractor < arrQuestionAnswers.length; thisDistractor++)
arrQuestionAnswers[thisDistractor].isSelected = false;
for(thisElement = 0; thisElement < arrSelectedAnswers.length; thisElement++)
for(thisDistractor = 0; thisDistractor < arrQuestionAnswers.length; thisDistractor++)
{
thisSelValue = arrSelectedAnswers[thisElement];
thisTestValue = arrQuestionAnswers[thisDistractor].txtValue;
if(questionType == "text")
{
thisTestValue = new RegExp(thisTestValue,"gi");
theSetValue = thisSelValue.match(thisTestValue);
}else{
theSetValue = (thisSelValue == thisTestValue);
}
if(theSetValue)
arrQuestionAnswers[thisDistractor].isSelected = true;
}
return true;
}else{
return false;
}
}
//Called by processActivity(), used to verify if answer provided for a given question is correct
function checkCorrect(objQuestion)
{
var theReturn = true, thisDistractor;
var arrQuestionDistractors = objQuestion.actDistractors;
for(thisDistractor = 0; thisDistractor < arrQuestionDistractors.length; thisDistractor++)
if(!arrQuestionDistractors[thisDistractor].isSelected == arrQuestionDistractors[thisDistractor].isCorrect)
theReturn = false;
objQuestion.answeredCorrectly = theReturn;
return(theReturn);
}
//Called by writeQuestionHTML(), used to determine the number of correct values for the provided Question
function getCorrect(objActQuestion)
{
var arrCorrectAnswers = new Array();
var distractorItem;
for (distractorItem = 0; distractorItem < objActQuestion.actDistractors.length; distractorItem++)
if(objActQuestion.actDistractors[distractorItem].isCorrect)
arrCorrectAnswers[arrCorrectAnswers.length] = objActQuestion.actDistractors[distractorItem].txtValue;
return(arrCorrectAnswers);
}
//Called by User in Lesson page to write the Activity Question
function writeActivityHTML(uniqueID)
{
var theActQuestion = rtnActQuestion(uniqueID);
var writeThis = "";
if(!theActQuestion)
return(writeThis);
var questionType = theActQuestion.actQuestionType;
var fieldName = theActQuestion.name;
writeThis = "
\n
";
return(writeThis);
}
//Called by User Submit Button, used to determine activity outcome and report results
function processActivity(formField, fieldName, uniqueID)
{
var theField = formField[fieldName];
var theActivityQuestion = rtnActQuestion(uniqueID);
var didSelect = setSelected(theField, theActivityQuestion);
if(didSelect)
{
var theResult = checkCorrect(theActivityQuestion);
var didShow = showActPopup(theActivityQuestion, 260, 200);
}else{
alert("Please " + theActivityQuestion.answerVerb + " an answer");
}
return false;
}
var ActID, thisID, thisOpt;
var arrActObjects = new Array();