1 //GENERAL UTILITY FUNCTIONS AND VARIABLES
3 //PAGE DIMENSION FUNCTIONS
5 //Get the page width and height
8 this.W = document.getElementsByTagName('body')[0].clientWidth;
9 this.H = document.getElementsByTagName('body')[0].clientHeight;
14 function GetPageXY(El) {
15 var XY = {x: 0, y: 0};
17 XY.x += El.offsetLeft;
24 function GetScrollTop(){
25 if (typeof(window.pageYOffset) == 'number'){
26 return window.pageYOffset;
29 if ((document.body)&&(document.body.scrollTop)){
30 return document.body.scrollTop;
33 if ((document.documentElement)&&(document.documentElement.scrollTop)){
34 return document.documentElement.scrollTop;
43 function GetViewportHeight(){
44 if (typeof window.innerHeight != 'undefined'){
45 return window.innerHeight;
48 if (((typeof document.documentElement != 'undefined')&&(typeof document.documentElement.clientHeight !=
49 'undefined'))&&(document.documentElement.clientHeight != 0)){
50 return document.documentElement.clientHeight;
53 return document.getElementsByTagName('body')[0].clientHeight;
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;}
69 thisKey = window.event.keyCode;
81 if (Suppress == true){
83 window.event.returnValue = false;
84 window.event.cancelBubble = true;
93 document.attachEvent('onkeydown',SuppressBackspace);
94 window.attachEvent('onkeydown',SuppressBackspace);
97 if (window.addEventListener){
98 window.addEventListener('keypress',SuppressBackspace,false);
102 function ReduceItems(InArray, ReduceToSize){
105 while (InArray.length > ReduceToSize){
106 ItemToDump = Math.floor(InArray.length*Math.random());
107 InArray.splice(ItemToDump, 1);
111 function Shuffle(InArray){
113 var Temp = new Array();
114 var Len = InArray.length;
118 for (var i=0; i<Len; i++){
119 Temp[i] = InArray[i];
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++) {
134 function WriteToInstructions(Feedback) {
135 document.getElementById('InstructionsDiv').innerHTML = Feedback;
145 function PreloadImages(){
146 var a = PreloadImages.arguments;
147 for (var i=0; i<a.length; i++){
148 Imgs[i] = new Image();
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;
162 function EscapeDoubleQuotes(InString){
163 return InString.replace(/"/g, '"')
166 function TrimString(InString){
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)
174 while ((InString.charAt(0) == '\u0020') || (InString.charAt(0) == '\u000A') || (InString.charAt(0) == '\u000D')){
175 InString = InString.substring(1, InString.length)
178 while (InString.indexOf(' ') != -1) {
179 x = InString.indexOf(' ')
180 InString = InString.substring(0, x) + InString.substring(x+1, InString.length)
191 function FindLongest(InArray){
192 if (InArray.length < 1){return -1;}
195 for (var i=1; i<InArray.length; i++){
196 if (InArray[i].length > InArray[Longest].length){
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)));
210 function IsCJK(CharNum){
211 return ((CharNum >= 0x3000)&&(CharNum < 0xd800));
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)){
222 if (NList[i].id.indexOf('Chk') > -1){
223 NList[i].checked = '';
228 //EXTENSION TO ARRAY OBJECT
229 function Array_IndexOf(Input){
231 for (var i=0; i<this.length; i++){
232 if (this[i] == Input){
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'));