{*******************************}
{*   Horizontal Menu Selection *}



Var horzloc : integer;
    ky1,ky2 : char;
    escape : boolean;
    startflag : boolean;


Procedure Horizontal_Menu;
var xx : integer;
begin
 clrscr;
 horzloc := 1; startflag := true;
 TextColor(0); TextBackGround(15);
 gotoxy(1,1); write('Add Records');
 TextColor(15); TextBackGround(0);
 gotoxy(21,1); write('Update Records');
 gotoxy(41,1); write('Print Report'); gotoxy(61,1); write('Exit Program');
 gotoxy(1,2);
  for xx := 1 to 79 do
   write(#205);

end;   {** procedure **}

Procedure Start_at_Left;
begin
 TextColor(15); TextBackGround(0);
 gotoxy(1,1); write('Add Records');
end;

Procedure Select_Print;
begin
    case horzloc of
  1 : write('Add Records');
  21 : write('Update Records');
  41 : write('Print Report');
  61 : write('Exit Program');
   end;

  startflag := false;
end;

Procedure Set_Highlight;
begin
 gotoxy(horzloc,1);
 TextColor(0); TextBackGround(15);
 Select_Print;
end;

Procedure Reset_Highlight;
begin
 TextColor(15); TextBackGround(0);
 gotoxy(horzloc,1);
 Select_Print;
end;

Procedure Move_Right;
begin
 if startflag = false then Reset_Highlight
  else
 Start_at_Left;
 horzloc := horzloc + 20;
 if horzloc > 61 then horzloc := 1;
 Set_Highlight;
end;

Procedure Move_Left;
begin
 if startflag = false then Reset_Highlight
  else
  Start_at_Left;
 horzloc := horzloc - 20;
 if horzloc < 1 then horzloc := 1;
 Set_Highlight;
end;

Procedure Select_by_Letter;
begin

if startflag = false then Reset_Highlight
 else
Start_at_Left;
 case ky1 of
  'A','a' : horzloc := 1;
  'U','u' : horzloc := 21;
  'P','p' : horzloc := 41;
  'E','e' : horzloc := 61;
 end;

Set_Highlight;
end; {** procedure **}

Procedure Branch_To_Selection;
begin
 TextBackground(0); TextColor(15);
 clrscr;
  case horzloc of
   1 : writeln('Add Records':40);
   21 : writeln('Update Records':40);
   41 : writeln('Print Report':40);
  end;
  delay(2000);
  Horizontal_Menu;
end; {** procedure **}

Procedure Read_Arrow_Keys;
begin
 repeat until keypressed;
 Read(Kbd,ky1);
 if ky1 = #13 then Branch_To_Selection;
 if (ky1 = #27) and keypressed then
   begin
    Read(Kbd,ky2);
    if ky2 = #77 then Move_Right;
    if ky2 = #75 then Move_Left;
   end
  else Select_by_Letter;
end;


begin
 Horizontal_Menu;
 repeat
 Read_Arrow_Keys;
 until horzloc = 61;
end.