659df41cd5aad9e3fedb77f7cccfdea25dd8437c
[atutor.git] / docs / mods / _standard / social / lib / js / livesearch.js
1 var xmlHttp;
2
3 function showResults(str, search_id, url) {
4         if (str.length==0) { 
5           document.getElementById(search_id).innerHTML="";
6           return;
7         }
8         xmlHttp=GetXmlHttpObject();
9         if (xmlHttp==null) {
10           alert ("Browser does not support HTTP Request");
11           return;
12         } 
13
14         url=url+"?q="+str;
15         xmlHttp.onreadystatechange=stateChanged;
16         xmlHttp.open("GET",url,true);
17         xmlHttp.send(null);
18
19
20 function stateChanged() { 
21         if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
22                 document.getElementById("livesearch").innerHTML=xmlHttp.responseText;
23         } 
24 }
25
26 function GetXmlHttpObject() {
27         var xmlHttp=null;
28         try {
29                 // Firefox, Opera 8.0+, Safari
30                 xmlHttp=new XMLHttpRequest();
31         } catch (e) {
32                 // Internet Explorer
33                 try {
34                         xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
35                 } catch (e) {
36                         xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
37                 }
38         }
39         return xmlHttp;
40 }