moved js code from html to js files
[xynt.git] / commons.js
1 function $(id) { return document.getElementById(id); }
2
3 function getStyle(x,IEstyleProp, MozStyleProp) 
4 {
5     if (x.currentStyle) {
6         var y = x.currentStyle[IEstyleProp];
7     } else if (window.getComputedStyle) {
8         var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(MozStyleProp);
9     }
10     return y;
11 }
12
13   /* replacement of setInterval on IE */
14 (function(){
15     /*if not IE, do nothing*/
16     if(!document.uniqueID){return;};
17
18     /*Copy the default setInterval behavior*/
19     var nativeSetInterval = window.setInterval;
20     window.setInterval = function(fn,ms) {              
21         var param = [];
22         if(arguments.length <= 2)       {
23             return nativeSetInterval(fn,ms);
24         }
25         else {
26             for(var i=2;i<arguments.length;i+=1) {
27                 param[i-2] =  arguments[i];
28             }   
29         }
30         
31         if(typeof(fn)=='function') {
32             
33             return (function (fn,ms,param) {
34                 var fo = function () {                                                          
35                     fn.apply(window,param);
36                 };                      
37                 return nativeSetInterval(fo,ms); 
38             })(fn,ms,param);
39         }
40         else if(typeof(fn)=='string')
41         {
42             return  nativeSetInterval(fn,ms);
43         }
44         else
45         {
46             throw Error('setInterval Error\nInvalid function type');
47         };
48     };
49
50     /*Copy the default setTimeout behavior*/
51     var nativeSetTimeout = window.setTimeout;
52     window.setTimeout = function(fn,ms) {               
53         var param = [];
54         if(arguments.length <= 2)       {
55             return nativeSetTimeout(fn,ms);
56         }
57         else {
58             for(var i=2;i<arguments.length;i+=1) {
59                 param[i-2] =  arguments[i];
60             }   
61         }
62         
63         if(typeof(fn)=='function') {
64             
65             return (function (fn,ms,param) {
66                 var fo = function () {                                                          
67                     fn.apply(window,param);
68                 };                      
69                 return nativeSetTimeout(fo,ms); 
70             })(fn,ms,param);
71         }
72         else if(typeof(fn)=='string')
73         {
74             return  nativeSetTimeout(fn,ms);
75         }
76         else
77         {
78             throw Error('setTimeout Error\nInvalid function type');
79         };
80     };
81
82 })()
83
84 function getStyle(x,IEstyleProp, MozStyleProp) 
85 {
86     if (x.currentStyle) {
87         var y = x.currentStyle[IEstyleProp];
88     } else if (window.getComputedStyle) {
89         var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(MozStyleProp);
90     }
91     return y;
92 }
93
94 function doSomething(e) {
95         if (!e) var e = window.event
96         // handle event
97         e.cancelBubble = true;
98         if (e.stopPropagation) e.stopPropagation();
99 }