/*global define: true */

define([], function () {
    "use strict";

    var trim = function (s) {
            return s.replace(/^\s+|\s+$/g, "");
        },

        getPathname = function (url) {
            var pathname = url.split('?')[0].split('#')[0].replace(/\w+:\/\/[\w\d\._\-]*/, '');
            return (pathname.match(/^\//)) ? pathname : ''; // only allow absolute urls
        },

        getQueryParams = function (url) {
            var queryParams = {},
                queryString = url.split('?')[1] || '',
                nameVals = null,
                i = null,
                nameVal = null;

            if (queryString) {
                nameVals = queryString.split('&');

                for (i = 0; i < nameVals.length; i = i + 1) {
                    nameVal = nameVals[i].split('=');
                    queryParams[trim(decodeURIComponent(nameVal[0]))] = trim(decodeURIComponent(nameVal[1]));
                }
            }

            return queryParams;
        };

    return function (url) {
        var pathname = getPathname(trim(decodeURIComponent(url))),
            queryParams = getQueryParams(url),
            pathParams = {};

        return {
            getPathname: function () {
                return pathname;
            },

            getQueryParams: function () {
                return queryParams;
            },

            getPathParams: function () {
                return pathParams;
            },

            setPathParam: function (name, val) {
                pathParams[name] = val;
            },

            getPathParam: function (name) {
                return pathParams[name] || null;
            },

            getQueryParam: function (name) {
                return queryParams[name] || null;
            },

            isSame: function (url) {
                var name, qp;

                if (pathname !== getPathname(url)) {
                    // pathname is different
                    return false;
                }

                qp = getQueryParams(url);

                for (name in queryParams) {
                    if (queryParams.hasOwnProperty(name) && (qp[name] === undefined || qp[name] !== queryParams[name])) {
                        // param is missing in qp or value is different
                        return false;
                    }
                }

                for (name in qp) {
                    if (qp.hasOwnProperty(name) && (queryParams[name] === undefined || qp[name] !== queryParams[name])) {
                        // param is missing in queryParams or value is different
                        return false;
                    }
                }

                return true;
            },

            debug: function () {
                console.log('getPathname(): ', this.getPathname());
                console.log('getQueryParams(): ', this.getQueryParams());
                console.log('getPathParams(): ', this.getPathParams());
            }
        };
    };
});
@@ -378,32 +378,138 @@
  urls%0A        %7D,
+%0A        %0A        getQueryString = function (url) %7B%0A            return url.split('?')%5B1%5D %7C%7C '';%0A        %7D,
 %0A%0A        getQue
@@ -600,39 +600,35 @@
 tring = 
-url.split('?')%5B1%5D %7C%7C ''
+getQueryString(url)
 ,%0A      
@@ -1194,16 +1194,63 @@
 url))),%0A
+            queryString = getQueryString(url),%0A
         
@@ -1415,32 +1415,138 @@
             %7D,%0A%0A
+            getQueryString: function () %7B%0A                return queryString;%0A            %7D,%0A            %0A
             getQ

Add getQueryString()