import rt 3.8.7
[freeside.git] / rt / share / html / NoAuth / js / ahah.js
1 /*
2 % $r->content_type('application/x-javascript');
3 */
4 // Fetched from http://www.opendarwin.org/~drernie/src/ahah.js - No Copyright - Public Domain
5 function ahah(url, target, delay) {
6   // document.getElementById(target).innerHTML = 'Loading <a href="'+url+'">'+url +'</a>...';
7   if (window.XMLHttpRequest) {
8     req = new XMLHttpRequest();
9   } else if (window.ActiveXObject) {
10     req = new ActiveXObject("Microsoft.XMLHTTP");
11   }
12
13   var use_get;
14   if ( /webkit|firefox\/2/i.test( navigator.userAgent ) ) {
15       // seems safari has weird problem with post: 
16       // it does remove the old content of target
17       // while doesn't replace that with new content
18       // so is firefox 2
19       use_get = 1;
20   }
21
22   if (req != undefined) {
23     req.onreadystatechange = function() {ahahDone(url, target, delay);};
24     if ( use_get == 1 ) {
25         req.open("GET", url, true);
26     }
27     else{
28         req.open("POST", url, true);
29     }
30     req.send("");
31   }
32 }  
33
34 function ahahDone(url, target, delay) {
35   if (req.readyState == 4) { // only if req is "loaded"
36     if (req.status == 200) { // only if "OK"
37       document.getElementById(target).innerHTML = req.responseText;
38     } else {
39       document.getElementById(target).innerHTML="Error loading '"+url+"':\n"+req.statusText;
40     }
41     if (delay != undefined) {
42        setTimeout("ahah(url,target,delay)", delay); // resubmit after delay
43             //server should ALSO delay before responding
44     }
45   }
46 }
47
48 % $m->abort();