/**
 * Adds a parameter to an URI.
 * 
 * Example :
 * we want to add a parameter with name = sectionTab and value = ACCESS_CARDS to
 * http://hertz-paris.eileo-dev.org:8080/ZenonV2/users/displayMember.do?mbr=30588
 * The resulting URI shall be http://hertz-paris.eileo-dev.org:8080/ZenonV2/users/displayMember.do?mbr=30588&sectionTab=ACCESS_CARDS
 * 
 * @param pURI a string representing an URI
 * @param pName the name of the parameter
 * @param pValue the value of the parameter
 * @return
 */
function LinkUtils_addParameter(pURI, pName, pValue) {
	var newURI = pURI;
	
	// if the URI already contains the specified parameter name then we do not add it again
	if(pURI.indexOf(pName) == -1)
	{
		var parameter = pName + "=" + pValue;
		
		// if the uri contains a "?" then the new parameter is added in front of the first old one.
		// example : http://www.toto.com?param0=val0 + param1=val1 is computed to http://www.toto.com?param1=val1&param0=val0
		if(pURI.indexOf("?") != -1) {
			newURI = newURI.replace(/\?/, "?" + parameter + "&");
		}
		// predicate : the uri does not contain any "?"
		// if the uri contains a "#" then the new parameter is added in front of the "#"
		// example : http://www.toto.com# + param0=val0 is computed to http://www.toto.com?param0=val0#
		else if(pURI.indexOf("#") != -1) {
			newURI = newURI.replace(/#/, "?" + parameter + "#");
		}
		// predicate : the uri does not contain any "?" nor "#"
		// the parameter is added to the uri
		// example : http://www.toto.com + param0=val0 is computed to http://www.toto.com?param0=val0
		else {
			newURI += "?" + parameter;
		}
	}
	
	return newURI;
}