############################################################
#
# stuff_html.pl
#
# Functions which generate HTML for parts of pages
#
############################################################

require "stuff_funcs.pl";


############################################################

sub write_debug
{
    my $m = join /,/, @memberList;
    print <<EOT;
    <pre>
    page="$page"
    arg1="$arg1"
    u_yyyymmdd="$yyyymmdd" b_yyyymmdd="$b_yyyymmdd" date_seed="$date_seed" birth_seed="$birth_seed"
    groups_size="$groups_size"
    memberList="$m"
    </pre>
    <hr>
EOT
}

sub write_debug_orig
{
    print <<EOT;

    <pre>
     DEBUG="$DEBUG"
     SCRIPT="$SCRIPT" PID="$PID" CGI_BIN="$CGI_BIN" DATADIR="$DATADIR" LISTDIR="$LISTDIR" POEMDIR="$POEMDIR"
     page="$page"
     r_sec="$r_sec" r_min="$r_min" r_hour="$r_hour" r_mday="$r_mday" r_mon="$r_mon" r_year="$r_year" r_wday="$r_wday" r_yday="$r_yday" r_isdst="$isdst"
     u_dayOfWeek="$u_dayOfWeek" u_mday="$u_mday" u_month="$u_month" u_mon="$u_mon" u_year="$u_year"
     b_dayOfWeek="$b_dayOfWeek" b_mday="$b_mday" b_month="$b_month" b_mon="$b_mon" b_year="$b_year"
     r_now="$r_now" u_format="$u_format"
     r_yyyymmdd="$r_yyyymmdd" u_yyyymmdd="$u_yyyymmdd" b_yyyymmdd="$b_yyyymmdd" 

     dayList[$u_wday]="$dayList[$u_wday]" u_mday="$u_mday" monthList[$u_mon]="$monthList[$u_mon]" u_year="$u_year"
     date_seed="$date_seed" fish_seed="$fish_seed" random_fish="$random_fish" todays_fish="$todays_fish"
     fish_lizard="$fish_lizard" fish_mollusc="$fish_mollusc"
     poem_yyyymmdd="$poem_yyyymmdd" poem_line="$poem_line"
     poem_file="$poem_file" poem_title="$poem_title" poem_author="$poem_author"
    </pre>
    <br clear="all"><hr>
EOT
}

############################################################

sub shite_title_toberemoved   # Special title for the default front page
{
    my ($title, $description) = @_;
    my $colour0 = "brown";
    my $colour1 = "#f0f0d0";

$colour0 = "blue";
$colour1 = "brown";

    $title = "www.shite.org - Shite Space, Stuff Today and Pooclub" if ($title eq "");
    $description = "The internet's most trifurcated URL" if ($description eq "");

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

<html>
<head>
  <title>$title</title>
  <meta name="Author" content="Mike Two-Sheds">
  <meta name="Description" content="$description">
  <meta name="Keywords" content="mike, kate, prospects, k-days, kday, events,
              poetry, poems, humour, humor, literature">
</head>
<body text="black" link="$colour0" vlink="$colour1">

EOT
}

############################################################

sub stuff_title   # Stuff Today HTML page starts getting written here
                  # including the Stuff Today title and menu bar
{
    my ($title, $description) = @_;
    my ($not_used, $u_day) = split / /, date_calc("-s $u_yyyymmdd");
    my $dayOfWeek = $u_day;
    my $ts = substr($timezone, 0, 1);  # + or - bit of timezone
    my $tz = substr($timezone, 1, 4);  # numeric part of timezone

    $title = "Stuff Today: " . $title if (! ($title =~ /^Stuff Today:/));
    $description = "Everything you need to know to cope with today" if ($description eq "");

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

<html>
<head>
  <title>$title</title>
  <meta name="Author" content="Mike Two-Sheds">
  <meta name="Description" content="$description">
  <meta name="Keywords" content="mike, kate, prospects, k-days, kday, events,
              poetry, poems, humour, humor, literature">
</head>
<body text="black" link="$colour[0]" vlink="$colour[1]"
      style="background-color: white;" />

<table align="left" border="0" width="700"
       style="background-color: white;" />
 <tr>
  <td align="center" valign="bottom" width="600">
   <font face="times" size="6"><i>
    Stuff Today!
   </i></font>
   <p>
   <table align="center" width="100%" border="0" bgcolor="$colour[0]" cellspacing="0" cellpadding="2">
    <tr>
     <td align="left">
      <font face="arial" size="2" color="white"><b>
       &nbsp;
       <a href="$THIS_CGI?p=stuff&$date_args">
        <font face="arial" size="2" color="white"><b>Home</b></font></a>
       |
       <a href="$THIS_CGI?p=prospects&$date_args">
        <font face="arial" size="2" color="white"><b>Prospects</b></font></a>
<!--------
       |
        Stocks
       |
        Groups
------>
       |
       <a href="$THIS_CGI?p=kday&$date_args">
        <font face="arial" size="2" color="white"><b>k-Day</b></font></a>
<!-------
       |
       <a href="$THIS_CGI?p=todayspoem&$date_args">
        <font face="arial" size="2" color="white"><b>Poem</b></font></a>
------->
       |
       <a href="$THIS_CGI?p=events&$date_args">
        <font face="arial" size="2" color="white"><b>Events</b></font></a>
       |
       <a href="$THIS_CGI?p=help&$date_args">
        <font face="arial" size="2" color="white"><b>Help</b></font></a>
      </b></font>
     </td>
     <td align="right">
      <font face="arial" size="2" color="white">
       <b>$r_now</b> 
       $ts<a href="$THIS_CGI?p=help&a=timezones&$date_args"><font face="arial" size="2" color="white">$tz</font></a>&nbsp;
      </font>
     </td>
    </tr>
   </table>
  </td>

  <td align="center" valign="bottom" width="100">

   <table cellpadding=1 cellspacing=1 border=0 width="80" bgcolor="black">
    <tr><td align="center">
     <table cellpadding=1 cellspacing=0 border=0 width="100%" bgcolor="white">
      <tr><td align="center">
       <font face="arial" size="2" color="black">
        $dayOfWeek<br>
       <font face="verdana,arial" size="6"><b><i>
        $u_mday
       </i></b></font>
         <br>
        <b>$u_month</b>
         <br>
        $u_year
       </font>
      </td></tr>
     </table>
    </td></tr>
   </table>

  </td>
 </tr>
</table>
<br clear="all">
EOT
}

############################################################

sub user_form  # This form allows the user to change
               # today's date and enter a date of birth
{
    my $align = shift(@_);
    $align = "center" if ($align eq "");

    print <<EOT;
    <br clear="all">
    <font face="verdana,arial" size="2">
        <form action = "$THIS_CGI" method = "GET">
EOT
    # Only show the k-day count on a k-day page
    if ($page eq "kday")
    {
        if ($arg1 eq "" || $arg1 < 1 || $arg1 > 99) {$arg1 = 30;}
        print <<EOT;
<br>
<center>
Show up to
<input type="TEXT" name="a" value="$arg1" size="2">
k-days
</center>
EOT
    }
    print <<EOT;
          <table border="0" align="$align" cellspacing="5">
EOT


    if ($page ne "whatisshite")  # Don't allow user to change actual date
    {                            # on "What Is Shite?" page
        print <<EOT;
            <tr>
              <td align="left"><font face="verdana,arial" size="2">
               Today's Date:</font></td>
              <td align="left">
                <select name="ud" size="1">
EOT
        for ($i = 1; $i < 32; $i++)
        {
            if ($i == $u_mday)   { print "<option selected>$i\n"; }
            else { print "<option>$i\n"; }
        }
        print <<EOT;
               </select>
              </td>
              <td align="left">
                <select name="um" size="1">
EOT
        for ($i = 0; $i < 12; $i++)
        {
                if ($monthList[$i] eq $u_month) { print "<option selected>$monthList[$i]\n"; }
        else { print "<option> $monthList[$i]\n"; }
        }
        print <<EOT;
                </select>  </td>
              <td align=left>
                <input type="TEXT" name="uy" value="$u_year" default="-" size="4"> </td>
              <td>&nbsp;</td>
              <td>
               <font face="arial" size="2">
                <a href="$THIS_CGI?p=$page&a=$arg1"><b>Reset</b></a></font>
              </td></tr>
EOT
    }

    print <<EOT;


            <tr>
              <td align="left"><font face="verdana,arial" size="2">
               Date Of Birth:</font></td>
              <td align="left">
                <select name="bd" size="1">
                 <option>-
EOT
    for ($i = 1; $i < 32; $i++)
    {
        if ($i == $b_mday)   { print "<option selected>$i\n"; }
        else { print "<option>$i\n"; }
    }
    print <<EOT;
               </select>
              </td>
              <td align="left">
                <select name="bm" size="1">
                 <option>-
EOT
    for ($i = 0; $i < 12; $i++)
    {
        if ($monthList[$i] eq $b_month) { print "<option selected>$monthList[$i]\n"; }
        else { print "<option> $monthList[$i]\n"; }
    }
    print <<EOT;
                </select>  </td>
              <td align=left>
                <input type="TEXT" name="by" value="$b_year" default="-" size="4"> </td>
              <td>&nbsp;</td>
              <td><input type="submit" value = "Go">
                  <input type="hidden" name="p" value="$page">
                  <input type="hidden" name="a" value="$arg1">
              </td></tr>

          </table>
          <br clear="all">
EOT
    # Calculate yesterday's date
    $yesterday = date_calc ("-d-1 $u_yyyymmdd");
    ($yo, $yd, $ym, $yy) = split /;/, parse_date ($yesterday);
    $yest_dates = "ud=$yd&um=$ym&uy=$yy&bd=$b_mday&bm=$b_month&by=$b_year";

    if ($page ne "whatisshite")  # Can't change real date on a "What Is Shite?" page
    {
    if ($DEBUG > 0 || $r_yyyymmdd != $u_yyyymmdd)  # Links to Yesterday and Tomorrow
    {
        # Calculate tomorrow's date
        $tomorrow= date_calc ("-d1 $u_yyyymmdd");
        ($to, $td, $tm, $ty) = split /;/, parse_date ($tomorrow);
        $tom_dates  = "ud=$td&um=$tm&uy=$ty&bd=$b_mday&bm=$b_month&by=$b_year";

        print <<EOT;
          <table border="0" align="$align" cellspacing="5" width="400">
            <tr>
             <td align="right" valign="middle">
               <a href="$THIS_CGI?p=$page&a=$arg1&$yest_dates">
                <img src="$IMGDIR2/left.gif" alt="Yesterday" border="0"></a>
             </td>
             <td align="left" valign="middle">
              <font face="verdana,arial" size="2">
               <a href="$THIS_CGI?p=$page&a=$arg1&$yest_dates">
                Yesterday</a>
              </font>
             </td>
             <td align="right" valign="middle">
              <font face="verdana,arial" size="2">
               <a href="$THIS_CGI?p=$page&a=$arg1&$tom_dates">
                Tomorrow</a>
              </font>
             </td>
             <td align="left" valign="middle">
               <a href="$THIS_CGI?p=$page&a=$arg1&$tom_dates">
                <img src="$IMGDIR2/right.gif" alt="Tomorrow" border="0"></a>
             </td>
            </tr>
          </table>
        <br clear="all">
EOT
    }
    else  # Don't show link to Tomorrow if today's date is the real date
          # (unless we're in debug mode)
    {
        print <<EOT;
          <table border="0" align="$align" cellspacing="5" width="400">
            <tr>
             <td align="right" valign="middle">
               <a href="$THIS_CGI?p=$page&a=$arg1&$yest_dates">
                <img src="$IMGDIR2/left.gif" alt="Yesterday" border="0"></a>
             </td>
             <td align="left" valign="middle">
              <font face="verdana,arial" size="2">
               <a href="$THIS_CGI?p=$page&a=$arg1&$yest_dates">
                Yesterday</a>
              </font>
             </td>
             <td align="right" valign="middle">
              &nbsp;
             </td>
             <td align="left" valign="middle">
               &nbsp;
             </td>
            </tr>
          </table>
        <br clear="all">
EOT
    }
    }

    print <<EOT;
        </form>
EOT
}

############################################################

#sub main_title
#{
#    print <<EOT;
#    <center> <font face="times" size="6">
#      <i><b><nobr>Stuff Today!</nobr></b> </i></font>
#    <p> </center>
#EOT
#}

############################################################

sub show_users_date
{
    print <<EOT;
   <font face="arial" size="2"> <b><nobr>$u_format</nobr></b><br></font>
   <font face="arial" color="gray" size="2"> $r_now (London) </font>
EOT
}

############################################################

sub show_stock_days
{
    my $s = "";   # stock ref
    my $itis = "It is";
    my $b_mmdd = substr ($b_yyyymmdd, 4, 4);
    my $u_mmdd = substr ($u_yyyymmdd, 4, 4);
    my $celebrations = 0;

    if (scalar (@stock_days) > 0)
    {
        print <<EOT;
            <center>
            <font face="verdana,arial,times" size="4" color="black">
             Congratulations!<br></font>
EOT

        print "<br>" if (scalar (@stock_days) > 1);

        for $s (@stock_days)
        {
            $celebrations++;

            print <<EOT;
                <font face="verdana,arial" size="3">$itis your
                <a href="$THIS_CGI?p=stock&a=$s&$date_args">
                <b>$stockHash->{$s}->{singular}</b></a> day!</font>
                <br>
EOT
            $itis = "and";
        }

        print "<br>";
    }

    if ($b_mmdd eq $u_mmdd)   # Birthday!
    {
        if ($celebrations == 0)
        {
            print "<center>";
        }

        $celebrations++;

        print <<EOT;
            <font face="verdana,arial,times" size="4" color="black">
             Happy Birthday!<br><br></font>
EOT
    }

    if ($celebrations > 0)
    {
        print "</center>\n";
    }
}

############################################################

sub show_stock_list
{
    # Get big long stock list for left-hand column

    my $stock_id = shift(@_);
    my $stock_list_file = "$LISTDIR/$stockHash->{$stock_id}->{filename}";
    my $stock_list_type = lc($stockHash->{$stock_id}->{plural});
    my @stock_list = ();
    my $stock_list_count = all_lines ($stock_list_file, \@stock_list);
    my $stock = "";

    print <<EOT;
    <font face="arial" size="1">
     <b>$stock_list_count top quality<br>$stock_list_type</b>
     <p>
     <font face="arial" size="1" color="gray">
EOT
    for $stock (@stock_list) { print "- $stock<br>\n"; }
    print "</font></font>\n";
}

############################################################

sub show_event
{
    # Displays todays event (beneath the calendar on the
    # main page).  
    # Events are found either in the "events.dat" file
    # or in the "events" directory under filenames
    # "January01", "January02", ... , "December31".
    # All events matching the parameterised date are shown.
    # If no events are found, nothing is displayed.

    my ($day, $size, $align, $hrwidth) = @_;

    # parameter defaults:
    $day     = $u_yyyymmdd if ($day eq "");
    $size    = 2           if ($size eq "");
    $hrwidth = "25%"       if ($hrwidth eq "");
    $align   = "center"    if ($hrwidth eq "");

    my ($not_used1, $mday, $month, $year) = split /;/, parse_date ($day);
    my $fname  = sprintf "%s%02d", $month, $mday;
    my $events = 0;

    print <<EOT;
        <table border="0" align="$align"><tr>
         <td align="left" valign="top">
          <font face="arial" size="$size">
EOT

    if (open (EVENTFILE, "$EVENTS_FILE"))
    {
        while (<EVENTFILE>)
        {
            chop;
            ($eYear, $monthDD, $text) = split /;/, $_, 3;
            $eYear =~ s/\s+//g;

            if ($monthDD eq $fname && ($eYear eq "Y" || $eYear eq "" || $eYear eq $year))
            {
                if ($events > 0) {print "<hr width=\"$hrwidth\" align=\"center\">\n";}
                $events++;
                print "<center>$text</center>\n";
            }
        }
        close (EVENTFILE);
    }

    if (open DATEFILE, "$EVENTDIR/$fname")
    {
        if ($events > 0) {print "<hr width=\"$hrwidth\" align=\"center\">\n";}

        while (<DATEFILE>) { print $_; }
        close (DATEFILE);

    }
    print <<EOT;
          </font>
         </td>
        </tr></table>
EOT
}

############################################################

sub passage
{
    my $i = 0;
    my $fname = random_line ("$PASSAGES_FILE", $u_yyyymmdd);
    $fname = "$PASSDIR/$fname";

    print <<EOT;
     <table align="center" cellpadding="0" cellspacing="0">
      <tr><td align="left">
       <font face="verdana,arial" size="2" color="black">
EOT

    open (INFILE, "$fname") || print "<b>No file: $fname</b><p>";

    while (<INFILE>)
    {
        if ($i == 0) { $author = $_; }
        else
        {
            if (/^\s*$/) { print "<p>"; }
            else { print "$_"; }
        }
        $i++;
    }
    close (INFILE);

    print <<EOT;
     </font>
      </td></tr>
      <tr><td align="right">
       <font face="verdana,arial" size="2" color="gray">
        $author </font>
      </td></tr>
     </table> </font> <br clear="all">
EOT
}

############################################################

sub new_word             # Today's New Word
{
    $newword_line = random_line ("$NEWWORD_FILE", $u_yyyymmdd);
    ($dic, $word, $definition) = split /;/, $newword_line;

    if ($dic eq "o")
    {
        $dic = "<b>Today's New Word</b><font face=arial size=1><br>
                (from the Oxtail English Dictionary)</font><p>";
    }
    elsif ($dic eq "y")
    {
        $dic = "<b>The Colourful World Of Yiddish</b>";
    }
    elsif ($dic eq "t")
    {
        $dic = "<font face=\"times\" size=\"3\"><i>Thought For The Day</i></font>";
    }
    else
    {
        $dic = "<font face=\"times\" size=\"3\"><i>Did You Know ...?</i></font>";
    }

    print <<EOT;
    <!---- Today's New Word ---->
    <table align="center" width="100%" border="0"
           cellspacing="0" cellpadding="10">
     <tr> <td align="left" valign="top" bgcolor="$colour[6]">
       <font face="arial" size="2">
         <center>$dic</center> <p> <b>$word</b> - $definition </font>
     </td> </tr>
    </table> <br clear="all">
EOT
}

############################################################


sub quotation   # Today's Quote
{
    my $quote_line = random_line ("$QUOTES_FILE", $u_yyyymmdd);
    my ($quote, $author) = split /;/, $quote_line;

    print <<EOT;
    <!---- Today's Quote ---->
    <table align="center" width="100%" border="0"
           cellspacing="0" cellpadding="0">
     <tr> <td align="center" valign="top">
       <font face="arial" size="2"> "$quote" </font>
     </td> </tr>
EOT
    if ($author ne "")  # Show author
    {
        print <<EOT;
         <tr> <td align="right" valign="top">
           <font face="arial" color="gray" size="2">
             - $author </font>
         </td> </tr>
EOT
    }
    print "</table> <br clear=all><br>";
}

############################################################

sub poo_club
{
    my @lt = localtime(time);
    my $randomSecond = $lt[0];
    my ($member, $sex, $name, $trooperFile) = 
        split /;/, random_line ("$TROOP_FILE", $randomSecond);
    $trooperFile = "$IMGTROOPDIR/" . $trooperFile;

    my $altTag = "foul-mouth fun at pooclub";

    if ($member eq "C")
    {
        $altTag = "Join " . $name . " for " . $altTag;
    }
    else
    {
        $altTag = "Join in the " . $altTag;
    }

    print <<EOT;
    <!---- Pooclub ---->
    <table align="center" valign="top" width="100%" border="0">
     <tr>
      <td align="left" valign="center">
       <a href="$POO_CGI">
        <img src="$trooperFile" alt="$altTag" border="0"></a>
      </td>
      <td align="left" valign="top">
       <font face="verdana,arial" size="5" color="brown">pooclub</font><br>
       <font face="verdana,arial" size="2">
         This fast action furious free-for-all forum
         has more f-words in it than you can fit in your fridge.<br>
        <a href="$POO_CGI"><b>pooclub</b></a>
       </font>
      </td>
     </tr>
    </table>
    <br clear="all">
EOT
}

############################################################

sub shite_space   # Shite Space and Today's Poem
{
    my $poem_record = todays_poem($r_yyyymmdd);
    my ($shiteId, $poemTitle, $poemAuthor, $poemType, $imageCode) = split /;/, $poem_record;

    print <<EOT;
    <!---- Shite Space ---->
    <table border="0" align="center" valign="top" width="100%">
     <tr>
      <td align="left" valign="top">
       <a href="$THIS_CGI?$date_args">
        <img src="${IMGSHITEDIR}/shitespace_logo.jpg"
             alt="Shitespace" border="0" width="150"></a>
      </td>
      <td align="left" valign="bottom">
       <font face="verdana,arial" size="4">
        www.shite.org
       </font>
       <p>
       <font face="verdana,arial" size="2">
        Branded the biggest pile of arse on the net by its own authors,
        <a href="$THIS_CGI?$date_args">
         <font face="verdana,arial,times" size="2" color="black"><b>Shite</b>space</font></a>
         proudly presents Today's&nbsp;Poem:
        <a href="$THIS_CGI?$date_args&p=shite#todays_poem">
         <b>$poemTitle</b></a>.
       </font>
      </td>
     </tr>
    </table>
EOT
}

############################################################

sub thecull
{
    print <<EOT;
    <!---- The Cull ---->
    <table align="left" valign="top" width="100%" border="0" cellpadding="10">
     <tr>
      <td align="left" valign="top">
       <a href="http://groups.yahoo.com/group/arseenders">
        <img src="$IMGPOODIR/cull_banner.jpg"
             alt="ArseEnders" border="0" width="200"></a>
       <br clear="all">
       <font face="verdana,arial" size="2">
        Celebrities, royalty, the senseless killing of innocent people.
        It's all here at
        <a href="${POO_CGI}?p=cull"><b>The&nbsp;Cull</b></a>.
       </font>
      </td>
     </tr>
    </table>
    <br clear="all">
EOT
}

############################################################

sub notnearmyhouse
{
    print <<EOT;
    <!---- Not Near My House ---->
    <table align="center" valign="top" width="100%" border="0" cellpadding="10">
     <tr>
      <td align="left" valign="top">
       <center>
<!---       <a href="http://groups.yahoo.com/group/NotNearMyHouse">   --->
        <nobr><font face="times,verdana,arial" size="5" color="gray">Not Near My House</font></nobr>
<!---        </a>  --->
       <br clear="all">
       <font face="times,verdana,arial" size="4">
        <nobr><i>You've got to get it to set it!</i></nobr>
       </font>
       </center>
       <font face="verdana,arial" size="2">
        Join this gripping play-by-mail global "hide and seek" game
        by finding a location that's
        <nobr><a href="http://groups.yahoo.com/group/NotNearMyHouse"><b>Not Near My House</b></a>.</nobr>
       </font>
      </td>
     </tr>
    </table>
    <br clear="all">
EOT
}

############################################################

sub arseenders
{
    print <<EOT;
    <!---- ArseEnders ---->
    <table align="center" valign="top" width="100%" border="0" cellpadding="10">
     <tr>
      <td align="left" valign="top">
       <center>
       <a href="http://groups.yahoo.com/group/arseenders">
        <img src="$IMGDIR2/arseenders.gif"
             alt="ArseEnders" border="0"></a>
       <br clear="all">
       <font face="verdana,arial" size="4">
        <b><i>Be A Soap Star!</i></b>
       </center>
       </font>
       <font face="verdana,arial" size="3">
        Join, or just follow, our exciting online,
        interactive soap opera,
        <a href="http://groups.yahoo.com/group/arseenders"><b>ArseEnders</b></a>.
       </font>
      </td>
     </tr>
    </table>
    <br clear="all">
EOT
}

############################################################

sub zigzagzoo
{
    print <<EOT;
    <!---- Zig Zag Zoo ---->
    <table align="center" width="100%" border="0">
     <tr>
      <td align="left" valign="top">
       <a href="http://www.zigzagzoo.com">
        <img src="$IMGDIR2/zzzbut60c.gif"
             alt="Zig Zag Zoo" border="0"></a>
      </td>
      <td align="left" valign="top">
       <font face="verdana,arial" size="2">
        The ultimate amalgamation of animal husbandry, stock market
        speculation and fun.  It's all happening at
        <a href="http://www.zigzagzoo.com"><b>Zig Zag Zoo</b></a>,
         and you can win prizes too!
       </font>
      </td>
     </tr>
    </table>
    <br clear="all">
EOT
}

############################################################

sub user_info
{
    my $primary = $greatList[0];
    my $prim = $stockHash->{$primary};
    my $stock_name = $prim->{singular};
    my $stock_file = $prim->{filename};
    my $todays_stock = random_line ("$LISTDIR/$stock_file", $date_seed);
    my $birth_stock = "";
    my $The = lc($prim->{article});

    print <<EOT;
   <font face="arial" size="2">
    Today's $stock_name is $The 
    <a href="$THIS_CGI?p=stock&a=$primary&$date_args">
     <b><nobr>$todays_stock</nobr></b></a>
   <p>
EOT

    if ($b_yyyymmdd)   # User has given date of birth
    {
        $birth_stock = random_line ("$LISTDIR/$stock_file", $birth_seed);
        print <<EOT;
        Your birth $stock_name is $The
        <a href="$THIS_CGI?p=stock&a=$primary&$date_args"><b><nobr>$birth_stock</nobr></b></a>
       <p>
        Your date of birth:<br><nobr>$b_format</nobr>
       <p>
        You are <b>$age</b> days old.<br>
EOT
        if ($age % 1000 == 0)
        {
            print "<b>Congratulations!</b><br>";
            print "It is your <a href=\"$THIS_CGI?p=kday&$date_args\"><b>k-day</b></a>!";
        }
        else
        {
            print "When is your next <a href=\"$THIS_CGI?p=kday&$date_args\"><b>k-day</b></a>?";
        }
    }
    print <<EOT;
   <p>
   </font>
   <br><br>
EOT
}

############################################################

sub stocks_menu
{
    my $nGreat = scalar(@greatList) - 1; # Ignore Guest stock for display
    my $nLesser = scalar(@lesserList);
    my $i = 0;
    my $s = "";  # stock id

    my $guest = $lesserList[0];
    my $num = $nGreat;
    $num = "Seven" if ($num == 7);

    print <<EOT;
    <!---- The Great Stocks ---->
    <table border="0" width="180"
           cellspacing="0" cellpadding="10">
     <tr>
      <td align="left" valign="top" bgcolor="$colour[3]">
       <font face="verdana,arial" size="2">
        <nobr><b>The $num Great Stocks</b></nobr><p>
EOT
    for ($i = 0; $i < $nGreat; $i++)
    {
        $s = $stockHash->{$greatList[$i]};
        print $i + 1;
        print ". <a href=\"$THIS_CGI?p=stock&a=$s->{id}&$date_args\">";
        print "$s->{singular}</a><br>\n";
    }
    $i++;
    print <<EOT;
        <p>
        <b>Today's Guest Stock</b><p>
        $i. <a href="$THIS_CGI?p=stock&a=$guest&$date_args">
        $stockHash->{$guest}->{singular}</a>
       </font>
       <br><br>

       <form action = "$THIS_CGI" method = "GET">
       <font face="verdana,arial" size="2">
        <b>The $nLesser Lesser Stocks</b><br>
         <select name="a" size="1">
EOT
    for $s (@lesserList)
    {
        print "<option value=\"$s\">$stockHash->{$s}->{singular}\n";
    }
    print <<EOT;
         </select>
         <br>
         <input type="submit" value="View">
         <input type="hidden" name="p" value="stock">
         <input type="hidden" name="ud" value="$u_mday">
         <input type="hidden" name="um" value="$u_month">
         <input type="hidden" name="uy" value="$u_year">
         <input type="hidden" name="bd" value="$b_mday">
         <input type="hidden" name="bm" value="$b_month">
         <input type="hidden" name="by" value="$b_year">        
        </font>
       </form>

       <br clear="all">

       <form action = "$THIS_CGI" method = "GET">
        <font face="verdana,arial" size="2">
          <b>Prospects&nbsp;Groups</b><br>
         <select name="a" size="1">
EOT
    for $group (@groupList)
    {
        print "<option value=\"$group\">$groupHash->{$group}->{groupname}\n";
    }
    print <<EOT;
         </select>
         <br>
         <input type="submit" value="View">
         <input type="hidden" name="p" value="group">
         <input type="hidden" name="ud" value="$u_mday">
         <input type="hidden" name="um" value="$u_month">
         <input type="hidden" name="uy" value="$u_year">
         <input type="hidden" name="bd" value="$b_mday">
         <input type="hidden" name="bm" value="$b_month">
         <input type="hidden" name="by" value="$b_year">
          <font face="verdana,arial" size="1">
           &nbsp;&nbsp;&nbsp;<a href="$THIS_CGI?p=help&a=group&$date_args">
            Add my group</a>
          </font>
        </font>
       </form>
      </td>
     </tr>

    </table>
    <br clear="all">
EOT
}

############################################################

sub groups_menu
{
    my $group;

    print <<EOT;
        <table border="0"><tr><td align="left">

        <form action = "$THIS_CGI" method = "GET">
         <font face="verdana,arial" size="2">
          <b>Prospects&nbsp;Groups</b><br>
         <select name="a" size="1">
EOT
    for $group (@groupList)
    {
        print "<option value=\"$group\">$groupHash->{$group}->{groupname}\n";
    }
    print <<EOT;
         </select>
         <br>
         <input type="submit" value="View">
         <input type="hidden" name="p" value="group">
         <input type="hidden" name="ud" value="$u_mday">
         <input type="hidden" name="um" value="$u_month">
         <input type="hidden" name="uy" value="$u_year">
         <input type="hidden" name="bd" value="$b_mday">
         <input type="hidden" name="bm" value="$b_month">
         <input type="hidden" name="by" value="$b_year">        
          <font face="verdana,arial" size="1">
           &nbsp;&nbsp;&nbsp;<a href="$THIS_CGI?p=help&a=group&$date_args">
            Add my group</a>
          </font>
       </font>
        </form>
      </td>
     </tr>
    </table>
EOT

}

############################################################

sub poems_opinion  # What the poem thinks of its reader
{
    my ($link, $textColour, $tableWidth, $shiteId, $shiteTitle) = @_;
    $textColour = "black"       if ($textColour eq "");
    $tableWidth = 350           if ($tableWidth eq "");
    $link       = "whatisshite" if ($link eq "");
    $link      .= "&a=poem"     if ($link eq "help");
    my $shiteFile = $poem_file;  # archaic

    $shiteFile = "$POETRYDIR/$shiteId.txt" if ($shiteId ne "");
    $shiteTitle = $poem_title if ($shiteTitle eq "");

    my $linkName = "[what's this all about?]";
    my $linkSize = 1;
    my $breakifnarrow = "";

    $breakifnarrow = "<br>" if ($tableWidth < 300);

    print <<EOT;
      <table border="0" align="left" cellspacing="0" cellpadding="0" width="$tableWidth">
       <tr><td align="left">
        <font face="arial,times,verdana" size="2" color="$textColour">
EOT

    if ($b_yyyymmdd > 0)
    {
        my $seed = get_seed($shiteId) + $b_yyyymmdd;
        my $opinion = random_line ("$LISTDIR/opinions.list", $seed);
        print <<EOT;
            "<b>$shiteTitle</b>"
            thinks ${opinion}.
EOT
    }
    else # No DoB so don't know opinion
    {
        print <<EOT;
            Enter your date of birth and find out what
            "<b>$shiteTitle</b>"
            thinks of you!
EOT
    }

    if ($link eq "" || $link =~ /poem/ || $link =~ /todayspoem/ || $link =~ /front/)
    {
        $linkName = "Read The Poem";
        $linkSize = 2;
        print "<br>";
    }

    print <<EOT;
        <br>
        <font face="arial,verdana" size="$linkSize">
         <a href="$THIS_CGI?poemNum=0&$date_args&p=$link&poemNum=0"><nobr>$linkName</nobr></a>
        </font>
       </font>
      </td></tr>
     </table>
    <br clear="all">
EOT
}

############################################################

sub about_poem
{
    my $lightYellow = "#ffffc0";

    print <<EOT;
      <table align="left" cellpadding="1" cellspacing="1" border="0" 
             bgcolor="brown">
       <tr><td align="center">
        <table align="center" border="0" cellspacing="0" cellpadding="5" width="100%"
               bgcolor="$lightYellow">
         <tr><td align="left">
EOT

    poems_opinion("whatisshite", "brown", 380);
    user_form("left");

    print <<EOT;
        </td></tr></table>
      </td></tr></table>
      <br clear="all">
EOT
}

############################################################

sub goodday
{
    my $seed = $u_yyyymmdd + $b_yyyymmdd;
    my $goodies = "";
    my $baddies = "";
    my @gooddayList = ();
    open (INFILE, "$LISTDIR/goodday.list");

    while (<INFILE>)
    {
        chop;
        next if (/^\s*$/);  # ignore blank lines
        next if (/^#/);     # ignore commented lines

        push @gooddayList, $_;
    }
    close (INFILE);
    random_sort(\@gooddayList, $seed);

    for ($i=0; $i<4; $i++)
    {
        $goodies .= "- $gooddayList[$i]<br>";
        $baddies .= "- $gooddayList[$i + 4]<br>";
    }

    print <<EOT;
    <table width="350" border="0">
     <tr>
      <td align="left" valign="top">

        <table border="0" align="left" valign="top" cellspacing="0" cellpadding="3" bgcolor="#c0c0c0">
         <tr>
          <td align="left" bgcolor="#c0c0c0">
           <font face="arial" size="2">
            <b>Today is a good day to</b>:
           </font>
          </td>
         </tr>
         <tr>
          <td align="left" bgcolor="#e0e0e0">
           <font face="arial" size="2">
            $goodies
           </font>
          </td>
         </tr>
        </table>

      </td>
      <td align="right" valign="top">
        <table border="0" align="right" valign="top" cellspacing="0" cellpadding="3" bgcolor="#c0c0c0">
         <tr>
          <td align="left" bgcolor="#c0c0c0">
           <font face="arial" size="2">
            <b>Today is a bad day to</b>:
           </font>
          </td>
         </tr>
         <tr>
          <td align="left" bgcolor="#e0e0e0">
           <font face="arial" size="2">
            $baddies
           </font>
          </td>
         </tr>
        </table>

      </td>
     </tr>
    </table>
EOT
}

############################################################

# Displays each date in k-day table

sub formatDate
{
    my ($theDate, $bold) = @_;

    my $yyyy = substr($theDate, 0, 4);
    my $mm   = substr($theDate, 4, 2);
    my $dd   = substr($theDate, 6, 2);
    my $mon  = substr($monthList[$mm - 1], 0, 3);
    my $font = "<font face=\"arial\" size=\"2\">";
    my $endFont = "</font>";
    my $bg = "";

    if ($bold eq "b")
    {
        $font = $font . "<b>";
        $endFont = "</b>" . $endFont;
        $bg = "bgcolor=\"$colour[5]\"";
#        print "<b>$dd </b></td><td> <b>$mon </b></td><td> <b>$yyyy</b>";
#    }
#    else
#    {
#        print "$dd </td><td> $mon </td><td> $yyyy";
    }

    print <<EOT;
        $font $dd $endFont </td>
        <td $bg>$font $mon $endFont </td>
        <td $bg>$font $yyyy $endFont
EOT
}


############################################################

sub shite_search
{
    print <<EOT;
   <!---- Shite Search --->
   <table align="center" border="0" cellspacing="2" cellpadding="2">
    <tr>
     <td align="left" valign="top">
      <font face="arial,verdana,times" size="2">
        <!-- Atomz Search HTML for Shite Space -->
         <form method="get" action="http://search.atomz.com/search/">
         <font face="times,arial,verdana" size="5" color="brown"><i>Shite&nbsp;Search</i></font>
         <input size="15" name="sp-q"><br> <input type="submit" value="Search">
         <input type="hidden" name="sp-a" value="sp1001d5eb"> </form>
      </font>
     </td>
     <td align="left" valign="top">
      <font face="arial,verdana,times" size="2">
       Not quite what you're looking for?
       Use Shite Search to find the perfect
       words for your mood right now.
      </font>
     </td>
    </tr>
   </table>
EOT
}

############################################################

sub shitespace_menubar
{
    print <<EOT;
   <!--------- Shite Space Menu bar ---------------->
   <table width="100%" bgcolor="brown" align="left"
    cellpadding="0" cellspacing="0">
    <tr>
     <td align="center" valign="middle" width="50">
      <a href="index.html">
      <img src="$IMGDIR1/back_arrow.gif" alt="Home" border="0"></a>
     </td>

     <td align="center" valign="middle" bgcolor="beige" width="200">
      <a href="$HOST/main/index.html"><img src="$IMGDIR2/logob.gif"
                                           alt="Shite Space" border="0"></a>
     </td>

     <td align="right" valign="middle" color="white" width="100%">
      &nbsp;
      <a href="$HOST/main/authors.html">
       <font size="3" color="white">Authors</font></a>
       <font size="3" color="white"> | </font>
      <a href="$HOST/main/archives.html">
       <font size="3" color="white">Archives</font></a>
      &nbsp;&nbsp;
     </td>
    </tr>
   </table>
EOT
}

############################################################

sub header   # redundant
{
    print <<EOT;
Content-type: text/html

<html>
<head>
  <title>Stuff Today! Sod Yesterday! And Bollocks To Tomorrow!</title>
  <meta name="Author" content="Mike Two-Sheds">
  <meta name="Description" content="Everything you need to know to cope with today">
  <meta name="Keywords" content="mike, kate, prospects, k-days, kday, events,
              poetry, poems, humour, humor, literature">
</head>
<body text="black" link="$colour[0]" vlink="$colour[1]">
EOT
}

############################################################

sub copyright
{
    my ($names, $hr) = @_;
    my $years = $r_year;
    my $ref="ss";

    if ($names eq "") { $names = "Stuff Today Ltd"; }
    $years = "1995-$years" if ($names =~ /^Shitespace/);
    $years = "2000-$years" if ($names =~ /^Pooclub/);

    print <<EOT;
    <!--- Copyright --->
    <br clear="all">
<table width="100%" border="0">
 <tr><td align="left">
<font size="1" face="verdana,arial,geneva,helvetica" color="#777777">
<a href="http://lilyvillas.com?ref=$ref">Luxury</a>
<a href="http://lilyvillas.com?ref=$ref">Private</a>
<a href="http://lilyvillas.com?ref=$ref">Holiday</a>
<a href="http://lilyvillas.com?ref=$ref">Villas</a>
<a href="http://lilyvillas.com?ref=$ref">in</a>
<a href="http://lilyvillas.com?ref=$ref">Bodrum</a>
<a href="http://lilyvillas.com?ref=$ref">Turkey</a>
</font>
 </td>
 <td align="center">
<font size="1" face="verdana,arial,geneva,helvetica" color="#777777">
</font>
</td>
<td align="center">
<font size="1" face="verdana,arial,geneva,helvetica" color="#777777">
<a href="$POO_CGI">pooclub</a> | 
<a href="http://pooclub.pbwiki.com">poowiki</a> |
<a href="http://groups.google.com/group/pooclub">subscribe</a>
</font>
</td><td align="right">
<font size="1" face="verdana,arial,geneva,helvetica" color="#777777">
</font>
 </td><td align="right">
<font size="1" face="verdana,arial,geneva,helvetica" color="#777777">
<a href="http://lilyvillas.com?ref=$ref">Cheap</a>
<a href="http://lilyvillas.com?ref=$ref">Holiday</a>
<a href="http://lilyvillas.com?ref=$ref">Villas</a>
<a href="http://lilyvillas.com?ref=$ref">To</a>
<a href="http://lilyvillas.com?ref=$ref">Rent</a>
</font>
 </td></tr>
</table>
$hr
    <center>
     <font size="1" face="verdana,arial,geneva,helvetica"
           color="#777777">
     <nobr>Copyright &copy; $years $names.</nobr>
     <nobr>All rights reserved.</nobr>
     </font>
    </center><br>
 </body>
</html>
EOT
}

############################################################

1;

############################################################
# END OF FILE
############################################################
