// Parses the ampersand-separated query string name=value pairs of the current
// page's URL. It stores the name/value pairs in properties of an object and 
// returns that object.
//
// Example: eval("lnk" + queryString().state + ".coords = '0'");
//
// Note: 'queryString().state' returns true if 'state' is in the query string
// AND its value is not blank.  Do 'queryString().state != null' to test for
// existence only.
//
function queryString(loc)								// loc can be null or for instance "top.location"
{
	loc = (loc ? loc : location);
	var sQS = loc.search.substring(1);					// get the query string
	var args = new Object();
	var rgsPropValue = sQS.split("&");					// split at ampersand
	for (var i = 0; i < rgsPropValue.length; i++)
	{
		var j = rgsPropValue[i].indexOf('=');			// look for "name=value"
		if (j == -1)									// if not found
			continue;									// skip
		var sName  = rgsPropValue[i].substring(0, j);	// extract the name
		var sValue = rgsPropValue[i].substring(j+1);	// extract the value
		args[sName] = unescape(sValue);					// store name/value
		//
		// Note: In JavaScript 1.5, use decodeURIComponent() not unescape().
		//
	}	
	return args;
}

// Appends the specified name/value pair to the provided query string (if not already present).
//
function appendQueryString(qs, name, value)
{
	if (qs.indexOf("?") == -1)
		return (qs += ("?" + name + "=" + value));
	if (qs.toLowerCase().indexOf(name.toLowerCase()) == -1)
		return (qs += ("&" + name + "=" + value));
	return qs;
}