root/trunk/max-javahotpot-tutorial/tutorial/jquiz2.htm @ 35

Revision 35, 50.9 KB (checked in by max, 23 months ago)

mario.izquierdo
max-javahotpot-tutorial (3.1.max1)

  • New release
Line 
1<?xml version="1.0"?>
2       <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "xhtml11.dtd">
3       <html xmlns="http://www.w3.org/1999/xhtml"
4             xml:lang="en"><head><meta name="author" content="Created with Hot Potatoes by Half-Baked Software, registered to Ismail Ali Gago."></meta><meta name="keywords" content="Hot Potatoes, Hot Potatoes, Half-Baked Software, Windows, University of Victoria"></meta>
5
6<link rel="schema.DC" href="http://purl.org/dc/elements/1.1/" />
7<meta name="DC:Creator" content="Ismail Ali Gago" />
8<meta name="DC:Creator" content="Martin Holmes" />
9<meta name="DC:Title" content="Ejemplo de ejercicio JQuiz que muestra los cuatro tipos de preguntas" />
10
11
12<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
13
14<title>
15Ejemplo de ejercicio JQuiz que muestra los cuatro tipos de preguntas
16</title>
17
18<!-- Made with executable version 6.0 Release 2 Build 0 -->
19
20<!-- The following insertion allows you to add your own code directly to this head tag from the configuration screen -->
21
22
23
24<style type="text/css">
25
26
27/* This is the CSS stylesheet used in the exercise. */
28/* Elements in square brackets are replaced by data based on configuration settings when the exercise is built. */
29
30
31body{
32        font-family: Geneva,Arial;
33        background-color: #ffffff;
34        color: #000000;
35 
36        margin-right: 5%;
37        margin-left: 5%;
38        font-size: small;
39}
40
41p{
42        text-align: left;
43        margin: 0px;
44        font-size: small;
45}
46
47div,span,td{
48        font-size: small;
49        color: #000000;
50}
51
52.RTLText{
53        text-align: right;
54        font-size: 150%;
55        direction: rtl;
56        font-family: "Simplified Arabic", "Traditional Arabic", "Times New Roman", Geneva,Arial;
57}
58
59.CentredRTLText{
60        text-align: center;
61        font-size: 150%;
62        direction: rtl;
63        font-family: "Simplified Arabic", "Traditional Arabic", "Times New Roman", Geneva,Arial;
64}
65
66button p.RTLText{
67        text-align: center;
68}
69
70.RTLGapBox{
71        text-align: right;
72        font-size: 150%;
73        direction: rtl;
74        font-family: "Times New Roman", Geneva,Arial;
75}
76
77.Guess{
78        font-weight: bold;
79}
80
81.CorrectAnswer{
82        font-weight: bold;
83}
84
85div.Titles{
86        padding: 10px;
87        text-align: center;
88        color: #000000;
89}
90
91button{
92        display: inline;
93}
94
95.ExerciseTitle{
96        font-size: large;
97        color: #000000;
98}
99
100.ExerciseSubtitle{
101        color: #000000;
102}
103
104div#Timer{
105        padding: 6px;
106        margin-left: auto;
107        margin-right: auto;
108        text-align: center;
109}
110
111span#TimerText{
112        padding: 6px;
113        border-width: 1px;
114        border-style: solid;
115        font-weight: bold;
116        display: none;
117}
118
119span.Instructions{
120
121}
122
123div.ExerciseText{
124
125}
126
127.FeedbackText{
128        color: #000000;
129}
130
131span.LeftItem{
132        font-size: small;
133        color: #000000;
134}
135
136span.RightItem{
137        font-weight: bold;
138        font-size: small;
139        color: #000000;
140}
141
142span.CorrectMark{
143
144}
145
146div.Feedback {
147        background-color: #ffffff;
148        left: 33%;
149        width: 34%;
150        top: 33%;
151        z-index: 1;
152        border-style: solid;
153        border-width: 1px;
154        padding: 5px;
155        text-align: center;
156        color: #000000;
157        position: absolute;
158        display: none;
159        font-size: small;
160}
161
162
163
164
165div.ExerciseDiv{
166        color: #000000;
167}
168
169/* JMatch flashcard styles */
170table.FlashcardTable{
171        background-color: transparent;
172        color: #000000;
173        border-color: #000000;
174        margin-left: 5%;
175        margin-right: 5%;
176        margin-top: 2em;
177        margin-bottom: 2em;
178        width: 90%;
179        position: relative;
180        align: center;
181        padding: 0px;
182}
183
184table.FlashcardTable tr{
185        border-style: none;
186        margin: 0px;
187        padding: 0px;
188        background-color: #dddddd;
189}
190
191table.FlashcardTable td.Showing{
192        font-size: large;
193        text-align: center;
194        width: 50%;
195        display: table-cell;
196        padding: 2em;
197        margin: 0px;
198        border-style: solid;
199        border-width: 1px;
200        color: #000000;
201        background-color: #dddddd;
202}
203
204table.FlashcardTable td.Hidden{
205        display: none;
206}
207
208/* JMix styles */
209div#SegmentDiv{
210        margin-top: 2em;
211        margin-bottom: 2em;
212        text-align: center;
213}
214
215a.ExSegment{
216        font-size: medium;
217        font-weight: bold;
218        text-decoration: none;
219        color: #000000;
220}
221
222span.RemainingWordList{
223        font-style: italic;
224}
225
226div.DropLine {
227        position: absolute;
228        text-align: center;
229        border-bottom-style: solid;
230        border-bottom-width: 1px;
231        border-bottom-color: #000000;
232        width: 80%;
233}
234
235/* JCloze styles */
236
237input{
238        font-family: Geneva,Arial;
239        font-size: larger;
240}
241
242.ClozeWordList{
243        text-align: center;
244        font-weight: bold;
245}
246
247div.ClozeBody{
248        text-align: left;
249        margin-top: 2em;
250        margin-bottom: 2em;
251        line-height: 2.0
252}
253
254span.GapSpan{
255        font-weight: bold;
256}
257
258/* JCross styles */
259
260table.CrosswordGrid{
261        margin: auto auto 1em auto;
262        border-collapse: collapse;
263        padding: 0px;
264}
265
266table.CrosswordGrid td{
267        width: 1.5em;
268        height: 1.5em;
269        text-align: center;
270        vertical-align: middle;
271        font-size: large;
272        padding: 0px;
273        margin: 0px;
274        border-style: solid;
275        border-width: 1px;
276        border-color: #000000;
277}
278
279table.CrosswordGrid td.BlankCell{
280        background-color: #000000;
281        color: #000000;
282}
283
284table.CrosswordGrid td.LetterOnlyCell{
285        text-align: center;
286        vertical-align: middle;
287        background-color: #ffffff;
288        color: #000000;
289        font-weight: bold;
290}
291
292table.CrosswordGrid td.NumLetterCell{
293        text-align: left;
294        vertical-align: top;
295        background-color: #ffffff;
296        color: #000000;
297        padding: 1px;
298        font-weight: bold;
299}
300
301.NumLetterCellText{
302        cursor: pointer;
303}
304
305.GridNum{
306        vertical-align: super;
307        font-size: x-small;
308        font-weight: bold;
309        text-decoration: none;
310        color: #000000;
311}
312
313table#Clues{
314        margin: auto;
315        vertical-align: top;
316}
317
318table#Clues td{
319        vertical-align: top;
320}
321
322table.ClueList{
323  margin: auto;
324}
325
326td.ClueNum{
327        text-align: right;
328        font-weight: bold;
329        vertical-align: top;
330}
331
332td.Clue{
333        text-align: left;
334}
335
336div#ClueEntry{
337        text-align: left;
338        margin-bottom: 1em;
339}
340
341/* Keypad styles */
342
343div.Keypad{
344        text-align: center;
345}
346
347div.Keypad button{
348        font-family: Geneva,Arial;
349        font-size: 120%;
350        background-color: #ffffff;
351        color: #000000;
352        width: 2em;
353}
354
355/* JQuiz styles */
356
357div.QuestionNavigation{
358        text-align: center;
359}
360
361.QNum{
362        margin: 0em 1em 0.5em 1em;
363        font-weight: bold;
364        vertical-align: middle;
365}
366
367textarea{
368        font-family: Geneva,Arial;
369        font-size: larger;
370}
371
372.QuestionText{
373
374}
375
376.Answer{
377        font-size: 120%;
378        letter-spacing: 0.1em;
379}
380
381.Highlight{
382        color: #000000;
383        background-color: #ffff00;
384        font-weight: bold;
385        font-size: 120%;
386}
387
388ol.QuizQuestions{
389        text-align: left;
390        list-style-type: none;
391}
392
393li.QuizQuestion{
394        padding: 1em;
395        border-style: solid;
396        border-width: 0px 0px 1px 0px;
397}
398
399ol.MCAnswers{
400        text-align: left;
401        list-style-type: upper-alpha;
402        padding: 1em;
403}
404
405ol.MCAnswers li{
406        margin-bottom: 1em;
407}
408
409ol.MSelAnswers{
410        text-align: left;
411        list-style-type: lower-alpha;
412        padding: 1em;
413}
414
415div.ShortAnswer{
416        padding: 1em;
417}
418
419div.StdDiv{
420        background-color: #dddddd;
421        text-align: center;
422        font-size: small;
423        color: #000000;
424        padding: 8px;
425        border-style: solid;
426        border-width: 1px 1px 1px 1px;
427        border-color: #000000;
428        margin: 1px;
429}
430
431.FuncButton {
432        text-align: center;
433        border-style: solid;
434
435        border-left-color: #eeeeee;
436        border-top-color: #eeeeee;
437        border-right-color: #6e6e6e;
438        border-bottom-color: #6e6e6e;
439        color: #000000;
440        background-color: #dddddd;
441
442        border-width: 2px;
443        padding: 3px 6px 3px 6px;
444        cursor: pointer;
445}
446
447.FuncButtonUp {
448        color: #dddddd;
449        text-align: center;
450        border-style: solid;
451
452        border-left-color: #eeeeee;
453        border-top-color: #eeeeee;
454        border-right-color: #6e6e6e;
455        border-bottom-color: #6e6e6e;
456
457        background-color: #000000;
458        color: #dddddd;
459        border-width: 2px;
460        padding: 3px 6px 3px 6px;
461        cursor: pointer;
462}
463
464.FuncButtonDown {
465        color: #dddddd;
466        text-align: center;
467        border-style: solid;
468
469        border-left-color: #6e6e6e;
470        border-top-color: #6e6e6e;
471        border-right-color: #eeeeee;
472        border-bottom-color: #eeeeee;
473        background-color: #000000;
474        color: #dddddd;
475
476        border-width: 2px;
477        padding: 3px 6px 3px 6px;
478        cursor: pointer;
479}
480
481/*BeginNavBarStyle*/
482
483div.NavButtonBar{
484        background-color: #999999;
485        text-align: center;
486        margin: 2px 0px 2px 0px;
487        clear: both;
488        font-size: small;
489}
490
491.NavButton {
492        border-style: solid;
493       
494        border-left-color: #cccccc;
495        border-top-color: #cccccc;
496        border-right-color: #4c4c4c;
497        border-bottom-color: #4c4c4c;
498        background-color: #999999;
499        color: #000000;
500
501        border-width: 2px;
502        cursor: pointer;       
503}
504
505.NavButtonUp {
506        border-style: solid;
507
508        border-left-color: #cccccc;
509        border-top-color: #cccccc;
510        border-right-color: #4c4c4c;
511        border-bottom-color: #4c4c4c;
512        color: #999999;
513        background-color: #000000;
514
515        border-width: 2px;
516        cursor: pointer;       
517}
518
519.NavButtonDown {
520        border-style: solid;
521
522        border-left-color: #4c4c4c;
523        border-top-color: #4c4c4c;
524        border-right-color: #cccccc;
525        border-bottom-color: #cccccc;
526        color: #999999;
527        background-color: #000000;
528
529        border-width: 2px;
530        cursor: pointer;       
531}
532
533/*EndNavBarStyle*/
534
535a{
536        color: #0000cc;
537}
538
539a: visited{
540        color: #0000ff;
541}
542
543a:hover{
544        color: #0000cc;
545}
546
547div.CardStyle {
548        position: absolute;
549        font-family: Geneva,Arial;
550        font-size: small;
551        padding: 5px;
552        border-style: solid;
553        border-width: 1px;
554        color: #000000;
555        background-color: #dddddd;
556        left: -50px;
557        top: -50px;
558        overflow: visible;
559}
560
561.rtl{
562        text-align: right;
563        font-size: large;
564}
565
566
567</style>
568
569<script type="text/javascript">
570
571//<![CDATA[
572
573<!--
574
575
576function Client(){
577//if not a DOM browser, hopeless
578        this.min = false; if (document.getElementById){this.min = true;};
579
580        this.ua = navigator.userAgent;
581        this.name = navigator.appName;
582        this.ver = navigator.appVersion; 
583
584//Get data about the browser
585        this.mac = (this.ver.indexOf('Mac') != -1);
586        this.win = (this.ver.indexOf('Windows') != -1);
587
588//Look for Gecko
589        this.gecko = (this.ua.indexOf('Gecko') > 1);
590        if (this.gecko){
591                this.geckoVer = parseInt(this.ua.substring(this.ua.indexOf('Gecko')+6, this.ua.length));
592                if (this.geckoVer < 20020000){this.min = false;}
593        }
594       
595//Look for Firebird
596        this.firebird = (this.ua.indexOf('Firebird') > 1);
597       
598//Look for Safari
599        this.safari = (this.ua.indexOf('Safari') > 1);
600        if (this.safari){
601                this.gecko = false;
602        }
603       
604//Look for IE
605        this.ie = (this.ua.indexOf('MSIE') > 0);
606        if (this.ie){
607                this.ieVer = parseFloat(this.ua.substring(this.ua.indexOf('MSIE')+5, this.ua.length));
608                if (this.ieVer < 5.5){this.min = false;}
609        }
610       
611//Look for Opera
612        this.opera = (this.ua.indexOf('Opera') > 0);
613        if (this.opera){
614                this.operaVer = parseFloat(this.ua.substring(this.ua.indexOf('Opera')+6, this.ua.length));
615                if (this.operaVer < 7.04){this.min = false;}
616        }
617        if (this.min == false){
618                alert('Your browser may not be able to handle this page.');
619        }
620       
621//Special case for the horrible ie5mac
622        this.ie5mac = (this.ie&&this.mac&&(this.ieVer<6));
623}
624
625var C = new Client();
626
627//for (prop in C){
628//      alert(prop + ': ' + C[prop]);
629//}
630
631
632
633//CODE FOR HANDLING NAV BUTTONS AND FUNCTION BUTTONS
634
635//[strNavBarJS]
636function NavBtnOver(Btn){
637        if (Btn.className != 'NavButtonDown'){Btn.className = 'NavButtonUp';}
638}
639
640function NavBtnOut(Btn){
641        Btn.className = 'NavButton';
642}
643
644function NavBtnDown(Btn){
645        Btn.className = 'NavButtonDown';
646}
647//[/strNavBarJS]
648
649function FuncBtnOver(Btn){
650        if (Btn.className != 'FuncButtonDown'){Btn.className = 'FuncButtonUp';}
651}
652
653function FuncBtnOut(Btn){
654        Btn.className = 'FuncButton';
655}
656
657function FuncBtnDown(Btn){
658        Btn.className = 'FuncButtonDown';
659}
660
661function FocusAButton(){
662        if (document.getElementById('CheckButton1') != null){
663                document.getElementById('CheckButton1').focus();
664        }
665        else{
666                if (document.getElementById('CheckButton2') != null){
667                        document.getElementById('CheckButton2').focus();
668                }
669                else{
670                        document.getElementsByTagName('button')[0].focus();
671                }
672        }
673}
674
675
676
677
678//CODE FOR HANDLING DISPLAY OF POPUP FEEDBACK BOX
679
680var topZ = 1000;
681
682function ShowMessage(Feedback){
683        var Output = Feedback + '<br /><br />';
684        document.getElementById('FeedbackContent').innerHTML = Output;
685        var FDiv = document.getElementById('FeedbackDiv');
686        topZ++;
687        FDiv.style.zIndex = topZ;
688        FDiv.style.top = TopSettingWithScrollOffset(30) + 'px';
689//IE can't focus a hidden div; Moz needs to focus before display to avoid jumping
690        if (C.gecko){
691                document.getElementById('FeedbackOKButton').focus();
692        }
693        FDiv.style.display = 'block';
694
695        ShowElements(false, 'input');
696        ShowElements(false, 'select');
697        ShowElements(false, 'object');
698        if (C.ie){
699                document.getElementById('FeedbackOKButton').focus();
700        }
701       
702//
703}
704
705function ShowElements(Show, TagName){
706//Special for IE bug -- hide all the form elements that will show through the popup
707        if (C.ie){
708                var Els = document.getElementsByTagName(TagName);
709                for (var i=0; i<Els.length; i++){
710                        if (Show == true){
711                                Els[i].style.display = 'inline';
712                        }
713                        else{
714                                Els[i].style.display = 'none';
715                        }
716                }
717        }
718}
719
720function HideFeedback(){
721        document.getElementById('FeedbackDiv').style.display = 'none';
722        ShowElements(true, 'input');
723        ShowElements(true, 'select');
724        ShowElements(true, 'object');
725        if (Finished == true){
726                Finish();
727        }
728}
729
730
731//GENERAL UTILITY FUNCTIONS AND VARIABLES
732
733//PAGE DIMENSION FUNCTIONS
734function PageDim(){
735//Get the page width and height
736        this.W = 600;
737        this.H = 400;
738        this.W = document.getElementsByTagName('body')[0].clientWidth;
739        this.H = document.getElementsByTagName('body')[0].clientHeight;
740}
741
742var pg = null;
743
744function GetPageXY(El) {
745        var XY = {x: 0, y: 0};
746        while(El){
747                XY.x += El.offsetLeft;
748                XY.y += El.offsetTop;
749                El = El.offsetParent;
750        }
751        return XY;
752}
753
754function GetScrollTop(){
755        if (document.documentElement && document.documentElement.scrollTop){
756                return document.documentElement.scrollTop;
757        }
758        else{
759                if (document.body){
760                        return document.body.scrollTop;
761                }
762                else{
763                        return window.pageYOffset;
764                }
765        }
766}
767
768function GetViewportHeight(){
769        if (window.innerWidth){
770                return window.innerWidth;
771        }
772        else{
773                return document.getElementsByTagName('body')[0].clientHeight;
774        }
775}
776
777function TopSettingWithScrollOffset(TopPercent){
778        var T = Math.floor(GetViewportHeight() * (TopPercent/100));
779        return GetScrollTop() + T;
780}
781
782//CODE FOR AVOIDING LOSS OF DATA WHEN BACKSPACE KEY INVOKES history.back()
783var InTextBox = false;
784
785function SuppressBackspace(e){
786        if (InTextBox == true){return;}
787        if (C.ie) {
788                thisKey = window.event.keyCode;
789        }
790        else {
791                thisKey = e.keyCode;
792        }
793
794        var Suppress = false;
795
796        if (thisKey == 8) {
797                Suppress = true;
798        }
799
800        if (Suppress == true){
801                if (C.ie){
802                        window.event.returnValue = false;       
803                        window.event.cancelBubble = true;
804                }
805                else{
806                        e.preventDefault();
807                }
808        }
809}
810
811if (C.ie){
812        document.attachEvent('onkeydown',SuppressBackspace);
813        window.attachEvent('onkeydown',SuppressBackspace);
814}
815else{
816        window.addEventListener('keypress',SuppressBackspace,false);
817}
818
819function ReduceItems(InArray, ReduceToSize){
820        var ItemToDump=0;
821        var j=0;
822        while (InArray.length > ReduceToSize){
823                ItemToDump = Math.floor(InArray.length*Math.random());
824                InArray.splice(ItemToDump, 1);
825        }
826}
827
828function Shuffle(InArray){
829        Temp = new Array();
830        var Len = InArray.length;
831
832        var j = Len;
833
834        for (var i=0; i<Len; i++){
835                Temp[i] = InArray[i];
836        }
837
838        for (i=0; i<Len; i++){
839                Num = Math.floor(j  *  Math.random());
840                InArray[i] = Temp[Num];
841
842                for (var k=Num; k < j; k++) {
843                        Temp[k] = Temp[k+1];
844                }
845                j--;
846        }
847        return InArray;
848}
849
850function WriteToInstructions(Feedback) {
851//      Feedback = '<span class="FeedbackText">' + Feedback + '</span>';
852        document.getElementById('InstructionsDiv').innerHTML = Feedback;
853
854}
855
856
857
858
859function EscapeDoubleQuotes(InString){
860        return InString.replace(/"/g, '&quot;')
861}
862
863function FocusAButton(){
864        if (document.getElementById('CheckButton1') != null){
865                document.getElementById('CheckButton1').focus();
866        }
867        else{
868                document.getElementsByTagName('button')[0].focus();
869        }
870}
871
872function TrimString(InString){
873        var x = 0;
874
875        if (InString.length != 0) {
876                while ((InString.charAt(InString.length - 1) == '\u0020') || (InString.charAt(InString.length - 1) == '\u000A') || (InString.charAt(InString.length - 1) == '\u000D')){
877                        InString = InString.substring(0, InString.length - 1)
878                }
879
880                while ((InString.charAt(0) == '\u0020') || (InString.charAt(0) == '\u000A') || (InString.charAt(0) == '\u000D')){
881                        InString = InString.substring(1, InString.length)
882                }
883
884                while (InString.indexOf('  ') != -1) {
885                        x = InString.indexOf('  ')
886                        InString = InString.substring(0, x) + InString.substring(x+1, InString.length)
887                 }
888
889                return InString;
890        }
891
892        else {
893                return '';
894        }
895}
896
897function FindLongest(InArray){
898        if (InArray.length < 1){return -1;}
899
900        var Longest = 0;
901        for (var i=1; i<InArray.length; i++){
902                if (InArray[i].length > InArray[Longest].length){
903                        Longest = i;
904                }
905        }
906        return Longest;
907}
908
909//UNICODE CHARACTER FUNCTIONS
910function IsCombiningDiacritic(CharNum){
911        var Result = (((CharNum >= 0x0300)&&(CharNum <= 0x370))||((CharNum >= 0x20d0)&&(CharNum <= 0x20ff)));
912        Result = Result || (((CharNum >= 0x3099)&&(CharNum <= 0x309a))||((CharNum >= 0xfe20)&&(CharNum <= 0xfe23)));
913        return Result;
914}
915
916function IsCJK(CharNum){
917        return ((CharNum >= 0x3000)&&(CharNum < 0xd800));
918}
919
920//SETUP FUNCTIONS
921//BROWSER WILL REFILL TEXT BOXES FROM CACHE IF NOT PREVENTED
922function ClearTextBoxes(){
923        var NList = document.getElementsByTagName('input');
924        for (var i=0; i<NList.length; i++){
925                if (NList[i].id.indexOf('Guess') > -1){
926                        NList[i].value = '';
927                }
928                if (NList[i].id.indexOf('Chk') > -1){
929                        NList[i].checked = '';
930                }
931        }
932}
933
934//EXTENSION TO ARRAY OBJECT
935function Array_IndexOf(Input){
936        var Result = -1;
937        for (var i=0; i<this.length; i++){
938                if (this[i] == Input){
939                        Result = i;
940                }
941        }
942        return Result;
943}
944Array.prototype.indexOf = Array_IndexOf;
945
946//IE HAS RENDERING BUG WITH BOTTOM NAVBAR
947function RemoveBottomNavBarForIE(){
948        if (C.ie){
949                if (document.getElementById('BottomNavBar') != null){
950                        document.getElementById('TheBody').removeChild(document.getElementById('BottomNavBar'));
951                }
952        }
953}
954
955
956
957
958//HOTPOTNET-RELATED CODE
959
960var HPNStartTime = (new Date()).getTime();
961var SubmissionTimeout = 30000;
962var Detail = ''; //Global that is used to submit tracking data
963
964function Finish(){
965//If there's a form, fill it out and submit it
966        if (document.store != null){
967                Frm = document.store;
968                Frm.starttime.value = HPNStartTime;
969                Frm.endtime.value = (new Date()).getTime();
970                Frm.mark.value = Score;
971                Frm.detail.value = Detail;
972                Frm.submit();
973        }
974}
975
976
977
978//JQUIZ CORE JAVASCRIPT CODE
979
980var CurrQNum = 0;
981var CorrectIndicator = ':-)';
982var IncorrectIndicator = ':-(';
983var YourScoreIs = 'Su puntuaci&#x00F3;n es:';
984var ContinuousScoring = true;
985var CorrectFirstTime = 'Preguntas respondidas correctamente a la primera';
986var ShowCorrectFirstTime = false;
987var ShuffleQs = false;
988var ShuffleAs = false;
989var DefaultRight = 'Correcto';
990var DefaultWrong = 'Lo siento, pruebe de nuevo';
991var QsToShow = 4;
992var Score = 0;
993var Finished = false;
994var Qs = null;
995var QArray = new Array();
996var ShowingAllQuestions = false;
997var ShowAllQuestionsCaption = 'Mostrar todas las preguntas';
998var ShowOneByOneCaption = 'Mostrar las preguntas de una en una';
999var State = new Array();
1000var Feedback = '';
1001
1002function CompleteEmptyFeedback(){
1003        var QNum, ANum;
1004        for (QNum=0; QNum<I.length; QNum++){
1005                for (ANum = 0; ANum<I[QNum][3].length; ANum++){
1006                        if (I[QNum][3][ANum][1].length < 1){
1007                                if (I[QNum][3][ANum][2] > 0){
1008                                        I[QNum][3][ANum][1] = DefaultRight;
1009                                }
1010                                else{
1011                                        I[QNum][3][ANum][1] = DefaultWrong;
1012                                }
1013                        }
1014                }
1015        }
1016}
1017
1018function SetUpQuestions(){
1019        var AList = new Array();
1020        var QList = new Array();
1021        var i, j;
1022        Qs = document.getElementById('Questions');
1023        while (Qs.getElementsByTagName('li').length > 0){
1024                QList.push(Qs.removeChild(Qs.getElementsByTagName('li')[0]));
1025        }
1026        var DumpItem = 0;
1027        while (QsToShow < QList.length){
1028                DumpItem = Math.floor(QList.length*Math.random());
1029                for (j=DumpItem; j<(QList.length-1); j++){
1030                        QList[j] = QList[j+1];
1031                }
1032                QList.length = QList.length-1;
1033        }
1034        if (ShuffleQs == true){
1035                QList = Shuffle(QList);
1036        }
1037        if (ShuffleAs == true){
1038                var As;
1039                for (var i=0; i<QList.length; i++){
1040                        As = QList[i].getElementsByTagName('ol')[0];
1041                        if (As != null){
1042                        AList.length = 0;
1043                                while (As.getElementsByTagName('li').length > 0){
1044                                        AList.push(As.removeChild(As.getElementsByTagName('li')[0]));
1045                                }
1046                                AList = Shuffle(AList);
1047                                for (j=0; j<AList.length; j++){
1048                                        As.appendChild(AList[j]);
1049                                }
1050                        }
1051                }
1052        }
1053       
1054        for (i=0; i<QList.length; i++){
1055                Qs.appendChild(QList[i]);
1056                QArray[QArray.length] = QList[i];
1057        }
1058
1059//Show the first item
1060        QArray[0].style.display = '';
1061       
1062//Now hide all except the first item
1063        for (i=1; i<QArray.length; i++){
1064                QArray[i].style.display = 'none';
1065        }               
1066        SetQNumReadout();
1067}
1068
1069function ChangeQ(ChangeBy){
1070        if (((CurrQNum + ChangeBy) < 0)||((CurrQNum + ChangeBy) >= QArray.length)){return;}
1071        QArray[CurrQNum].style.display = 'none';
1072        CurrQNum += ChangeBy;
1073        QArray[CurrQNum].style.display = '';
1074        SetQNumReadout();
1075//if there's a textbox, set the focus in it
1076        if (QArray[CurrQNum].getElementsByTagName('input')[0] != null){
1077                QArray[CurrQNum].getElementsByTagName('input')[0].focus();
1078        }
1079}
1080
1081function SetQNumReadout(){
1082        document.getElementById('QNumReadout').innerHTML = (CurrQNum+1) + ' / ' + QArray.length;
1083}
1084
1085I=new Array();
1086I[0]=new Array();I[0][0]=100;
1087I[0][1]='';
1088I[0][2]='0';
1089I[0][3]=new Array();
1090I[0][3][0]=new Array('Microsoft','Lo siento, Microsoft es ua compa\u00F1\u00EDa muy seria y nunca utilizar\u00EDa una patata como logotipo. Pruebe otra vez.',0,0,1);
1091I[0][3][1]=new Array('Apple','Lo siento, Apple no desarrolla aplicaciones para Windows. Pruebe otra vez.',0,0,1);
1092I[0][3][2]=new Array('Half-Baked Software','\u00A1Esos somos nostros! Half-Baked Software Inc ha desarrollado Hot Potatoes y Quandary.',1,100,1);
1093I[0][3][3]=new Array('Adobe','Lo siento,  el software de Adobe est\u00E1 relacionado con el dise\u00F1o gr\u00E1fico. Pruebe otra vez.',0,0,1);
1094I[1]=new Array();I[1][0]=100;
1095I[1][1]='';
1096I[1][2]='1';
1097I[1][3]=new Array();
1098I[1][3][0]=new Array('JCross','Lo siento, JCross se usa para hacer crucigramas.',0,0,1);
1099I[1][3][1]=new Array('JQuiz','Correcto, JQuiz es el programa utilizado para crear ejercicios basados en preguntas.',1,100,1);
1100I[1][3][2]=new Array('JCloze','Lo siento, JCloze se usa para hacer ejercicios de rellenar huecos.',0,0,1);
1101I[2]=new Array();I[2][0]=100;
1102I[2][1]='';
1103I[2][2]='2';
1104I[2][3]=new Array();
1105I[2][3][0]=new Array('JCloze','Correcto, JCloze se usa para hacer ejercicios de rellenar huecos.',1,100,1);
1106I[2][3][1]=new Array('JCross','Lo siento, JCross se usa para hacer crucigramas.',0,0,1);
1107I[2][3][2]=new Array('JQuiz','Lo siento, JQuiz es el programa utilizado para crear ejercicios basado sne preguntas.',0,0,1);
1108I[2][3][3]=new Array('JMix','Lo siento, JMix es el programa utilizado para crear ejercicios de ordenadr palabras o letras.',0,0,1);
1109I[2][3][4]=new Array('JMatch','Lo siento, JMatch se usa para hacer ejercicios de asociaci\u00F3n.',0,0,1);
1110I[3]=new Array();I[3][0]=100;
1111I[3][1]='';
1112I[3][2]='3';
1113I[3][3]=new Array();
1114I[3][3][0]=new Array('JCloth','Pista:JCloth se usa para limpiar la cocina.',0,0,1);
1115I[3][3][1]=new Array('JCPenney','Pista: JCPenney es una almacen.',0,0,1);
1116I[3][3][2]=new Array('JQuiz','Pista: JQuiz es una patata.',1,100,1);
1117I[3][3][3]=new Array('JMix','Pista: JMix es una patata.',1,100,1);
1118I[3][3][4]=new Array('JLo','Pista: JLo es un cantante famoso.',0,0,1);
1119I[3][3][5]=new Array('JMatch','Pista: JMatch es una patata.',1,100,1);
1120I[3][3][6]=new Array('JCross','Pista: JCross es una patata.',1,100,1);
1121I[3][3][7]=new Array('JCloze','Pista: JCloze es una patata.',1,100,1);
1122I[3][3][8]=new Array('The Masher','Pista: The Masher es una patata.',1,100,1);
1123
1124
1125function StartUp(){
1126        RemoveBottomNavBarForIE();
1127       
1128
1129       
1130
1131       
1132        CompleteEmptyFeedback();
1133
1134        SetUpQuestions();
1135        ClearTextBoxes();
1136        CreateStatusArray();
1137       
1138
1139       
1140}
1141
1142function ShowHideQuestions(){
1143        FuncBtnOut(document.getElementById('ShowMethodButton'));
1144        document.getElementById('ShowMethodButton').style.display = 'none';
1145        if (ShowingAllQuestions == false){
1146                for (var i=0; i<QArray.length; i++){
1147                                QArray[i].style.display = '';
1148                        }
1149                document.getElementById('Questions').style.listStyleType = 'decimal';
1150                document.getElementById('OneByOneReadout').style.display = 'none';
1151                document.getElementById('ShowMethodButton').innerHTML = ShowOneByOneCaption;
1152                ShowingAllQuestions = true;
1153        }
1154        else{
1155                for (var i=0; i<QArray.length; i++){
1156                                if (i != CurrQNum){
1157                                        QArray[i].style.display = 'none';
1158                                }
1159                        }
1160                document.getElementById('Questions').style.listStyleType = 'none';
1161                document.getElementById('OneByOneReadout').style.display = '';
1162                document.getElementById('ShowMethodButton').innerHTML = ShowAllQuestionsCaption;
1163                ShowingAllQuestions = false;   
1164        }
1165        document.getElementById('ShowMethodButton').style.display = 'inline';
1166}
1167
1168function CreateStatusArray(){
1169        var QNum, ANum;
1170//For each item in the item array
1171        for (QNum=0; QNum<I.length; QNum++){
1172//Check if the question still exists (hasn't been nuked by showing a random selection)
1173                if (document.getElementById('Q_' + QNum) != null){
1174                        State[QNum] = new Array();
1175                        State[QNum][0] = -1; //Score for this q; -1 shows question not done yet
1176                        State[QNum][1] = new Array(); //answers
1177                        for (ANum = 0; ANum<I[QNum][3].length; ANum++){
1178                                State[QNum][1][ANum] = 0; //answer not chosen yet; when chosen, will store its position in the series of choices
1179                        }
1180                        State[QNum][2] = 0; //tries at this q so far
1181                        State[QNum][3] = 0; //incrementing percent-correct values of selected answers
1182                        State[QNum][4] = 0; //penalties incurred for hints
1183                        State[QNum][5] = ''; //Sequence of answers chosen by number
1184                }
1185                else{
1186                        State[QNum] = null;
1187                }
1188        }
1189}
1190
1191
1192
1193function CheckMCAnswer(QNum, ANum, Btn){
1194//if question doesn't exist, bail
1195        if (State[QNum].length < 1){return;}
1196       
1197//Get the feedback
1198        Feedback = I[QNum][3][ANum][1];
1199       
1200//Now show feedback and bail if question already complete
1201        if (State[QNum][0] > -1){
1202                ShowMessage(Feedback);
1203                return;
1204        }
1205       
1206//Hide the button while processing
1207        Btn.style.display = 'none';
1208
1209//Increment the number of tries
1210        State[QNum][2]++;
1211       
1212//Add the percent-correct value of this answer
1213        State[QNum][3] += I[QNum][3][ANum][3];
1214       
1215//Store the try number in the answer part of the State array, for tracking purposes
1216        State[QNum][1][ANum] = State[QNum][2];
1217        State[QNum][5] += String.fromCharCode(65+ANum) + ',';
1218       
1219//Should this answer be accepted as correct?
1220        if (I[QNum][3][ANum][2] < 1){
1221//It's wrong
1222
1223//Mark the answer
1224                Btn.innerHTML = IncorrectIndicator;
1225               
1226//Check whether this leaves just one MC answer unselected, in which case the Q is terminated
1227                var RemainingAnswer = FinalAnswer(QNum);
1228                if (RemainingAnswer > -1){
1229//Behave as if the last answer had been selected, but give no credit for it
1230//Increment the number of tries
1231                        State[QNum][2]++;               
1232               
1233//Calculate the score for this question
1234                        CalculateMCQuestionScore(QNum);
1235
1236//Get the overall score and add it to the feedback
1237                        CalculateOverallScore();
1238                        if ((ContinuousScoring == true)||(Finished == true)){
1239                                Feedback += '<br />' + YourScoreIs + ' ' + Score + '%.';
1240                                WriteToInstructions(YourScoreIs + ' ' + Score + '%.');
1241                        }
1242                }
1243        }
1244        else{
1245//It's right
1246//Mark the answer
1247                Btn.innerHTML = CorrectIndicator;
1248                               
1249//Calculate the score for this question
1250                CalculateMCQuestionScore(QNum);
1251
1252//Get the overall score and add it to the feedback
1253                if (ContinuousScoring == true){
1254                        CalculateOverallScore();
1255                        if ((ContinuousScoring == true)||(Finished == true)){
1256                                Feedback += '<br />' + YourScoreIs + ' ' + Score + '%.';
1257                                WriteToInstructions(YourScoreIs + ' ' + Score + '%.');
1258                        }
1259                }
1260        }
1261       
1262//Show the button again
1263        Btn.style.display = 'inline';
1264       
1265//Finally, show the feedback   
1266        ShowMessage(Feedback);
1267       
1268//Check whether all questions are now done
1269        CheckFinished();
1270}
1271
1272function CalculateMCQuestionScore(QNum){
1273        var Tries = State[QNum][2] + State[QNum][4]; //include tries and hint penalties
1274        var PercentCorrect = State[QNum][3];
1275        var TotAns = GetTotalMCAnswers(QNum);
1276        var HintPenalties = State[QNum][4];
1277       
1278//Make sure it's not already complete
1279
1280        if (State[QNum][0] < 0){
1281//Allow for Hybrids
1282                if (HintPenalties >= 1){
1283                        State[QNum][0] = 0;
1284                }
1285                else{
1286                        State[QNum][0] = ((TotAns-(Tries-1))/TotAns)*(PercentCorrect/(100*Tries));
1287                }
1288                if (State[QNum][0] < 0){
1289                        State[QNum][0] = 0;
1290                }
1291        }
1292}
1293
1294function GetTotalMCAnswers(QNum){
1295        var Result = 0;
1296        for (var ANum=0; ANum<I[QNum][3].length; ANum++){
1297                if (I[QNum][3][ANum][4] == 1){ //This is an MC answer
1298                        Result++;
1299                }
1300        }
1301        return Result;
1302}
1303
1304function FinalAnswer(QNum){
1305        var UnchosenAnswers = 0;
1306        var FinalAnswer = -1;
1307        for (var ANum=0; ANum<I[QNum][3].length; ANum++){
1308                if (I[QNum][3][ANum][4] == 1){ //This is an MC answer
1309                        if (State[QNum][1][ANum] < 1){ //This answer hasn't been chosen yet
1310                                UnchosenAnswers++;
1311                                FinalAnswer = ANum;
1312                        }
1313                }
1314        }
1315        if (UnchosenAnswers == 1){
1316                return FinalAnswer;
1317        }
1318        else{
1319                return -1;
1320        }
1321}
1322
1323
1324
1325
1326
1327function CheckMultiSelAnswer(QNum){
1328//bail if question doesn't exist or exercise finished
1329        if ((State[QNum].length < 1)||(Finished == true)){return;}
1330
1331//Increment the tries for this question
1332        State[QNum][2]++;
1333       
1334        var ShouldBeChecked;
1335        var Matches = 0;
1336        State[QNum][5] += '|';
1337       
1338//Check if there are any mismatches
1339        Feedback = '';
1340        var CheckBox = null;
1341        for (var ANum=0; ANum<I[QNum][3].length; ANum++){
1342                CheckBox = document.getElementById('Q_' + QNum + '_' + ANum + '_Chk');
1343                if (CheckBox.checked == true){
1344                        State[QNum][5] += 'Y';
1345                }
1346                else{
1347                        State[QNum][5] += 'N';
1348                }
1349                ShouldBeChecked = (I[QNum][3][ANum][2] == 1);
1350                if (ShouldBeChecked == CheckBox.checked){
1351                        Matches++;
1352                }
1353                else{
1354                        Feedback = I[QNum][3][ANum][1];
1355                }
1356        }
1357//Add the hit readout
1358        Feedback = Matches + ' / ' + I[QNum][3].length + '<br />' + Feedback;
1359        if (Matches == I[QNum][3].length){
1360//It's right
1361                CalculateMultiSelQuestionScore(QNum);
1362                if (ContinuousScoring == true){
1363                        CalculateOverallScore();
1364                        if ((ContinuousScoring == true)||(Finished == true)){
1365                                Feedback += '<br />' + YourScoreIs + ' ' + Score + '%.';
1366                                WriteToInstructions(YourScoreIs + ' ' + Score + '%.');
1367                        }
1368                }
1369        }
1370//If it's wrong, no need to do anything but show the feedback
1371        ShowMessage(Feedback);
1372       
1373//Check whether all questions are now done
1374        CheckFinished();
1375}
1376
1377function CalculateMultiSelQuestionScore(QNum){
1378        var Tries = State[QNum][2];
1379        var TotAns = State[QNum][1].length;
1380       
1381//Make sure it's not already complete
1382        if (State[QNum][0] < 0){
1383                State[QNum][0] = (TotAns - (Tries-1)) / TotAns;
1384                if (State[QNum][0] < 0){
1385                        State[QNum][0] = 0;
1386                }
1387        }
1388}
1389
1390
1391
1392function CalculateOverallScore(){
1393        var TotalWeighting = 0;
1394        var TotalScore = 0;
1395       
1396        for (var QNum=0; QNum<State.length; QNum++){
1397                if (State[QNum] != null){
1398                        if (State[QNum][0] > -1){
1399                                TotalWeighting += I[QNum][0];
1400                                TotalScore += (I[QNum][0] * State[QNum][0]);
1401                        }
1402                }
1403        }
1404        Score = Math.floor((TotalScore/TotalWeighting)*100);
1405}
1406
1407function CheckFinished(){
1408        var FB = '';
1409        var AllDone = true;
1410        for (var QNum=0; QNum<State.length; QNum++){
1411                if (State[QNum] != null){
1412                        if (State[QNum][0] < 0){
1413                                AllDone = false;
1414                        }
1415                }
1416        }
1417        if (AllDone == true){
1418       
1419//Report final score and submit if necessary
1420                CalculateOverallScore();
1421                FB = YourScoreIs + ' ' + Score + '%.';
1422                if (ShowCorrectFirstTime == true){
1423                        var CFT = 0;
1424                        for (QNum=0; QNum<State.length; QNum++){
1425                                if (State[QNum] != null){
1426                                        if (State[QNum][0] >= 1){
1427                                                CFT++;
1428                                        }
1429                                }
1430                        }
1431                        FB += '<br />' + CorrectFirstTime + ' ' + CFT + '/' + QsToShow;
1432                }
1433                WriteToInstructions(FB);
1434               
1435                Finished == true;
1436
1437                TimeOver = true;
1438                Locked = true;
1439               
1440
1441
1442                Finished = true;
1443                Detail = '<?xml version="1.0"?><hpnetresult><fields>';
1444                for (QNum=0; QNum<State.length; QNum++){
1445                        if (State[QNum] != null){
1446                                if (State[QNum][5].length > 0){
1447                                        Detail += '<field><fieldname>Question #' + (QNum+1) + '</fieldname><fieldtype>question-tracking</fieldtype><fieldlabel>Q ' + (QNum+1) + '</fieldlabel><fieldlabelid>QuestionTrackingField</fieldlabelid><fielddata>' + State[QNum][5] + '</fielddata></field>';
1448                                }
1449                        }
1450                }
1451                Detail += '</fields></hpnetresult>';
1452                setTimeout('Finish()', SubmissionTimeout);
1453        }
1454}
1455
1456
1457
1458
1459
1460//CORE CODE FOR CHECKING SHORT ANSWER GUESSES AGAINST ANSWER ARRAYS
1461
1462var CaseSensitive = false;
1463var ShowAlsoCorrect = true;
1464var PleaseEnter = 'Por favor, escriba una respuesta';
1465var HybridTries = 2;
1466var PartlyIncorrect = 'Su respuesta es parcialmente incorrecta';
1467var CorrectList = 'Respuestas correctas:';
1468var NextCorrect = 'Siguiente letra correcta de la respuesta';
1469var CurrBox = null;
1470
1471function TrackFocus(BoxID){
1472        InTextBox = true;
1473        CurrBox = document.getElementById(BoxID);
1474}
1475
1476function LeaveGap(){
1477        InTextBox = false;
1478}
1479
1480function TypeChars(Chars){
1481        if (CurrBox != null){
1482//              if (CurrBox.style.display != 'none'){
1483                        CurrBox.value += Chars;
1484//              }
1485        }
1486}
1487
1488function CheckGuess(Guess, Answer, CaseSensitive, PercentCorrect, Feedback){
1489        this.Guess = Guess;
1490        this.Answer = Answer;
1491        this.PercentCorrect = PercentCorrect;
1492        this.Feedback = Feedback;
1493        if (CaseSensitive == false){
1494                this.WorkingGuess = Guess.toLowerCase();
1495                this.WorkingAnswer = Answer.toLowerCase();
1496        }
1497        else{
1498                this.WorkingGuess = Guess;
1499                this.WorkingAnswer = Answer;                           
1500        }
1501        this.Hint = '';
1502        this.HintPenalty = 1/Answer.length;
1503        this.CorrectStart = '';
1504        this.WrongMiddle = '';
1505        this.CorrectEnd = '';
1506        this.PercentMatch = 0;
1507        this.DoCheck();
1508}
1509
1510function CheckGuess_DoCheck(){
1511//Check if it's an exact match
1512        if (this.WorkingAnswer == this.WorkingGuess){
1513                this.PercentMatch = 100;
1514                this.CorrectStart = this.Guess;
1515        return;
1516        }
1517//Figure out how much of the beginning is correct
1518        var i = 0;
1519        var CorrectChars = 0;
1520        while (this.WorkingAnswer.charAt(i) == this.WorkingGuess.charAt(i)){
1521                i++;
1522                CorrectChars++;
1523        }
1524//Stash the hint
1525        this.Hint = this.Answer.charAt(i);
1526       
1527        this.CorrectStart = this.Guess.substring(0, i);
1528//Figure out how much of the end is correct
1529        var j = this.WorkingGuess.length-1;
1530        var k = this.WorkingAnswer.length-1;
1531        while ((this.WorkingAnswer.charAt(k) == this.WorkingGuess.charAt(j))&&(CorrectChars < this.Answer.length)){
1532                CorrectChars++;
1533                j--;
1534                k--;
1535        }
1536        this.CorrectEnd = this.Guess.substring(j+1, this.Guess.length);
1537        this.WrongMiddle = this.Guess.substring(i, j+1);
1538        if (TrimString(this.WrongMiddle).length < 1){this.WrongMiddle = '_____';}
1539//Calculate match score based on how much of the guess is correct
1540        if (CorrectChars < this.Answer.length){
1541                this.PercentMatch = Math.floor(100*CorrectChars)/this.Answer.length;
1542        }
1543        else{
1544                this.PercentMatch = Math.floor((100 * CorrectChars)/this.Guess.length);
1545        }       
1546}
1547
1548CheckGuess.prototype.DoCheck = CheckGuess_DoCheck;
1549
1550function CheckAnswerArray(CaseSensitive){
1551        this.CaseSensitive = CaseSensitive;
1552        this.Answers = new Array();
1553        this.Score = 0;
1554        this.Feedback = '';
1555        this.Hint = '';
1556        this.HintPenalty = 0;
1557        this.MatchedAnswerLength = 1;
1558        this.CompleteMatch = false;
1559        this.MatchNum = -1;
1560}
1561
1562function CheckAnswerArray_AddAnswer(Guess, Answer, PercentCorrect, Feedback){
1563        this.Answers.push(new CheckGuess(Guess, Answer, this.CaseSensitive, PercentCorrect, Feedback));
1564}
1565
1566CheckAnswerArray.prototype.AddAnswer = CheckAnswerArray_AddAnswer;
1567
1568function CheckAnswerArray_ClearAll(){
1569        this.Answers.length = 0;
1570}
1571
1572CheckAnswerArray.prototype.ClearAll = CheckAnswerArray_ClearAll;
1573
1574function CheckAnswerArray_GetBestMatch(){
1575//First check for a 100% match
1576        for (var i=0; i<this.Answers.length; i++){
1577                if (this.Answers[i].PercentMatch == 100){
1578                        this.Feedback = this.Answers[i].Feedback;
1579                        this.Score = this.Answers[i].PercentCorrect;
1580                        this.CompleteMatch = true;
1581                        this.MatchNum = i;
1582                        return;
1583                }
1584        }
1585//Now check for the best alternative match
1586        var PercentMatch = 0;
1587        var BestMatch = -1;
1588        for (i=0; i<this.Answers.length; i++){
1589                if ((this.Answers[i].PercentMatch > PercentMatch)&&(this.Answers[i].PercentCorrect == 100)){
1590                        BestMatch = i;
1591                        PercentMatch = this.Answers[i].PercentMatch;
1592                }
1593        }
1594        if (BestMatch > -1){
1595                this.Score = this.Answers[BestMatch].PercentMatch;
1596                this.Feedback = PartlyIncorrect + ' ';
1597                this.Feedback += '<span class="Answer">' + this.Answers[BestMatch].CorrectStart;
1598                this.Feedback += '<span class="Highlight">' + this.Answers[BestMatch].WrongMiddle + '</span>';
1599                this.Feedback += this.Answers[BestMatch].CorrectEnd + '</span>';
1600                this.Hint = '<span class="Answer">' + this.Answers[BestMatch].CorrectStart;
1601                this.Hint += '<span class="Highlight">' + this.Answers[BestMatch].Hint + '</span></span>';
1602                this.HintPenalty = this.Answers[BestMatch].HintPenalty;
1603        }
1604        else{
1605                this.Score = 0;
1606                this.Feedback = '';
1607        }
1608}
1609
1610CheckAnswerArray.prototype.GetBestMatch = CheckAnswerArray_GetBestMatch;
1611
1612function CheckShortAnswer(QNum){
1613//bail if question doesn't exist or exercise finished
1614        if ((State[QNum].length < 1)||(Finished == true)){return;}
1615       
1616//bail if question already complete
1617        if (State[QNum][0] > -1){return;}
1618
1619//Get the guess
1620        var G = document.getElementById('Q_' + QNum + '_Guess').value;
1621       
1622//If no guess, bail with message; no penalty
1623        if (G.length < 1){
1624                ShowMessage(PleaseEnter);
1625                return;
1626        }
1627
1628//Increment tries
1629        State[QNum][2]++;
1630       
1631//Create a check object
1632        var CA = new CheckAnswerArray(CaseSensitive);
1633
1634        CA.ClearAll();
1635        for (var ANum=0; ANum<I[QNum][3].length; ANum++){
1636                CA.AddAnswer(G, I[QNum][3][ANum][0], I[QNum][3][ANum][3], I[QNum][3][ANum][1]);
1637        }
1638        CA.GetBestMatch();
1639       
1640//Store any match in the state tracking field
1641        if (CA.MatchNum > -1){
1642                State[QNum][5] += String.fromCharCode(65+CA.MatchNum) + ',';
1643        }
1644
1645//Add the percent correct value for this answer to the Q State (works for all
1646//situations, wrong or right
1647        State[QNum][3] += CA.Score;
1648       
1649//Now branch, based on the nature of the match
1650//Is it a complete match?
1651        if (CA.CompleteMatch == true){
1652               
1653//Is it with a wrong answer, or a right answer?
1654                if (CA.Score == 100){
1655//It's right
1656                        CalculateShortAnsQuestionScore(QNum);
1657//Get correct answer list if required, assuming there are any other correct alternatives
1658                        if (ShowAlsoCorrect == true){
1659                                var AlsoCorrectList = GetCorrectList(QNum, G, false);
1660                                if (AlsoCorrectList.length > 0){
1661                                        CA.Feedback += '<br />' + CorrectList + '<br />' +  '<span class="Answer">' + AlsoCorrectList + '</span>';
1662                                }
1663                        }       
1664               
1665//Get the overall score and add it to the feedback
1666                        if (ContinuousScoring == true){
1667                                CalculateOverallScore();
1668                                CA.Feedback += '<br />' + YourScoreIs + ' ' + Score + '%.';
1669                                WriteToInstructions(YourScoreIs + ' ' + Score + '%.');
1670                        }
1671                        ShowMessage(CA.Feedback);
1672//Put the answer in
1673                        ReplaceGuessBox(QNum, G);
1674                        CheckFinished();
1675                        return;
1676                }
1677        }
1678       
1679//Otherwise, it's a match to a predicted wrong/partially correct, or a partial
1680//match to a right answer
1681        if (CA.Feedback.length < 1){CA.Feedback = DefaultWrong;}
1682        ShowMessage(CA.Feedback);
1683
1684//If necessary, switch a hybrid question to m/c
1685        if (State[QNum][2] >= HybridTries){
1686                SwitchHybridDisplay(QNum);
1687        }
1688}
1689
1690function CalculateShortAnsQuestionScore(QNum){
1691        var Tries = State[QNum][2] + State[QNum][4]; //include tries and hint penalties;
1692        var PercentCorrect = State[QNum][3];
1693        var HintPenalties = State[QNum][4];
1694
1695//Make sure it's not already complete
1696        if (State[QNum][0] < 0){
1697                if (HintPenalties >= 1){
1698                        State[QNum][0] = 0;
1699                }
1700                else{
1701                        State[QNum][0] = (PercentCorrect/(100*Tries));
1702                }
1703                if (State[QNum][0] < 0){
1704                        State[QNum][0] = 0;
1705                }
1706        }
1707}
1708
1709function SwitchHybridDisplay(QNum){
1710        if (document.getElementById('Q_' + QNum + '_Hybrid_MC') != null){
1711                document.getElementById('Q_' + QNum + '_Hybrid_MC').style.display = '';
1712                if (document.getElementById('Q_' + QNum + '_SA') != null){
1713                        document.getElementById('Q_' + QNum + '_SA').style.display = 'none';
1714                }
1715        }
1716}
1717
1718function GetCorrectArray(QNum){
1719        var Result = new Array();
1720        for (var ANum=0; ANum<I[QNum][3].length; ANum++){
1721                if (I[QNum][3][ANum][2] == 1){ //This is an acceptable correct answer
1722                        Result.push(I[QNum][3][ANum][0]);
1723                }
1724        }       
1725        return Result;
1726}
1727
1728function GetCorrectList(QNum, Answer, IncludeAnswer){
1729        var As = GetCorrectArray(QNum);
1730        var Result = '';
1731        for (var ANum=0; ANum<As.length; ANum++){
1732                if ((IncludeAnswer == true)||(As[ANum] != Answer)){
1733                        Result += As[ANum] + '<br />';
1734                }
1735        }
1736        return Result;
1737}
1738
1739function GetFirstCorrectAnswer(QNum){
1740        var As = GetCorrectArray(QNum);
1741        if (As.length > 0){
1742                return As[0];
1743        }
1744        else{
1745                return '';
1746        }
1747}
1748
1749function ReplaceGuessBox(QNum, Ans){
1750        if (document.getElementById('Q_' + QNum + '_SA') != null){
1751                var El = document.getElementById('Q_' + QNum + '_SA');
1752                while (El.childNodes.length > 0){
1753                        El.removeChild(El.childNodes[0]);
1754                }
1755                var A = document.createElement('span');
1756                A.setAttribute('class', 'Answer');
1757                var T = document.createTextNode(Ans);
1758                A.appendChild(T);
1759                El.appendChild(A);
1760        }
1761}
1762
1763
1764
1765function ShowAnswers(QNum){
1766//bail if question doesn't exist or exercise finished
1767        if ((State[QNum].length < 1)||(Finished == true)){return;}
1768       
1769//Get the answer list to display
1770        var Ans = GetCorrectList(QNum, '', false);
1771        Ans = CorrectList + '<br /><span class="Answer">' + Ans + '</span>';
1772       
1773//Display feedback
1774        ShowMessage(Ans);
1775       
1776//Set the score for this question to 0 if no
1777        if (State[QNum][0] < 1){
1778                State[QNum][0] = 0;
1779        }
1780
1781//Get the first correct answer
1782        var FirstAns = GetFirstCorrectAnswer(QNum);
1783       
1784//Replace the textbox
1785        ReplaceGuessBox(QNum, FirstAns);
1786       
1787//This may be the last, so check finished status
1788        CheckFinished();
1789}
1790
1791
1792
1793
1794
1795function ShowHint(QNum){
1796//bail if question doesn't exist or exercise finished
1797        if ((State[QNum].length < 1)||(Finished == true)){return;}
1798       
1799//bail if question already complete
1800        if (State[QNum][0] > -1){return;}
1801
1802//Get the guess
1803        var G = document.getElementById('Q_' + QNum + '_Guess').value;
1804       
1805//If no guess, give the first correct bit
1806        if (G.length < 1){
1807                var Ans = GetFirstCorrectAnswer(QNum);
1808                var Hint = Ans.charAt(0);
1809                ShowMessage(NextCorrect + '<br />' + Hint);
1810//Penalty for hint
1811                State[QNum][4] += (1/Ans.length);
1812                return;
1813        }
1814
1815//Increment tries
1816        State[QNum][2]++;
1817       
1818//Create a check object
1819        var CA = new CheckAnswerArray(CaseSensitive);
1820
1821        CA.ClearAll();
1822        for (var ANum=0; ANum<I[QNum][3].length; ANum++){
1823//Use only correct answers
1824                if (I[QNum][3][ANum][2] == 1){
1825                        CA.AddAnswer(G, I[QNum][3][ANum][0], I[QNum][3][ANum][3], I[QNum][3][ANum][1]);
1826                }
1827        }
1828        CA.GetBestMatch();
1829        if (CA.CompleteMatch == true){
1830//It's right!
1831                CheckShortAnswer(QNum);
1832                return;
1833        }
1834        else{
1835                if (CA.Hint.length > 0){
1836                        ShowMessage(NextCorrect + '<br />' + CA.Hint);
1837                        State[QNum][4] += CA.HintPenalty;
1838                }
1839                else{
1840                        ShowMessage(DefaultWrong + '<br />' + NextCorrect + '<br />' + GetFirstCorrectAnswer(QNum)[0]);
1841                }
1842        }
1843}
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853//-->
1854
1855//]]>
1856
1857</script>
1858
1859
1860</head>
1861
1862<body onload="StartUp()" id="TheBody">
1863
1864<!-- BeginTopNavButtons -->
1865
1866
1867
1868<!-- EndTopNavButtons -->
1869
1870<div class="Titles">
1871        <h2 class="ExerciseTitle">Ejemplo de ejercicio JQuiz que muestra los cuatro tipos de preguntas</h2>
1872        <h3 class="ExerciseSubtitle"></h3>
1873
1874
1875</div>
1876
1877<div id="InstructionsDiv" class="StdDiv">
1878        <p id="Instructions"></p>
1879</div>
1880
1881
1882
1883
1884<div id="MainDiv" class="StdDiv">
1885 
1886<div class="QuestionNavigation">
1887
1888<p style="text-align: right;">
1889<button id="ShowMethodButton" class="FuncButton" onfocus="FuncBtnOver(this)" onblur="FuncBtnOut(this)" onmouseover="FuncBtnOver(this)" onmouseout="FuncBtnOut(this)" onmousedown="FuncBtnDown(this)" onmouseup="FuncBtnOver(this)" onclick="ShowHideQuestions(); return false;">Mostrar todas las preguntas</button>
1890</p>
1891
1892<div id="OneByOneReadout">
1893<button id="PrevQButton" class="FuncButton" onfocus="FuncBtnOver(this)" onblur="FuncBtnOut(this)" onmouseover="FuncBtnOver(this)" onmouseout="FuncBtnOut(this)" onmousedown="FuncBtnDown(this)" onmouseup="FuncBtnOver(this)" onclick="ChangeQ(-1); return false;">&lt;=</button>
1894
1895<span id="QNumReadout" class="QNum">&nbsp;</span>
1896
1897<button id="NextQButton" class="FuncButton" onfocus="FuncBtnOver(this)" onblur="FuncBtnOut(this)" onmouseover="FuncBtnOver(this)" onmouseout="FuncBtnOut(this)" onmousedown="FuncBtnDown(this)" onmouseup="FuncBtnOver(this)" onclick="ChangeQ(1); return false;">=&gt;</button>
1898<br />
1899</div>
1900
1901</div>
1902 
1903<ol class="QuizQuestions" id="Questions">
1904<li class="QuizQuestion" id="Q_0" style="display: none;"><p class="QuestionText">Esta es una pregunta de respuestas m&#x00FA;ltiples.<br />&#x00BF;Qu&#x00E9; compa&#x00F1;&#x00ED;a ha desarrollado Hot Potatoes?</p><ol class="MCAnswers"><li id="Q_0_0"><button class="FuncButton" onfocus="FuncBtnOver(this)" onblur="FuncBtnOut(this)" onmouseover="FuncBtnOver(this)" onmouseout="FuncBtnOut(this)"  onmousedown="FuncBtnDown(this)" onmouseup="FuncBtnOut(this)" id="Q_0_0_Btn" onclick="CheckMCAnswer(0,0,this)">&nbsp;&nbsp;?&nbsp;&nbsp;</button>&nbsp;&nbsp;Microsoft</li><li id="Q_0_1"><button class="FuncButton" onfocus="FuncBtnOver(this)" onblur="FuncBtnOut(this)" onmouseover="FuncBtnOver(this)" onmouseout="FuncBtnOut(this)"  onmousedown="FuncBtnDown(this)" onmouseup="FuncBtnOut(this)" id="Q_0_1_Btn" onclick="CheckMCAnswer(0,1,this)">&nbsp;&nbsp;?&nbsp;&nbsp;</button>&nbsp;&nbsp;Apple</li><li id="Q_0_2"><button class="FuncButton" onfocus="FuncBtnOver(this)" onblur="FuncBtnOut(this)" onmouseover="FuncBtnOver(this)" onmouseout="FuncBtnOut(this)"  onmousedown="FuncBtnDown(this)" onmouseup="FuncBtnOut(this)" id="Q_0_2_Btn" onclick="CheckMCAnswer(0,2,this)">&nbsp;&nbsp;?&nbsp;&nbsp;</button>&nbsp;&nbsp;Half-Baked Software</li><li id="Q_0_3"><button class="FuncButton" onfocus="FuncBtnOver(this)" onblur="FuncBtnOut(this)" onmouseover="FuncBtnOver(this)" onmouseout="FuncBtnOut(this)"  onmousedown="FuncBtnDown(this)" onmouseup="FuncBtnOut(this)" id="Q_0_3_Btn" onclick="CheckMCAnswer(0,3,this)">&nbsp;&nbsp;?&nbsp;&nbsp;</button>&nbsp;&nbsp;Adobe</li></ol></li>
1905<li class="QuizQuestion" id="Q_1" style="display: none;"><p class="QuestionText">Esta es una pregunta de respuesta corta. La respuesta correcta es "JQuiz". Pruebe a escribir una respuesta incorrecta (como, por ejemplo, "JCloze") para ver las indicaciones que se le dan para esa respuesta, y pruebe tambi&#x00E9;n a escribir una res`puesta que sea parcialmente correcta (como, por ejemplo, "JQuoz") para ver la respuesta que obtiene.<br /><br />&#x00BF;Qu&#x00E9; programa se ja utilizado para elaborar este test?</p><div class="ShortAnswer" id="Q_1_SA"><form method="post" action="" onsubmit="return false;"><div><input type="text" id="Q_1_Guess" onfocus="TrackFocus('Q_1_Guess')" onblur="LeaveGap()" class="GapBox" size="9"></input><br /><br /><button class="FuncButton" onfocus="FuncBtnOver(this)" onblur="FuncBtnOut(this)" onmouseover="FuncBtnOver(this)" onmouseout="FuncBtnOut(this)"  onmousedown="FuncBtnDown(this)" onmouseup="FuncBtnOut(this)" onclick="CheckShortAnswer(1)">Comprobar</button><button class="FuncButton" onfocus="FuncBtnOver(this)" onblur="FuncBtnOut(this)" onmouseover="FuncBtnOver(this)" onmouseout="FuncBtnOut(this)"  onmousedown="FuncBtnDown(this)" onmouseup="FuncBtnOut(this)" onclick="ShowHint(1)">Pista</button><button class="FuncButton" onfocus="FuncBtnOver(this)" onblur="FuncBtnOut(this)" onmouseover="FuncBtnOver(this)" onmouseout="FuncBtnOut(this)"  onmousedown="FuncBtnDown(this)" onmouseup="FuncBtnOut(this)" onclick="ShowAnswers(1)">Mostrar respuesta</button></div></form></div></li>
1906<li class="QuizQuestion" id="Q_2" style="display: none;"><p class="QuestionText">Esta es una pregunta "h&#x00ED;brida". Tendr&#x00E1; dos intentos para acertar la respuesta; si no lo consigue, el ejercicio se convertir&#x00E1; en uno de respuestas m&#x00FA;ltiples.<br /><br />&#x00BF;Que programa se utiliza para elaborar ejercicios de rellenar huecos?</p><div class="ShortAnswer" id="Q_2_SA"><form method="post" action="" onsubmit="return false;"><div><input type="text" id="Q_2_Guess" onfocus="TrackFocus('Q_2_Guess')" onblur="LeaveGap()" class="GapBox" size="9"></input><br /><br /><button class="FuncButton" onfocus="FuncBtnOver(this)" onblur="FuncBtnOut(this)" onmouseover="FuncBtnOver(this)" onmouseout="FuncBtnOut(this)"  onmousedown="FuncBtnDown(this)" onmouseup="FuncBtnOut(this)" onclick="CheckShortAnswer(2)">Comprobar</button><button class="FuncButton" onfocus="FuncBtnOver(this)" onblur="FuncBtnOut(this)" onmouseover="FuncBtnOver(this)" onmouseout="FuncBtnOut(this)"  onmousedown="FuncBtnDown(this)" onmouseup="FuncBtnOut(this)" onclick="ShowHint(2)">Pista</button><button class="FuncButton" onfocus="FuncBtnOver(this)" onblur="FuncBtnOut(this)" onmouseover="FuncBtnOver(this)" onmouseout="FuncBtnOut(this)"  onmousedown="FuncBtnDown(this)" onmouseup="FuncBtnOut(this)" onclick="ShowAnswers(2)">Mostrar respuesta</button></div></form></div><ol class="MCAnswers" id="Q_2_Hybrid_MC" style="display: none;"><li id="Q_2_0"><button class="FuncButton" onfocus="FuncBtnOver(this)" onblur="FuncBtnOut(this)" onmouseover="FuncBtnOver(this)" onmouseout="FuncBtnOut(this)"  onmousedown="FuncBtnDown(this)" onmouseup="FuncBtnOut(this)" id="Q_2_0_Btn" onclick="CheckMCAnswer(2,0,this)">&nbsp;&nbsp;?&nbsp;&nbsp;</button>&nbsp;&nbsp;JCloze</li><li id="Q_2_1"><button class="FuncButton" onfocus="FuncBtnOver(this)" onblur="FuncBtnOut(this)" onmouseover="FuncBtnOver(this)" onmouseout="FuncBtnOut(this)"  onmousedown="FuncBtnDown(this)" onmouseup="FuncBtnOut(this)" id="Q_2_1_Btn" onclick="CheckMCAnswer(2,1,this)">&nbsp;&nbsp;?&nbsp;&nbsp;</button>&nbsp;&nbsp;JCross</li><li id="Q_2_2"><button class="FuncButton" onfocus="FuncBtnOver(this)" onblur="FuncBtnOut(this)" onmouseover="FuncBtnOver(this)" onmouseout="FuncBtnOut(this)"  onmousedown="FuncBtnDown(this)" onmouseup="FuncBtnOut(this)" id="Q_2_2_Btn" onclick="CheckMCAnswer(2,2,this)">&nbsp;&nbsp;?&nbsp;&nbsp;</button>&nbsp;&nbsp;JQuiz</li><li id="Q_2_3"><button class="FuncButton" onfocus="FuncBtnOver(this)" onblur="FuncBtnOut(this)" onmouseover="FuncBtnOver(this)" onmouseout="FuncBtnOut(this)"  onmousedown="FuncBtnDown(this)" onmouseup="FuncBtnOut(this)" id="Q_2_3_Btn" onclick="CheckMCAnswer(2,3,this)">&nbsp;&nbsp;?&nbsp;&nbsp;</button>&nbsp;&nbsp;JMix</li><li id="Q_2_4"><button class="FuncButton" onfocus="FuncBtnOver(this)" onblur="FuncBtnOut(this)" onmouseover="FuncBtnOver(this)" onmouseout="FuncBtnOut(this)"  onmousedown="FuncBtnDown(this)" onmouseup="FuncBtnOut(this)" id="Q_2_4_Btn" onclick="CheckMCAnswer(2,4,this)">&nbsp;&nbsp;?&nbsp;&nbsp;</button>&nbsp;&nbsp;JMatch</li></ol></li>
1907<li class="QuizQuestion" id="Q_3" style="display: none;"><p class="QuestionText">Esta &#x00FA;ltima pergunta es de multiselecci&#x00F3;n.<br />&#x00BF;Cu&#x00E1;l de los siguientes programas forman parte de Hot Potatoes?</p><ol class="MSelAnswers"><li id="Q_3_0"><form method="post" action="" onsubmit="return false;"><div><input type="checkbox" id="Q_3_0_Chk" class="MSelCheckbox" />JCloth</div></form></li><li id="Q_3_1"><form method="post" action="" onsubmit="return false;"><div><input type="checkbox" id="Q_3_1_Chk" class="MSelCheckbox" />JCPenney</div></form></li><li id="Q_3_2"><form method="post" action="" onsubmit="return false;"><div><input type="checkbox" id="Q_3_2_Chk" class="MSelCheckbox" />JQuiz</div></form></li><li id="Q_3_3"><form method="post" action="" onsubmit="return false;"><div><input type="checkbox" id="Q_3_3_Chk" class="MSelCheckbox" />JMix</div></form></li><li id="Q_3_4"><form method="post" action="" onsubmit="return false;"><div><input type="checkbox" id="Q_3_4_Chk" class="MSelCheckbox" />JLo</div></form></li><li id="Q_3_5"><form method="post" action="" onsubmit="return false;"><div><input type="checkbox" id="Q_3_5_Chk" class="MSelCheckbox" />JMatch</div></form></li><li id="Q_3_6"><form method="post" action="" onsubmit="return false;"><div><input type="checkbox" id="Q_3_6_Chk" class="MSelCheckbox" />JCross</div></form></li><li id="Q_3_7"><form method="post" action="" onsubmit="return false;"><div><input type="checkbox" id="Q_3_7_Chk" class="MSelCheckbox" />JCloze</div></form></li><li id="Q_3_8"><form method="post" action="" onsubmit="return false;"><div><input type="checkbox" id="Q_3_8_Chk" class="MSelCheckbox" />The Masher</div></form></li></ol><button class="FuncButton" onfocus="FuncBtnOver(this)" onblur="FuncBtnOut(this)" onmouseover="FuncBtnOver(this)" onmouseout="FuncBtnOut(this)"  onmousedown="FuncBtnDown(this)" onmouseup="FuncBtnOut(this)" onclick="CheckMultiSelAnswer(3)">Comprobar</button></li></ol>
1908
1909
1910
1911</div>
1912
1913
1914
1915<div class="Feedback" id="FeedbackDiv">
1916<div class="FeedbackText" id="FeedbackContent"></div>
1917<button id="FeedbackOKButton" class="FuncButton" onfocus="FuncBtnOver(this)" onblur="FuncBtnOut(this)" onmouseover="FuncBtnOver(this)" onmouseout="FuncBtnOut(this)" onmousedown="FuncBtnDown(this)" onmouseup="FuncBtnOut(this)" onclick="HideFeedback(); return false;">&nbsp;OK&nbsp;</button>
1918</div>
1919
1920<!-- BeginBottomNavButtons -->
1921
1922
1923
1924<!-- EndBottomNavButtons -->
1925
1926<!-- BeginSubmissionForm -->
1927
1928<!-- EndSubmissionForm -->
1929
1930</body>
1931
1932</html>
Note: See TracBrowser for help on using the browser.