#!/usr/bin/perl

@q = ( "When I see a blank sheet of plain, white paper, the adjective that comes to mind is:",
       "Empty",
       "Superfluous",
       "Sad",
       "Inspirational",
       "Heretical",

       "The fruit that best describes me is a(n):",
       "Apple",
       "Orange",
       "Grape",
       "Passion Fruit",
       "Tomato",

       "If I were a writing implement, I'd be a(n):",
       "Pen",
       "Crayon",
       "Inking Brush",
       "Pencil",
       "Mechanical Pencil",

       "My favorite beverage is:",
       "Coke",
       "Pepsi",
       "Moxie",
       "Beer",
       "Schnapps",

       "Memories of grade school make me:",
       "Bitter",
       "Weep",
       "Cringe",
       "Crazy",
       "Froth at the Mouth",

       "If I were a Traveling Wilbury, I'd be:",
       "Tom Petty",
       "Bob Dylan",
       "Jeff Lynne",
       "Dead",
       "Dead as Well",

       "There's nothing wrong with:",
       "Having a Little Fun Now and Then",
       "Me, Damnit",
       "the Republican Party",
       "Legumes",
       "Arbitration",

       "Dan Rather:",
       "Rox",
       "Sux",
       "Has S00per Hair",
       "Raised Me Like His Own Child",
       "Is Standing Behind Me, Forcing Me to Answer 'Rox'",

       "If I Were a Carpenter:",
       "You'd Be My Lady",
       "I'd Hammer On My Piglet",
       "I Would Start a Band With a Sibling",
       "I'd Change My Name to 'Woody'",
       "I'd Build a House In the Middle of Our Street",

       "The Band 'Creed' are:",
       "Overrated",
       "Good Looking But Overrated",
       "Awful and Overrated",
       "Awfully Overrated",
       "Standing Behind Me, Forcing Me to Answer 'S00per'",
     );

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs)
  {
    ($name, $value) = split(/=/, $pair);
    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    $FORM{$name} = $value;
  }

if (!(exists($FORM{"qno"})))
  {
    $qno = 0;
  }
else
  {
    $qno = $FORM{"qno"};
    $rubbish = (time() % 100);
  }

print "Content-type: text/html\n\n";

if ($qno == 10)
  {
    print "<HTML><HEAD><TITLE>Y A R K (freak quiz: results)</TITLE>\n";
    print "<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"../style.css\"></HEAD><BODY>\n";
    open(INF, "<../nhead.htm");
    while (<INF>) { print; }
    close INF;
    print "<TR VALIGN=\"top\"><TD CLASS=\"data\"><CENTER><BR>FREAK<BR>QUIZ";
    print "<BR><BR>RESULTS\n";
    print "<BR><BR><A HREF=\"../text/\">TEXT</A><BR><BR></CENTER></TD>\n";
    print "<TD CLASS=\"data\"><BR>\n\n";

    print "According to our scientific calculations, you are:<BR><BR>\n";
    print "<CENTER><IMG SRC=\"../images/freak.png\"></CENTER>\n";
    print "<BR>Thanks for participating!<BR>\n";

    print "<BR>To put this on your site, use the following text:<BR><BR>\n";
    print "<CENTER><TEXTAREA ROWS=\"10\" NAME=\"TEMP\" cols=\"40\">\n";
    print "<CENTER><A HREF=\"http://www.yark.org/\">YARK</A> says I am...<BR>";
    print "<IMG SRC=\"http://www.yark.org/images/freak.png\"><BR>";
    print "<FONT SIZE=1><A HREF=\"http://www.yark.org/text/freak.shtml\">Are you a freak?</A>";
    print "</FONT></CENTER>\n</TEXTAREA><BR>\n";
    print "<BR><CENTER>( <A HREF=\"freak.pl\">try again</A> )</CENTER>\n";
  }
else
  {
    print "<HTML><HEAD><TITLE>Y A R K (freak quiz: question " . ($qno + 1) . ")</TITLE>\n";
    print "<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"../style.css\"></HEAD><BODY>\n";
    open(INF, "<../nhead.htm");
    while (<INF>) { print; }
    close INF;
    print "<TR VALIGN=\"top\"><TD CLASS=\"data\"><CENTER><BR>FREAK<BR>QUIZ";
    print "<BR><BR>QUESTION<BR><FONT SIZE=+2>" . ($qno + 1) . "</FONT>\n";
    print "<BR><BR><A HREF=\"../text/\">TEXT</A><BR><BR></CENTER></TD>\n";
    print "<TD CLASS=\"data\"><BR>\n\n";

    print "<FORM ACTION=\"freak.pl\" METHOD=\"POST\">\n";
    print "" . $q[$qno * 6] . "\n<UL>\n";
    print "<INPUT TYPE=\"radio\" NAME=\"choice\" VALUE=\"c1\" CHECKED> " . $q[$qno * 6 + 1] . "<BR>\n";
    for $_ (2 .. 5)
      {
        print "<INPUT TYPE=\"radio\" NAME=\"choice\" VALUE=\"c${_}\"> " . $q[$qno * 6 + $_] . "<BR>\n";
      }
    print "</UL>\n<CENTER><INPUT TYPE=\"submit\" VALUE=\"Submit\"></CENTER>\n";
    print "<INPUT TYPE=\"hidden\" NAME=\"qno\" VALUE=\"" . ($qno + 1) . "\">\n";
    if ($qno > 0)
      {
        print "<INPUT TYPE=\"hidden\" NAME=\"score\" VALUE=\"${rubbish}\">\n";
      }
    print "</FORM>\n";
  }
open(INF, "<../nfoot.htm");
while (<INF>) { print; }
close INF;
