/*
	parameterHandling.js (c)2006 Meridian Technique Limited
	Author: Adrian Jones | http://www.orthoview.com

	This script handles parameters being passed in via the url.
*/
var params = getParams();

// Gets the parameters
function getParams() 
{
	var idx = document.URL.indexOf('?');
	var params = new Array();
	if (idx != -1) 
	{
		var position = 0;
		var parameters = document.URL.substring(idx+1, document.URL.length);
		while ( parameters.length != 0)
		{
			var andPos = parameters.indexOf('&');  // check for the standard &
			var plusPos = parameters.indexOf('+'); // aldo check for the + - CWeb doesn't support &
// alert( "parameters: " + parameters + ", andPos: " + andPos + ", plusPos: " + plusPos);

			if ( plusPos != -1 && andPos > plusPos )	{	position = plusPos;	}
			else if ( andPos != -1 && plusPos > andPos ){	position = andPos;	}
			else if ( plusPos != -1){						position = plusPos;	}
			else if ( andPos != -1)	{						position = andPos;	}
			else					{						position = parameters.length; }
			
			var entry = parameters.substring( 0, position);
			if ( entry.indexOf( "=") != -1)
			{
				nameVal = entry.split('=');
				paramName = nameVal[0].toLowerCase();
				paramValue = nameVal[1];
// alert("paramValue: " + paramValue);
				if ( paramValue.lastIndexOf( "#") == paramValue.length - 1) // this removes the # off the end (if there is one)
				{
					paramValue = paramValue.substring( 0, paramValue.length -1);
				}
			}
			else
			{
				paramName = entry;
				paramValue = "";
				if ( paramName.lastIndexOf( "#") == paramName .length - 1) // this removes the # off the end (if there is one)
				{
					paramName  = paramName .substring( 0, paramName .length -1);
				}
			}
			params[paramName] = paramValue;
			params.push( paramName);
// alert("PARAMETERS: " + paramName + "=" + params[paramName]);
			if ( position >= parameters.length) {	parameters = ""; }
			else {	parameters = parameters.substring( position+1, parameters.length); }
		}
	}
	return params;
}