home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 December / CMCD1203.ISO / Software / Shareware / Programare / toolkit / toolkitsetup.msi / Instal01.cab / _5ED5CEB7E5D64103AA892EBF6EE02F0E < prev    next >
Text File  |  2003-10-07  |  9KB  |  211 lines

  1. //Called by processActivity() , used to display Activity Popup window
  2. function showActPopup(theActivityQuestion, widthVal, heightVal)
  3. {
  4.     closePopup();
  5.     var labelText = (theActivityQuestion.answeredCorrectly) ? "Correct": "Incorrect";
  6.     var htmlHeader = "<br clear='all'>\n<table width='90%' border=0 cellpadding=4 cellspacing=0 align='center' class='popupTable'>\n<tr>\n" +
  7.         "<td bgcolor='#336699' class='popupTitle'>\n"
  8.     var htmlTween = "</td>\n</tr>\n<tr>\n<td valign='middle' class='popupBorder'><br clear='all'>\n";
  9.     var actDef = (theActivityQuestion.actRationale != "") ? theActivityQuestion.actRationale: "That is " + labelText;
  10.     var htmlFooter = "<p align='right'><a href='javascript: window.close();'>Close Window</a> </p></td>\n</tr>\n</table>";
  11.     window.popupWindowContents = htmlHeader + labelText + htmlTween + actDef + htmlFooter;
  12.     window.setTimeout("openPopup(" + widthVal + ", " + heightVal + ")", 500);
  13.     return true;
  14. }
  15.  
  16. //OBJECT: Activity Object created by USER in inc_Activities
  17. function objActQuestion(uniqueID, txtQuestionType)
  18. {
  19.     this.type = 'ActivityQuestion';
  20.     this.uniqueID = uniqueID;
  21.     this.name = "q"+uniqueID;
  22.     this.actQuestion = '';
  23.     this.actQuestionType = txtQuestionType.toLowerCase();
  24.     this.actRationale = '';
  25.     this.actDistractors = new Array();
  26.     this.addDistractor = setDistractor;
  27.     this.shuffleDistractors = randomizeDistractors;
  28.     this.answeredCorrectly = false;
  29.     var instrVerb = (this.actQuestionType == "text") ? "Enter": "Select";
  30.     this.answerVerb = instrVerb.toLowerCase();
  31.     var instrNum = (this.actQuestionType == "checkbox") ? "s": "";
  32.     this.txtInstructions = "<b>" + instrVerb + " the correct answer" + instrNum + " and click the 'Submit' button.</b>\n";
  33.     return(this);
  34. }
  35.  
  36. //OBJECT: Question Distractor Object created by setDistractor()
  37. function buildDistractor(blnCorrect)
  38. {
  39.     this.isCorrect = blnCorrect;
  40.     this.txtValue = '';
  41.     this.txtDisplay = '';
  42.     this.isSelected = false;
  43.     this.txtInput = '';
  44.     return(this);
  45. }
  46.  
  47. //Called by objActQuestion(): addDistractor() method to create a Distractor (potential answer)
  48. function setDistractor(blnCorrect)
  49. {
  50.     this.actDistractors[this.actDistractors.length] = new buildDistractor(blnCorrect);
  51. }
  52.  
  53. //Called by objActQuestion(): shuffleDistractors() used to shuffle the order of the Distractors
  54. function randomizeDistractors()
  55. {
  56.     shuffle(this.actDistractors);
  57. }
  58.  
  59. //Called by randomizeDistractors() and inc_Activities, used to shuffle the order of Distractors
  60. function shuffle(arrToShuffle)
  61. {
  62.     var j, tempHolder;
  63.     for(var i = 0; i < arrToShuffle.length; i++)
  64.     {
  65.         j = Math.floor(Math.random() * arrToShuffle.length);
  66.         tempHolder = arrToShuffle[i];
  67.         arrToShuffle[i] = arrToShuffle[j];
  68.         arrToShuffle[j] = tempHolder;
  69.     }
  70.     return(arrToShuffle);
  71. }
  72.  
  73. //Called by writeActivityHTML() and processActivity(), used to return a reference to an Activity Question Object by UniqueID
  74. function rtnActQuestion(uniqueID)
  75. {
  76.     var actQuestion;
  77.     var theID = uniqueID.toString();
  78.     for(actQuestion = 0; actQuestion < arrActObjects.length; actQuestion++)
  79.         if(arrActObjects[actQuestion].uniqueID.toString() == theID)
  80.             return(arrActObjects[actQuestion]);
  81.     return false;
  82. }
  83.  
  84. //Called by processActivity(), used to return the answer provided
  85. function setSelected(theActFormField, objQuestion)
  86. {
  87.     var arrSelectedAnswers = new Array();
  88.     if(theActFormField.length)
  89.     {
  90.         var thisElement;
  91.         for(thisElement = 0; thisElement < theActFormField.length; thisElement++)
  92.             if(((theActFormField[thisElement].checked) || (theActFormField[thisElement].selected)))
  93.                 arrSelectedAnswers[arrSelectedAnswers.length] = theActFormField[thisElement].value;
  94.     }else{
  95.         arrSelectedAnswers[arrSelectedAnswers.length] = theActFormField.value;
  96.     }
  97.  
  98.     if(arrSelectedAnswers.length > 0)
  99.     {
  100.         var arrQuestionAnswers = objQuestion.actDistractors;
  101.         var questionType = objQuestion.actQuestionType;
  102.         var thisDistractor, thisSelValue, thisTestValue, theSetValue;
  103.         for(thisDistractor = 0; thisDistractor < arrQuestionAnswers.length; thisDistractor++)
  104.             arrQuestionAnswers[thisDistractor].isSelected = false;
  105.         for(thisElement = 0; thisElement < arrSelectedAnswers.length; thisElement++)
  106.             for(thisDistractor = 0; thisDistractor < arrQuestionAnswers.length; thisDistractor++)
  107.             {
  108.                 thisSelValue = arrSelectedAnswers[thisElement];
  109.                 thisTestValue = arrQuestionAnswers[thisDistractor].txtValue;
  110.                 if(questionType == "text")
  111.                 {
  112.                     thisTestValue = new RegExp(thisTestValue,"gi");
  113.                     theSetValue = thisSelValue.match(thisTestValue);
  114.                 }else{
  115.                     theSetValue = (thisSelValue == thisTestValue);
  116.                 }
  117.                 if(theSetValue)
  118.                     arrQuestionAnswers[thisDistractor].isSelected = true;
  119.             }
  120.         return true;
  121.     }else{
  122.         return false;
  123.     }
  124. }
  125.  
  126. //Called by processActivity(), used to verify if answer provided for a given question is correct
  127. function checkCorrect(objQuestion)
  128. {
  129.     var theReturn = true, thisDistractor;
  130.     var arrQuestionDistractors = objQuestion.actDistractors;
  131.     for(thisDistractor = 0; thisDistractor < arrQuestionDistractors.length; thisDistractor++)
  132.         if(!arrQuestionDistractors[thisDistractor].isSelected == arrQuestionDistractors[thisDistractor].isCorrect)
  133.             theReturn = false;
  134.     objQuestion.answeredCorrectly = theReturn;
  135.     return(theReturn);
  136. }
  137.  
  138. //Called by writeQuestionHTML(), used to determine the number of correct values for the provided Question
  139. function getCorrect(objActQuestion)
  140. {
  141.     var arrCorrectAnswers = new Array();
  142.     var distractorItem;
  143.     for (distractorItem = 0; distractorItem < objActQuestion.actDistractors.length; distractorItem++)
  144.         if(objActQuestion.actDistractors[distractorItem].isCorrect)
  145.             arrCorrectAnswers[arrCorrectAnswers.length] = objActQuestion.actDistractors[distractorItem].txtValue;
  146.     return(arrCorrectAnswers);
  147. }
  148.  
  149. //Called by User in Lesson page to write the Activity Question
  150. function writeActivityHTML(uniqueID)
  151. {
  152.     var theActQuestion = rtnActQuestion(uniqueID);
  153.     var writeThis = "";
  154.     if(!theActQuestion)
  155.         return(writeThis);
  156.     var questionType = theActQuestion.actQuestionType;
  157.     var fieldName = theActQuestion.name;
  158.     writeThis = "<br clear='all'>\n<table width='100%' align='center' cellpadding=5 cellspacing=0 border=0 class='popupTable'>\n<form name='theForm' id='theForm' onSubmit='return parentRef.processActivity(this, \"" + fieldName + "\", " + theActQuestion.uniqueID + ");'><tr><td class='popupTitle'><b>Q&A</b></td></tr><tr><td>" + theActQuestion.actQuestion + "<br><br>" +
  159.             theActQuestion.txtInstructions +
  160.             "<br clear='all'><table width='100%' align='center' cellpadding=3 cellspacing=0 border=0><tr><td width=35 height=1><img src='./images/kleer.gif' width=35 height=1 border=0></td>" +
  161.             "<td width=1 height=1><img src='./images/kleer.gif' width=1 height=1 border=0></td>" +
  162.             "<td width='100%' height=1><img src='./images/kleer.gif' height=1 border=0></td></tr>\n";
  163.     if(questionType == "select")
  164.     {
  165.         var actAnswers = getCorrect(theActQuestion);
  166.         var multiAttribute = (actAnswers.length > 1) ? " MULTIPLE size='" + (theActQuestion.actDistractors.length) + "'": "";
  167.         writeThis += "<tr><td> </td><td align='left' colspan=2 width='100%'>\n<select name='" + fieldName + "' id='" + fieldName + "'" + multiAttribute + ">";
  168.     }
  169.     var distractorItem;
  170.     for(distractorItem in theActQuestion.actDistractors)
  171.     {
  172.         switch(questionType)
  173.         {
  174.             case "select":
  175.                 writeThis += "<option value='" + theActQuestion.actDistractors[distractorItem].txtValue + "'>" +  theActQuestion.actDistractors[distractorItem].txtDisplay + "</option>\n";
  176.                 break;
  177.             case "checkbox":
  178.             case "radio":
  179.                 writeThis += "<tr><td> </td><td valign='top'><input type='" + questionType + "' name='" + fieldName + "' id='" + fieldName + "' value='" + theActQuestion.actDistractors[distractorItem].txtValue + "'></td><td width='100%'>" + theActQuestion.actDistractors[distractorItem].txtDisplay + "</td></tr>\n";
  180.                 break;
  181.             case "text":
  182.                 writeThis += "<tr><td> </td><td valign='top' width='100%'><input type='" + questionType + "' name='" + fieldName + "' id='" + fieldName + "' value='' size=20></td><td> </td></tr>\n";
  183.                 break;
  184.             default:
  185.                 break;
  186.         }
  187.     }
  188.     if(questionType == "select")
  189.         writeThis += "</select><br><br></td></tr>\n";
  190.     writeThis += "</table>\n</td></tr>\n<tr><td align='right'><input type='submit' name='theButton' id='theButton' value='Submit'></td></tr>\n</form></table><br clear='all'>";
  191.     return(writeThis);
  192. }
  193.  
  194. //Called by User Submit Button, used to determine activity outcome and report results
  195. function processActivity(formField, fieldName, uniqueID)
  196. {
  197.     var theField = formField[fieldName];
  198.     var theActivityQuestion = rtnActQuestion(uniqueID);
  199.     var didSelect = setSelected(theField, theActivityQuestion);
  200.     if(didSelect)
  201.     {
  202.         var theResult = checkCorrect(theActivityQuestion);
  203.         var didShow = showActPopup(theActivityQuestion, 260, 200);
  204.     }else{
  205.         alert("Please " + theActivityQuestion.answerVerb + " an answer");
  206.     }
  207.     return false;
  208. }
  209.  
  210. var ActID, thisID, thisOpt;
  211. var arrActObjects = new Array();