function RSHUrl (url_string) {
    this.url_string = url_string.unescapeHTML();
	this.url_object = parseUri(this.url_string);
	this.host = this.url_object.host; 
    this.anchor_object = parseUri(this.url_object.anchor);	
	this.file = this.anchor_object.file;
	this.queryKey = this.anchor_object.queryKey;
	
	/*query_string = this.anchor_object.query;
	this.queryKey = {};
	if (query_string){
		query_array = query_string.split("&amp;");
		i = 0;
		while (i < query_array.length) {
			query = query_array[i].split("=");
			param = query[0];
			value = query[1];
			this.queryKey[param]=value;
			++i;
		}
	}*/	
	
	this.directory = this.anchor_object.directory;
	if (this.directory.charAt(this.directory.length-1) != "/"){
		//there's no trailing slash, so we add one.
		this.directory += "/";
	}
	
	this.queryList = function() {
		return Object.keys(this.queryKey);	
	};
	
	this.query = function() {
		i=0;
		query_string = "";		
		while (i<this.queryList().length){			
			if (i != 0){
				query_string += "&";
			}
			param = this.queryList()[i];
			value = this.queryKey[this.queryList()[i]];
			//alert (param + ": " + value);
			query_string +=  param + "=" + value;
			++i;
		}
		return query_string;
    };
	
	this.path = function() {
		return this.directory + this.file;
	}
	
	this.anchor = function() {
		anchor_string = this.path();
		if (this.query()) {
			  anchor_string += "?" + this.query();
		}
		return anchor_string;
	}
	
	this.relative = function() {
		if (this.anchor()){
			return "/#" + this.anchor();
		}	
		else {
			return "";
		}
	}
	
	this.absolute = function() {
		return this.host + this.relative();
	}
	
	this.add_param = function(param,value) {
		this.queryKey[param] = value;	
	}
	
	this.get_param = function(param) {
		return this.queryKey[param];	
	}
	
	this.remove_param = function(param_to_remove) {
		i=0;
		new_queryKey = {};	
		while (i<this.queryList().length){
			
			param = this.queryList()[i];
			if (param != param_to_remove) {
				value = this.queryKey[this.queryList()[i]];
				new_queryKey[param] = value;
			}
			++i;
		}
		this.queryKey = new_queryKey;			
	}			
}

function rsh_url(url_string){
	return new RSHUrl(url_string);	
}


