]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/javascript/lib/js/util/CGI.js
removing old opac images and css
[working/Evergreen.git] / Open-ILS / src / javascript / lib / js / util / CGI.js
1 function CGI() {
2         /* load up the url parameters */
3
4         this._keys = new Array();
5         this.data = new Object();
6
7         var string = location.search.replace(/^\?/,"");
8
9         var key = ""; 
10         var value = "";
11         var inkey = true;
12         var invalue = false;
13
14         for( var idx = 0; idx!= string.length; idx++ ) {
15
16                 var c = string.charAt(idx);
17
18                 if( c == "=" )  {
19                         invalue = true;
20                         inkey = false;
21                         continue;
22                 } 
23
24                 if(c == "&" || c == ";") {
25                         inkey = 1;
26                         invalue = 0;
27                         this.data[key] = decodeURIComponent(value);
28                         this._keys.push(key);
29                         key = ""; value = "";
30                         continue;
31                 }
32
33                 if(inkey) key += c;
34                 else if(invalue) value += c;
35         }
36
37         this.data[key] = decodeURIComponent(value);
38         this._keys.push(key);
39 }
40
41 /* returns the value for the given param.  If there is only one value for the
42    given param, it returns that value.  Otherwise it returns an array of values
43  */
44 CGI.prototype.param = function(p) {
45         if(this.data[p] == null) return null;
46
47         if(this.data[p].length == 1)
48                 return this.data[p][0];
49         return this.data[p];
50 }
51
52 /* returns an array of param names */
53 CGI.prototype.keys = function() {
54         return this._keys;
55 }
56
57 /* debuggin method */
58 CGI.prototype.toString = function() {
59         var string = "";
60         var keys = this.keys();
61
62         for( var k in keys ) {
63                 string += keys[k] + " : ";
64                 var params = this.param(keys[k]);
65
66                 for( var p in params ) {
67                         string +=  params[p] + " ";
68                 }
69                 string += "\n";
70         }
71         return string;
72 }
73
74