1 //GENERAL UTILITY FUNCTIONS AND VARIABLES
\r
3 //PAGE DIMENSION FUNCTIONS
\r
5 //Get the page width and height
\r
8 this.W = document.getElementsByTagName('body')[0].clientWidth;
\r
9 this.H = document.getElementsByTagName('body')[0].clientHeight;
\r
14 function GetPageXY(El) {
\r
15 var XY = {x: 0, y: 0};
\r
17 XY.x += El.offsetLeft;
\r
18 XY.y += El.offsetTop;
\r
19 El = El.offsetParent;
\r
24 function GetScrollTop(){
\r
25 if (document.documentElement && document.documentElement.scrollTop){
\r
26 return document.documentElement.scrollTop;
\r
30 return document.body.scrollTop;
\r
33 return window.pageYOffset;
\r
38 function GetViewportHeight(){
\r
39 if (window.innerHeight){
\r
40 return window.innerHeight;
\r
43 return document.getElementsByTagName('body')[0].clientHeight;
\r
47 function TopSettingWithScrollOffset(TopPercent){
\r
48 var T = Math.floor(GetViewportHeight() * (TopPercent/100));
\r
49 return GetScrollTop() + T;
\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
58 thisKey = window.event.keyCode;
\r
61 thisKey = e.keyCode;
\r
64 var Suppress = false;
\r
70 if (Suppress == true){
\r
72 window.event.returnValue = false;
\r
73 window.event.cancelBubble = true;
\r
82 document.attachEvent('onkeydown',SuppressBackspace);
\r
83 window.attachEvent('onkeydown',SuppressBackspace);
\r
86 if (window.addEventListener){
\r
87 window.addEventListener('keypress',SuppressBackspace,false);
\r
91 function ReduceItems(InArray, ReduceToSize){
\r
94 while (InArray.length > ReduceToSize){
\r
95 ItemToDump = Math.floor(InArray.length*Math.random());
\r
96 InArray.splice(ItemToDump, 1);
\r
100 function Shuffle(InArray){
\r
102 var Temp = new Array();
\r
103 var Len = InArray.length;
\r
107 for (var i=0; i<Len; i++){
\r
108 Temp[i] = InArray[i];
\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
123 function WriteToInstructions(Feedback) {
\r
124 document.getElementById('InstructionsDiv').innerHTML = Feedback;
\r
125 [inclPreloadImages]
\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
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
149 [/inclPreloadImages]
\r
151 function EscapeDoubleQuotes(InString){
\r
152 return InString.replace(/"/g, '"')
\r
155 function TrimString(InString){
\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
163 while ((InString.charAt(0) == '\u0020') || (InString.charAt(0) == '\u000A') || (InString.charAt(0) == '\u000D')){
\r
164 InString = InString.substring(1, InString.length)
\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
180 function FindLongest(InArray){
\r
181 if (InArray.length < 1){return -1;}
\r
184 for (var i=1; i<InArray.length; i++){
\r
185 if (InArray[i].length > InArray[Longest].length){
\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
199 function IsCJK(CharNum){
\r
200 return ((CharNum >= 0x3000)&&(CharNum < 0xd800));
\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
211 if (NList[i].id.indexOf('Chk') > -1){
\r
212 NList[i].checked = '';
\r
217 //EXTENSION TO ARRAY OBJECT
\r
218 function Array_IndexOf(Input){
\r
220 for (var i=0; i<this.length; i++){
\r
221 if (this[i] == Input){
\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