// Author:      lewiser
// Date:        2003-02-13
// Description: Gets URL parameters, decodes them and puts them into the two arrays "key"
//              and "value". Also lets a script access a certain parameter (key) directly.
// Usage:
// get_value (         Gets the value for the given parameter.
//    parameter        The URL parameters whose value is required.
// )
// Returns:
// value               The value of the URL parameter.
//
// get_parameters (    Gets all the URL parameters and saves them in the arrays "key" and "value". This is done automatically, so don't use this function!
// )
// HTML usage:
// For a URL http://www.whatever.com/whatever.html?bla=1&etc=2&whatever=3
// <head>
// <script src="/common_scripts/get_parameters.js" type="text/javascript" language="javascript"></script>
// <script language="javascript">
// alert(key[0] + " = " + value[0]);
// alert(get_value('whatever'));
// </script>
// </head>
//
// will show two alert boxes with "bla = 1" and "3".


key = new Array();
value = new Array();
get_parameters();

function get_parameters() {
	// Get the URL
	var url = window.location.search;
	var index = 0;
	if (url != "") {
		url = url.substring(1, url.length);
		list = url.split("&");
		for (i = 0; i <= list.length-1; i++) {
			temp = list[i].split("=");
			key[i] = temp[0];
			value[i] = temp[1];
		}
		// Replace + with blanks and unescape other non-standard characters
		for (i = 0; i <= key.length-1; i++) {
			key[i] = key[i].replace(/\+/g," ");
			value[i] = value[i].replace(/\+/g," ");
			key[i] = unescape(key[i]);
			value[i] = unescape(value[i]);
		}
	}
}

function get_value(searchKey) {
	var keyValue = '';
	for (i = 0; i <= key.length-1; i++) {
		if (key[i] == searchKey) {
			keyValue = value[i];
		}
	}
	return keyValue;
}

