#!/usr/local/bin/perl5

if ($ENV{QUERY_STRING}=~ /name=(gryffindor|slytherin|hufflepuff|ravenclaw)/) {
   $teamname= $1;
} else {
  print("Location: index.html\n\n");
  exit(0);
}
$new= $ENV{QUERY_STRING}=~ /newjoin/;

if ($new) {
    $desc= "<img src=sorting/$teamname.gif>";
} else {
    $desc="";
}


open(POP, "enroll/people");

$count= 1;
$totalcount= 1;
$list= "";


if ($teamname eq "gryffindor") {
    $Teamname = "Gryffindor";
    $color = "#CC0000";
    $fontcolor = "#FFCC00";
}
elsif ($teamname eq "slytherin") {
    $Teamname = "Slytherin";
    $color = "#114E11";
    $fontcolor = "#D0D0D0";
}
elsif ($teamname eq "hufflepuff") {
    $Teamname = "Hufflepuff";
#    $color = "#FFEE66";
    $color = "#ffee44";
#    $fontcolor = "#6655cc";
    $fontcolor = "#111166";
}
else {
    $Teamname = "Ravenclaw";
    $color = "#000080";
#    $fontcolor = "#CCDDFF";
    $fontcolor = "#ffa500";
#    $fontcolor = "#AC9873";
}



while (<POP>) {
    ($name, $email, $effort, $team, $img, $quotation)= split(/\#\#\#/);
    if( $team eq $teamname ) {
        $list.= "<TR align=center>\n<TD align=center bgcolor=black>";
        # Make the cell with the image:
        if ($img && $img ne "http://") {
            $list.= "<A href=\"$img\"><img src=\"$img\"";
        } else {
            $list.= "<IMG src=crests/$teamname.jpg";
        }
        $list.= " border=0 height=70></A></TD>\n";
        # Make the cell with the name:
        $list.= "<TD align=center>";
        $list.= "<A href=mailto:$email><FONT color=$fontcolor size=+1><NOBR>$name</NOBR></FONT><\A>";

        if( $totalcount <= 4 ) {
            $list.= "<BR>House Captain";
        }
        $list.= "</TD>\n";
        $quotation=~ s!///!<BR>!g;
        # Make the cell with the quotation:
        $list.= "<TD align=center><FONT color=$fontcolor>$quotation";
        $list.= "</FONT></td></tr>\n";
        $count++;
    }
    elsif ($team eq $teamname) {
        $capmail = $email;
    }

    $totalcount++;
}

$pic = $teamname._pic;
$n = $teamname._name;

$email = $teamname . "\@ai.mit.edu";

print <<EOF;
Content-type: text/html

<html>
<head>
<title>$Teamname</title>
<link href="style.css" rel=stylesheet type=text/css>
</head>

<body bgcolor=black text=$fontcolor link=$fontcolor vlink=$fontcolor alink=$fontcolor >
<center>
<font face="Arial,Helvetica,Geneva">
<font size=+2>
<b>$desc</b>
</font>

<p>
<img src=crests/$teamname.gif>
<p>
<table cellspacing=5 border=1 bgcolor=$color valign=center
bordercolor=$fontcolor bordercolordark=$fontcolor bordercolorlight=$fontcolor> 
<tr >
<td align=center>
<img src=captains/$teamname.jpg width=210><br>
<font style="background-color:$color" size=300% color=$fontcolor><b> $Teamname
</b></td>
</tr>
</table>
<p>
<font color=$color>Email all your team members at: <a href=mailto:$email>$email</a></font>
<p>
<table cellspacing=5 border=1 width=700 bgcolor=$color bordercolor=$fontcolor bordercolordark=$fontcolor bordercolorlight=$fontcolor> 
<font color=$fontcolor>
<style type=text/css>
<!--
    body {color:$fontcolor; link=$fontcolor; vlink=$fontcolor; 
    alink=$fontcolor }
-->
</style>
$list
</font>
</table>


<p>

</font>
<a href="index.html"><img height=70 src=crests/hogwarts.gif border=0></a><br>
</center>
</body>
</html>
EOF
    ;
