text changes to registration mail content
[namibia] / public / ape-source / Core / Utility.js
1 String.implement({
2
3         addSlashes: function(){
4                 return this.replace(/("|'|\\|\0)/g, '\\$1');
5         },
6
7         stripSlashes: function(){
8                 return this.replace(/\\("|'|\\|\0)/g, '$1');
9         }
10 });
11
12 var B64 = new Hash({
13
14         $p: '=',
15         $tab: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
16
17         /***
18          * Base 64 encode / Base 64 decode
19          * Taken from orbited project - http://www.orbited.org
20          */
21         encode: function(ba){
22                 //  Encode a string as a base64-encoded string
23                 var s = [], l = ba.length;
24                 var rm = l%3;
25                 var x = l - rm;
26                 var t;
27                 for (var i = 0; i < x;){
28                         t = ba.charCodeAt(i++)<<16|ba.charCodeAt(i++)<<8|ba.charCodeAt(i++);
29                         s.push(B64.$tab.charAt((t>>>18)&0x3f)); 
30                         s.push(B64.$tab.charAt((t>>>12)&0x3f));
31                         s.push(B64.$tab.charAt((t>>>6)&0x3f));
32                         s.push(B64.$tab.charAt(t&0x3f));
33                 }
34                 // deal with trailers, based on patch from Peter Wood.
35                 switch (rm){
36                         case 2:
37                                 t = ba.charCodeAt(i++)<<16|ba.charCodeAt(i++)<<8;
38                                 s.push(B64.$tab.charAt((t>>>18)&0x3f));
39                                 s.push(B64.$tab.charAt((t>>>12)&0x3f));
40                                 s.push(B64.$tab.charAt((t>>>6)&0x3f));
41                                 s.push(B64.$p);
42                         break;
43                         case 1:
44                                 t = ba.charCodeAt(i++)<<16;
45                                 s.push(B64.$tab.charAt((t>>>18)&0x3f));
46                                 s.push(B64.$tab.charAt((t>>>12)&0x3f));
47                                 s.push(B64.$p);
48                                 s.push(B64.$p);
49                         break;
50                 }
51
52                 return s.join(''); // string
53         },
54
55         decode: function(str){
56                 var s = str.split(''), out = [];
57                 var l = s.length;
58                 var tl = 0;
59                 while(s[--l] == B64.$p){ ++tl; } // strip off trailing padding
60                 for (var i = 0; i < l;){
61                         var t = B64.$tab.indexOf(s[i++])<<18;
62                         if(i <= l) t|=B64.$tab.indexOf(s[i++])<<12;
63                         if(i <= l) t|=B64.$tab.indexOf(s[i++])<<6;
64                         if(i <= l) t|=B64.$tab.indexOf(s[i++]);
65                         out.push(String.fromCharCode((t>>>16)&0xff));
66                         out.push(String.fromCharCode((t>>>8)&0xff));
67                         out.push(String.fromCharCode(t&0xff));
68                 }
69                 // strip off trailing padding
70                 while(tl--){ out.pop(); }
71                 return out.join(''); //  string
72         }
73 });
74 try {
75         //Avoid showing error if window.parent.setInterval() is not working (ie : permission denied)
76         window.parent.setInterval();
77
78         //Override setInterval to be done outside the frame (there is some issue inside the frame with FF3 and WebKit)
79         if (!Browser.Engine.trident && !Browser.Engine.presto && !(Browser.Engine.gecko && Browser.Engine.version<=18)) {
80                 setInterval = function(fn,time) {
81                         return window.parent.setInterval(fn, time);
82                 };
83                 
84                 setTimeout = function(fn,time) {
85                         return window.parent.setTimeout(fn, time);
86                 };
87                 
88                 clearInterval = function(id) {
89                         return window.parent.clearInterval(id);
90                 };
91                 
92                 clearTimeout = function(id) {
93                         return window.parent.clearTimeout(id);
94                 };
95         }
96 } catch (e) {};