#!/usr/local/perl/perl

print "Content-type: text/html\n\n";
print "<HTML>\n\n";
print "<HEAD>\n\n";
print "<TITLE>A home I would like to buy...";
print "</TITLE>\n";
print "</HEAD>\n\n";
print "<BODY BGCOLOR=FFFFFF>\n\n";
print "<H1>A home I would like to buy...";
print "</H1>\n\n";
print "<HR SIZE=5 NOSHADE><P>\n\n";

chop($post = <>);

@lines = split(/\&/, $post);

foreach(@lines) {
  @kv = split(/=/);
  $key = &unescape(@kv[0]);
  $value = &unescape(@kv[1]);

  if ($key eq "name") {
    $message .= "Name -- $value<P>\n\n";
	next;
  }
  if ($key eq "address") {
    $message .= "Address -- $value<P>\n\n";
	next;
  }
  if ($key eq "ph-number") {
    $message .= "Area Code and Phone 
                 Number -- $value<P>\n\n";
	next;
  }
  if ($key eq "e-name") {
    $message .= "E-Mail Address -- 
                 $value<P>\n\n";
	next;
  }
  if ($key eq "price") {
    $message .= "In what price range are you 
                 looking? -- $value<P>\n\n";
	next;
  }
  if ($key eq "area") {
    $message .= "In what area 
     (West Lafayette, Lafayette, Tippecanoe 
     county, other) would you like to find 
     a home? -- $value<P>\n\n";
	next;
  }
  if ($key eq "frame") {
    $message .= "What is your time frame 
     for looking at and purchasing a home? 
     -- $value<P>\n\n";
	next;
  }
  if ($key eq "bedrooms") {
    $message .= "How many bedrooms would you 
     prefer? -- $value<P>\n\n";
	next;
  }
  if ($key eq "footage") {
    $message .= "Approximately how much 
     square footage would you prefer? -- 
     $value<P>\n\n";
	next;
  }
  if ($key eq "special") {
    $message .= "Are there any special 
     considerations you would like 
     (for example, finished basement, 
     1-story home, sun room)? 
     -- $value<P>\n\n";
	next;
  }
}

print "$message\n";
print "</BODY>\n\n";
print "</HTML>\n\n";

exit;


sub unescape {
  local($_) = @_[0];
  s/\+/ /g;
  s/%([\da-f]{1,2})/pack(C,hex($1))/eig;
  $_;
}
