﻿/*--------------------------------------------------------------------------*/
/*  QueryString Object
 *  (c) 2006 Jesse Gavin <jesse@nontalk.com>
 *
 *  Depends upon:
 *  - Prototype JavaScript framework, version 1.6.0
 *    (c) 2005 Sam Stephenson <sam@conio.net> , 2008 twolf
 *
 *  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()),
    retval : null,
    get : function(key, defaultValue) {
	if (defaultValue == null) defaultValue = null;
        var value = this.params.get(key);
        if (value==null) value = defaultValue;
        return value;
    },
    
    set : function(key, value) {
		this.params.set(key,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();
    }
}
