//Last Updated: 2004-02-29

//Begin URL Object
function URL()
{
	this.href		= location.href;		//complete URL
	this.host		= location.host;		//host + domain name (i.e. www.creartivity.org)
	this.port		= location.port;		//port number
	this.pathname	= location.pathname;	//path after host and before search
	this.hostname	= location.hostname;	//host:port
	this.hash		= location.hash;		//anchor name of URL including #
	this.search		= location.search;		//query info of URL including ?

	//URL Functions
	this.Value	= urlValue;
	this.Variables = urlVariables;

	//return this.href;
}
//------------------------------------
function urlValue(varName)
/*
In: varName -	a string representing the name of the variable whose value
				should be retrieved (specified in the url as http://www.url.com/?varName=value)
Out: the value of varName specified in the URL
*/
{
	var str = this.search;
	var posVar = str.indexOf(varName+"=", 0);
	if(posVar == -1){return ""}

	var posAmp = str.indexOf("&", posVar);
	if(posAmp == -1){posAmp = str.length}

	var ret = str.substring(posVar+varName.length+1,posAmp);
	var i;
	while((i = ret.indexOf('%')) != -1){
		ret = ret.substr(0,i) + String.fromCharCode(parseInt(ret.substr(i+1,2),16)) + ret.substr(i+3,ret.length);
	}
	
	return ret;
}
//------------------------------------
function urlVariables()
/*
Out: an array of strings representing the variables passed via the URL
*/
{
	var arrRet = new Array(0);

	var str = this.search;

	var pos1 = 0;
	while(pos1 != -1){
		var posEqu = str.indexOf("=",pos1+1);
		var posAmp = str.indexOf("&",pos1+1);
		pos2 = posEqu > posAmp && posAmp != -1 ? posAmp : posEqu;
		if(pos2 == -1){pos2 = str.length}
		arrRet[arrRet.length] = str.substring(pos1+1,pos2);
		pos1 = str.indexOf("&",pos2);
	}

	return arrRet;
}
//------------------------------------
//End URL Object

