Incorrect variable name used for parameter.
[moodle-linuxchix.git] / mod / hotpot / v6 / source / hp6utilities.js_
blob6e41a5f1cdc78c5c46e6f74e0fbb2b1080158f25
1 //GENERAL UTILITY FUNCTIONS AND VARIABLES\r
2 \r
3 //PAGE DIMENSION FUNCTIONS\r
4 function PageDim(){\r
5 //Get the page width and height\r
6         this.W = 600;\r
7         this.H = 400;\r
8         this.W = document.getElementsByTagName('body')[0].clientWidth;\r
9         this.H = document.getElementsByTagName('body')[0].clientHeight;\r
10 }\r
12 var pg = null;\r
14 function GetPageXY(El) {\r
15         var XY = {x: 0, y: 0};\r
16         while(El){\r
17                 XY.x += El.offsetLeft;\r
18                 XY.y += El.offsetTop;\r
19                 El = El.offsetParent;\r
20         }\r
21         return XY;\r
22 }\r
24 function GetScrollTop(){\r
25         if (document.documentElement && document.documentElement.scrollTop){\r
26                 return document.documentElement.scrollTop;\r
27         }\r
28         else{\r
29                 if (document.body){\r
30                         return document.body.scrollTop;\r
31                 }\r
32                 else{\r
33                         return window.pageYOffset;\r
34                 }\r
35         }\r
36 }\r
38 function GetViewportHeight(){\r
39         if (window.innerHeight){\r
40                 return window.innerHeight;\r
41         }\r
42         else{\r
43                 return document.getElementsByTagName('body')[0].clientHeight;\r
44         }\r
45 }\r
47 function TopSettingWithScrollOffset(TopPercent){\r
48         var T = Math.floor(GetViewportHeight() * (TopPercent/100));\r
49         return GetScrollTop() + T; \r
50 }\r
52 //CODE FOR AVOIDING LOSS OF DATA WHEN BACKSPACE KEY INVOKES history.back()\r
53 var InTextBox = false;\r
55 function SuppressBackspace(e){ \r
56         if (InTextBox == true){return;}\r
57         if (C.ie) {\r
58                 thisKey = window.event.keyCode;\r
59         }\r
60         else {\r
61                 thisKey = e.keyCode;\r
62         }\r
64         var Suppress = false;\r
66         if (thisKey == 8) {\r
67                 Suppress = true;\r
68         }\r
70         if (Suppress == true){\r
71                 if (C.ie){\r
72                         window.event.returnValue = false;       \r
73                         window.event.cancelBubble = true;\r
74                 }\r
75                 else{\r
76                         e.preventDefault();\r
77                 }\r
78         }\r
79 }\r
81 if (C.ie){\r
82         document.attachEvent('onkeydown',SuppressBackspace);\r
83         window.attachEvent('onkeydown',SuppressBackspace);\r
84 }\r
85 else{\r
86         if (window.addEventListener){\r
87                 window.addEventListener('keypress',SuppressBackspace,false);\r
88         }\r
89 }\r
91 function ReduceItems(InArray, ReduceToSize){\r
92         var ItemToDump=0;\r
93         var j=0;\r
94         while (InArray.length > ReduceToSize){\r
95                 ItemToDump = Math.floor(InArray.length*Math.random());\r
96                 InArray.splice(ItemToDump, 1);\r
97         }\r
98 }\r
100 function Shuffle(InArray){\r
101         var Num;\r
102         var Temp = new Array();\r
103         var Len = InArray.length;\r
105         var j = Len;\r
107         for (var i=0; i<Len; i++){\r
108                 Temp[i] = InArray[i];\r
109         }\r
111         for (i=0; i<Len; i++){\r
112                 Num = Math.floor(j  *  Math.random());\r
113                 InArray[i] = Temp[Num];\r
115                 for (var k=Num; k < (j-1); k++) {\r
116                         Temp[k] = Temp[k+1];\r
117                 }\r
118                 j--;\r
119         }\r
120         return InArray;\r
123 function WriteToInstructions(Feedback) {\r
124         document.getElementById('InstructionsDiv').innerHTML = Feedback;\r
125 [inclPreloadImages]\r
126         RefreshImages();\r
127 [/inclPreloadImages]\r
131 [inclPreloadImages]\r
132 Imgs = new Array();\r
134 function PreloadImages(){\r
135         var a = PreloadImages.arguments;\r
136         for (var i=0; i<a.length; i++){\r
137                 Imgs[i] = new Image();\r
138                 Imgs[i].src = a[i];\r
139         }\r
142 function RefreshImages(){\r
143         for (var i=0; i<document.images.length; i++){\r
144                 if (document.images[i].name.substring(0,6) != 'NavBar'){\r
145                         document.images[i].src = document.images[i].src;\r
146                 }\r
147         }\r
149 [/inclPreloadImages]\r
151 function EscapeDoubleQuotes(InString){\r
152         return InString.replace(/"/g, '&quot;')\r
155 function TrimString(InString){\r
156         var x = 0;\r
158         if (InString.length != 0) {\r
159                 while ((InString.charAt(InString.length - 1) == '\u0020') || (InString.charAt(InString.length - 1) == '\u000A') || (InString.charAt(InString.length - 1) == '\u000D')){\r
160                         InString = InString.substring(0, InString.length - 1)\r
161                 }\r
163                 while ((InString.charAt(0) == '\u0020') || (InString.charAt(0) == '\u000A') || (InString.charAt(0) == '\u000D')){\r
164                         InString = InString.substring(1, InString.length)\r
165                 }\r
167                 while (InString.indexOf('  ') != -1) {\r
168                         x = InString.indexOf('  ')\r
169                         InString = InString.substring(0, x) + InString.substring(x+1, InString.length)\r
170                  }\r
172                 return InString;\r
173         }\r
175         else {\r
176                 return '';\r
177         }\r
180 function FindLongest(InArray){\r
181         if (InArray.length < 1){return -1;}\r
183         var Longest = 0;\r
184         for (var i=1; i<InArray.length; i++){\r
185                 if (InArray[i].length > InArray[Longest].length){\r
186                         Longest = i;\r
187                 }\r
188         }\r
189         return Longest;\r
192 //UNICODE CHARACTER FUNCTIONS\r
193 function IsCombiningDiacritic(CharNum){\r
194         var Result = (((CharNum >= 0x0300)&&(CharNum <= 0x370))||((CharNum >= 0x20d0)&&(CharNum <= 0x20ff)));\r
195         Result = Result || (((CharNum >= 0x3099)&&(CharNum <= 0x309a))||((CharNum >= 0xfe20)&&(CharNum <= 0xfe23)));\r
196         return Result;\r
199 function IsCJK(CharNum){\r
200         return ((CharNum >= 0x3000)&&(CharNum < 0xd800));\r
203 //SETUP FUNCTIONS\r
204 //BROWSER WILL REFILL TEXT BOXES FROM CACHE IF NOT PREVENTED\r
205 function ClearTextBoxes(){\r
206         var NList = document.getElementsByTagName('input');\r
207         for (var i=0; i<NList.length; i++){\r
208                 if ((NList[i].id.indexOf('Guess') > -1)||(NList[i].id.indexOf('Gap') > -1)){\r
209                         NList[i].value = '';\r
210                 }\r
211                 if (NList[i].id.indexOf('Chk') > -1){\r
212                         NList[i].checked = '';\r
213                 }\r
214         }\r
217 //EXTENSION TO ARRAY OBJECT\r
218 function Array_IndexOf(Input){\r
219         var Result = -1;\r
220         for (var i=0; i<this.length; i++){\r
221                 if (this[i] == Input){\r
222                         Result = i;\r
223                 }\r
224         }\r
225         return Result;\r
227 Array.prototype.indexOf = Array_IndexOf;\r
229 //IE HAS RENDERING BUG WITH BOTTOM NAVBAR\r
230 function RemoveBottomNavBarForIE(){\r
231         if ((C.ie)&&(document.getElementById('Reading') != null)){\r
232                 if (document.getElementById('BottomNavBar') != null){\r
233                         document.getElementById('TheBody').removeChild(document.getElementById('BottomNavBar'));\r
234                 }\r
235         }\r