#!/usr/bin/ruby

require 'cgi'

# Get the 'q' parameter out of the incoming Query String
cgi = CGI.new
q = cgi.params['to']

# Our limited 'database' contains a few users
# with their username and full name
data = [
	{
		"user" => "amon",
		"name" => "N. Equalist"
	},
	{
		"user" => "android18",
		"name" => "Bad Ass"
	},
	{
		"user" => "ayeka",
		"name" => "Crown Princess of the Imperial Family of Jurai"
	},
	{
		"user" => "gaara",
		"name" => "Sandy"
	},
	{
		"user" => "goku",
		"name" => "Kakarot"
	},
	{
		"user" => "hiruma",
		"name" => "Yoichi Hiruma"
	},
	{
		"user" => "naruto",
		"name" => "The next Hokage"
	},
	{
		"user" => "rockLee",
		"name" => "Rock Lee"
	},
	{
		"user" => "ryoko",
		"name" => "Space Pirate Ryoko"
	},
	{
		"user" => "sakura",
		"name" => "S&S Forever"
	},
	{
		"user" => "sasuke",
		"name" => "Sasuke Uchiha"
	},
	{
		"user" => "vegeta",
		"name" => "Saiyan Prince"
	}
]

# Make sure that we print out the correct HTML header
print "Content-type: text/html\n\n"

# Now we "search" through the data
for row in data
	# Looking for users that match our auto-complete search
	if(row["user"] =~ /#{q[0]}/i || row["name"] =~ /#{q[0]}/i)
		
		print '<li id="' + row["user"] + '">
			<img src="icons/' + row["user"] + '.png"/>
			<div>
				<span id="username">' + row["user"] + '</span>
				<span id="fullname">' + row["name"] + '</span>
			</div>
		</li>'
	end
end