var query_string_tools = {
    revision: 1,
    percentDecode : function(s, plusAsSpace) {
        if (typeof plusAsSpace !== "boolean") {
            plusAsSpace = true;
        }
        if (plusAsSpace) {
            s = s.replace(/\+/g, " ");
        }
        try {
            return decodeURIComponent(s).replace(/\r\n|\r|\n/g, "\r\n");
        } catch (e) {
            return "percentDecoded error";
        }
    },
    getQueryStringKeyMap : function(win, caseInsensitiveMatching, ignoreEmptyValues, plusAsSpace) {
        if (typeof win === "undefined") {
            win = window;
        }
        if (typeof caseInsensitiveMatching !== "boolean") {
            caseInsenstiveMatching = true;
        }
        if (typeof ignoreEmptyValues !== "boolean") {
            ignoreEmptyValues = true;
        }
        if (typeof plusAsSpace !== "boolean") {
            plusAsSpace = true;
        }
        var qs = win.location.search;
        var multimap = {};
        if (qs.length > 1) {
            var ref = this;
            qs.substr(1).replace(/([^=&]+)=([^&]*)/g, function(match, hfname, hfvalue) {
                var name = plusAsSpace ? ref.percentDecode(hfname, true) : ref.percentDecode(hfname, false);
                var value = plusAsSpace ? ref.percentDecode(hfvalue, true) : ref.percentDecode(hfvalue, false);
                if (caseInsensitiveMatching) {
                    name = name.toLowerCase();
                }
                if (name.length > 0) {
                    if ((ignoreEmptyValues && value.length > 0) || !ignoreEmptyValues) {
                        if (!multimap.hasOwnProperty(name)) {
                            multimap[name] = [];
                        }
                        multimap[name].push(value);
                    }
                }
            });
        }
        return multimap;
    },
    getKeyValueArrayFromKeyMap : function(map, name) {
        if (map.hasOwnProperty(name)) {
            return map[name];
        }
        return [];    
    },
    getKeyValueFromKeyMap : function(map, name) {
        var arr = this.getKeyValueArrayFromKeyMap(map, name);
        if (arr.length > 0) {
            return arr[arr.length - 1];
        }
        return "";    
    }
};
//var qst = query_string_tools;
//var keys = qst.getQueryStringKeyMap();
//alert(qst.getKeyValueFromKeyMap(keys, "test"));