function QueryString(url) {
    /// <summary>
    ///     Extract query string parmaeters from given url
    ///     and save in a dictionary
    /// </summary>
    /// <returns type="String" />
    /// <param name="url" type="String">
    ///     The url to find the querystring in.
    /// </param>

    // constant values
    var queryStringSeparator = "?";
    var queryStringParameterSeparator = "&";
    var keyValueSeparator = "=";

    // if url contains ?
    if (url.indexOf(queryStringSeparator) > -1) {
        this.q = url.split(queryStringSeparator)[1];
    } else {
        this.q = null;
    }

    // This dictionary will save all the query string parameters
    this.keyValuePairs = [];

    // Only deal if query is non-null/undefined
    if (this.q) {

        // Split query with ampersand sign, the query string separator
        var queryParameters = this.q.split(queryStringParameterSeparator);

        // Fill the keyValuePairs dictionary from query
        for (var i = 0; i < queryParameters.length; i++) {

            // Get the current queryParameter in the loop
            var queryParam = queryParameters[i].split(keyValueSeparator);

            // Save the key and its value in the dictionary
            this.keyValuePairs[queryParam[0]] = queryParam[1];
        }
    }
    
    

    this.get = function(key) {
        /// <summary>
        ///     Gets the value associated with the specified key. If the specified key is not
        ///     found, 'undefined' is returned
        /// </summary>
        /// <returns type="String" />
        /// <param name="key" type="String">
        ///     The key of the value to get.
        /// </param>

        // Return the value of specified key from dictionary
        return this.keyValuePairs[key];
    };
}

function getQueryString(key, url) {
    /// <summary>
    ///     Gets the value associated with the specified key. If the specified key is not
    ///     found, 'undefined' is returned
    /// </summary>
    /// <returns type="String" />
    /// <param name="key" type="String">
    ///     The key of the value to get.
    /// </param>
    /// <param name="url" type="String" optional="true">
    ///     The Url to find the querystring in. The default value is window.location
    /// </param>


    // Set the default value of url, if not defined.
    if (!url) {
        // Get the current window url
        url = window.location;
    }

    // Crate new object of QueryString
    var query = new QueryString(url);

    // Get the value from
    var val = query.get(key);

    // Return the unescaped value
    return unescape(unescape(val));
}

function SetQueryStringParamValue(key, url, newvalue) {

    // Set the default value of url, if not defined.
    if (!url) {
        // Get the current window url
        url = window.location;
    }
    var oldvalue = getQueryString(key, url);
    if (oldvalue == "undefined")
        url = url +"&"+key+"=" + newvalue;
    else
    url = url.replace(key+"="+oldvalue,key+"="+newvalue);
    return unescape(url);
}