@flds = split(/&/,$ENV{"QUERY_STRING"});
foreach $fld (@flds) {
    ($fkey, $fval) = split(/=/,$fld);
    $fval =~ tr/+/ /;
    $fval =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    $fkey =~ tr/+/ /;
    $fkey =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    $in{$fkey} = $fval;
}
if (length($in{"date"}) == 8){
    $today = $in{"date"};
}else{
    ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)
        = localtime(time);
    if ($year < 97){
        $year = $year + 2000;
    }else{
        $year = $year + 1900;
    }
    $today = (10000 * $year) + (100 * ($mon+1)) + $mday;
}
$path = $ENV{PATH_TRANSLATED};
$path =~ tr/\\/\//;
while (($path ne "") &&
       (substr($path,length($path)-1,1) ne "/")) {
    chop($path);
}
$cnt = 0;
@imgs[0] = "transad.gif";
@urls[0] = "#";
open(ADS, $path . "ontrack.txt");
while(!eof(ADS)){
   $ads = <ADS>;
   $ads =~ tr/\x0a\x0d//d;
   ($beg,$end,$img,$url) = split(/,/,$ads);
   if (($beg <= $today) && ($end >= $today)){
       @imgs[$cnt] = $img;
       @urls[$cnt] = $url;
       $cnt = $cnt + 1;
   }
}
$imgDir = "../../images/";
srand;
$choice = int(rand($#imgs+1));
print <<"EOP";
Content-type: text/html

<html>
<head>
<title>On-Track Messenger Service</title>
<style>
<!--
 TD { font-family: Arial, sans-serif; font-size: 125%;
      font-weight: bold; font-style: italic ; color: #906;}
 H1 {color: black}
-->
</style>
</head>
<body bgcolor="#FFFFFF">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
  <tr>
    <td>
      <img src="../../images/biker2.gif" alt="On-Track"
           width="156" height="100"></td>
    <td align="center">
       <h1>On-Track Messenger Service</h1></td>
    <td align="right">
      <img src="../../images/biker1.gif" alt="On-Track"
           width="156" height="100"></td>
  </tr>
</table>
<center>
<a href="$urls[$choice]">
<img src="$imgDir$imgs[$choice]"
     height=60 width=468 border=0></a>
</center>
<center>
<table border="0" cellpadding="6" cellspacing="0">
  <tr>
    <td>
      <img src="../../images/package.gif" alt="Package"
           width="101" height="64"></td>
    <td>Speedy Delivery!</td>
  </tr>
  <tr>
    <td>
      <img src="../../images/package.gif" alt="Package"
           width="101" height="64"></td>
    <td>Fully Insured!</td>
  </tr>
  <tr>
    <td>
      <img src="../../images/package.gif" alt="Package"
           width="101" height="64"></td>
    <td>Tight Shorts! (M/F, Your Choice)</td>
  </tr>
</table>
</center>
</body>
</html>

EOP
exit 0;
