﻿/*--------------------------------------------------------------------------*/
/*  QueryString Object
 *  (c) 2006 Jesse Gavin <jesse@nontalk.com>
 *
 *  Depends upon:
 *  - Prototype JavaScript framework, version 1.4.0
 *    (c) 2005 Sam Stephenson <sam@conio.net>
 *
 *  This script is freely distributable under the terms of an MIT-style license.
 *  For details, see: http://code.nontalk.com/
 *
/*--------------------------------------------------------------------------*/

var QueryString = {
    params : $H(window.location.search.toQueryParams()),
    
    get : function(key, defaultValue) {
        if (defaultValue == null) defaultValue = null;
        var value = this.params[key]
        if (value==null) value = defaultValue;
        return value;
    },
    
    set : function(key, value) {
        this.params[key] = encodeURIComponent(value);
    },
    
    remove : function(key) {
        this.params = this.params.collect(function(param) {
            if (key != param.key) return param;
        }).compact();
    },
    
    make : function() {
        return "?" + this.params.collect(function(param) {
            return escape(param.key) +"="+ escape(param.value);
        }).join("&");
    },
    
    go : function() {
        window.location.href = location.pathname + this.make();
    }
}
