CGI: refresh page and timeout

Hi, I've been able to put together an HTML page that calls on a cgi program (via ksh) to do some server side processing, then send it back to the user's browser window. The script basically tails a log file and refreshes every # seconds (user chosen) by using the "refresh" meta tag (html).

My problem is, I want the script to be able to timeout after a certain amount of time but am not sure how to approach this. Since the meta tage causes the page to refresh automatically, I cannot use a loop to count for a timeout session. I was thinking of going with some sort of javascript (not too familiar with it) in order to take care of the refresh and timeout. Does anyone have any suggestions or ideas they can throw my way? I'd really appreciate any help that I can get on this. My code is below if anyone wants to make any suggestions (structural criticism is very welcome):

#!/bin/ksh

echo "Content-type: text/html"
echo
PATH=/usr/local/kccmds:$PATH

refresh=`echo $QUERY_STRING | cut -d"&" -f3 | cut -d"=" -f2 | cut -d"-" -f2`
echo "<HTML>
<HEAD>
<TITLE>`KCSUN Region Tails` Region Tail</TITLE> </HEAD>
<PRE>
<meta http-equiv="refresh" content="$refresh; URL=d3tail.cgi">
</PRE>
<BODY>

<BR>"
#
region=`echo $QUERY_STRING | cut -d"=" -f2 | cut -d"&" -f1`
tail1=`echo $QUERY_STRING | cut -d"&" -f2 | cut -d"=" -f2`
check=`echo $QUERY_STRING | cut -d"&" -f2 | cut -d"." -f2 `


if [ "$refresh" = "x" ]; then
   refresh_msg="page refresh has been deactivated."
else
   refresh_msg="which refreshes every $refresh seconds,"

fi

region_dsp=`echo $region`
typeset -u region_dsp

if [ "$check" = "err" ];
   then
      buffer="sys/"
      tail1="unikixmain.err"
elif
   [ "$check" = "log" ];
   then
      buffer="sys/"
      tail1="unikixmain.log"
else
   buffer=""
fi

case $tail1 in
   kc.sysout) msg="You are viewing d3tail, $refresh_msg"
   ;;
   kc.syslog) msg="You are viewing d3tail1, $refresh_msg"
   ;;
   unikixmain.err) msg="You are viewing d3tail2, $refresh_msg"
   ;;
   unikixmain.log) msg="You are viewing d3tail3, $refresh_msg"
   ;;
esac

. d3env$region
echo "<PRE>"
echo "<hr>"
echo "<center><h2>You are in MTP Region $region_dsp</h2></center>"
echo "<center><h4>$msg</h4></center>"
echo "<hr>"

echo "<form method="LINK" ACTION="cat-tail.cgi" target="_blank">"
echo "<INPUT TYPE=submit name="$region-$tail1" value="Display_entire_log">"
echo " "
tail -20 $d3/$buffer$tail1

echo "<br>"
echo "<br>"
echo "</form>"
echo "</PRE>"

echo " <BODY>"
<HTML>
<Head>
<title>SUN Tail/Reports Menu</title>
</Head>
<body bgcolor="#000099">

<center><table>
<form method="LINK" ACTION="SUN Reports Menu.html" target="_blank">
<INPUT TYPE=submit value="   Reports   ">
</form>
</table></center>

<center><table border="3">
<tr bgcolor="white">
<td>
<form method="get" action="http://kcsun.kirchman.com/cgi-bin/d3tail.cgi" target="MAIN">
<select name="region">
        <option value="a">Region A
        <option value="b">Region B 
        <option value="c">Region C 
        <option value="d">Region D
        <option selected value="e">Region E 
        <option value="f">Region F
        <option value="g">Region G 
        <option value="h">Region H 
        <option value="i">Region I 
        <option value="j">Region J 
        <option value="k">Region K 
        <option value="l">Region L 
        <option value="m">Region M 
        <option value="n">Region N 
        <option value="o">Region O 
        <option value="p">Region P 
        <option value="q">Region Q 
        <option value="r">Region R 
        <option value="s">Region S 
        <option value="t">Region T 
        <option value="u">Region U 
        <option value="v">Region V 
        <option value="w">Region W
        <option value="x">Region X 
        <option value="y">Region Y 
        <option value="z">Region Z 
</select>
</td>
</tr>


<tr bgcolor="white"><td><input type="radio" name="d3tail" checked="d3tail" value="kc.sysout">d3tail</td></tr>
<tr bgcolor="white"><td><input type="radio" name="d3tail" value="kc.syslog">d3tail1</td></tr>
<tr bgcolor="white"><td><input type="radio" name="d3tail" value="sys/unikixmain.err">d3tail2</td></tr>
<tr bgcolor="white"><td><input type="radio" name="d3tail" value="sys/unikixmain.log">d3tail3</td></tr>

<center><td><h4><font color="white">Refresh Rate</h4></td></center>

<tr bgcolor="white"><td><input type="radio" name="refresh" checked="None" value="refresh-x">STOP</td></tr>

<tr bgcolor="white"><td><input type="radio" name="refresh" checked="5 sec." value="refresh-5">5 sec.</td></tr>

<tr bgcolor="white"><td><input type="radio" name="refresh" value="refresh-15">15 sec.</td></tr>

<tr bgcolor="white"><td><input type="radio" name="refresh" value="refresh-30">30 sec.</td></tr>

<tr bgcolor="white"><td><input type="radio" name="refresh" value="refresh-60">60sec.</td></tr>

<tr bgcolor="#000066"><td><center><input type="submit" value="   Submit   "></center></td><tr>


</form>
</table>


</body>

</HTML>