procedure clear_window(on : boolean);
begin
  if (on) then
            begin
              brite_blanks;
              auxcolor;
            end
          else
            begin
              norm_blanks;
              normcolor;
            end;
end;

procedure login;
var i : integer;
    old_x, old_y : integer;
    test_prefix : pre_str;
    test_area : char;
    test_suffix : post_str;
    key : char;

 procedure show_call(p : integer; brite : boolean);
 begin
   if NOT (p in [0..13]) then exit;
   if brite = FALSE
   then
     auxcolor
   else
     brite_auxcolor;
   gotoxy(x[p],y[p]);
   case p of
     0 : write(test_suffix:6);
     1..13 : with net_list[call[p]]^ do
               write(Trim(prefix) + area + suffix : 6) ;
     end;
   gotoxy(x[p],y[p]);
 end;

  procedure all_ready_logged;
  begin
    window(32,8,79,16);
    textcolor(status_f);
    textbackground(norm_b);
    gotoxy(30,1);
    write('ALREADY LOGGED',#7);
    delay(500);
    gotoxy(30,1);
    ClrEol;
    window(1,1,80,25);
  end;


  procedure new_call;
  var test_prefix : string[3];
      test_area   : string[1];
  begin
    if (new_pntr = max_new) then
    begin
      window(32,8,79,16);
      textcolor(status_f);
      textbackground(status_b);
      gotoxy(30,1); ClrEol; write('No NEW CALL memory left',#7);
      normcolor;
      window(1,1,80,25);
    end
    else
    begin
      window(32,8,79,16);
      normcolor;
      Set_Confirm_On;
      test_prefix := '  ';
      sayget(30,1,'Prefix ',test_prefix,_S,2,0);
      picture('@!');
      test_area := ' ';
      sayget(30,2,'Area   ',test_area,_S,1,0);
      picture('9');
      readgets;
      Set_Confirm_Off;
      if test_prefix = '  ' then
        begin
          gotoxy(30,1); ClrEol;
          gotoxy(30,2); ClrEol;
          window(1,1,80,25);
          exit;                 { this call is rejected }
        end;
      gotoxy(30,1); ClrEol;
      gotoxy(30,2); ClrEol;
      if (new_there(test_prefix,test_area,test_suffix) = TRUE) then
      begin
        all_ready_logged;
        exit;
      end;
      new_pntr := new_pntr + 1;
      top_pntr := top_pntr + 1;
      with checkins[top_pntr] do
      begin
        list_nbr := 1;
        position := new_pntr;
        hr_min   := copy(SystemTime,1,5);
      end;
      with new_list[new_pntr]^ do
      begin
        prefix    := test_prefix;
        area      := test_area;
        suffix    := test_suffix;
        name      := '';
        net_nbr   := ' ';
        log_date  := SystemDate;
        xref      := top_pntr;
        with NBase do
        begin
          _PREFIX  := prefix;
          _AREA    := area;
          _SUFFIX  := suffix;
          _NAME    := name;
          _LOGDATE := SystemDate;
        end;
        APPEND;
        recnbr := RecNo;
      end;
      gotoxy(1,1); InsLine;
      write(Trim(test_prefix) + test_area + test_suffix:6);
      if (max_new - new_pntr = 5) then
      begin
        textcolor(status_f);
        textbackground(norm_b);
        gotoxy(25,2); write('Only 5 more new logins');
        gotoxy(25,3); write('allowed.');
      end;
      window(1,1,80,25);
      display_checkin(top_pntr);
      if top_pntr = 1 then top_of_roster;
      update_flag := TRUE;
      status;
    end;
  end;

  procedure add_call;
  begin
    if net_list[call[call_count]]^.xref = 0
    then
    begin
      top_pntr := top_pntr + 1;
      with checkins[top_pntr] do
      begin
        list_nbr := 0;
        position := call[call_count];
        hr_min   := copy(SystemTime,1,5);
        net_list[position]^.xref := top_pntr;
        window(32,8,79,16);
        normcolor;
        gotoxy(1,1); InsLine;
        with net_list[position]^ do
        begin
          write((Trim(prefix) + area + suffix):6,' ',name:10);
          if (net_nbr <> ' ') then
            write(net_nbr:5);
        end;
        window(1,1,80,25);
      end;
      display_checkin(top_pntr);
      if top_pntr = 1 then top_of_roster;
      update_flag := TRUE;
      status;
    end
    else
      all_ready_logged;
  end;

begin
  old_x := WhereX; old_y := WhereY;
  window(32,8,79,16);
  normcolor;
  ClrScr;
  window(1,1,80,25);
repeat
  test_suffix := '   ';
  clear_window(true);
  sayget(x[0],y[0],'',test_suffix,_S,3,0);
  picture('@!');
  readgets;
  if (test_suffix <> '   ') then
  begin
    gotoxy(32,2);
    textcolor(status_f);
    textbackground(border_b);
    write('NuCall');
    find_call(test_suffix);
    show_call(0,FALSE);
    key := #0;
    if multiple > 0
    then
      begin
        for call_count := 1 to multiple do
          show_call(call_count,FALSE);
        gotoxy(x[first],y[first]);
        call_count := first;
        show_call(first,TRUE);
        repeat
          key := readkey;
          if key = #0 then
            begin
              key := readkey;
              case key of
                #77 : { -> } begin
                      if call_count < multiple then
                      begin
                        show_call(call_count, FALSE);
                        call_count := call_count + 1;
                        show_call(call_count,TRUE);
                      end;
                    end;
                 #75 : { <- }
                     begin
                       if call_count > 0 then
                       begin
                         show_call(call_count,FALSE);
                         call_count := call_count - 1;
                         show_call(call_count,TRUE);
                       end;
                     end;
                 end;
                 key := #0;
            end;
      until (key in [#13,#27]);
      end;
  end;
  if key <> #27 then
    begin
      if test_suffix > '   ' then
        if (call_count = 0) OR (multiple = 0)
          then new_call
          else add_call;
    end;
  textcolor(border_f);
  textbackground(border_b);
  gotoxy(32,2);
  write('SUFFIX');
until (test_suffix = '   ');
  clear_window(false);
  gotoxy(old_x,old_y);
end;
