/*! http://mths.be/punycode v1.2.3 by @mathias */

/*!
 * URI.js - Mutating URLs
 * IPv6 Support
 *
 * Version: 1.11.2
 *
 * Author: Rodney Rehm
 * Web: http://medialize.github.com/URI.js/
 *
 * Licensed under
 *   MIT License http://www.opensource.org/licenses/mit-license
 *   GPL v3 http://opensource.org/licenses/GPL-3.0
 *
 */

/*!
 * URI.js - Mutating URLs
 * Second Level Domain (SLD) Support
 *
 * Version: 1.11.2
 *
 * Author: Rodney Rehm
 * Web: http://medialize.github.com/URI.js/
 *
 * Licensed under
 *   MIT License http://www.opensource.org/licenses/mit-license
 *   GPL v3 http://opensource.org/licenses/GPL-3.0
 *
 */

/*!
 * URI.js - Mutating URLs
 *
 * Version: 1.11.2
 *
 * Author: Rodney Rehm
 * Web: http://medialize.github.com/URI.js/
 *
 * Licensed under
 *   MIT License http://www.opensource.org/licenses/mit-license
 *   GPL v3 http://opensource.org/licenses/GPL-3.0
 *
 */

(function(e){function S(e){throw RangeError(g[e])}function x(e,t){var n=e.length;while(n--)e[n]=t(e[n]);return e}function T(e,t){return x(e.split(m),t).join(".")}function N(e){var t=[],n=0,r=e.length,i,s;while(n<r)i=e.charCodeAt(n++),i>=55296&&i<=56319&&n<r?(s=e.charCodeAt(n++),(s&64512)==56320?t.push(((i&1023)<<10)+(s&1023)+65536):(t.push(i),n--)):t.push(i);return t}function C(e){return x(e,function(e){var t="";return e>65535&&(e-=65536,t+=w(e>>>10&1023|55296),e=56320|e&1023),t+=w(e),t}).join("")}function k(e){return e-48<10?e-22:e-65<26?e-65:e-97<26?e-97:o}function L(e,t){return e+22+75*(e<26)-((t!=0)<<5)}function A(e,t,n){var r=0;e=n?b(e/l):e>>1,e+=b(e/t);for(;e>y*a>>1;r+=o)e=b(e/y);return b(r+(y+1)*e/(e+f))}function O(e){var t=[],n=e.length,r,i=0,f=h,l=c,d,v,m,g,y,w,E,x,T,N;d=e.lastIndexOf(p),d<0&&(d=0);for(v=0;v<d;++v)e.charCodeAt(v)>=128&&S("not-basic"),t.push(e.charCodeAt(v));for(m=d>0?d+1:0;m<n;){for(g=i,y=1,w=o;;w+=o){m>=n&&S("invalid-input"),E=k(e.charCodeAt(m++)),(E>=o||E>b((s-i)/y))&&S("overflow"),i+=E*y,x=w<=l?u:w>=l+a?a:w-l;if(E<x)break;N=o-x,y>b(s/N)&&S("overflow"),y*=N}r=t.length+1,l=A(i-g,r,g==0),b(i/r)>s-f&&S("overflow"),f+=b(i/r),i%=r,t.splice(i++,0,f)}return C(t)}function M(e){var t,n,r,i,f,l,d,v,m,g,y,E=[],x,T,C,k;e=N(e),x=e.length,t=h,n=0,f=c;for(l=0;l<x;++l)y=e[l],y<128&&E.push(w(y));r=i=E.length,i&&E.push(p);while(r<x){for(d=s,l=0;l<x;++l)y=e[l],y>=t&&y<d&&(d=y);T=r+1,d-t>b((s-n)/T)&&S("overflow"),n+=(d-t)*T,t=d;for(l=0;l<x;++l){y=e[l],y<t&&++n>s&&S("overflow");if(y==t){for(v=n,m=o;;m+=o){g=m<=f?u:m>=f+a?a:m-f;if(v<g)break;k=v-g,C=o-g,E.push(w(L(g+k%C,0))),v=b(k/C)}E.push(w(L(v,0))),f=A(n,T,r==i),n=0,++r}}++n,++t}return E.join("")}function _(e){return T(e,function(e){return d.test(e)?O(e.slice(4).toLowerCase()):e})}function D(e){return T(e,function(e){return v.test(e)?"xn--"+M(e):e})}var t=typeof exports=="object"&&exports,n=typeof module=="object"&&module&&module.exports==t&&module,r=typeof global=="object"&&global;if(r.global===r||r.window===r)e=r;var i,s=2147483647,o=36,u=1,a=26,f=38,l=700,c=72,h=128,p="-",d=/^xn--/,v=/[^ -~]/,m=/\x2E|\u3002|\uFF0E|\uFF61/g,g={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},y=o-u,b=Math.floor,w=String.fromCharCode,E;i={version:"1.2.3",ucs2:{decode:N,encode:C},decode:O,encode:M,toASCII:D,toUnicode:_};if(typeof define=="function"&&typeof define.amd=="object"&&define.amd)define("punycode",[],function(){return i});else if(t&&!t.nodeType)if(n)n.exports=i;else for(E in i)i.hasOwnProperty(E)&&(t[E]=i[E]);else e.punycode=i})(this),function(e,t){typeof exports=="object"?module.exports=t():typeof define=="function"&&define.amd?define("IPv6",t):e.IPv6=t(e)}(this,function(e){function n(e){var t=e.toLowerCase(),n=t.split(":"),r=n.length,i=8;n[0]===""&&n[1]===""&&n[2]===""?(n.shift(),n.shift()):n[0]===""&&n[1]===""?n.shift():n[r-1]===""&&n[r-2]===""&&n.pop(),r=n.length,n[r-1].indexOf(".")!==-1&&(i=7);var s;for(s=0;s<r;s++)if(n[s]==="")break;if(s<i){n.splice(s,1,"0000");while(n.length<i)n.splice(s,0,"0000");r=n.length}var o;for(var u=0;u<i;u++){o=n[u].split("");for(var a=0;a<3;a++){if(!(o[0]==="0"&&o.length>1))break;o.splice(0,1)}n[u]=o.join("")}var f=-1,l=0,c=0,h=-1,p=!1;for(u=0;u<i;u++)p?n[u]==="0"?c+=1:(p=!1,c>l&&(f=h,l=c)):n[u]=="0"&&(p=!0,h=u,c=1);c>l&&(f=h,l=c),l>1&&n.splice(f,l,""),r=n.length;var d="";n[0]===""&&(beststr=":");for(u=0;u<r;u++){d+=n[u];if(u===r-1)break;d+=":"}return n[r-1]===""&&(d+=":"),d}function r(){return e.IPv6===this&&(e.IPv6=t),this}var t=e&&e.IPv6;return{best:n,noConflict:r}}),function(e,t){typeof exports=="object"?module.exports=t():typeof define=="function"&&define.amd?define("SecondLevelDomains",t):e.SecondLevelDomains=t(e)}(this,function(e){var t=e&&e.SecondLevelDomains,n=Object.prototype.hasOwnProperty,r={list:{ac:"com|gov|mil|net|org",ae:"ac|co|gov|mil|name|net|org|pro|sch",af:"com|edu|gov|net|org",al:"com|edu|gov|mil|net|org",ao:"co|ed|gv|it|og|pb",ar:"com|edu|gob|gov|int|mil|net|org|tur",at:"ac|co|gv|or",au:"asn|com|csiro|edu|gov|id|net|org",ba:"co|com|edu|gov|mil|net|org|rs|unbi|unmo|unsa|untz|unze",bb:"biz|co|com|edu|gov|info|net|org|store|tv",bh:"biz|cc|com|edu|gov|info|net|org",bn:"com|edu|gov|net|org",bo:"com|edu|gob|gov|int|mil|net|org|tv",br:"adm|adv|agr|am|arq|art|ato|b|bio|blog|bmd|cim|cng|cnt|com|coop|ecn|edu|eng|esp|etc|eti|far|flog|fm|fnd|fot|fst|g12|ggf|gov|imb|ind|inf|jor|jus|lel|mat|med|mil|mus|net|nom|not|ntr|odo|org|ppg|pro|psc|psi|qsl|rec|slg|srv|tmp|trd|tur|tv|vet|vlog|wiki|zlg",bs:"com|edu|gov|net|org",bz:"du|et|om|ov|rg",ca:"ab|bc|mb|nb|nf|nl|ns|nt|nu|on|pe|qc|sk|yk",ck:"biz|co|edu|gen|gov|info|net|org",cn:"ac|ah|bj|com|cq|edu|fj|gd|gov|gs|gx|gz|ha|hb|he|hi|hl|hn|jl|js|jx|ln|mil|net|nm|nx|org|qh|sc|sd|sh|sn|sx|tj|tw|xj|xz|yn|zj",co:"com|edu|gov|mil|net|nom|org",cr:"ac|c|co|ed|fi|go|or|sa",cy:"ac|biz|com|ekloges|gov|ltd|name|net|org|parliament|press|pro|tm","do":"art|com|edu|gob|gov|mil|net|org|sld|web",dz:"art|asso|com|edu|gov|net|org|pol",ec:"com|edu|fin|gov|info|med|mil|net|org|pro",eg:"com|edu|eun|gov|mil|name|net|org|sci",er:"com|edu|gov|ind|mil|net|org|rochest|w",es:"com|edu|gob|nom|org",et:"biz|com|edu|gov|info|name|net|org",fj:"ac|biz|com|info|mil|name|net|org|pro",fk:"ac|co|gov|net|nom|org",fr:"asso|com|f|gouv|nom|prd|presse|tm",gg:"co|net|org",gh:"com|edu|gov|mil|org",gn:"ac|com|gov|net|org",gr:"com|edu|gov|mil|net|org",gt:"com|edu|gob|ind|mil|net|org",gu:"com|edu|gov|net|org",hk:"com|edu|gov|idv|net|org",id:"ac|co|go|mil|net|or|sch|web",il:"ac|co|gov|idf|k12|muni|net|org","in":"ac|co|edu|ernet|firm|gen|gov|i|ind|mil|net|nic|org|res",iq:"com|edu|gov|i|mil|net|org",ir:"ac|co|dnssec|gov|i|id|net|org|sch",it:"edu|gov",je:"co|net|org",jo:"com|edu|gov|mil|name|net|org|sch",jp:"ac|ad|co|ed|go|gr|lg|ne|or",ke:"ac|co|go|info|me|mobi|ne|or|sc",kh:"com|edu|gov|mil|net|org|per",ki:"biz|com|de|edu|gov|info|mob|net|org|tel",km:"asso|com|coop|edu|gouv|k|medecin|mil|nom|notaires|pharmaciens|presse|tm|veterinaire",kn:"edu|gov|net|org",kr:"ac|busan|chungbuk|chungnam|co|daegu|daejeon|es|gangwon|go|gwangju|gyeongbuk|gyeonggi|gyeongnam|hs|incheon|jeju|jeonbuk|jeonnam|k|kg|mil|ms|ne|or|pe|re|sc|seoul|ulsan",kw:"com|edu|gov|net|org",ky:"com|edu|gov|net|org",kz:"com|edu|gov|mil|net|org",lb:"com|edu|gov|net|org",lk:"assn|com|edu|gov|grp|hotel|int|ltd|net|ngo|org|sch|soc|web",lr:"com|edu|gov|net|org",lv:"asn|com|conf|edu|gov|id|mil|net|org",ly:"com|edu|gov|id|med|net|org|plc|sch",ma:"ac|co|gov|m|net|org|press",mc:"asso|tm",me:"ac|co|edu|gov|its|net|org|priv",mg:"com|edu|gov|mil|nom|org|prd|tm",mk:"com|edu|gov|inf|name|net|org|pro",ml:"com|edu|gov|net|org|presse",mn:"edu|gov|org",mo:"com|edu|gov|net|org",mt:"com|edu|gov|net|org",mv:"aero|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro",mw:"ac|co|com|coop|edu|gov|int|museum|net|org",mx:"com|edu|gob|net|org",my:"com|edu|gov|mil|name|net|org|sch",nf:"arts|com|firm|info|net|other|per|rec|store|web",ng:"biz|com|edu|gov|mil|mobi|name|net|org|sch",ni:"ac|co|com|edu|gob|mil|net|nom|org",np:"com|edu|gov|mil|net|org",nr:"biz|com|edu|gov|info|net|org",om:"ac|biz|co|com|edu|gov|med|mil|museum|net|org|pro|sch",pe:"com|edu|gob|mil|net|nom|org|sld",ph:"com|edu|gov|i|mil|net|ngo|org",pk:"biz|com|edu|fam|gob|gok|gon|gop|gos|gov|net|org|web",pl:"art|bialystok|biz|com|edu|gda|gdansk|gorzow|gov|info|katowice|krakow|lodz|lublin|mil|net|ngo|olsztyn|org|poznan|pwr|radom|slupsk|szczecin|torun|warszawa|waw|wroc|wroclaw|zgora",pr:"ac|biz|com|edu|est|gov|info|isla|name|net|org|pro|prof",ps:"com|edu|gov|net|org|plo|sec",pw:"belau|co|ed|go|ne|or",ro:"arts|com|firm|info|nom|nt|org|rec|store|tm|www",rs:"ac|co|edu|gov|in|org",sb:"com|edu|gov|net|org",sc:"com|edu|gov|net|org",sh:"co|com|edu|gov|net|nom|org",sl:"com|edu|gov|net|org",st:"co|com|consulado|edu|embaixada|gov|mil|net|org|principe|saotome|store",sv:"com|edu|gob|org|red",sz:"ac|co|org",tr:"av|bbs|bel|biz|com|dr|edu|gen|gov|info|k12|name|net|org|pol|tel|tsk|tv|web",tt:"aero|biz|cat|co|com|coop|edu|gov|info|int|jobs|mil|mobi|museum|name|net|org|pro|tel|travel",tw:"club|com|ebiz|edu|game|gov|idv|mil|net|org",mu:"ac|co|com|gov|net|or|org",mz:"ac|co|edu|gov|org",na:"co|com",nz:"ac|co|cri|geek|gen|govt|health|iwi|maori|mil|net|org|parliament|school",pa:"abo|ac|com|edu|gob|ing|med|net|nom|org|sld",pt:"com|edu|gov|int|net|nome|org|publ",py:"com|edu|gov|mil|net|org",qa:"com|edu|gov|mil|net|org",re:"asso|com|nom",ru:"ac|adygeya|altai|amur|arkhangelsk|astrakhan|bashkiria|belgorod|bir|bryansk|buryatia|cbg|chel|chelyabinsk|chita|chukotka|chuvashia|com|dagestan|e-burg|edu|gov|grozny|int|irkutsk|ivanovo|izhevsk|jar|joshkar-ola|kalmykia|kaluga|kamchatka|karelia|kazan|kchr|kemerovo|khabarovsk|khakassia|khv|kirov|koenig|komi|kostroma|kranoyarsk|kuban|kurgan|kursk|lipetsk|magadan|mari|mari-el|marine|mil|mordovia|mosreg|msk|murmansk|nalchik|net|nnov|nov|novosibirsk|nsk|omsk|orenburg|org|oryol|penza|perm|pp|pskov|ptz|rnd|ryazan|sakhalin|samara|saratov|simbirsk|smolensk|spb|stavropol|stv|surgut|tambov|tatarstan|tom|tomsk|tsaritsyn|tsk|tula|tuva|tver|tyumen|udm|udmurtia|ulan-ude|vladikavkaz|vladimir|vladivostok|volgograd|vologda|voronezh|vrn|vyatka|yakutia|yamal|yekaterinburg|yuzhno-sakhalinsk",rw:"ac|co|com|edu|gouv|gov|int|mil|net",sa:"com|edu|gov|med|net|org|pub|sch",sd:"com|edu|gov|info|med|net|org|tv",se:"a|ac|b|bd|c|d|e|f|g|h|i|k|l|m|n|o|org|p|parti|pp|press|r|s|t|tm|u|w|x|y|z",sg:"com|edu|gov|idn|net|org|per",sn:"art|com|edu|gouv|org|perso|univ",sy:"com|edu|gov|mil|net|news|org",th:"ac|co|go|in|mi|net|or",tj:"ac|biz|co|com|edu|go|gov|info|int|mil|name|net|nic|org|test|web",tn:"agrinet|com|defense|edunet|ens|fin|gov|ind|info|intl|mincom|nat|net|org|perso|rnrt|rns|rnu|tourism",tz:"ac|co|go|ne|or",ua:"biz|cherkassy|chernigov|chernovtsy|ck|cn|co|com|crimea|cv|dn|dnepropetrovsk|donetsk|dp|edu|gov|if|in|ivano-frankivsk|kh|kharkov|kherson|khmelnitskiy|kiev|kirovograd|km|kr|ks|kv|lg|lugansk|lutsk|lviv|me|mk|net|nikolaev|od|odessa|org|pl|poltava|pp|rovno|rv|sebastopol|sumy|te|ternopil|uzhgorod|vinnica|vn|zaporizhzhe|zhitomir|zp|zt",ug:"ac|co|go|ne|or|org|sc",uk:"ac|bl|british-library|co|cym|gov|govt|icnet|jet|lea|ltd|me|mil|mod|national-library-scotland|nel|net|nhs|nic|nls|org|orgn|parliament|plc|police|sch|scot|soc",us:"dni|fed|isa|kids|nsn",uy:"com|edu|gub|mil|net|org",ve:"co|com|edu|gob|info|mil|net|org|web",vi:"co|com|k12|net|org",vn:"ac|biz|com|edu|gov|health|info|int|name|net|org|pro",ye:"co|com|gov|ltd|me|net|org|plc",yu:"ac|co|edu|gov|org",za:"ac|agric|alt|bourse|city|co|cybernet|db|edu|gov|grondar|iaccess|imt|inca|landesign|law|mil|net|ngo|nis|nom|olivetti|org|pix|school|tm|web",zm:"ac|co|com|edu|gov|net|org|sch"},has_expression:null,is_expression:null,has:function(e){return!!e.match(r.has_expression)},is:function(e){return!!e.match(r.is_expression)},get:function(e){var t=e.match(r.has_expression);return t&&t[1]||null},noConflict:function(){return e.SecondLevelDomains===this&&(e.SecondLevelDomains=t),this},init:function(){var e="";for(var t in r.list){if(!n.call(r.list,t))continue;var i="("+r.list[t]+")."+t;e+="|("+i+")"}r.has_expression=new RegExp("\\.("+e.substr(1)+")$","i"),r.is_expression=new RegExp("^("+e.substr(1)+")$","i")}};return r.init(),r}),function(e,t){typeof exports=="object"?module.exports=t(require("./punycode"),require("./IPv6"),require("./SecondLevelDomains")):typeof define=="function"&&define.amd?define("URI",["./punycode","./IPv6","./SecondLevelDomains"],t):e.URI=t(e.punycode,e.IPv6,e.SecondLevelDomains,e)}(this,function(e,t,n,r){function s(e,t){return this instanceof s?(e===undefined&&(typeof location!="undefined"?e=location.href+"":e=""),this.href(e),t!==undefined?this.absoluteTo(t):this):new s(e,t)}function a(e){return e.replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")}function f(e){return e===undefined?"Undefined":String(Object.prototype.toString.call(e)).slice(8,-1)}function l(e){return f(e)==="Array"}function c(e,t){var n={},r,i;if(l(t))for(r=0,i=t.length;r<i;r++)n[t[r]]=!0;else n[t]=!0;for(r=0,i=e.length;r<i;r++)n[e[r]]!==undefined&&(e.splice(r,1),i--,r--);return e}function h(e,t){var n,r;if(l(t)){for(n=0,r=t.length;n<r;n++)if(!h(e,t[n]))return!1;return!0}var i=f(t);for(n=0,r=e.length;n<r;n++)if(i==="RegExp"){if(typeof e[n]=="string"&&e[n].match(t))return!0}else if(e[n]===t)return!0;return!1}function p(e,t){if(!l(e)||!l(t))return!1;if(e.length!==t.length)return!1;e.sort(),t.sort();for(var n=0,r=e.length;n<r;n++)if(e[n]!==t[n])return!1;return!0}function d(e){return escape(e)}function v(e){return encodeURIComponent(e).replace(/[!'()*]/g,d).replace(/\*/g,"%2A")}var i=r&&r.URI,o=s.prototype,u=Object.prototype.hasOwnProperty;s._parts=function(){return{protocol:null,username:null,password:null,hostname:null,urn:null,port:null,path:null,query:null,fragment:null,duplicateQueryParameters:s.duplicateQueryParameters,escapeQuerySpace:s.escapeQuerySpace}},s.duplicateQueryParameters=!1,s.escapeQuerySpace=!0,s.protocol_expression=/^[a-z][a-z0-9-+-]*$/i,s.idn_expression=/[^a-z0-9\.-]/i,s.punycode_expression=/(xn--)/i,s.ip4_expression=/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/,s.ip6_expression=/^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$/,s.find_uri_expression=/\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/ig,s.defaultPorts={http:"80",https:"443",ftp:"21",gopher:"70",ws:"80",wss:"443"},s.invalid_hostname_characters=/[^a-zA-Z0-9\.-]/,s.domAttributes={a:"href",blockquote:"cite",link:"href",base:"href",script:"src",form:"action",img:"src",area:"href",iframe:"src",embed:"src",source:"src",track:"src",input:"src"},s.getDomAttribute=function(e){if(!e||!e.nodeName)return undefined;var t=e.nodeName.toLowerCase();return t==="input"&&e.type!=="image"?undefined:s.domAttributes[t]},s.encode=v,s.decode=decodeURIComponent,s.iso8859=function(){s.encode=escape,s.decode=unescape},s.unicode=function(){s.encode=v,s.decode=decodeURIComponent},s.characters={pathname:{encode:{expression:/%(24|26|2B|2C|3B|3D|3A|40)/ig,map:{"%24":"$","%26":"&","%2B":"+","%2C":",","%3B":";","%3D":"=","%3A":":","%40":"@"}},decode:{expression:/[\/\?#]/g,map:{"/":"%2F","?":"%3F","#":"%23"}}},reserved:{encode:{expression:/%(21|23|24|26|27|28|29|2A|2B|2C|2F|3A|3B|3D|3F|40|5B|5D)/ig,map:{"%3A":":","%2F":"/","%3F":"?","%23":"#","%5B":"[","%5D":"]","%40":"@","%21":"!","%24":"$","%26":"&","%27":"'","%28":"(","%29":")","%2A":"*","%2B":"+","%2C":",","%3B":";","%3D":"="}}}},s.encodeQuery=function(e,t){var n=s.encode(e+"");return t?n.replace(/%20/g,"+"):n},s.decodeQuery=function(e,t){e+="";try{return s.decode(t?e.replace(/\+/g,"%20"):e)}catch(n){return e}},s.recodePath=function(e){var t=(e+"").split("/");for(var n=0,r=t.length;n<r;n++)t[n]=s.encodePathSegment(s.decode(t[n]));return t.join("/")},s.decodePath=function(e){var t=(e+"").split("/");for(var n=0,r=t.length;n<r;n++)t[n]=s.decodePathSegment(t[n]);return t.join("/")};var m={encode:"encode",decode:"decode"},g,y=function(e,t){return function(n){return s[t](n+"").replace(s.characters[e][t].expression,function(n){return s.characters[e][t].map[n]})}};for(g in m)s[g+"PathSegment"]=y("pathname",m[g]);s.encodeReserved=y("reserved","encode"),s.parse=function(e,t){var n;return t||(t={}),n=e.indexOf("#"),n>-1&&(t.fragment=e.substring(n+1)||null,e=e.substring(0,n)),n=e.indexOf("?"),n>-1&&(t.query=e.substring(n+1)||null,e=e.substring(0,n)),e.substring(0,2)==="//"?(t.protocol=null,e=e.substring(2),e=s.parseAuthority(e,t)):(n=e.indexOf(":"),n>-1&&(t.protocol=e.substring(0,n)||null,t.protocol&&!t.protocol.match(s.protocol_expression)?t.protocol=undefined:t.protocol==="file"?e=e.substring(n+3):e.substring(n+1,n+3)==="//"?(e=e.substring(n+3),e=s.parseAuthority(e,t)):(e=e.substring(n+1),t.urn=!0))),t.path=e,t},s.parseHost=function(e,t){var n=e.indexOf("/"),r,i;return n===-1&&(n=e.length),e.charAt(0)==="["?(r=e.indexOf("]"),t.hostname=e.substring(1,r)||null,t.port=e.substring(r+2,n)||null):e.indexOf(":")!==e.lastIndexOf(":")?(t.hostname=e.substring(0,n)||null,t.port=null):(i=e.substring(0,n).split(":"),t.hostname=i[0]||null,t.port=i[1]||null),t.hostname&&e.substring(n).charAt(0)!=="/"&&(n++,e="/"+e),e.substring(n)||"/"},s.parseAuthority=function(e,t){return e=s.parseUserinfo(e,t),s.parseHost(e,t)},s.parseUserinfo=function(e,t){var n=e.indexOf("/"),r=n>-1?e.lastIndexOf("@",n):e.indexOf("@"),i;return r>-1&&(n===-1||r<n)?(i=e.substring(0,r).split(":"),t.username=i[0]?s.decode(i[0]):null,i.shift(),t.password=i[0]?s.decode(i.join(":")):null,e=e.substring(r+1)):(t.username=null,t.password=null),e},s.parseQuery=function(e,t){if(!e)return{};e=e.replace(/&+/g,"&").replace(/^\?*&*|&+$/g,"");if(!e)return{};var n={},r=e.split("&"),i=r.length,o,u,a;for(var f=0;f<i;f++)o=r[f].split("="),u=s.decodeQuery(o.shift(),t),a=o.length?s.decodeQuery(o.join("="),t):null,n[u]?(typeof n[u]=="string"&&(n[u]=[n[u]]),n[u].push(a)):n[u]=a;return n},s.build=function(e){var t="";return e.protocol&&(t+=e.protocol+":"),!e.urn&&(t||e.hostname)&&(t+="//"),t+=s.buildAuthority(e)||"",typeof e.path=="string"&&(e.path.charAt(0)!=="/"&&typeof e.hostname=="string"&&(t+="/"),t+=e.path),typeof e.query=="string"&&e.query&&(t+="?"+e.query),typeof e.fragment=="string"&&e.fragment&&(t+="#"+e.fragment),t},s.buildHost=function(e){var t="";return e.hostname?(s.ip6_expression.test(e.hostname)?e.port?t+="["+e.hostname+"]:"+e.port:t+=e.hostname:(t+=e.hostname,e.port&&(t+=":"+e.port)),t):""},s.buildAuthority=function(e){return s.buildUserinfo(e)+s.buildHost(e)},s.buildUserinfo=function(e){var t="";return e.username&&(t+=s.encode(e.username),e.password&&(t+=":"+s.encode(e.password)),t+="@"),t},s.buildQuery=function(e,t,n){var r="",i,o,a,f;for(o in e)if(u.call(e,o)&&o)if(l(e[o])){i={};for(a=0,f=e[o].length;a<f;a++)e[o][a]!==undefined&&i[e[o][a]+""]===undefined&&(r+="&"+s.buildQueryParameter(o,e[o][a],n),t!==!0&&(i[e[o][a]+""]=!0))}else e[o]!==undefined&&(r+="&"+s.buildQueryParameter(o,e[o],n));return r.substring(1)},s.buildQueryParameter=function(e,t,n){return s.encodeQuery(e,n)+(t!==null?"="+s.encodeQuery(t,n):"")},s.addQuery=function(e,t,n){if(typeof t=="object")for(var r in t)u.call(t,r)&&s.addQuery(e,r,t[r]);else{if(typeof t!="string")throw new TypeError("URI.addQuery() accepts an object, string as the name parameter");if(e[t]===undefined){e[t]=n;return}typeof e[t]=="string"&&(e[t]=[e[t]]),l(n)||(n=[n]),e[t]=e[t].concat(n)}},s.removeQuery=function(e,t,n){var r,i,o;if(l(t))for(r=0,i=t.length;r<i;r++)e[t[r]]=undefined;else if(typeof t=="object")for(o in t)u.call(t,o)&&s.removeQuery(e,o,t[o]);else{if(typeof t!="string")throw new TypeError("URI.addQuery() accepts an object, string as the first parameter");n!==undefined?e[t]===n?e[t]=undefined:l(e[t])&&(e[t]=c(e[t],n)):e[t]=undefined}},s.hasQuery=function(e,t,n,r){if(typeof t=="object"){for(var i in t)if(u.call(t,i)&&!s.hasQuery(e,i,t[i]))return!1;return!0}if(typeof t!="string")throw new TypeError("URI.hasQuery() accepts an object, string as the name parameter");switch(f(n)){case"Undefined":return t in e;case"Boolean":var o=Boolean(l(e[t])?e[t].length:e[t]);return n===o;case"Function":return!!n(e[t],t,e);case"Array":if(!l(e[t]))return!1;var a=r?h:p;return a(e[t],n);case"RegExp":if(!l(e[t]))return Boolean(e[t]&&e[t].match(n));if(!r)return!1;return h(e[t],n);case"Number":n=String(n);case"String":if(!l(e[t]))return e[t]===n;if(!r)return!1;return h(e[t],n);default:throw new TypeError("URI.hasQuery() accepts undefined, boolean, string, number, RegExp, Function as the value parameter")}},s.commonPath=function(e,t){var n=Math.min(e.length,t.length),r;for(r=0;r<n;r++)if(e.charAt(r)!==t.charAt(r)){r--;break}if(r<1)return e.charAt(0)===t.charAt(0)&&e.charAt(0)==="/"?"/":"";if(e.charAt(r)!=="/"||t.charAt(r)!=="/")r=e.substring(0,r).lastIndexOf("/");return e.substring(0,r+1)},s.withinString=function(e,t){return e.replace(s.find_uri_expression,t)},s.ensureValidHostname=function(t){if(t.match(s.invalid_hostname_characters)){if(!e)throw new TypeError("Hostname '"+t+"' contains characters other than [A-Z0-9.-] and Punycode.js is not available");if(e.toASCII(t).match(s.invalid_hostname_characters))throw new TypeError("Hostname '"+t+"' contains characters other than [A-Z0-9.-]")}},s.noConflict=function(e){if(e){var n={URI:this.noConflict()};return URITemplate&&typeof URITemplate.noConflict=="function"&&(n.URITemplate=URITemplate.noConflict()),t&&typeof t.noConflict=="function"&&(n.IPv6=t.noConflict()),SecondLevelDomains&&typeof SecondLevelDomains.noConflict=="function"&&(n.SecondLevelDomains=SecondLevelDomains.noConflict()),n}return r.URI===this&&(r.URI=i),this},o.build=function(e){if(e===!0)this._deferred_build=!0;else if(e===undefined||this._deferred_build)this._string=s.build(this._parts),this._deferred_build=!1;return this},o.clone=function(){return new s(this)},o.valueOf=o.toString=function(){return this.build(!1)._string},m={protocol:"protocol",username:"username",password:"password",hostname:"hostname",port:"port"},y=function(e){return function(t,n){return t===undefined?this._parts[e]||"":(this._parts[e]=t||null,this.build(!n),this)}};for(g in m)o[g]=y(m[g]);m={query:"?",fragment:"#"},y=function(e,t){return function(n,r){return n===undefined?this._parts[e]||"":(n!==null&&(n+="",n.charAt(0)===t&&(n=n.substring(1))),this._parts[e]=n,this.build(!r),this)}};for(g in m)o[g]=y(g,m[g]);m={search:["?","query"],hash:["#","fragment"]},y=function(e,t){return function(n,r){var i=this[e](n,r);return typeof i=="string"&&i.length?t+i:i}};for(g in m)o[g]=y(m[g][1],m[g][0]);o.pathname=function(e,t){if(e===undefined||e===!0){var n=this._parts.path||(this._parts.hostname?"/":"");return e?s.decodePath(n):n}return this._parts.path=e?s.recodePath(e):"/",this.build(!t),this},o.path=o.pathname,o.href=function(e,t){var n;if(e===undefined)return this.toString();this._string="",this._parts=s._parts();var r=e instanceof s,i=typeof e=="object"&&(e.hostname||e.path||e.pathname);if(e.nodeName){var o=s.getDomAttribute(e);e=e[o]||"",i=!1}!r&&i&&e.pathname!==undefined&&(e=e.toString());if(typeof e=="string")this._parts=s.parse(e,this._parts);else{if(!r&&!i)throw new TypeError("invalid input");var a=r?e._parts:e;for(n in a)u.call(this._parts,n)&&(this._parts[n]=a[n])}return this.build(!t),this},o.is=function(e){var t=!1,r=!1,i=!1,o=!1,u=!1,a=!1,f=!1,l=!this._parts.urn;this._parts.hostname&&(l=!1,r=s.ip4_expression.test(this._parts.hostname),i=s.ip6_expression.test(this._parts.hostname),t=r||i,o=!t,u=o&&n&&n.has(this._parts.hostname),a=o&&s.idn_expression.test(this._parts.hostname),f=o&&s.punycode_expression.test(this._parts.hostname));switch(e.toLowerCase()){case"relative":return l;case"absolute":return!l;case"domain":case"name":return o;case"sld":return u;case"ip":return t;case"ip4":case"ipv4":case"inet4":return r;case"ip6":case"ipv6":case"inet6":return i;case"idn":return a;case"url":return!this._parts.urn;case"urn":return!!this._parts.urn;case"punycode":return f}return null};var b=o.protocol,w=o.port,E=o.hostname;o.protocol=function(e,t){if(e!==undefined&&e){e=e.replace(/:(\/\/)?$/,"");if(e.match(/[^a-zA-z0-9\.+-]/))throw new TypeError("Protocol '"+e+"' contains characters other than [A-Z0-9.+-]")}return b.call(this,e,t)},o.scheme=o.protocol,o.port=function(e,t){if(this._parts.urn)return e===undefined?"":this;if(e!==undefined){e===0&&(e=null);if(e){e+="",e.charAt(0)===":"&&(e=e.substring(1));if(e.match(/[^0-9]/))throw new TypeError("Port '"+e+"' contains characters other than [0-9]")}}return w.call(this,e,t)},o.hostname=function(e,t){if(this._parts.urn)return e===undefined?"":this;if(e!==undefined){var n={};s.parseHost(e,n),e=n.hostname}return E.call(this,e,t)},o.host=function(e,t){return this._parts.urn?e===undefined?"":this:e===undefined?this._parts.hostname?s.buildHost(this._parts):"":(s.parseHost(e,this._parts),this.build(!t),this)},o.authority=function(e,t){return this._parts.urn?e===undefined?"":this:e===undefined?this._parts.hostname?s.buildAuthority(this._parts):"":(s.parseAuthority(e,this._parts),this.build(!t),this)},o.userinfo=function(e,t){if(this._parts.urn)return e===undefined?"":this;if(e===undefined){if(!this._parts.username)return"";var n=s.buildUserinfo(this._parts);return n.substring(0,n.length-1)}return e[e.length-1]!=="@"&&(e+="@"),s.parseUserinfo(e,this._parts),this.build(!t),this},o.resource=function(e,t){var n;return e===undefined?this.path()+this.search()+this.hash():(n=s.parse(e),this._parts.path=n.path,this._parts.query=n.query,this._parts.fragment=n.fragment,this.build(!t),this)},o.subdomain=function(e,t){if(this._parts.urn)return e===undefined?"":this;if(e===undefined){if(!this._parts.hostname||this.is("IP"))return"";var n=this._parts.hostname.length-this.domain().length-1;return this._parts.hostname.substring(0,n)||""}var r=this._parts.hostname.length-this.domain().length,i=this._parts.hostname.substring(0,r),o=new RegExp("^"+a(i));return e&&e.charAt(e.length-1)!=="."&&(e+="."),e&&s.ensureValidHostname(e),this._parts.hostname=this._parts.hostname.replace(o,e),this.build(!t),this},o.domain=function(e,t){if(this._parts.urn)return e===undefined?"":this;typeof e=="boolean"&&(t=e,e=undefined);if(e===undefined){if(!this._parts.hostname||this.is("IP"))return"";var n=this._parts.hostname.match(/\./g);if(n&&n.length<2)return this._parts.hostname;var r=this._parts.hostname.length-this.tld(t).length-1;return r=this._parts.hostname.lastIndexOf(".",r-1)+1,this._parts.hostname.substring(r)||""}if(!e)throw new TypeError("cannot set domain empty");s.ensureValidHostname(e);if(!this._parts.hostname||this.is("IP"))this._parts.hostname=e;else{var i=new RegExp(a(this.domain())+"$");this._parts.hostname=this._parts.hostname.replace(i,e)}return this.build(!t),this},o.tld=function(e,t){if(this._parts.urn)return e===undefined?"":this;typeof e=="boolean"&&(t=e,e=undefined);if(e===undefined){if(!this._parts.hostname||this.is("IP"))return"";var r=this._parts.hostname.lastIndexOf("."),i=this._parts.hostname.substring(r+1);return t!==!0&&n&&n.list[i.toLowerCase()]?n.get(this._parts.hostname)||i:i}var s;if(!e)throw new TypeError("cannot set TLD empty");if(e.match(/[^a-zA-Z0-9-]/)){if(!n||!n.is(e))throw new TypeError("TLD '"+e+"' contains characters other than [A-Z0-9]");s=new RegExp(a(this.tld())+"$"),this._parts.hostname=this._parts.hostname.replace(s,e)}else{if(!this._parts.hostname||this.is("IP"))throw new ReferenceError("cannot set TLD on non-domain host");s=new RegExp(a(this.tld())+"$"),this._parts.hostname=this._parts.hostname.replace(s,e)}return this.build(!t),this},o.directory=function(e,t){if(this._parts.urn)return e===undefined?"":this;if(e===undefined||e===!0){if(!this._parts.path&&!this._parts.hostname)return"";if(this._parts.path==="/")return"/";var n=this._parts.path.length-this.filename().length-1,r=this._parts.path.substring(0,n)||(this._parts.hostname?"/":"");return e?s.decodePath(r):r}var i=this._parts.path.length-this.filename().length,o=this._parts.path.substring(0,i),u=new RegExp("^"+a(o));return this.is("relative")||(e||(e="/"),e.charAt(0)!=="/"&&(e="/"+e)),e&&e.charAt(e.length-1)!=="/"&&(e+="/"),e=s.recodePath(e),this._parts.path=this._parts.path.replace(u,e),this.build(!t),this},o.filename=function(e,t){if(this._parts.urn)return e===undefined?"":this;if(e===undefined||e===!0){if(!this._parts.path||this._parts.path==="/")return"";var n=this._parts.path.lastIndexOf("/"),r=this._parts.path.substring(n+1);return e?s.decodePathSegment(r):r}var i=!1;e.charAt(0)==="/"&&(e=e.substring(1)),e.match(/\.?\//)&&(i=!0);var o=new RegExp(a(this.filename())+"$");return e=s.recodePath(e),this._parts.path=this._parts.path.replace(o,e),i?this.normalizePath(t):this.build(!t),this},o.suffix=function(e,t){if(this._parts.urn)return e===undefined?"":this;if(e===undefined||e===!0){if(!this._parts.path||this._parts.path==="/")return"";var n=this.filename(),r=n.lastIndexOf("."),i,o;return r===-1?"":(i=n.substring(r+1),o=/^[a-z0-9%]+$/i.test(i)?i:"",e?s.decodePathSegment(o):o)}e.charAt(0)==="."&&(e=e.substring(1));var u=this.suffix(),f;if(!u){if(!e)return this;this._parts.path+="."+s.recodePath(e)}else e?f=new RegExp(a(u)+"$"):f=new RegExp(a("."+u)+"$");return f&&(e=s.recodePath(e),this._parts.path=this._parts.path.replace(f,e)),this.build(!t),this},o.segment=function(e,t,n){var r=this._parts.urn?":":"/",i=this.path(),s=i.substring(0,1)==="/",o=i.split(r);e!==undefined&&typeof e!="number"&&(n=t,t=e,e=undefined);if(e!==undefined&&typeof e!="number")throw new Error("Bad segment '"+e+"', must be 0-based integer");s&&o.shift(),e<0&&(e=Math.max(o.length+e,0));if(t===undefined)return e===undefined?o:o[e];if(e===null||o[e]===undefined){if(l(t)){o=[];for(var u=0,a=t.length;u<a;u++){if(!t[u].length&&(!o.length||!o[o.length-1].length))continue;o.length&&!o[o.length-1].length&&o.pop(),o.push(t[u])}}else if(t||typeof t=="string")o[o.length-1]===""?o[o.length-1]=t:o.push(t)}else t||typeof t=="string"&&t.length?o[e]=t:o.splice(e,1);return s&&o.unshift(""),this.path(o.join(r),n)},o.segmentCoded=function(e,t,n){var r,i,o;typeof e!="number"&&(n=t,t=e,e=undefined);if(t===undefined){r=this.segment(e,t,n);if(!l(r))r=r!==undefined?s.decode(r):undefined;else for(i=0,o=r.length;i<o;i++)r[i]=s.decode(r[i]);return r}if(!l(t))t=typeof t=="string"?s.encode(t):t;else for(i=0,o=t.length;i<o;i++)t[i]=s.decode(t[i]);return this.segment(e,t,n)};var S=o.query;return o.query=function(e,t){if(e===!0)return s.parseQuery(this._parts.query,this._parts.escapeQuerySpace);if(typeof e=="function"){var n=s.parseQuery(this._parts.query,this._parts.escapeQuerySpace),r=e.call(this,n);return this._parts.query=s.buildQuery(r||n,this._parts.duplicateQueryParameters,this._parts.escapeQuerySpace),this.build(!t),this}return e!==undefined&&typeof e!="string"?(this._parts.query=s.buildQuery(e,this._parts.duplicateQueryParameters,this._parts.escapeQuerySpace),this.build(!t),this):S.call(this,e,t)},o.setQuery=function(e,t,n){var r=s.parseQuery(this._parts.query,this._parts.escapeQuerySpace);if(typeof e=="object")for(var i in e)u.call(e,i)&&(r[i]=e[i]);else{if(typeof e!="string")throw new TypeError("URI.addQuery() accepts an object, string as the name parameter");r[e]=t!==undefined?t:null}return this._parts.query=s.buildQuery(r,this._parts.duplicateQueryParameters,this._parts.escapeQuerySpace),typeof e!="string"&&(n=t),this.build(!n),this},o.addQuery=function(e,t,n){var r=s.parseQuery(this._parts.query,this._parts.escapeQuerySpace);return s.addQuery(r,e,t===undefined?null:t),this._parts.query=s.buildQuery(r,this._parts.duplicateQueryParameters,this._parts.escapeQuerySpace),typeof e!="string"&&(n=t),this.build(!n),this},o.removeQuery=function(e,t,n){var r=s.parseQuery(this._parts.query,this._parts.escapeQuerySpace);return s.removeQuery(r,e,t),this._parts.query=s.buildQuery(r,this._parts.duplicateQueryParameters,this._parts.escapeQuerySpace),typeof e!="string"&&(n=t),this.build(!n),this},o.hasQuery=function(e,t,n){var r=s.parseQuery(this._parts.query,this._parts.escapeQuerySpace);return s.hasQuery(r,e,t,n)},o.setSearch=o.setQuery,o.addSearch=o.addQuery,o.removeSearch=o.removeQuery,o.hasSearch=o.hasQuery,o.normalize=function(){return this._parts.urn?this.normalizeProtocol(!1).normalizeQuery(!1).normalizeFragment(!1).build():this.normalizeProtocol(!1).normalizeHostname(!1).normalizePort(!1).normalizePath(!1).normalizeQuery(!1).normalizeFragment(!1).build()},o.normalizeProtocol=function(e){return typeof this._parts.protocol=="string"&&(this._parts.protocol=this._parts.protocol.toLowerCase(),this.build(!e)),this},o.normalizeHostname=function(n){return this._parts.hostname&&(this.is("IDN")&&e?this._parts.hostname=e.toASCII(this._parts.hostname):this.is("IPv6")&&t&&(this._parts.hostname=t.best(this._parts.hostname)),this._parts.hostname=this._parts.hostname.toLowerCase(),this.build(!n)),this},o.normalizePort=function(e){return typeof this._parts.protocol=="string"&&this._parts.port===s.defaultPorts[this._parts.protocol]&&(this._parts.port=null,this.build(!e)),this},o.normalizePath=function(e){if(this._parts.urn)return this;if(!this._parts.path||this._parts.path==="/")return this;var t,n=this._parts.path,r,i;n.charAt(0)!=="/"&&(t=!0,n="/"+n),n=n.replace(/(\/(\.\/)+)|(\/\.$)/g,"/").replace(/\/{2,}/g,"/");for(;;){r=n.indexOf("/../");if(r===-1)break;if(r===0){n=n.substring(3);break}i=n.substring(0,r).lastIndexOf("/"),i===-1&&(i=r),n=n.substring(0,i)+n.substring(r+3)}return t&&this.is("relative")&&(n=n.substring(1)),n=s.recodePath(n),this._parts.path=n,this.build(!e),this},o.normalizePathname=o.normalizePath,o.normalizeQuery=function(e){return typeof this._parts.query=="string"&&(this._parts.query.length?this.query(s.parseQuery(this._parts.query,this._parts.escapeQuerySpace)):this._parts.query=null,this.build(!e)),this},o.normalizeFragment=function(e){return this._parts.fragment||(this._parts.fragment=null,this.build(!e)),this},o.normalizeSearch=o.normalizeQuery,o.normalizeHash=o.normalizeFragment,o.iso8859=function(){var e=s.encode,t=s.decode;return s.encode=escape,s.decode=decodeURIComponent,this.normalize(),s.encode=e,s.decode=t,this},o.unicode=function(){var e=s.encode,t=s.decode;return s.encode=v,s.decode=unescape,this.normalize(),s.encode=e,s.decode=t,this},o.readable=function(){var t=this.clone();t.username("").password("").normalize();var n="";t._parts.protocol&&(n+=t._parts.protocol+"://"),t._parts.hostname&&(t.is("punycode")&&e?(n+=e.toUnicode(t._parts.hostname),t._parts.port&&(n+=":"+t._parts.port)):n+=t.host()),t._parts.hostname&&t._parts.path&&t._parts.path.charAt(0)!=="/"&&(n+="/"),n+=t.path(!0);if(t._parts.query){var r="";for(var i=0,o=t._parts.query.split("&"),u=o.length;i<u;i++){var a=(o[i]||"").split("=");r+="&"+s.decodeQuery(a[0],this._parts.escapeQuerySpace).replace(/&/g,"%26"),a[1]!==undefined&&(r+="="+s.decodeQuery(a[1],this._parts.escapeQuerySpace).replace(/&/g,"%26"))}n+="?"+r.substring(1)}return n+=s.decodeQuery(t.hash(),!0),n},o.absoluteTo=function(e){var t=this.clone(),n=["protocol","username","password","hostname","port"],r,i,o;if(this._parts.urn)throw new Error("URNs do not have any generally defined hierarchical components");e instanceof s||(e=new s(e)),t._parts.protocol||(t._parts.protocol=e._parts.protocol);if(this._parts.hostname)return t;for(i=0;o=n[i];i++)t._parts[o]=e._parts[o];n=["query","path"];for(i=0;o=n[i];i++)!t._parts[o]&&e._parts[o]&&(t._parts[o]=e._parts[o]);return t.path().charAt(0)!=="/"&&(r=e.directory(),t._parts.path=(r?r+"/":"")+t._parts.path,t.normalizePath()),t.build(),t},o.relativeTo=function(e){var t=this.clone().normalize(),n,r,i,o,u;if(t._parts.urn)throw new Error("URNs do not have any generally defined hierarchical components");e=(new s(e)).normalize(),n=t._parts,r=e._parts,o=t.path(),u=e.path();if(o.charAt(0)!=="/")throw new Error("URI is already relative");if(u.charAt(0)!=="/")throw new Error("Cannot calculate a URI relative to another relative URI");n.protocol===r.protocol&&(n.protocol=null);if(n.username!==r.username||n.password!==r.password)return t.build();if(n.protocol!==null||n.username!==null||n.password!==null)return t.build();if(n.hostname!==r.hostname||n.port!==r.port)return t.build();n.hostname=null,n.port=null;if(o===u)return n.path="",t.build();i=s.commonPath(t.path(),e.path());if(!i)return t.build();var a=r.path.substring(i.length).replace(/[^\/]*$/,"").replace(/.*?\//g,"../");return n.path=a+n.path.substring(i.length),t.build()},o.equals=function(e){var t=this.clone(),n=new s(e),r={},i={},o={},a,f,c;t.normalize(),n.normalize();if(t.toString()===n.toString())return!0;a=t.query(),f=n.query(),t.query(""),n.query("");if(t.toString()!==n.toString())return!1;if(a.length!==f.length)return!1;r=s.parseQuery(a,this._parts.escapeQuerySpace),i=s.parseQuery(f,this._parts.escapeQuerySpace);for(c in r)if(u.call(r,c)){if(!l(r[c])){if(r[c]!==i[c])return!1}else if(!p(r[c],i[c]))return!1;o[c]=!0}for(c in i)if(u.call(i,c)&&!o[c])return!1;return!0},o.duplicateQueryParameters=function(e){return this._parts.duplicateQueryParameters=!!e,this},o.escapeQuerySpace=function(e){return this._parts.escapeQuerySpace=!!e,this},s});