adding some strings
[moodle-linuxchix.git] / mod / hotpot / template / v6 / hp6utilities.js_
blob2f12775229cb7b05db44125c67424e447c6b9f28
1 //GENERAL UTILITY FUNCTIONS AND VARIABLES
3 //PAGE DIMENSION FUNCTIONS
4 function PageDim(){
5 //Get the page width and height
6         this.W = 600;
7         this.H = 400;
8         this.W = document.getElementsByTagName('body')[0].clientWidth;
9         this.H = document.getElementsByTagName('body')[0].clientHeight;
12 var pg = null;
14 function GetPageXY(El) {
15         var XY = {x: 0, y: 0};
16         while(El){
17                 XY.x += El.offsetLeft;
18                 XY.y += El.offsetTop;
19                 El = El.offsetParent;
20         }
21         return XY;
24 function GetScrollTop(){
25         if (typeof(window.pageYOffset) == 'number'){
26                 return window.pageYOffset;
27         }
28         else{
29                 if ((document.body)&&(document.body.scrollTop)){
30                         return document.body.scrollTop;
31                 }
32                 else{
33                         if ((document.documentElement)&&(document.documentElement.scrollTop)){
34                                 return document.documentElement.scrollTop;
35                         }
36                         else{
37                                 return 0;
38                         }
39                 }
40         }
43 function GetViewportHeight(){
44         if (typeof window.innerHeight != 'undefined'){
45                 return window.innerHeight;
46         }
47         else{
48                 if (((typeof document.documentElement != 'undefined')&&(typeof document.documentElement.clientHeight !=
49      'undefined'))&&(document.documentElement.clientHeight != 0)){
50                         return document.documentElement.clientHeight;
51                 }
52                 else{
53                         return document.getElementsByTagName('body')[0].clientHeight;
54                 }
55         }
58 function TopSettingWithScrollOffset(TopPercent){
59         var T = Math.floor(GetViewportHeight() * (TopPercent/100));
60         return GetScrollTop() + T; 
63 //CODE FOR AVOIDING LOSS OF DATA WHEN BACKSPACE KEY INVOKES history.back()
64 var InTextBox = false;
66 function SuppressBackspace(e){ 
67         if (InTextBox == true){return;}
68         if (C.ie) {
69                 thisKey = window.event.keyCode;
70         }
71         else {
72                 thisKey = e.keyCode;
73         }
75         var Suppress = false;
77         if (thisKey == 8) {
78                 Suppress = true;
79         }
81         if (Suppress == true){
82                 if (C.ie){
83                         window.event.returnValue = false;       
84                         window.event.cancelBubble = true;
85                 }
86                 else{
87                         e.preventDefault();
88                 }
89         }
92 if (C.ie){
93         document.attachEvent('onkeydown',SuppressBackspace);
94         window.attachEvent('onkeydown',SuppressBackspace);
96 else{
97         if (window.addEventListener){
98                 window.addEventListener('keypress',SuppressBackspace,false);
99         }
102 function ReduceItems(InArray, ReduceToSize){
103         var ItemToDump=0;
104         var j=0;
105         while (InArray.length > ReduceToSize){
106                 ItemToDump = Math.floor(InArray.length*Math.random());
107                 InArray.splice(ItemToDump, 1);
108         }
111 function Shuffle(InArray){
112         var Num;
113         var Temp = new Array();
114         var Len = InArray.length;
116         var j = Len;
118         for (var i=0; i<Len; i++){
119                 Temp[i] = InArray[i];
120         }
122         for (i=0; i<Len; i++){
123                 Num = Math.floor(j  *  Math.random());
124                 InArray[i] = Temp[Num];
126                 for (var k=Num; k < (j-1); k++) {
127                         Temp[k] = Temp[k+1];
128                 }
129                 j--;
130         }
131         return InArray;
134 function WriteToInstructions(Feedback) {
135         document.getElementById('InstructionsDiv').innerHTML = Feedback;
136 [inclPreloadImages]
137         RefreshImages();
138 [/inclPreloadImages]
142 [inclPreloadImages]
143 Imgs = new Array();
145 function PreloadImages(){
146         var a = PreloadImages.arguments;
147         for (var i=0; i<a.length; i++){
148                 Imgs[i] = new Image();
149                 Imgs[i].src = a[i];
150         }
153 function RefreshImages(){
154         for (var i=0; i<document.images.length; i++){
155                 if (document.images[i].name.substring(0,6) != 'NavBar'){
156                         document.images[i].src = document.images[i].src;
157                 }
158         }
160 [/inclPreloadImages]
162 function EscapeDoubleQuotes(InString){
163         return InString.replace(/"/g, '&quot;')
166 function TrimString(InString){
167         var x = 0;
169         if (InString.length != 0) {
170                 while ((InString.charAt(InString.length - 1) == '\u0020') || (InString.charAt(InString.length - 1) == '\u000A') || (InString.charAt(InString.length - 1) == '\u000D')){
171                         InString = InString.substring(0, InString.length - 1)
172                 }
174                 while ((InString.charAt(0) == '\u0020') || (InString.charAt(0) == '\u000A') || (InString.charAt(0) == '\u000D')){
175                         InString = InString.substring(1, InString.length)
176                 }
178                 while (InString.indexOf('  ') != -1) {
179                         x = InString.indexOf('  ')
180                         InString = InString.substring(0, x) + InString.substring(x+1, InString.length)
181                  }
183                 return InString;
184         }
186         else {
187                 return '';
188         }
191 function FindLongest(InArray){
192         if (InArray.length < 1){return -1;}
194         var Longest = 0;
195         for (var i=1; i<InArray.length; i++){
196                 if (InArray[i].length > InArray[Longest].length){
197                         Longest = i;
198                 }
199         }
200         return Longest;
203 //UNICODE CHARACTER FUNCTIONS
204 function IsCombiningDiacritic(CharNum){
205         var Result = (((CharNum >= 0x0300)&&(CharNum <= 0x370))||((CharNum >= 0x20d0)&&(CharNum <= 0x20ff)));
206         Result = Result || (((CharNum >= 0x3099)&&(CharNum <= 0x309a))||((CharNum >= 0xfe20)&&(CharNum <= 0xfe23)));
207         return Result;
210 function IsCJK(CharNum){
211         return ((CharNum >= 0x3000)&&(CharNum < 0xd800));
214 //SETUP FUNCTIONS
215 //BROWSER WILL REFILL TEXT BOXES FROM CACHE IF NOT PREVENTED
216 function ClearTextBoxes(){
217         var NList = document.getElementsByTagName('input');
218         for (var i=0; i<NList.length; i++){
219                 if ((NList[i].id.indexOf('Guess') > -1)||(NList[i].id.indexOf('Gap') > -1)){
220                         NList[i].value = '';
221                 }
222                 if (NList[i].id.indexOf('Chk') > -1){
223                         NList[i].checked = '';
224                 }
225         }
228 //EXTENSION TO ARRAY OBJECT
229 function Array_IndexOf(Input){
230         var Result = -1;
231         for (var i=0; i<this.length; i++){
232                 if (this[i] == Input){
233                         Result = i;
234                 }
235         }
236         return Result;
238 Array.prototype.indexOf = Array_IndexOf;
240 //IE HAS RENDERING BUG WITH BOTTOM NAVBAR
241 function RemoveBottomNavBarForIE(){
242         if ((C.ie)&&(document.getElementById('Reading') != null)){
243                 if (document.getElementById('BottomNavBar') != null){
244                         document.getElementById('TheBody').removeChild(document.getElementById('BottomNavBar'));
245                 }
246         }