/* 

This object roughly replicates the ability of the JSP "request" object (javax.
servlet.HttpServletRequest) to extract parameters from a query string.  Note
that unlike in the case of JSP, this object can only process request parameters
found on the query string -- since javascript doesn't have access to request
parameters passed via the POST method, processing POSTed params is not possible
with this or any other javascript object.

Note that this object requires /scripts/HashMap.js to have been SCRIT-SRCed 
prior to the SCRIPT-SRCing of this file.

This file creates an instance of the _Request object; users will always access
the object as request.methodName().  There are three methods, all nearly 
identical to their HttpServletRequest versions:

getParameter(name) - returns the param named name, or null if it doesn't exist.

getParameterNames() - returns an array of all param names on the query string

getParameterValues(name) - returns an array of all params named name, or null if
there are none.  (as with JSP, getParameter() is generally the way to get a param's
value, but getParameter() is not of use when the request contains multiple parameters
with the same name, such as would be the case with a set of (identically named) 
checkboxes.

*/

function _Request(locHref) {

	if (!window.hashMapLoaded) {
		alert("Request.js requires HashMap.js to be included prior to it; this include was not found.")
		return
	}
	this.locHref=locHref

	// methods:
	this.getParameter=__Request_getParameter
	this.getParameterNames=__Request_getParameterNames
	this.getParameterValues=__Request_getParameterValues

	this.params=new HashMap() // keys are param names; values are an array containing one or more param values
	var queryString=""
	if (locHref.indexOf("?")>-1) {
		queryString=locHref.substring(locHref.indexOf("?")+1,locHref.length)
	}
	if (queryString!="") {
		var nvPairs;
		if (queryString.indexOf("&")==-1) {
			nvPairs=[queryString]
		}
		else {
			nvPairs=queryString.split("&")
		}
		for (var i=0; i<nvPairs.length; i++) {
			var name
			var value
			if (nvPairs[i].indexOf("=")>-1) {
				name=unescape(nvPairs[i].replace(/\+/g," ").split("=")[0])
				value=unescape(nvPairs[i].replace(/\+/g," ").split("=")[1])
			}
			else {
				name=nvPairs[i]
				value=null
			}
			if (this.params.get(name)==null) {
				this.params.put(name, [value])
			}
			else {
				var currValues=this.params.get(name)
				currValues[currValues.length]=value
				this.params.put(currValues)
			}
		}
	}
}

function __Request_getParameter(name) {
	if (this.params.get(name)==null) {
		return null
	}
	else {
		return this.params.get(name)[0]
	}
}

function __Request_getParameterNames() {
	return this.params.keys()
}

function __Request_getParameterValues(name) {
	return this.params.get(name)
}



var request=new _Request(location.href)

var requestLoaded=true

