/* Copyright 2009 Michael Little, Christian Biggins */
if(typeof FLQ=="undefined"){var FLQ=function(){}}FLQ.URL=function(A){this.scheme=null;this.host=null;this.port=null;this.path=null;this.args={};this.anchor=null;if(arguments.length>0){this.set(A)}};FLQ.URL.thisURL=function(){return new FLQ.URL(window.location.href)};FLQ.URL.prototype=new Object();FLQ.URL.prototype.set=function(A){var B;if(B=this.parseURL(A)){this.scheme=B.scheme;this.host=B.host;this.port=B.port;this.path=B.path;this.args=this.parseArgs(B.args);this.anchor=B.anchor}};FLQ.URL.prototype.removeArg=function(A){if(A&&String(A.constructor)==String(Array)){var C=this.args;for(var B=0;B<A.length-1;B++){if(typeof C[A[B]]!="undefined"){C=C[A[B]]}else{return false}}delete C[A[A.length-1]];return true}else{if(typeof this.args[A]!="undefined"){delete this.args[A];return true}}return false};FLQ.URL.prototype.addArg=function(B,A,E){if(B&&String(B.constructor)==String(Array)){var D=this.args;for(var C=0;C<B.length-1;C++){if(typeof D[B[C]]=="undefined"){D[B[C]]={}}D=D[B[C]]}if(E||typeof D[B[B.length-1]]=="undefined"){D[B[B.length-1]]=A}}else{if(E||typeof this.args[B]=="undefined"){this.args[B]=A;return true}}return false};FLQ.URL.prototype.parseURL=function(B){var C={},A;if(A=B.match(/((s?ftp|https?):\/\/)?([^\/:]+)?(:([0-9]+))?([^\?#]+)?(\?([^#]+))?(#(.+))?/)){C.scheme=(A[2]?A[2]:"http");C.host=(A[3]?A[3]:window.location.host);C.port=(A[5]?A[5]:null);C.path=(A[6]?A[6]:null);C.args=(A[8]?A[8]:null);C.anchor=(A[10]?A[10]:null);return C}return false};FLQ.URL.prototype.parseArgs=function(I){var F={};if(I&&I.length){var G,D;var A;if((G=I.split("&"))&&G.length){for(var C=0;C<G.length;C++){if((D=G[C].split("="))&&D.length==2){if(A=D[0].split(/(\[|\]\[|\])/)){for(var E=0;E<A.length;E++){if(A[E]=="]"||A[E]=="["||A[E]=="]["){A.splice(E,1)}}var H=F;for(var B=0;B<A.length-1;B++){if(typeof H[A[B]]=="undefined"){H[A[B]]={}}H=H[A[B]]}H[A[A.length-1]]=D[1]}else{F[D[0]]=D[1]}}}}}return F};FLQ.URL.prototype.toArgs=function(A,D){if(arguments.length<2){D=""}if(A&&typeof A=="object"){var C="";for(i in A){if(typeof A[i]!="function"){if(C.length){C+="&"}if(typeof A[i]=="object"){var B=(D.length?D+"["+i+"]":i);C+=this.toArgs(A[i],B)}else{C+=D+(D.length&&i!=""?"[":"")+i+(D.length&&i!=""?"]":"")+"="+A[i]}}}return C}return""};FLQ.URL.prototype.toAbsolute=function(){var A="";if(this.scheme!=null){A+=this.scheme+"://"}if(this.host!=null){A+=this.host}if(this.port!=null){A+=":"+this.port}A+=this.toRelative();return A};FLQ.URL.prototype.toRelative=function(){var B="";if(this.path!=null){B+=this.path}var A=this.toArgs(this.args);if(A.length){B+="?"+A}if(this.anchor!=null){B+="#"+this.anchor}return B};FLQ.URL.prototype.isHost=function(){var A=FLQ.URL.thisURL();return(this.host==null||this.host==A.host?true:false)};FLQ.URL.prototype.toString=function(){return(this.isHost()?this.toRelative():this.toAbsolute())};