//////////////////////////////////////////////////////////////
// DIAL UP script file for use in conjuntion with OFFLINER. //
//////////////////////////////////////////////////////////////
Main()
{
  Int File,t,Connect,Done,Count,Number,Test,
  C1=0,C2=0,C3=0,C4=0,C5=0,C6=0,C7=0,C8=0,C9=0,C10=0;

  Str
  _1nr[30],
  _2nr[30],
  _3nr[30],
  _4nr[30],
  _5nr[30],
  _6nr[30],
  _7nr[30],
  _8nr[30],
  _9nr[30],
  _10nr[30],
  Line[7],
  Path[64],
  Dial_Str[30],
  Filename[80],
  Stat_line[80],
  Start_hour[2],
  Start_min[2],
  Retries[4],
  Timeout[4];

  _time_format = 1;
  Path = _script_dir;
  StrCat(Path,"\");
  Filename = Path;
  StrCat(Filename,"DIAL.CFG");
  File = FOpen(Filename,"r");
  If (!FError(File))
  {
    FGetS(Line,7,File);
    If (Line != "")
    {
      SubStr(Line,0,2,Start_hour);
      SubStr(Line,3,2,Start_min);
    }
    else
      Start_hour = "";
    FGetS(Retries,4,File);
    FGetS(Timeout,4,File);
    FClose(File);
    Filename = Path;
    StrCat(Filename,"DIAL.LST");
    File = FOpen(Filename,"r");
    If (!FError(File))
    {
      FGetS(_1nr,30,File);
      FGetS(_2nr,30,File);
      FGetS(_3nr,30,File);
      FGetS(_4nr,30,File);
      FGetS(_5nr,30,File);
      FGetS(_6nr,30,File);
      FGetS(_7nr,30,File);
      FGetS(_8nr,30,File);
      FGetS(_9nr,30,File);
      FGetS(_10nr,30,File);
      _dial_time = StoI(Timeout);
      If (_dial_time == 0) _dial_time = 60;
      If (Start_hour != "")
      While(1)
      {
        t = CurTime();
        If (THour(t) == StoI(Start_hour) && TMin(t) == StoI(Start_min))
          Break;
        else
        {
          Stat_line = "Dialing delayed to ";
          StrCat(Stat_line,Start_hour);
          StrCat(Stat_line,":");
          StrCat(Stat_line,Start_min);
          StrCat(Stat_line,". Time is now ");
          ItoS(THour(t),line);
          StrCat(Stat_line,line);
          StrCat(Stat_line,":");
          ItoS(TMin(t),line);
          StrCat(Stat_line,line);
          StrCat(Stat_line,".");
          Status_Wind(Stat_line,50);
        }
      }
      Done = 0;
      
      While(!Done)
      {
        If (Count == 1)  Dial_Str = _1nr;
        If (Count == 2)  Dial_Str = _2nr;
        If (Count == 3)  Dial_Str = _3nr;
        If (Count == 4)  Dial_Str = _4nr;
        If (Count == 5)  Dial_Str = _5nr;
        If (Count == 6)  Dial_Str = _6nr;
        If (Count == 7)  Dial_Str = _7nr;
        If (Count == 8)  Dial_Str = _8nr;
        If (Count == 9)  Dial_Str = _9nr;
        If (Count == 10) Dial_Str = _10nr;
        If (Dial_Str == "^Z") Dial_Str = "";
        If (Dial_Str != "")
        {
          t      = 0;
          Number = 0;
          While(t < StrLen(Dial_Str))
          {
            Test = StrPos(Dial_Str," ",t);
            If (Test != -1)
              ++ Number;
            ++ t;
          }
          If (Number == 0) Number = 1;
          Delay_Scr(10);
          Connect = Dial(Dial_Str,Number,0);
        }
        If (Count == 1)
        {
          ++ C1;
          If (C1 >= StoI(Retries) || Connect != 0 || Connect == -1)
            _1nr = "";
        }
        If (Count == 2)
        {
          ++ C2;
          If (C2 >= StoI(Retries) || Connect != 0 || Connect == -1)
            _2nr = "";
        }
        If (Count == 3)
        {
          ++ C3;
          If (C3 >= StoI(Retries) || Connect != 0 || Connect == -1)
            _3nr = "";
        }
        If (Count == 4)
        {
          ++ C4;
          If (C4 >= StoI(Retries) || Connect != 0 || Connect == -1)
            _4nr = "";
        }
        If (Count == 5)
        {
          ++ C5;
          If (C5 >= StoI(Retries) || Connect != 0 || Connect == -1)
            _5nr = "";
        }
        If (Count == 6)
        {
          ++ C6;
          If (C6 >= StoI(Retries) || Connect != 0 || Connect == -1)
            _6nr = "";
        }
        If (Count == 7)
        {
          ++ C7;
          If (C7 >= StoI(Retries) || Connect != 0 || Connect == -1)
            _7nr = "";
        }
        If (Count == 8)
        {
          ++ C8;
          If (C8 >= StoI(Retries) || Connect != 0 || Connect == -1)
            _8nr = "";
        }
        If (Count == 9)
        {
          ++ C9;
          If (C9 >= StoI(Retries) || Connect != 0 || Connect == -1)
            _9nr = "";
        }
        If (Count == 10)
        {
          ++ C10;
          If (C10 >= StoI(Retries) || Connect != 0 || Connect == -1)
            _10nr = "";
        }
        If (Count == 10)
        {
          Done = 1;
          If (_1nr  != "") Done = 0;
          If (_2nr  != "") Done = 0;
          If (_3nr  != "") Done = 0;
          If (_4nr  != "") Done = 0;
          If (_5nr  != "") Done = 0;
          If (_6nr  != "") Done = 0;
          If (_7nr  != "") Done = 0;
          If (_8nr  != "") Done = 0;
          If (_9nr  != "") Done = 0;
          If (_10nr != "") Done = 0;
          Count = 0;
        }
        ++ Count;
      }
    }
    else
      PrintS("Error opening DIAL.LST. Dial aborted!");
  }
  else
    PrintS("Error opening DIAL.CFG. Dial Aborted!");
  HangUp();
  ExitTelix(0,1);
}
