// Function:		Return the value of the specified name-value pair in a URI query string.
// Author:			E3webdesign
// Modified:		08-Oct-2008	- First setup.
// Notes:			-
// Known bugs:		-
// Suggestions:		-

function getQueryVariable(name)
{	var query	= window.location.search.substring(1);
	var vars	= query.split("&");

//D	window.alert ('Function getQueryVariable: ' +
//D		'\nLooking for value of: ' + name +
//D		'\nQuery string: ' + query +
//D		'\nvars.length: ' + vars.length +
//D		'\nvars[0]: ' + vars[0].toString(16) +
//D		'\nvars[1]: ' + vars[1].toString(16));

	//Check if at least one name-value pair is present in the query string.
	//If not, exit the function, and return an empty string.
	//(For this check, the length of the vars array is not a good measure. It starts at 1, also when there is
	//no name-value pair present.)
	if (vars[0] == "") return "";

	for (var i=0;i<vars.length;i++)
	{	var pair = vars[i].split("=");
		if (pair[0] == name)			//pair[0] is the name part of the name-value pair
		{	var indexOfTarget = 0;
			while (indexOfTarget != -1)
			{	//Replace all '+' in the query string by '%20'
				//These '+' represent spaces, and are set by the default uri encoding function used by
				//the GET method in the form input field. Not very handy, since the default decoding function
				//in javascript (as used below) passes these '+' unchanged. So you can either not pass '+' or
				//spaces by using the deafult functions.

//D				window.alert ('Function getQueryVariable: ' +
//D					'\nLooking for value of: ' + name +
//D					'\nquery string: ' + query +
//D					'\nname part of name-value pair: ' + pair[0] +
//D					'\nvalue part of name-value pair: ' + pair[1] +
//D					'\nindexOfTarget: '+ indexOfTarget);

				pair[1] = pair[1].replace("+","%20");		//pair[1] is the value part of the name-value pair
				indexOfTarget = pair[1].indexOf("+",indexOfTarget);
			}
			return unescape(pair[1]);	//'unescape' to replace the special characters
										//in the query string by the original characters (spaces, comma's, etc.)
    	}
  	}
  	return "";	//No matching name-value pair found
}


