// JavaScript Document

//
// query_string function
//
// use this function to pass multiple values through the query_string in the URL (i.e. 
// http://thaturl?key1=value1&key2=value2[&key3=value3]
//
//  original source (with slight changes and my own description): 
//  http://javascript.about.com/library/scripts/blquerystring.htm


// STEP ONE: define arrays to store individual key & value data

query_string.keys = new Array();
query_string.values = new Array();

// STEP TWO: create query_string_parse() function to parse the actual passed querystring in  
// order to create separate key and value strings to call in the query_string() function

function query_string_parse()
{
	var query = window.location.search.substring(1);
	
	var pairs = query.split("&");
	
	for (var i=0;i<pairs.length;i++)
	{
		var pos = pairs[i].indexOf('=');
		if (pos >= 0)
		{
			var argname = pairs[i].substring(0,pos);
			var value = pairs[i].substring(pos+1);
			query_string.keys[query_string.keys.length] = argname;
			query_string.values[query_string.values.length] = value;

		}
	}

}

// STEP THREE:  parse the query_string immediately by calling the query_string_parse 
// function() in the document's header so that the "query_string()" function can be called 
// at any point within the document.

query_string_parse();

// STEP FOUR: create query_string() function.  passing the "key" to the function will return the
// "value" ...  i.e. in the URL:  http://www.thisurl.com?make=toyota&model=corolla, calling 
// query_string("make") will return a value of "toyota".


function query_string(key)
{
	var value = null;
	for (var i=0;i<query_string.keys.length;i++)
	{
		if (query_string.keys[i]==key)
		{
			value = query_string.values[i];
						
			break;
		}
	}
	return value;
}