+ 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";

	var key;

	for (key in this.qParams) {
		var vals = this.qParams[key];

		debug += key + " -> [";

		if (!vals) {
			alert("missing: " + key);
			continue;
		}

		for (var i = 0 ; i < vals.length; i++) {
			debug += vals[i] + (i != (vals.length-1) ? "," : "");
		}

		debug += "]\n";
	}

	alert(debug);
}
// ---------------------------------------------------------------------
function URL_getParameter(key, defval) {
	if (!key)
		return defval;

	var toret = this.qParams[key];

	if (toret == null) {
		return defval;
	} else {
		return toret[0];
	}
}
// ---------------------------------------------------------------------
function URL_getParameterValues(key) {
	return this.qParams[key];
}
// ---------------------------------------------------------------------
function URL_getParameterNames() {
	var key;
	var keys = new Array();

	for (key in this.qParams) {
		keys[keys.length] = key;
	}

	return keys;
}
// ---------------------------------------------------------------------
function parseURL(u, spec, start, limit) {
	var protocol 	= u.protocol;
	var authority 	= u.authority;
	var userInfo 	= u.userInfo;
	var host 		= u.host;
	var port 		= u.port;
	var file 		= u.file;
	var ref 		= u.ref;	// This field has already been parsed

	var query 		= null;

	var isRelPath 	= false;
	var queryOnly 	= false;


	// FIX: should not assume query if opaque
	// Strip off the query part
	if (start < limit) {
		var queryStart = spec.indexOf('?');
		queryOnly = (queryStart == start);

		if (queryStart != -1) {
			query = spec.substring(queryStart+1, limit);

			if (limit > queryStart)
				limit = queryStart;

			spec = spec.substring(0, queryStart);
		}
	}

	var i = 0;
	// Parse the authority part if any
	if ((start <= limit - 2) && (spec.charAt(start) == '/') && (spec.charAt(start + 1) == '/')) {
		start += 2;
		i = spec.indexOf('/', start);
		if (i < 0) {
			i = spec.indexOf('?', start);

			if (i < 0)
				i = limit;
		}

		host = authority = spec.substring(start, i);

		var ind = authority.indexOf('@');

		if (ind != -1) {
			userInfo = authority.substring(0, ind);
			host = authority.substring(ind+1);
		}

		ind = host.indexOf(':');
		port = -1;
		if (ind >= 0) {
			// port can be null according to RFC2396
			if (host.length > (ind + 1)) {
				port = parseInt(host.substring(ind + 1));
			}
			host = host.substring(0, ind);
		}

		start = i;
		// If the authority is defined then the path is defined by the
		// spec only; See RFC 2396 Section 5.2.4.
		if (authority != null && authority.length > 0)
			file = "";
	}

	if (host == null) {
		host = "";
	}

	// Parse the file path if any
	if (start < limit) {
		if (spec.charAt(start) == '/') {
			file = spec.substring(start, limit);
		} else if (file != null && file.length > 0) {
			isRelPath = true;
			var ind = file.lastIndexOf('/');

			var seperator = "";

			if (ind == -1 && authority != null)
				seperator = "/";

			file = file.substring(0, ind + 1) + seperator + spec.substring(start, limit);
		} else {
			var seperator = (authority != null) ? "/" : "";
			file = seperator + spec.substring(start, limit);
		}
	} else if (queryOnly && file != null) {
		var ind = file.lastIndexOf('/');
		if (ind < 0)
			ind = 0;
		file = file.substring(0, ind) + "/";
	}

	if (file == null)
		file = "";

	if (isRelPath) {
		// Remove embedded /./
		while ((i = file.indexOf("/./")) >= 0) {
			file = file.substring(0, i) + file.substring(i + 2);
		}
		// Remove embedded /../
		while ((i = file.indexOf("/../")) >= 0) {
			if ((limit = file.lastIndexOf('/', i - 1)) >= 0) {
				file = file.substring(0, limit) + file.substring(i + 3);
			} else {
				file = file.substring(i + 3);
			}
		}
		// Remove trailing ..
		while (file.substring(file.length - 3, file.length) == "/..") {
		//while (file.endsWith("/..")) {
			i = file.indexOf("/..");
			if ((limit = file.lastIndexOf('/', i - 1)) >= 0) {
				file = file.substring(0, limit+1);
			} else {
				file = file.substring(0, i);
			}
		}
		// Remove trailing .
		if (file.substring(file.length - 2, file.length) == "/.")
		//if (file.endsWith("/."))
			file = file.substring(0, file.length() -1);
	}

	setURL(u, protocol, host, port, authority, userInfo, file, query, ref);
}
// ---------------------------------------------------------------------
function setURL(u, protocol, host, port, authority, userInfo, path, query, ref) {
	u.set(u.protocol, host, port, authority, userInfo, path, query, ref);
}
// ---------------------------------------------------------------------
function URL_isValidProtocol(protocol) {
	return true;
	/*var len = protocol.length;

	if (len < 1)
		return false;

    var c = protocol.charAt(0);

	//if (!Character.isLetter(c))
	if (!isNaN(c))
		return false;

	for (var i = 1 ; i < len ; i++) {
	    c = protocol.charAt(i);

	    if (!Character.isLetterOrDigit(c) && c != '.' && c != '+' && c != '-') {
			return false;
	    }
	}
	return true;*/
}
// ---------------------------------------------------------------------
function URL_setParameter(key, val, replace) {
	if (!key)
		return;

	if (replace || this.qParams[key] == null) {
		this.qParams[key] = new Array();
	}

	this.qParams[key][this.qParams[key].length] = val;
}
// ---------------------------------------------------------------------
function URL_removeParameter(key) {
	var _key;
	var newQParams = new Object();

	for (_key in this.qParams) {
		if (_key != key) {
			newQParams[_key] = this.qParams[_key];
		}
	}

	this.qParams = newQParams;
}
// ---------------------------------------------------------------------
function URL_removeAllParams() {
	var newQParams = new Object();
	this.qParams = newQParams;
}
// ---------------------------------------------------------------------
function URL_parseQueryString() {
	var s;

	if (this.query == null || this.query.length == 0)
		return;
	else
		s = "&" + this.query;

	var idx2;
	var idx = s.indexOf("&");

	while (idx != -1) {
		var kvPair = null;
		var kvPos = 0;

		idx2 = s.indexOf("&", idx+1);

		if (idx2 != -1) {
			kvPair = s.substring(idx+1, idx2);
		} else {
			kvPair = s.substr(idx+1);
		}

		kvPos = kvPair.indexOf("=");

		if (kvPos != -1) {
			var key = kvPair.substring(0, kvPos);
			var val = kvPair.substr(kvPos+1);

			this.setParameter(key, val);
		}

		idx = idx2;
	}
}
// ---------------------------------------------------------------------
function URL_toExternalForm() {
	var result = this.protocol;

	result += ":";

	if (this.authority != null && this.authority.length > 0) {
		result += "//";
		result += this.authority;
	}

	/*if (this.file != null) {
		result += this.file;
	}*/
	if (this.path != null) {
		result += this.path;
	}

	var query = "";
	var key;

	for (key in this.qParams) {
		var vals = this.qParams[key];

		for (var i = 0 ; i < vals.length ; i++) {
			if (query.length == 0) {
				query += key + "=" + vals[i];
			} else {
				query += "&" + key + "=" + vals[i];
			}
		}
	}

	if (query.length > 0) {
		result += "?" + query;
	}

	if (this.ref != null) {
		result += "#";
		result += this.ref;
	}

	return result;
}
// ---------------------------------------------------------------------
function URL_setSession() {
	var sess_pair = getSessionPair();

	if (sess_pair[0] && sess_pair[1]) {
		this.setParameter(sess_pair[0], sess_pair[1], true);
		this.setParameter(CM_SESSION_KEY_KEY, sess_pair[0], true);

		return true;
	}

	return false;
}
// ---------------------------------------------------------------------

 {
		return defval;
	} else {
		return toret[0];
	}
}
// ---------------------------------------------------------------------
function URL_getParameterValues(key) {
	return this.qParams[key];
}
// ---------------------------------------------------------------------
function URL_getParameterNames() {
	var key;
	var keys = new Array();

	for (key in this.qParams) {
		keys[keys.length] = key;
	}

	return keys;
}
// ---------------------------------------------------------------------
function parseURL(u, spec, start, limit) {
	var protocol 	= u.protocol;
	var authority 	= u.authority;
	var userInfo 	= u.userInfo;
	var host 		= u.host;
	var port 		= u.port;
	var file 		= u.file;
	var ref 		= u.ref;	// This field has already been parsed

	var query 		= null;

	var isRelPath 	= false;
	var queryOnly 	= false;


	// FIX: should not assume query if opaque
	// Strip off the query part
	if (start < limit) {
		var queryStart = spec.indexOf('?');
		queryOnly = (queryStart == start);

		if (queryStart != -1) {
			query = spec.substring(queryStart+1, limit);

			if (limit > queryStart)
				limit = queryStart;

			spec = spec.substring(0, queryStart);
		}
	}

	var i = 0;
	// Parse the authority part if any
	if ((start <= limit - 2) && (spec.charAt(start) == '/') && (spec.charAt(start + 1) == '/')) {
		start += 2;
		i = spec.indexOf('/', start);
		if (i < 0) {
			i = spec.indexOf('?', start);

			if (i < 0)
				i = limit;
		}

		host = authority = spec.substring(start, i);

		var ind = authority.indexOf('@');

		if (ind != -1) {
			userInfo = authority.substring(0, ind);
			host = authority.substring(ind+1);
		}

		ind = host.indexOf(':');
		port = -1;
		if (ind >= 0) {
			// port can be null according to RFC2396
			if (host.length > (ind + 1)) {
				port = parseInt(host.substring(ind + 1));
			}
			host = host.substring(0, ind);
		}

		start = i;
		// If the authority is defined then the path is defined by the
		// spec only; See RFC 2396 Section 5.2.4.
		if (authority != null && authority.length > 0)
			file = "";
	}

	if (host == null) {
		host = "";
	}

	// Parse the file path if any
	if (start < limit) {
		if (spec.charAt(start) == '/') {
			file = spec.substring(start, limit);
		} else if (file != null && file.length > 0) {
			isRelPath = true;
			var ind = file.lastIndexOf('/');

			var seperator = "";

			if (ind == -1 && authority != null)
				seperator = "/";

			file = file.substring(0, ind + 1) + seperator + spec.substring(start, limit);
		} else {
			var seperator = (authority != null) ? "/" : "";
			file = seperator + spec.substring(start, limit);
		}
	} else if (queryOnly && file != null) {
		var ind = file.lastIndexOf('/');
		if (ind < 0)
			ind = 0;
		file = file.substring(0, ind) + "/";
	}

	if (file == null)
		file = "";

	if (isRelPath) {
		// Remove embedded /./
		while ((i = file.indexOf("/./")) >= 0) {
			file = file.substring(0, i) + file.substring(i + 2);
		}
		// Remove embedded /../
		while ((i = file.indexOf("/../")) >= 0) {
			if ((limit = file.lastIndexOf('/', i - 1)) >= 0) {
				file = file.substring(0, limit) + file.substring(i + 3);
			} else {
				file = file.substring(i + 3);
			}
		}
		// Remove trailing ..
		while (file.substring(file.length - 3, file.length) == "/..") {
		//while (file.endsWith("/..")) {
			i = file.indexOf("/..");
			if ((limit = file.lastIndexOf('/', i - 1)) >= 0) {
				file = file.substring(0, limit+1);
			} else {
				file = file.substring(0, i);
			}
		}
		// Remove trailing .
		if (file.substring(file.length - 2, file.length) == "/.")
		//if (file.endsWith("/."))
			file = file.substring(0, file.length() -1);
	}

	setURL(u, protocol, host, port, authority, userInfo, file, query, ref);
}
// ---------------------------------------------------------------------
function setURL(u, protocol, host, port, authority, userInfo, path, query, ref) {
	u.set(u.protocol, host, port, authority, userInfo, path, query, ref);
}
// ---------------------------------------------------------------------
function URL_isValidProtocol(protocol) {
	return true;
	/*var len = protocol.length;

	if (len < 1)
		return false;

    var c = protocol.charAt(0);

	//if (!Character.isLetter(c))
	if (!isNaN(c))
		return false;

	for (var i = 1 ; i < len ; i++) {
	    c = protocol.charAt(i);

	    if (!Character.isLetterOrDigit(c) && c != '.' && c != '+' && c != '-') {
			return false;
	    }
	}
	return true;*/
}
// ---------------------------------------------------------------------
function URL_setParameter(key, val, replace) {
	if (!key)
		return;

	if (replace || this.qParams[key] == null) {
		this.qParams[key] = new Array();
	}

	this.qParams[key][this.qParams[key].length] = val;
}
// ---------------------------------------------------------------------
function URL_removeParameter(key) {
	var _key;
	var newQParams = new Object();

	for (_key in this.qParams) {
		if (_key != key) {
			newQParams[_key] = this.qParams[_key];
		}
	}

	this.qParams = newQParams;
}
// ---------------------------------------------------------------------
function URL_removeAllParams() {
	var newQParams = new Object();
	this.qParams = newQParams;
}
// ---------------------------------------------------------------------
function URL_parseQueryString() {
	var s;

	if (this.query == null || this.query.length == 0)
		return;
	else
		s = "&" + this.query;

	var idx2;
	var idx = s.indexOf("&");

	while (idx != -1) {
		var kvPair = null;
		var kvPos = 0;

		idx2 = s.indexOf("&", idx+1);

		if (idx2 != -1) {
			kvPair = s.substring(idx+1, idx2);
		} else {
			kvPair = s.substr(idx+1);
		}

		kvPos = kvPair.indexOf("=");

		if (kvPos != -1) {
			var key = kvPair.substring(0, kvPos);
			var val = kvPair.substr(kvPos+1);

			this.setParameter(key, val);
		}

		idx = idx2;
	}
}
// ---------------------------------------------------------------------
function URL_toExternalForm() {
	var result = this.protocol;

	result += ":";

	if (this.authority != null && this.authority.length > 0) {
		result += "//";
		result += this.authority;
	}

	/*if (this.file != null) {
		result += this.file;
	}*/
	if (this.path != null) {
		result += this.path;
	}

	var query = "";
	var key;

	for (key in this.qParams) {
		var vals = this.qParams[key];

		for (var i = 0 ; i < vals.length ; i++) {
			if (query.length == 0) {
				query += key + "=" + vals[i];
			} else {
				query += "&" + key + "=" + vals[i];
			}
		}
	}

	if (query.length > 0) {
		result += "?" + query;
	}

	if (this.ref != null) {
		result += "#";
		result += this.ref;
	}

	return result;
}
// ---------------------------------------------------------------------
function URL_setSession() {
	var sess_pair = getSessionPair();

	if (sess_pair[0] && sess_pair[1]) {
		this.setParameter(sess_pair[0], sess_pair[1], true);
		this.setParameter(CM_SESSION_KEY_KEY, sess_pair[0], true);

		return true;
	}

	return false;
}
// ---------------------------------------------------------------------

