﻿var CM_SESSION_KEY_KEY="cmSessionKeyKey";function getSessionPair(a){return URL.getSessionPair(a)}function getSessionHref(){return URL.getSessionHref()}function processLinkz(a){URL.processLinkz(a)}function getSessionString(){return URL.getSessionString()}function jdecode(a){return URL.jdecode(a)}function jencode(a){return URL.jencode(a)}URL.buildURL=function(b){if(b.indexOf(":")==-1){var a=new URL(document.location.href);if(b.indexOf("./")==0||b.indexOf("../")==0){var c=a.path.lastIndexOf("/");if(c!=-1)a.path=a.path.substring(0,c)+"/";return a.protocol+"://"+a.authority+a.path+b}else return a.protocol+"://"+a.authority+b}else return b};URL.getSessionPair=function(c){var d,a=window.top.cmSessionKey,b=window.top.cmSessionValue;if(!c)c=document.location.href;if(!a||!b){d=new URL(c,true,true);a=d.getParameter(CM_SESSION_KEY_KEY,"");b=d.getParameter(a,"")}return [a,b]};URL.getSessionHref=function(){var a=new URL(document.location.href,true,true);a.setSession();return a.toExternalForm()};URL.processLinkz=function(b){if(!b)b=window.document;var e=getSessionPair(),c=e[0],f=e[1];for(var d=0;d<b.links.length;d++){var g=b.links[d],a=new URL(g.href,true,true),h=a.getParameter("*session*id*key*","");if(h=="*session*id*val*"){a.removeParameter("*session*id*key*");if(c&&f){a.setParameter(c,f,true);a.setParameter(CM_SESSION_KEY_KEY,c,true)}g.href=a.toExternalForm()}}};URL.getSessionString=function(){var a=getSessionPair();if(a[0]&&a[1])return a[0]+"="+a[1]+"&"+CM_SESSION_KEY_KEY+"="+a[0];else return ""};URL.jdecode=function(a){var b=/\+/g;a=a.replace(b,"%20");return unescape(a)};URL.deamplify=function(a){var b=/&amp;/g;a=a.replace(b,"&");return a};URL.jencode=function(a){var b=/\+/g,c=/%20/g;a=escape(a);return a.replace(b,"%2B").replace(c,"+")};URL.prototype.set=URL_set;URL.prototype.debug=URL_debug;URL.prototype.isValidProtocol=URL_isValidProtocol;URL.prototype.toExternalForm=URL_toExternalForm;URL.prototype.toString=URL_toExternalForm;URL.prototype.parseQueryString=URL_parseQueryString;URL.prototype.getParameter=URL_getParameter;URL.prototype.getParameterValues=URL_getParameterValues;URL.prototype.getParameterNames=URL_getParameterNames;URL.prototype.setParameter=URL_setParameter;URL.prototype.removeParameter=URL_removeParameter;URL.prototype.setSession=URL_setSession;URL.prototype.removeAllParams=URL_removeAllParams;function URL(a,j,i){a=URL.buildURL(a);this.protocol=null;this.host=null;this.port=-1;this.file=null;this.query=null;this.authority=null;this.path=null;this.userInfo=null;this.ref=null;this.qParams={};var c,d,g,k=a,b=0,e=null,f=false;d=a.length;while(d>0&&a.charAt(d-1)<=" ")d--;while(b<d&&a.charAt(b)<=" ")b++;if(a.substr(b,4).toLowerCase()=="url:")b+=4;if(b<a.length&&a.charAt(b)=="#")f=true;for(c=b;!f&&c<d&&(g=a.charAt(c))!="/";c++)if(g==":"){var h=a.substring(b,c).toLowerCase();if(this.isValidProtocol(h)){e=h;b=c+1}break}this.protocol=e;if(this.protocol==null);c=a.indexOf("#",b);if(c>=0){this.ref=a.substring(c+1,d);d=c}parseURL(this,a,b,d);this.parseQueryString();if(!j)this.setSession();if(!i)this.setParameter("cc",Math.random(),true)}function URL_set(d,f,g,c,e,b,a,h){this.protocol=d;this.host=f;this.port=g;this.file=a==null?b:b+"?"+a;this.userInfo=e;this.path=b;this.ref=h;this.query=a;this.authority=c}function URL_debug(){var a="protocol:  "+this.protocol+"\n"+"host:      "+this.host+"\n"+"port:      "+this.port+"\n"+"file:      "+this.file+"\n"+"userInfo:  "+this.userInfo+"\n"+"path:      "+this.path+"\n"+"ref:       "+this.ref+"\n"+"query:     "+this.query+"\n"+"authority: "+this.authority+"\n\n",c;for(c in this.qParams){var b=this.qParams[c];a+=c+" -> [";if(!b){alert("missing: "+c);continue}for(var d=0;d<b.length;d++)a+=b[d]+(d!=b.length-1?",":"");a+="]\n"}alert(a)}function URL_getParameter(c,a){if(!c)return a;var b=this.qParams[c];if(b==null)return a;else return b[0]}function URL_getParameterValues(a){return this.qParams[a]}function URL_getParameterNames(){var b,a=[];for(b in this.qParams)a[a.length]=b;return a}function parseURL(i,e,c,d){var q=i.protocol,h=i.authority,o=i.userInfo,g=i.host,l=i.port,a=i.file,r=i.ref,p=null,m=false,n=false;if(c<d){var j=e.indexOf("?");n=j==c;if(j!=-1){p=e.substring(j+1,d);if(d>j)d=j;e=e.substring(0,j)}}var b=0;if(c<=d-2&&e.charAt(c)=="/"&&e.charAt(c+1)=="/"){c+=2;b=e.indexOf("/",c);if(b<0){b=e.indexOf("?",c);if(b<0)b=d}g=h=e.substring(c,b);var f=h.indexOf("@");if(f!=-1){o=h.substring(0,f);g=h.substring(f+1)}f=g.indexOf(":");l=-1;if(f>=0){if(g.length>f+1)l=parseInt(g.substring(f+1));g=g.substring(0,f)}c=b;if(h!=null&&h.length>0)a=""}if(g==null)g="";if(c<d)if(e.charAt(c)=="/")a=e.substring(c,d);else if(a!=null&&a.length>0){m=true;var f=a.lastIndexOf("/"),k="";if(f==-1&&h!=null)k="/";a=a.substring(0,f+1)+k+e.substring(c,d)}else{var k=h!=null?"/":"";a=k+e.substring(c,d)}else if(n&&a!=null){var f=a.lastIndexOf("/");if(f<0)f=0;a=a.substring(0,f)+"/"}if(a==null)a="";if(m){while((b=a.indexOf("/./"))>=0)a=a.substring(0,b)+a.substring(b+2);while((b=a.indexOf("/../"))>=0)if((d=a.lastIndexOf("/",b-1))>=0)a=a.substring(0,d)+a.substring(b+3);else a=a.substring(b+3);while(a.substring(a.length-3,a.length)=="/.."){b=a.indexOf("/..");if((d=a.lastIndexOf("/",b-1))>=0)a=a.substring(0,d+1);else a=a.substring(0,b)}if(a.substring(a.length-2,a.length)=="/.")a=a.substring(0,a.length()-1)}setURL(i,q,g,l,h,o,a,p,r)}function setURL(a,i,e,g,b,c,f,d,h){a.set(a.protocol,e,g,b,c,f,d,h)}function URL_isValidProtocol(){return true}function URL_setParameter(a,c,b){if(!a)return;if(b||this.qParams[a]==null)this.qParams[a]=[];this.qParams[a][this.qParams[a].length]=c}function URL_removeParameter(c){var a,b={};for(a in this.qParams)if(a!=c)b[a]=this.qParams[a];this.qParams=b}function URL_removeAllParams(){var a={};this.qParams=a}function URL_parseQueryString(){var c;if(this.query==null||this.query.length==0)return;else c="&"+this.query;var e,b=c.indexOf("&");while(b!=-1){var a=null,d=0;e=c.indexOf("&",b+1);if(e!=-1)a=c.substring(b+1,e);else a=c.substr(b+1);d=a.indexOf("=");if(d!=-1){var f=a.substring(0,d),g=a.substr(d+1);this.setParameter(f,g)}b=e}}function URL_toExternalForm(){var a=this.protocol;a+=":";if(this.authority!=null&&this.authority.length>0){a+="//";a+=this.authority}if(this.path!=null)a+=this.path;var b="",c;for(c in this.qParams){var e=this.qParams[c];for(var d=0;d<e.length;d++)if(b.length==0)b+=c+"="+e[d];else b+="&"+c+"="+e[d]}if(b.length>0)a+="?"+b;if(this.ref!=null){a+="#";a+=this.ref}return a}function URL_setSession(){var a=getSessionPair();if(a[0]&&a[1]){this.setParameter(a[0],a[1],true);this.setParameter(CM_SESSION_KEY_KEY,a[0],true);return true}return false}
