/* Code for "requestQuery.js" 
This code will parse a URL containing a search string generated by the "get" 
method of a submitted form (or manually encoded into the URL) into two arrays. 
It also includes the function "QString()" that will return the 
value of the field name as its argument. 

To use these funtions, copy and paste into the header of your html document 
between the tags <script language="JavaScript"> and </script>, or better yet 
save this text as "requestQuery.js", save it to the same directory as the html 
pages you wish to use it with and include it in your header with the line: 

<script language="JavaScript" src="requestQuery.js"></script> 

Once that is done, references to field values from the form used to "get" 
the current page can be obtained by using "QString('fieldname')" 
in place of the value where "fieldname" is the the name of the form field desired. 

Written by Chris Broski 1/2000 
www.chrisbroski.com 
*/ 

//Code starts here ------------------------------------------- 
//Define variables 
var string_loop, value_loop, field_name, get_info, value_count 
var get_info_length, name_value_flag, new_character 

//Assign initial values 
value_loop=0 
name_value_flag="N" 
get_info=document.location.search 
get_info_length=get_info.length 

//Count total number of queries 
value_count=0 
for (x=1; x<=get_info_length; ++x) 
 { 
 if (get_info.charAt(x) == "=") {++value_count} 
 } 

//Define arrays 
get_name=new Array(value_count) 
get_value=new Array(value_count) 
get_name[0]="" 

//Parse search string into 2 arrays 
for (string_loop=1; string_loop <= get_info_length; ++string_loop) 
 { 
 //Flag the information as a name or a value. 
 if (get_info.charAt(string_loop) == "&") 
  { 
  name_value_flag="N" 
  ++value_loop 
  get_name[value_loop] = "" 
  } 
 else if (get_info.charAt(string_loop) == "=") 
  { 
  name_value_flag="V" 
  get_value[value_loop] = "" 
  } 
 else 
  {fill_array(value_loop)} 
 } 

function fill_array(value_number) 
{ 
new_character = get_info.charAt(string_loop) 

 //If the character is a "+" or "%", replace with the correct symbol 
 if (new_character == "+") {new_character = " "} 
 else if (new_character == "%") 
 { 
 new_character = unescape(get_info.charAt(string_loop) + get_info.charAt(string_loop -1*-1) + get_info.charAt(string_loop - 2*-1)) 
 string_loop = string_loop + 2 
 } 

 //Update the name or value array with the next character 
 if (name_value_flag == "N") 
  {get_name[value_number]=get_name[value_number] + new_character} 
 else 
  {get_value[value_number]=get_value[value_number] + new_character} 
} 

//Main function: returns value of a form field 
function QString(field_name) 
{ 
 for (x=0; x<value_count; ++x) 
 { 
 if (get_name[x] == field_name) 
  { 
  return get_value[x] 
  break 
  } 
 } 
} 
//Code ends here --------------------------------------------- 
