function NGUrl(a){this.reset();if(arguments.length>0){this.set(a)}}NGUrl.PORTS={80:"http",443:"https"};NGUrl.encode=function(b){if(!isStr(b)){if(isNull(b)||!isDef(b)){return null}try{if(isFunc(b.toString)){b=b.toString()}else{return null}}catch(a){return null}}return encodeURIComponent(b).replace(/%20/g,"+")};NGUrl.decode=function(a){if(!isStr(a)){return null}return decodeURIComponent(a.replace(/\+/g,"%20"))};NGUrl.parseUrl=function(b){var c=/^(([a-z0-9\.\+\-]+):(\/\/)?((([^#\/\?\/:]+)(:([^#\/\?\/:]*))?@)?([^#\/\?\/:]+)(:([0-9]+))?)?)?([^#\?]+)?((#(.*?))?\?([^#]*))?(#([^#\?]*)$)?$/;var a=c.exec(b);if(a===null){return null}var e={scheme:2,schemejoin:3,user:6,password:8,host:9,port:11,path:12,query:16,fragment:18};var f={};for(var d in e){if(!isFunc(e[d])){f[d]=(typeof a[e[d]]!="undefined"&&a[e[d]].length>0?a[e[d]]:null)}}if(f.port!==null&&f.port.length>5){return null}if(f.scheme!==null&&f.host===null&&f.schemejoin=="//"&&f.path[0]==="/"){f.path=f.path.substring(1);f.schemejoin+="/"}return f};NGUrl.parseVar=function(c){var b=[""];for(var a=0;a<c.length;a++){if(c.substr(a,1)=="["){b.push("")}else{if(c.substr(a,1)!="]"){b[b.length-1]+=c.substr(a,1)}}}return b};NGUrl.parseQuery=function(g){var b={};var h=g.split(/&/);var j={};for(var f,d,c,e=0;e<h.length;e++){c=h[e].split(/=/);if(c.length>0){c[0]=NGUrl.decode(c[0])}if(c.length>1){c[1]=NGUrl.decode(c[1])}if(c.length>0&&/^[^\[\]]+(\[[^\[\]]*\])+$/.test(c[0])){d=NGUrl.parseVar(c[0]);if(d[d.length-1].length==0){if(!isDef(typeof j[c[0]])){j[c[0]]=0}else{j[c[0]]++}d[d.length-1]=j[c[0]]}f=NGUrl._layPath(b,d);f[d[d.length-1]]=(c.length>1?c[1]:null)}else{b[c[0]]=(c.length>1?c[1]:null)}}return b};NGUrl.argDump=function(a){var c="";if(isArr(a)){for(var b=0;b<a.length;b++){if(c!=""){c+=", "}c+=NGUrl.argDump(a[b])}c="[ "+c+" ]"}else{if(isObj(a)){for(var b in a){if(!isFunc(a[b])){if(c!=""){c+=", "}c+=b+" : "+NGUrl.argDump(a[b])}}c="{ "+c+" }"}else{c=a}}return c};NGUrl.argToString=function(e,g){var b=[];if(!isArr(e)){e=[e]}if(isArr(g)){for(var d,c=0;c<g.length;c++){b=b.concat(NGUrl.argToString(e.concat([c]),g[c]))}}else{if(isObj(g)){for(var c in g){if(!isFunc(g[c])){b=b.concat(NGUrl.argToString(e.concat([c]),g[c]))}}}else{var f=e.shift();if(e.length>0){f+="["+e.join("][")+"]"}if(g===null){b.push(NGUrl.encode(f))}else{b.push(NGUrl.encode(f)+"="+NGUrl.encode(g))}}}return b};NGUrl.thisRequest=function(a){if(!a){a=window}return new NGUrl(a.location.href)};NGUrl.redirect=function(a,b){if(!b){b=window}b.location=a};NGUrl.prototype.reset=function(){this.scheme=this.host=this.port=this.path=this.fragment=null;this.arguments={}};NGUrl.prototype.toString=function(){var a="";if(this.scheme!==null){a+=this.scheme+":";if(this.schemejoin!==null){a+=this.schemejoin}if(this.host!==null){if(this.user!==null){a+=this.user;if(this.password!==null){a+=":"+this.password}a+="@"}a+=this.host;if(this.port!==null&&(!isDef(typeof NGUrl.PORTS[this.port])||NGUrl.PORTS[this.port]!=this.scheme.toLowerCase())){a+=":"+this.port}}}if(this.path!==null){a+=this.path}if(this.arguments!==null){var c=[];for(var b in this.arguments){if(!isFunc(this.arguments[b])){c=c.concat(NGUrl.argToString(b,this.arguments[b]))}}if(c.length>0){a+="?"+c.join("&")}}if(this.fragment!==null){a+="#"+this.fragment}return a};NGUrl.prototype.set=function(a){this.reset();var b=NGUrl.parseUrl(a);if(b===null){return false}this.scheme=b.scheme;this.schemejoin=b.schemejoin;this.user=b.user;this.password=b.password;this.host=b.host;this.port=b.port;this.path=b.path;this.fragment=b.fragment;if(b.query!==null){this.arguments=NGUrl.parseQuery(b.query)}return this.isValid()};NGUrl._layPath=function(g,c){var f=g;for(var a,e=0;e<c.length-1;e++){if(!isDef(typeof f[c[e]])){if(c[e+1]===""||c[e+1]===null){f[c[e]]=[];c[e+1]="0"}else{if(c[e+1]==="0"||c[e+1]===0){f[c[e]]=[]}else{f[c[e]]={}}}}else{if(isArr(f[c[e]])&&f[c[e]].length!=c[e+1]){if(c[e+1]===""||c[e+1]===null){c[e+1]=f[c[e]].length}else{if(c[e+1]>f[c[e]].length){a={};for(var d=0;d<f[c[e]].length;d++){a[d]=f[c[e]][d]}f[c[e]]=a}}}}f=f[c[e]]}return f};NGUrl._getPath=function(d,a){var c=d;for(var b=0;b<a.length-1;b++){if(!isDef(typeof c[a[b]])||!isObj(c[a[b]])){return null}c=c[a[b]]}return c};NGUrl._mergeArgs=function(){var b=arguments;var f=true;for(var e=0;f&&e<b.length;e++){if(!isArr(b[e])){f=false}}if(f){var d=[];for(var e=b.length-1;e>=0;e--){if(b[e].length>d.length){d=d.concat(b[e].slice(d.length-b[e].length))}}}else{var d={};for(var e=0;e<b.length;e++){if(isArr(b[e])){for(var c=0;c<b[e].length;c++){d[c]=b[e][c]}}else{for(var c in b[e]){if(!isFunc(b[e][c])){d[c]=b[e][c]}}}}}return d};NGUrl.prototype.addArgument=function(c,d,b){if(isFunc(d)){throw ("Value passed was a function in NGUrl::addArgument()")}if(isArr(c)){var a=NGUrl._layPath(this.arguments,c);c=c[c.length-1]}else{var a=this.arguments}if(!isDef(typeof a[c])||b){if(isObj(a[c])&&isObj(d)){a[c]=NGUrl._mergeArgs(a[c],d)}else{a[c]=d}}};NGUrl.flatArgs=function(c){var b=[];for(var d=0;d<c.length;d++){if(isArr(c[d])){b=b.concat(c[d])}else{b.push(c[d])}}return b};NGUrl.prototype.delArgument=function(){var a=NGUrl.flatArgs(arguments);var b=NGUrl._getPath(this.arguments,a);if(b===null||!isDef(typeof b[a[a.length-1]])){return false}delete b[a[a.length-1]];return true};NGUrl.prototype.getArgument=function(){var a=NGUrl.flatArgs(arguments);var b=NGUrl._getPath(this.arguments,a);if(b===null||!isDef(typeof b[a[a.length-1]])){return null}return b[a[a.length-1]]};NGUrl.prototype.isRelative=function(){return(this.path!==null&&this.path[0]!="/")};NGUrl.prototype.isAbsolute=function(){return !this.isRelative()};NGUrl.prototype.isValid=function(){return(this.arguments!==null)};NGUrl.prototype.redirect=function(a){NGUrl.redirect(this.toString(),a)};