feedbrowser: import expand code from narcissus
[angstrom:feedbrowser.git] / scripts / js / repo.js
1 /* The following function creates an XMLHttpRequest object... */
2
3 function createRequestObject(){
4         var request_o; //declare the variable to hold the object.
5         var browser = navigator.appName; //find the browser name
6         if(browser == "Microsoft Internet Explorer"){
7                 /* Create the object using MSIE's method */
8                 request_o = new ActiveXObject("Microsoft.XMLHTTP");
9         } else {
10                 /* Create the object using other browser's method */
11                 request_o = new XMLHttpRequest();
12         }
13         return request_o; //return the object
14 }
15
16 /* The variable http will hold our new XMLHttpRequest object. */
17 var sectionHTTP = createRequestObject();
18 var queryHTTP = createRequestObject(); 
19 var http = createRequestObject(); 
20
21 var qsParm = new Array();
22 qsParm['pkgsearch'] = null;
23 qsParm['arch'] = null;
24 qsParm['section'] = null;
25 qsParm['pkgname'] = null;
26
27
28 function qs() {
29         var query = window.location.search.substring(1);
30         var parms = query.split('&');
31         for (var i=0; i<parms.length; i++) {
32                 var pos = parms[i].indexOf('=');
33                 if (pos > 0) {
34                         var key = parms[i].substring(0,pos);
35                         var val = parms[i].substring(pos+1);
36                         qsParm[key] = val;
37                 }
38         }
39         if (qsParm['pkgsearch']) {
40                 document.getElementById('pkgsearch').value = qsParm['pkgsearch'];
41                 pkgQuery();
42         }
43         if (qsParm['pkgname']) {
44                 document.getElementById('pkgsearch').value = qsParm['pkgname'];
45                 pkgQuery();
46         }
47         if (qsParm['section']) {
48                 pkgQuery();
49         }
50         
51 }
52
53 function pkgQuery() {
54         var action = 'pkgquery';
55         var params = '';
56         
57         if (qsParm['pkgname']) {
58                 action = 'pkgname';
59                 params = '&pkgname=' + qsParm['pkgname'];
60                 qsParm['pkgname'] = null;
61         } 
62         
63         if (document.getElementById('pkgsearch').value != "") {
64                 params = params + '&pkgsearch=' + document.getElementById('pkgsearch').value;
65         } else {
66                 if (qsParm['pkgsearch']) {
67                         params = params + '&pkgsearch=' + qsParm['pkgsearch'];
68                 }
69         }
70         if (qsParm['arch']) {
71                 params = params + '&arch=' + qsParm['arch'];
72                 qsParm['arch'] = null;
73         }
74         if (qsParm['section']) {
75                 action = 'section';
76                 params = params + '&section=' + qsParm['section'];
77                 qsParm['section'] = null;
78         }
79         
80         params = '&action=' + action + params;
81         
82         queryHTTP.open('post', 'section.php');
83         queryHTTP.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
84         queryHTTP.onreadystatechange = queryProgress; 
85         queryHTTP.send(params);
86         
87 }
88
89 function getLetter() {
90         var params = 'action=searchletter';
91         http.open('post', 'section.php');
92         http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
93         http.onreadystatechange = letterProgress; 
94         http.send(params);
95         
96
97
98 function getSection() {
99         var params = 'action=sectionslist';
100         sectionHTTP.open('post', 'section.php');
101         sectionHTTP.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
102         sectionHTTP.onreadystatechange = sectionProgress; 
103         sectionHTTP.send(params);
104         
105
106
107 function letterProgress() {
108         if(http.readyState == 4){ 
109                 var response = http.responseText;
110                 document.getElementById('searchletter').innerHTML = response;
111                 
112         }
113 }
114
115 function sectionProgress() {
116         if(sectionHTTP.readyState == 4){ 
117                 var response = sectionHTTP.responseText;
118                 document.getElementById('sectionslist').innerHTML = response;
119                 
120         }
121 }
122
123 function queryProgress() {
124         document.getElementById('opkgoutput').innerHTML = "loading, please wait";
125         if(queryHTTP.readyState == 4){ 
126                 var response = queryHTTP.responseText;
127                 document.getElementById('opkgoutput').innerHTML = response;
128                 
129         }
130 }
131
132 function toggleVisibility(elementId) {
133         var elementObj = document.getElementById(elementId);
134         if (elementObj.style.display == '') {
135                 elementObj.style.display = 'none';
136         }
137         else {
138                 elementObj.style.display = '';
139         }
140 }
141