#!/usr/bin/perl
#
  do "acqPATHs.pl";
  $wdr = $ENV{"QUERY_STRING"};
  if ($wdr ne "") { $wdr .= "/"; }
  print "Content-type: text/html; charset=iso-8859-1\n\n";
#
  $htmlbody =<<EOM;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<link rel="stylesheet" type="text/css" href="/AMXS/amxs.css">
<title>AMXS selfnm</title>
<script type="text/javascript">
<!--
function SelFnm(fnam) {
  parent.Ftop.document.FM.fnm.value = fnam;
  parent.Fhid.document.FM.fnm.value = fnam;
  location.replace("/AMXS/forms/blank.html");
}
function cancel() {
  location.replace("/AMXS/forms/blank.html");
}
//-->
</script>
</head>
<body bgcolor="ivory" style="margin: 4px 7px;">
<form name="FM">
<hr>
<b>Select file</b> &nbsp; &nbsp; &nbsp;
 <input type="button" value="Clear" onclick='SelFnm("")'> &nbsp;
 <input type="button" value="cancel" onclick="cancel()"><br>
<table>
EOM
  print $htmlbody;
#
  $n = 0;
  opendir(DIR, "$DATAPATH/$wdr");
  while ($fnam = readdir(DIR)) {
    if ($fnam =~ /^(\w+\.)*\w+$/) {
      if (-f "$DATAPATH/$wdr$fnam") { $rnam[$n] = $fnam; $n++; }
    }
  }
  closedir(DIR);
  @dnam = sort(@rnam);
  if ($n < 30) { $nl = 5; }
  else { $nl = ($n + 5 - (($n-1) % 6)) / 6; }
  for ($l=0; $l<$nl; $l++) {
    print " <tr>\n";
    for ($c=0; $c<6; $c++) {
      $m = $c*$nl + $l;
      if ($m < $n) {
        print '  <td> &nbsp; <a href="#" ';
        print 'onclick=\'SelFnm("' . $dnam[$m] . '")\'>';
        print $dnam[$m] . "</a></td>\n";
      }
      else { print "  <td> &nbsp; </td>\n"; }
    }
    print " </tr>\n";
  }
#
  print "</table>\n</form>\n</body>\n</html>\n";
  exit(0);
