fixing unicode escaping in JSON
[Evergreen.git] / Open-ILS / web / opac / common / js / 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         //if(this.data[p].length == 1)
47                 //return this.data[p][0];
48         return this.data[p];
49 }
50
51 /* returns an array of param names */
52 CGI.prototype.keys = function() {
53         return this._keys;
54 }
55
56 /* debuggin method */
57 CGI.prototype.toString = function() {
58         var string = "";
59         var keys = this.keys();
60
61         for( var k in keys ) {
62                 string += keys[k] + " : ";
63                 var params = this.param(keys[k]);
64
65                 for( var p in params ) {
66                         string +=  params[p] + " ";
67                 }
68                 string += "\n";
69         }
70         return string;
71 }
72
73