#
# Parsing cookies
# The one arg should be the value of the cookie to look up
# returns that value of that cookie, or undef if no cookie found
sub GetCookie
{
	my($target) = shift;
	$cookies = $ENV{"HTTP_COOKIE"};
	print "<br>The Cookies String:  $cookies<br>\n";
	@the_cookies = split("; ", $ENV{"HTTP_COOKIE"});
	foreach $this_cookie (@the_cookies)
	{
		#print "This Cookie = \"$this_cookie\"\n";
		($value_string, $junk) = split(" ", $this_cookie);
		($name, $value) = split("=", $value_string);
		if ($name eq $target) { return $value; }
		#print "<br>$name = $value\n";
	}
}

#
# Returns a string in the correct format to set an expire date
# for a cookie.
# Only Arg:  The time to expire
# Example:  $timestring = CookieDate(time+3600);
sub CookieDate
{
   local( $time, $format )= @_;

   local( $sec, $min, $hour, $mday, $mon, $year,$wday, $yday, $isdst )= localtime( $time );

   $sec = "0$sec" if ($sec < 10);
   $min = "0$min" if ($min < 10);
   $hour = "0$hour" if ($hour < 10);
   $mon = "0$mon" if ($mon < 10);
   $mday = "0$mday" if ($mday < 10);
   local( $month )= ($mon + 1);
   local( @months )= ( "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" );

   local( @weekday )=( "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" );

   return "$weekday[$wday], $month-$mday-$year $hour\:$min\:$sec GMT";
}
1;
