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

  1. var correctAnswers = lastPage = currentPage = 0;
  2. var evalCompleted = false;
  3. var pageURL = hasQuery = queryString = queryParts = whatStep = evalUniqueID = "";
  4.  
  5. //OBJECT: Evaluation Question Object created by USER in inc_Questions and inc_Objectives 
  6. function objEvalQuestion(intUniqueID, txtQuestionType)
  7. {
  8.     this.type = 'EvaluationQuestion';
  9.     this.evalUniqueID = intUniqueID;
  10.     this.name = "q"+intUniqueID;
  11.     this.evalQuestion = '';
  12.     this.evalQuestionType = txtQuestionType.toLowerCase();
  13.     this.evalPointValue = 1;
  14.     this.evalDistractors = new Array();
  15.     this.addDistractor = setDistractor;
  16.     this.answeredCorrectly = true;
  17.     var instrVerb = (this.evalQuestionType == "text") ? "Enter": "Select";
  18.     this.txtInstructions = "<b>" + instrVerb + " the appropriate answer and click the 'Submit' button</b>\n";
  19.     return(this);
  20. }
  21.  
  22. //OBJECT: Question Distractor Object created by setDistractor()
  23. function buildDistractor(blnCorrect)
  24. {
  25.     this.isCorrect = blnCorrect;
  26.     this.txtValue = '';
  27.     this.txtDisplay = '';
  28.     this.isSelected = false;
  29.     this.txtInput = '';
  30.     return(this);
  31. }
  32.  
  33. //Called by evalDisplay AND getStarted() to set all variables for the current page's use
  34. function setEnvironment()
  35. {
  36.     pageURL = parent.frames.surveyFrame.location.href;
  37.     hasQuery = (pageURL.indexOf("?") > 0) ? true: false;
  38.     queryString = (hasQuery) ? pageURL.split("?")[1]: "";
  39.     whatStep = (getQueryStringValue("whatStep") == "") ? "overview": getQueryStringValue("whatStep");
  40.     lastPage = (getQueryStringValue("currentPage") == "") ? 0: parseInt(getQueryStringValue("currentPage"));
  41.     currentPage = (whatStep == "next") ? lastPage + 1: lastPage;
  42.     evalUniqueID = getQueryStringValue("evalUniqueID");
  43. }
  44.  
  45. //Called by User in Lesson Page, used to retrieve the CopyRight statement
  46. function txtCopyRight()
  47. {
  48.     var theReturn = (copyright != "") ? copyright: " ";
  49.     return theReturn;
  50. }
  51.  
  52. ///Called by surveyDisplay, evaluates the current state and draws the correct page
  53. function getStarted()
  54. {
  55.     setEnvironment();
  56.     var theReturn;
  57.     var evalToCheck = rtnEvalQuestion(evalUniqueID, arrQuestions);
  58.     var answerSubmitted = getQueryStringValue(evalToCheck.name);
  59.     answerSubmitted = (answerSubmitted) ? answerSubmitted: answerSubmitted = " ";
  60.     setSelected(answerSubmitted, evalToCheck);
  61.     evalCompleted = (intNumQuestions == currentPage) ? true: false;
  62.     if(whatStep == "overview")
  63.     {
  64.         theReturn = writeOverviewHTML();
  65.     }else{
  66.         theReturn = (intNumQuestions >= currentPage) ? writeQuestionHTML(arrQuestions[lastPage]): writeResultsHTML();
  67.     }
  68.     return(theReturn);
  69. }
  70.  
  71. //Called by getStarted() AND setEnvironment(), used to extract a named value from Querystring
  72. function getQueryStringValue(fieldName)
  73. {
  74.     var theFieldName = fieldName + "=";
  75.     var rtnValue = "";
  76.     var tmpHolder = new Array();
  77.     var arrRtnValue = new Array();
  78.     if(hasQuery)
  79.     {
  80.         if(queryString.indexOf(theFieldName) > -1)
  81.         {
  82.             tmpHolder = queryString.split(theFieldName);
  83.             if(tmpHolder.length < 3)
  84.                 rtnValue = tmpHolder[1].split("&")[0];
  85.             else
  86.                 for(i = 1; i < tmpHolder.length; i++)
  87.                     arrRtnValue[arrRtnValue.length] = tmpHolder[i].split("&")[0];
  88.         }
  89.     }
  90.     if(arrRtnValue.length < 1)
  91.         return(rtnValue);
  92.     else
  93.         return(arrRtnValue);
  94. }
  95.  
  96. //Called by surveyDisplay to write the page title
  97. function writePageTitle()
  98. {
  99.     return(modTitle);
  100. }
  101.  
  102. //Called by surveyDisplay to write the "page number of pages" images
  103. function writePageInfo()
  104. {
  105.     var txtPageInfo;
  106.     if(currentPage == 0)
  107.     {
  108.         txtPageInfo = 'Overview';
  109.     }else{
  110.         if(currentPage <= intNumQuestions)
  111.         {
  112.             txtPageInfo = 'Question ' + currentPage + ' of ' + intNumQuestions;
  113.         }else{
  114.             txtPageInfo = 'Results';
  115.         }
  116.     }
  117.     return(txtPageInfo);
  118. }
  119.  
  120. //Called by getStarted(), uses to return a reference to an Evaluation Question Object by UniqueID
  121. function rtnEvalQuestion(intTheUniqueID, arrEvalQuestions)
  122. {
  123.     var found = false, evalQuestion;
  124.     for(evalQuestion in arrEvalQuestions)
  125.         if(arrEvalQuestions[evalQuestion].evalUniqueID == intTheUniqueID)
  126.             return(arrEvalQuestions[evalQuestion]);
  127.     return(found);
  128. }
  129.  
  130. //Called by getStarted(), used to verify identify the answer provided
  131. function setSelected(theSelectedAnswers, objQuestion)
  132. {
  133.     var arrQuestionAnswers = objQuestion.evalDistractors;
  134.     var arrSelectedAnswers = new Array();
  135.     var questionType = objQuestion.evalQuestionType;
  136.     if(theSelectedAnswers[1])
  137.         arrSelectedAnswers = theSelectedAnswers;
  138.     else
  139.         arrSelectedAnswers[0] = theSelectedAnswers;
  140.     if(questionType == "text")
  141.     {
  142.         var thisTestValue;
  143.         thisTestValue = new RegExp(objQuestion.evalDistractors[0].txtValue,"gi");
  144.         theSelectedAnswers = cleanText(arrSelectedAnswers[0]);
  145.         objQuestion.evalDistractors[0].isSelected = true;
  146.         objQuestion.evalDistractors[0].txtDisplay = theSelectedAnswers;
  147.         objQuestion.evalDistractors[0].txtValue = "";
  148.     }else{
  149.         var thisDistractor, thisAnswer;
  150.         for(thisAnswer in arrSelectedAnswers)
  151.             for(thisDistractor in arrQuestionAnswers)
  152.                 if(arrSelectedAnswers[thisAnswer] == arrQuestionAnswers[thisDistractor].txtValue)
  153.                     arrQuestionAnswers[thisDistractor].isSelected = true;
  154.     }
  155.     return true;
  156. }
  157.  
  158. //Called by setSelected(), used to format selected values
  159. function cleanText(inText)
  160. {
  161.     var theReturn = unescape(inText).replace(/\s|\+/gi, " ").replace("\"", """).replace(/\'/gi, "´");
  162.     return(theReturn);
  163. }
  164.  
  165. //Called by objEvalQuestion(): addDistractor() method to create a Distractor (potential answer)
  166. function setDistractor(blnCorrect)
  167. {
  168.     this.evalDistractors[this.evalDistractors.length] = new buildDistractor(blnCorrect);
  169. }
  170.  
  171. //Called by getStarted(), used to write the QUESTION pages
  172. function writeQuestionHTML(theEvalQuestion)
  173. {
  174.     var questionType = theEvalQuestion.evalQuestionType;
  175.     var writeThis = "<br clear='all'>\n<table width='100%' align='center' cellpadding=0 cellspacing=0 border=0>\n<form name='theForm'" + getValidation(theEvalQuestion) + "><tr>\n<td><b>Question " + currentPage + ": </b>" + theEvalQuestion.evalQuestion + "<br><br clear='all'>\n" +
  176.             theEvalQuestion.txtInstructions +
  177.             "<table width='100%' cellpadding=0 cellspacing=0><tr><td width=35 height=1><img src='./images/kleer.gif' width=35 height=1 border=0></td>" +
  178.             "<td width=35 height=1><img src='./images/kleer.gif' width=35 height=1 border=0></td>" +
  179.             "<td width='100%' height=1><img src='./images/kleer.gif' height=1 border=0></td>\n</tr>\n";
  180.     var distractorItem;
  181.     for(distractorItem in theEvalQuestion.evalDistractors)
  182.     {
  183.         switch(questionType)
  184.         {
  185.             case "radio":
  186.             case "checkbox":
  187.                 writeThis += "<tr><td> </td><td valign='top'><input type='" + questionType + "' name='" + theEvalQuestion.name + "' value='" + theEvalQuestion.evalDistractors[distractorItem].txtValue + "'></td><td>" + theEvalQuestion.evalDistractors[distractorItem].txtDisplay + "</td></tr>\n";
  188.                 break;
  189.             case "text":
  190.                 writeThis += "<tr><td> </td><td valign='top'><input type='" + questionType + "' name='" + theEvalQuestion.name + "' value='' size=6 maxlength=6></td><td> <i>minutes</i></td></tr>\n";
  191.                 break;
  192.             default:
  193.                 break;
  194.         }
  195.     }
  196.     writeThis += "<input type='hidden' name='currentPage' value='" + currentPage + "'>\n" +
  197.         "<input type='hidden' name='whatStep' value='next'>\n" +
  198.         "<input type='hidden' name='evalUniqueID' value='" + theEvalQuestion.evalUniqueID + "'>\n" +
  199.         "</td>\n</tr>\n</table></td></tr>\n<tr><td align='right'><input type='submit' name='theButton' value='Submit'></td>" +
  200.         "</tr>\n</form>\n</table>";
  201.     return(writeThis);
  202. }
  203.  
  204. //Called by writeQuestionHTML(), used to insert form validation code
  205. function getValidation(objEvlQuestion)
  206. {
  207.     var validationScript = "";
  208.     if(objEvlQuestion.evalQuestionType == "text")
  209.         validationScript = " onSubmit=\"return validateForm(theForm." + objEvlQuestion.name + ".value, '" + objEvlQuestion.evalDistractors[0].txtValue + "', 'Please enter a number.');\"";
  210.     return validationScript;
  211. }
  212.  
  213. //Called by getStarted(), used to write the INSTRUCTIONS page
  214. function writeOverviewHTML()
  215. {
  216.     var writeThis = "<b>Instructions</b><br clear='all'><br>\n" +
  217.         "Thank you for choosing to complete this survey. All results are anonymous.<br><br>\n" +
  218.         "As you complete each question, click on the 'Submit' button.<br><br>\n" +
  219.         "Click 'Next' to begin.<br><br>\n" +
  220.         "<form name='theForm'>" +
  221.         "<input type='hidden' name='currentPage' value=0>\n" +
  222.         "<input type='hidden' name='whatStep' value='next'>\n" +
  223.         "<div align='right'><input type='submit' name='theButton' value='Next'></div>\n" +
  224.         "</form>\n";
  225.     return(writeThis);
  226. }
  227.  
  228. //Called by getStarted(), used to write the RESULTS page
  229. function writeResultsHTML()
  230. {
  231.     var writeThis = "<br clear='all'><table width='100%' cellpadding=0 cellspacing=0 align='center'><form name='theForm'><tr><td><b>Results</b><br><br>\n" +
  232.             "<b>Thank you for participating in this survey.</b><br>\n";
  233.     if(useSCORM)
  234.     {
  235.         writeThis += "Please click to submit the results.<br><br></td></tr>\n" +
  236.             "<tr><td align='right'><input type='button' name='submitEval' value='Submit Results' onclick='parent.frames.codeFrame.SubmitCompletion();'></td>" +
  237.             "</tr></form></table>";
  238.     }else{
  239.         writeThis += "Please print this page and submit the results.<br><br></td></tr>\n";
  240.         var thisQuestion, thisAnswer;
  241.         for(thisQuestion in arrQuestions)
  242.         {
  243.             writeThis += "<tr><td align='left'>" + arrQuestions[thisQuestion].evalQuestion + "<ul>\n";
  244.             for(thisAnswer in arrQuestions[thisQuestion].evalDistractors)
  245.             {
  246.                 if(arrQuestions[thisQuestion].evalDistractors[thisAnswer].isSelected)
  247.                 {
  248.                     if(arrQuestions[thisQuestion].evalDistractors[thisAnswer].evalQuestionType == "text")
  249.                     {
  250.                         writeThis += "<li type='disk'>" + arrQuestions[thisQuestion].evalDistractors[thisAnswer].txtDisplay + "<br>\n";
  251.                     }else{
  252.                         writeThis += "<li type='disk'>" + arrQuestions[thisQuestion].evalDistractors[thisAnswer].txtValue + " " + arrQuestions[thisQuestion].evalDistractors[thisAnswer].txtDisplay + "<br>\n";
  253.                     }
  254.                 }else{
  255.                     if(arrQuestions[thisQuestion].evalDistractors[thisAnswer].evalQuestionType == "text")
  256.                     {
  257.                         writeThis += "<li type='circle'>" + arrQuestions[thisQuestion].evalDistractors[thisAnswer].txtDisplay + "<br>\n";
  258.                     }else{
  259.                         writeThis += "<li type='circle'>" + arrQuestions[thisQuestion].evalDistractors[thisAnswer].txtValue + " " + arrQuestions[thisQuestion].evalDistractors[thisAnswer].txtDisplay + "<br>\n";
  260.                     }
  261.                 }
  262.             }
  263.             writeThis += "</ul></td></tr>";
  264.         }
  265.         writeThis += "</form></table>";
  266.     }
  267.     return(writeThis);
  268. }
  269.  
  270. var arrQuestions = new Array();
  271. var EvalID, thisID, intNumQuestions, thisOpt;
  272. //Called by surveyDisplay, used to detect if this file is loaded
  273. var isEvalLoaded = true;