/*******************************************************************************

'args.js', by Charlton Rose

Permission is granted to use and modify this script for any purpose,
provided that this credit header is retained, unmodified, in the script.

*******************************************************************************/


// This function is included to overcome a bug in Netscape's implementation
// of the escape () function:

function myunescape (str) {
	str = '' + str;
	while (true) {
		var i = str . indexOf ('+');
		if (i < 0) break;
		str = str . substring (0, i) + ' ' + str . substring (i + 1, str . length);
	}
	return unescape (str);
}



// This function creates the args [] array and populates it with data
// found in the URL's search string:

function args_init () {
	args = new Array ();
	var argstring = window . location . search;
	if (argstring . charAt (0) != '?')
		return;
	argstring = argstring . substring (1, argstring . length);
	var argarray = argstring . split ('&');
	var i;
	var singlearg;
	for (i = 0; i < argarray . length; ++ i) {
		singlearg = argarray [i] . split ('=');
		if (singlearg . length != 2)
			continue;
		var key = myunescape (singlearg [0]);
		var value = myunescape (singlearg [1]);
		args [key] = value;
	}
}



// Call the args_init () function to set up the args [] array:

args_init ();

//--------------------------------------------------------------------------------
//					EXPLAIN
//--------------------------------------------------------------------------------
// HTML document must include: <script src="args.js"></script>
// http://www.mysite.com/mypage.html?param1=value1&param2=value2&...&paramn=valuen

// http://www.mysite.com/mypage.html?name=Charlie+Brown&password=snoopy
// The variable args['name']		returns: Charlie Brown
// The variable args['password']	returns: snoopy

// http://sharkysoft.com/tutorials/jsa/content/043.1.html?item=cat&price=5.25&qty=2
// args ["item"]  = "cat"
// args ["price"] = "5.25"
// args ["qty"]   = "2"
//--------------------------------------------------------------------------------
