// The function parses a standard formatted querystring from the URL and
// returns an object that acts like an associative array.

// A properly formed querystring looks like this:
//    ?key1=value1&key2=value2&key3=value3

// Assuming you know the keys in your querystring, you can access them as follows:
// queryData["myKey']    or   queryData.myKey

// for (var word in items)
//    listString += items[word] + ", ";


function parseQuerystring()
{
	// get the querystring:
	var queryString = window.location.search;
	
	// Strip off the leading question mark
	queryString = queryString.substring(1);

	// queryString now looks like this: key1=value1&key2=value2&key3=value3

	// Then use the split function to split each set of pairs around the &'s
	var pairsArray = queryString.split("&");

	// The pairsArray has elements that look like this:
	//         key1=value1
	//         key2=value2
	//         key3=value3

	var queryData = new Object();
	// Now look at each element of the pairsArray:
	
	// Here's an alternate way to loop through all elements of an array, replacing:
	//      for (i=0; i<pairsArray.length; i++)
	for (var i in pairsArray)
	{
	   // split this element around the "="
	   var pair = pairsArray[i].split("=");
	   
	   // pair[0] holds the key, pair[1] holds the value
	   var value = pair[1];
	   // replace all the + signs with spaces (from the URL encoding)
	   value = value.replace(/\+/g,' '); 
	   // unescape translates the %40 type of urlencoding back to the ASCII characters
	   value = unescape(value);
	   
	   // set an object property/value with this pair
	   queryData[pair[0]] = value;
	   
	   
	}

	return queryData;
}

