sub prepare_search_page
{
 # Declare our variables as local to this subroutine:
 my ($entry_hash,$search_opts,$newpage,@search_page);
 
 
	# Get the two things we need:
 
	# 1. A reference to a 2D entry hash.
	# 2. The HTML that makes up the search page.
 
 $entry_hash = shift;
 @search_page = getfile($search_template,0);
 
 
	# Now we prepare a list of fields to search as follows:
 
	# 1. Loop over each field name from the first entry found.
	# 2. Create an "<option>" tag for each field and put into $search_opts.
 
 foreach my $key (sort keys %{$$entry_hash{0}}){
  $search_opts .= "<option value='$key'>".ucfirst($key)."</option>\n";
 }
 
 # Finally we need to prepare the page as follows:
 
 # 1. Loop over each line of HTML from @search_page and do as follows:
 
 #	a. Feed the line through expand_vars() to handle generic content tags.
 #	b. Replace all occurances of the "<!--%%SEARCH_OPTS%%-->" tag with a list of options (above).
 #  c. Add the line to $newpage ready to be returned.
 
 foreach my $line (@search_page){
  $line = expand_vars($line,'');
  $line =~ s!<\!--\%\%SEARCH_OPTS\%\%-->!$search_opts!g;
  $newpage .= $line;
 }

 # Now the very last thing we do is return the prepared page:
 return $newpage;
}
1;