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