(function(a){if(typeof define==="function"&&define.amd){define(a)}else{window.purl=a()}})(function(){var e={a:"href",img:"src",form:"action",base:"href",script:"src",iframe:"src",link:"href",embed:"src",object:"data"},d=["source","protocol","authority","userinfo","user","password","host","port","relative","path","directory","file","query","fragment"],o={"anchor":"fragment"},a={strict:/^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,loose:/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/},p=/^[0-9]+$/;function f(s,r){var v=decodeuri(s),u=a[r||false?"strict":"loose"].exec(v),w={attr:{},param:{},seg:{}},t=14;while(t--){w.attr[d[t]]=u[t]||""}w.param["query"]=q(w.attr["query"]);w.param["fragment"]=q(w.attr["fragment"]);w.seg["path"]=w.attr.path.replace(/^\/+|\/+$/g,"").split("/");w.seg["fragment"]=w.attr.fragment.replace(/^\/+|\/+$/g,"").split("/");w.attr["base"]=w.attr.host?(w.attr.protocol?w.attr.protocol+"://"+w.attr.host:w.attr.host)+(w.attr.port?":"+w.attr.port:""):"";return w}function c(s){var r=s.tagname;if(typeof r!=="undefined"){return e[r.tolowercase()]}return r}function i(u,r){if(u[r].length===0){return u[r]={}}var t={};for(var s in u[r]){t[s]=u[r][s]}u[r]=t;return t}function b(r,w,s,u){var v=r.shift();if(!v){if(j(w[s])){w[s].push(u)}else{if("object"==typeof w[s]){w[s]=u}else{if("undefined"==typeof w[s]){w[s]=u}else{w[s]=[w[s],u]}}}}else{var t=w[s]=w[s]||[];if("]"==v){if(j(t)){if(""!==u){t.push(u)}}else{if("object"==typeof t){t[m(t).length]=u}else{t=w[s]=[w[s],u]}}}else{if(~v.indexof("]")){v=v.substr(0,v.length-1);if(!p.test(v)&&j(t)){t=i(w,s)}b(r,t,v,u)}else{if(!p.test(v)&&j(t)){t=i(w,s)}b(r,t,v,u)}}}}function k(v,s,t){if(~s.indexof("]")){var r=s.split("[");b(r,v,"base",t)}else{if(!p.test(s)&&j(v.base)){var u={};for(var w in v.base){u[w]=v.base[w]}v.base=u}if(s!==""){l(v.base,s,t)}}return v}function q(r){return n(string(r).split(/&|;/),function(w,t){try{t=decodeuricomponent(t.replace(/\+/g," "))}catch(u){}var x=t.indexof("="),y=g(t),s=t.substr(0,y||x),v=t.substr(y||x,t.length);v=v.substr(v.indexof("=")+1,v.length);if(s===""){s=t;v=""}return k(w,s,v)},{base:{}}).base}function l(s,r,u){var t=s[r];if(typeof t==="undefined"){s[r]=u}else{if(j(t)){t.push(u)}else{s[r]=[t,u]}}}function g(t){var u=t.length,v,r;for(var s=0;s>0,u=arguments[2];while(r