
Rai(adr)  //  принимаем адрес по старому;
{
 char adr1[250], adr2[250], rai[90];
 sprintf(adr1,"%s",to_string(adr));  FreeSpaceString(adr1,3,"");

 string raion=GetElementFromString(3,adr1,",");    // считываем 3-й эл-т из строки адреса
 string kol="КОЛОМНА Г";

 string adr_0=GetElementFromString(0,adr1,",");
 string adr_1=GetElementFromString(1,adr1,",");
 string adr_2=GetElementFromString(2,adr1,",");

 string adr_4=GetElementFromString(4,adr1,",");
 string adr_5=GetElementFromString(5,adr1,",");
 string adr_6=GetElementFromString(6,adr1,",");
 string adr_7=GetElementFromString(7,adr1,",");
 string adr_8=GetElementFromString(8,adr1,",");

 int r_1=0;
 if(raion == kol)    // если это "КОЛОМНА Г" переставляем  во вторую позицию и создаём adr2
  {
    r_1 = 111;   
    sprintf(adr2,"%s,%s,%s,%s,%s,%s,%s,%s,%s",to_string(adr_0),to_string(adr_1),to_string(raion),to_string(adr_2),to_string(adr_4),to_string(adr_5),to_string(adr_6),to_string(adr_7),to_string(adr_8));

  }
  if(r_1 == 111)  return adr2;
  if(r_1 == 0)    return adr1;
  // return adr2;         //return r_1;         //return kol;      
}




RazDate(d1,r1)  //если r1==1 то формир строку d1_2 как копию d1 (для даты)
{
 char d1_2[250], r1_2[9];
 sprintf(r1_2,"%s",static_cast_to_string(r1));  FreeSpaceString(r1_2,3,"");

 int r1_3 = atoi(r1_2);

 if (r1_3 == 1)
  {
   sprintf(d1_2,"%s",static_cast_to_string(d1));
   FreeSpaceString(d1_2,3,"");
  }
 return d1_2;
}



RazDolg(d1,r1)  //если r1==1 то формир строку d1_2 как копию d1  (для должности)
{
 char d1_2[250], r1_2[9];
 sprintf(r1_2,"%s",static_cast_to_string(r1));  FreeSpaceString(r1_2,3,"");

 int r1_3 = atoi(r1_2);

 if (r1_3 == 1)
  {
   sprintf(d1_2,"%s",static_cast_to_string(d1));
   FreeSpaceString(d1_2,3,"");
  }
 return d1_2;
}



CmpDolg(tab,d1,d2)  // сравнение поля должность в таблице и в КЧ
{
   char tn[91], ls1[255];
   sprintf(tn,"%.90s",static_cast_to_string(tab));   FreeSpaceString(tn,3,"");
   double tabn = atof(tn);

   lsname(Find_Full_TN(tabn),ls1);      FreeSpaceString(ls1,3,"");
   lsread(ls1,0);                       // инициализация ТН

 char d1_2[250], d2_2[250]; 
 sprintf(d1_2,"%s",static_cast_to_string(d1));  FreeSpaceString(d1_2,3,"");
 sprintf(d2_2,"%s",static_cast_to_string(d2));  FreeSpaceString(d2_2,3,"");

 int razn = strcmp(d1_2, d2_2);    // если равны то 0
 if (razn != 0) razn = 1;

      if (ESC==Panel_Zapros(" Прием информации из таблиц ","",
                        "  d1_2: ",d1_2, 30,
                        "  d2_2: ",d2_2, 30,  
                        "  razn: ",razn, 30)  
                                                              ) return ESC;


 return   razn;
}


TNdolg_2(tab)
{
   char tn[91], ls1[255];
   sprintf(tn,"%.90s",static_cast_to_string(tab));
   FreeSpaceString(tn,3,"");
   double tabn = atof(tn);

   if(tabn != 0)
    {
      lsname(Find_Full_TN(tabn),ls1);
      FreeSpaceString(ls1,3,"");
      double llss = atof(ls1);
      lsread(ls1,0);                   // инициализация ТН

      char str1[250], DolgNm[250];
      kch_from("dolgnost",str1);
     // DolgNm=GetDoljnFromSpravByID(str1).Getname(); //Получает название должности из справочника должностей
      return str1;
    }
}



TNdolg(tab)   // должность из КЧ
{
   char tn[91], ls1[255];
   sprintf(tn,"%.90s",static_cast_to_string(tab));
   FreeSpaceString(tn,3,"");
   double tabn = atof(tn);

   if(tabn != 0)
    {
      lsname(Find_Full_TN(tabn),ls1);
      FreeSpaceString(ls1,3,"");
      double llss = atof(ls1);
      lsread(ls1,0);                   // инициализация ТН

      char str1[250], DolgNm[250];
      kch_from("dolgnost",str1);
      int nomdlg=atoi(str1);
      DolgNm=GetDoljnFromSpravByID(nomdlg).Getname(); //Получает название должности из справочника должностей
      return DolgNm;
    }
}



StagLg(dd,pr,ps)
{

   char s1[91];
   sprintf(s1,"%s",static_cast_to_string(dd));
   FreeSpaceString(s1,3,"");
   char s2[91];
   sprintf(s2,"%s",static_cast_to_string(pr));
   FreeSpaceString(s2,3,"");
   char s3[91];
   sprintf(s3,"%s",static_cast_to_string(ps));
   FreeSpaceString(s3,3,"");

   char TrLgSt[91];

   if( strlen(s2) > 0 )
    {
     sprintf(TrLgSt,"%s,2,,,%s,%s,,,,,,,,,,",s1,s2,s3);
    }

   FreeSpaceString(TrLgSt,3,"");

   return TrLgSt;   
}



ContDlg(d1,tab)
{

   char d2[91];
   sprintf(d2,"%.90s",static_cast_to_string(d1));
   FreeSpaceString(d2,3,"");

   char tn[91], ls1[255];
   sprintf(tn,"%.90s",static_cast_to_string(tab));
   FreeSpaceString(tn,3,"");
   double tabn = atof(tn);

   lsname(Find_Full_TN(tabn),ls1);
   FreeSpaceString(ls1,3,"");
   lsread(ls1,0);                   // инициализация ТН

   char str1[255];
   kch_from("dolgnost",str1);
   FreeSpaceString(str1,3,"");

   int ddd = Str_Cmp(d2,str1," ");
   if ( ddd != 0 ) ddd = 1;
   return ddd;
   
}



ContrTN(tab)
{
   char tn[91], ls1[255];
   sprintf(tn,"%.90s",static_cast_to_string(tab));
   FreeSpaceString(tn,3,"");
   double tabn = atof(tn);

   lsname(Find_Full_TN(tabn),ls1);    FreeSpaceString(ls1,3,"");

   int ls_false =0;
   if ((strlen(ls1) == 10) || (substr(ls1,1,1) == 0)) ls_false =1; // т.е. если
                                                                   //Z0\p00000/
   return ls_false;
}

ContrAdr(d1,tab,nov)
{

   char nn[91];
   sprintf(nn,"%.90s",static_cast_to_string(nov));
   FreeSpaceString(nn,3,"");

   if ( atoi(nn) != 1  )
   {
    char d2[91];
    sprintf(d2,"%.90s",static_cast_to_string(d1));
    FreeSpaceString(d2,3,"");

    char tn[91], ls1[255];
    sprintf(tn,"%.90s",static_cast_to_string(tab));
    FreeSpaceString(tn,3,"");
    double tabn = atof(tn);
    lsname(Find_Full_TN(tabn),ls1);
    FreeSpaceString(ls1,3,"");

    lsread(ls1,0);                   // инициализация ТН

    char str1[255];
    kch_from("adres",str1);
    FreeSpaceString(str1,3,"");

    int ddd = compare(d2,str1,"1");
    if ( ddd != 0 ) ddd = 0;
    else ddd = 1;

   // int ddd = Str_Cmp(d2,str1," ");   
   // if ( ddd != 0 ) ddd = 1;

    return ddd;
   } 
}


ContrSem(d1,tab,nov)
{
   char nn[91];
   sprintf(nn,"%.90s",static_cast_to_string(nov));
   FreeSpaceString(nn,3,"");

   if ( atoi(nn) != 1  )
   {
   char d2[91];
   sprintf(d2,"%.90s",static_cast_to_string(d1));
   FreeSpaceString(d2,3,"");

   char tn[91], ls1[255];
   sprintf(tn,"%.90s",static_cast_to_string(tab));
   FreeSpaceString(tn,3,"");
   double tabn = atof(tn);

   lsname(Find_Full_TN(tabn),ls1);
   FreeSpaceString(ls1,3,"");

   lsread(ls1,0);                   // инициализация ТН
   char str1[255];
   kch_from("sem",str1);
   FreeSpaceString(str1,3,"");

   int ddd = Str_Cmp(d2,str1," ");
   if ( ddd != 0 ) ddd = 1;
   return ddd;
   } 
}



ContrKat(d1,tab,nov)
{
   char nn[91];
   sprintf(nn,"%.90s",static_cast_to_string(nov));
   FreeSpaceString(nn,3,"");

   if ( atoi(nn) != 1  )
   {

   char d2[91];
   sprintf(d2,"%.90s",static_cast_to_string(d1));
   FreeSpaceString(d2,3,"");

   char tn[91], ls1[255];
   sprintf(tn,"%.90s",static_cast_to_string(tab));
   FreeSpaceString(tn,3,"");
   double tabn = atof(tn);

   lsname(Find_Full_TN(tabn),ls1);
   FreeSpaceString(ls1,3,"");

   lsread(ls1,0);                   // инициализация ТН

   char str1[255];
   kch_from("kat",str1);
   FreeSpaceString(str1,3,"");

   int ddd = Str_Cmp(d2,str1," ");
   if ( ddd != 0 ) ddd = 1;
   return ddd;
   }
}


ContrDlg(d1,tab,nov)
{
   char nn[91];
   sprintf(nn,"%.90s",static_cast_to_string(nov));
   FreeSpaceString(nn,3,"");

   if ( atoi(nn) != 1  )
   {

   char d2[91];
   sprintf(d2,"%.90s",static_cast_to_string(d1));
   FreeSpaceString(d2,3,"");

   char tn[91], ls1[255];
   sprintf(tn,"%.90s",static_cast_to_string(tab));
   FreeSpaceString(tn,3,"");
   double tabn = atof(tn);

   lsname(Find_Full_TN(tabn),ls1);
   FreeSpaceString(ls1,3,"");
   lsread(ls1,0);                   // инициализация ТН

   char str1[255];
   kch_from("dolgnost",str1);
   FreeSpaceString(str1,3,"");

   int ddd = Str_Cmp(d2,str1," ");
   if ( ddd != 0 ) ddd = 1;
   return ddd;
   }
}


ContrPod(d1,tab,nov)
{
   char nn[91];
   sprintf(nn,"%.90s",static_cast_to_string(nov));
   FreeSpaceString(nn,3,"");

   if ( atoi(nn) != 1  )
   {

   char d2[91];
   sprintf(d2,"%.90s",static_cast_to_string(d1));
   FreeSpaceString(d2,3,"");

   char tn[91], ls1[255];
   sprintf(tn,"%.90s",static_cast_to_string(tab));
   FreeSpaceString(tn,3,"");
   double tabn = atof(tn);

   lsname(Find_Full_TN(tabn),ls1);
   FreeSpaceString(ls1,3,"");
   lsread(ls1,0);                   // инициализация ТН

   char str1[255];
   kch_from("podr",str1);
   FreeSpaceString(str1,3,"");

   int ddd = Str_Cmp(d2,str1," ");
   if ( ddd != 0 ) ddd = 1;
   return ddd;
   }
}


ContrGod(d1,tab,nov)
{
   char nn[91];
   sprintf(nn,"%.90s",static_cast_to_string(nov));
   FreeSpaceString(nn,3,"");

   if ( atoi(nn) != 1  )
   {

   char d2[91];
   sprintf(d2,"%.90s",static_cast_to_string(d1));
   FreeSpaceString(d2,3,"");

   char tn[91], ls1[255];
   sprintf(tn,"%.90s",static_cast_to_string(tab));
   FreeSpaceString(tn,3,"");
   double tabn = atof(tn);

   lsname(Find_Full_TN(tabn),ls1);
   FreeSpaceString(ls1,3,"");
   lsread(ls1,0);                   // инициализация ТН

   char str1[255];
   kch_from("data_13",str1);
   FreeSpaceString(str1,3,"");

   int ddd = Str_Cmp(d2,str1," ");
   if ( ddd != 0 ) ddd = 1;
   return ddd;
   }
}


ContrInn(d1,tab,nov)
{
   char nn[91];
   sprintf(nn,"%.90s",static_cast_to_string(nov));
   FreeSpaceString(nn,3,"");

   if ( atoi(nn) != 1  )
   {

   char d2[91];
   sprintf(d2,"%.90s",static_cast_to_string(d1));
   FreeSpaceString(d2,3,"");

   char tn[91], ls1[255];
   sprintf(tn,"%.90s",static_cast_to_string(tab));
   FreeSpaceString(tn,3,"");
   double tabn = atof(tn);

   lsname(Find_Full_TN(tabn),ls1);
   FreeSpaceString(ls1,3,"");
   lsread(ls1,0);                   // инициализация ТН

   char str1[255];
   kch_from("inn_fl",str1);
   FreeSpaceString(str1,3,"");

   int ddd = Str_Cmp(d2,str1," ");
   if ( ddd != 0 ) ddd = 1;
   return ddd;
   }
}

ContrPrUv(d1,tab,nov)
{
   char nn[91];
   sprintf(nn,"%.90s",static_cast_to_string(nov));
   FreeSpaceString(nn,3,"");

   if ( atoi(nn) != 1  )
   {

   char d2[91];
   sprintf(d2,"%.90s",static_cast_to_string(d1));
   FreeSpaceString(d2,3,"");

   char tn[91], ls1[255];
   sprintf(tn,"%.90s",static_cast_to_string(tab));
   FreeSpaceString(tn,3,"");
   double tabn = atof(tn);

   lsname(Find_Full_TN(tabn),ls1);
   FreeSpaceString(ls1,3,"");
   lsread(ls1,0);                   // инициализация ТН

   char str1[255];
   kch_from("uvol",str1);
   FreeSpaceString(str1,3,"");

   int ddd = Str_Cmp(d2,str1," ");
   if ( ddd != 0 ) ddd = 1;
   return ddd;
   }
}



ContrUvo(d1,tab,nov)
{
   char nn[91];
   sprintf(nn,"%.90s",static_cast_to_string(nov));
   FreeSpaceString(nn,3,"");

   if ( atoi(nn) != 1  )
   {

   char d2[91];
   sprintf(d2,"%.90s",static_cast_to_string(d1));
   FreeSpaceString(d2,3,"");

   char tn[91], ls1[255];
   sprintf(tn,"%.90s",static_cast_to_string(tab));
   FreeSpaceString(tn,3,"");
   double tabn = atof(tn);

   lsname(Find_Full_TN(tabn),ls1);
   FreeSpaceString(ls1,3,"");
   lsread(ls1,0);                   // инициализация ТН

   char str1[255];
   kch_from("data_uv",str1);
   FreeSpaceString(str1,3,"");

   int ddd = Str_Cmp(d2,str1," ");
   if ( ddd != 0 ) ddd = 1;
   return ddd;
   }
}


ContrPri(d1,tab,nov)
{
   char nn[91];
   sprintf(nn,"%.90s",static_cast_to_string(nov));
   FreeSpaceString(nn,3,"");

   if ( atoi(nn) != 1  )
   {

   char d2[91];
   sprintf(d2,"%.90s",static_cast_to_string(d1));
   FreeSpaceString(d2,3,"");

   char tn[91], ls1[255];
   sprintf(tn,"%.90s",static_cast_to_string(tab));
   FreeSpaceString(tn,3,"");
   double tabn = atof(tn);

   lsname(Find_Full_TN(tabn),ls1);
   FreeSpaceString(ls1,3,"");
   lsread(ls1,0);                   // инициализация ТН

   char str1[255];
   kch_from("data_rb",str1);
   FreeSpaceString(str1,3,"");

   int ddd = Str_Cmp(d2,str1," ");
   if ( ddd != 0 ) ddd = 1;
   return ddd;
   }
}


ContrPen(d1,tab,nov)
{
   char nn[91];
   sprintf(nn,"%.90s",static_cast_to_string(nov));
   FreeSpaceString(nn,3,"");

   if ( atoi(nn) != 1  )
   {

   char d2[91];
   sprintf(d2,"%.90s",static_cast_to_string(d1));
   FreeSpaceString(d2,3,"");

   char tn[91], ls1[255];
   sprintf(tn,"%.90s",static_cast_to_string(tab));
   FreeSpaceString(tn,3,"");
   double tabn = atof(tn);

   lsname(Find_Full_TN(tabn),ls1);
   FreeSpaceString(ls1,3,"");
   lsread(ls1,0);                   // инициализация ТН

   char str1[255];
   kch_from("strah_n",str1);
   FreeSpaceString(str1,3,"");

   int ddd = Str_Cmp(d2,str1," ");
   if ( ddd != 0 ) ddd = 1;
   return ddd;
   }
}


ContrVy(d1,tab,nov)
{
   char nn[91];
   sprintf(nn,"%.90s",static_cast_to_string(nov));
   FreeSpaceString(nn,3,"");

   if ( atoi(nn) != 1  )
   {

   char d2[91];
   sprintf(d2,"%.90s",static_cast_to_string(d1));
   FreeSpaceString(d2,3,"");

   char tn[91], ls1[255];
   sprintf(tn,"%.90s",static_cast_to_string(tab));
   FreeSpaceString(tn,3,"");
   double tabn = atof(tn);

   lsname(Find_Full_TN(tabn),ls1);
   FreeSpaceString(ls1,3,"");
   lsread(ls1,0);                   // инициализация ТН

   char str1[255];
   kch_from("datavys",str1);
   FreeSpaceString(str1,3,"");

   int ddd = Str_Cmp(d2,str1," ");
   if ( ddd != 0 ) ddd = 1;
   return ddd;
   }
}


ContrSt(d1,tab,nov)
{
   char nn[91];
   sprintf(nn,"%.90s",static_cast_to_string(nov));
   FreeSpaceString(nn,3,"");

   if ( atoi(nn) != 1  )
   {

   char d2[91];
   sprintf(d2,"%.90s",static_cast_to_string(d1));
   FreeSpaceString(d2,3,"");

   char tn[91], ls1[255];
   sprintf(tn,"%.90s",static_cast_to_string(tab));
   FreeSpaceString(tn,3,"");
   double tabn = atof(tn);

   lsname(Find_Full_TN(tabn),ls1);
   FreeSpaceString(ls1,3,"");
   lsread(ls1,0);                   // инициализация ТН

   char str1[255];
   kch_from("data_st",str1);
   FreeSpaceString(str1,3,"");

   int ddd = Str_Cmp(d2,str1," ");
   if ( ddd != 0 ) ddd = 1;
   return ddd;
   }
}


ContrPo(d1,tab,nov)
{
   char nn[91];
   sprintf(nn,"%.90s",static_cast_to_string(nov));
   FreeSpaceString(nn,3,"");

   if ( atoi(nn) != 1  )
   {

   char d2[91];
   sprintf(d2,"%.90s",static_cast_to_string(d1));
   FreeSpaceString(d2,3,"");

   char tn[91], ls1[255];
   sprintf(tn,"%.90s",static_cast_to_string(tab));
   FreeSpaceString(tn,3,"");
   double tabn = atof(tn);

   lsname(Find_Full_TN(tabn),ls1);
   FreeSpaceString(ls1,3,"");
   lsread(ls1,0);                   // инициализация ТН

   char str1[255];
   kch_from("pol",str1);
   FreeSpaceString(str1,3,"");

   int ddd = Str_Cmp(d2,str1," ");
   if ( ddd != 0 ) ddd = 1;
   return ddd;
   }
}


ContrRo(d1,tab,nov)
{
   char nn[91];
   sprintf(nn,"%.90s",static_cast_to_string(nov));
   FreeSpaceString(nn,3,"");

   if ( atoi(nn) != 1  )
   {

   char d2[91];
   sprintf(d2,"%.90s",static_cast_to_string(d1));
   FreeSpaceString(d2,3,"");

   char tn[91], ls1[255];
   sprintf(tn,"%.90s",static_cast_to_string(tab));
   FreeSpaceString(tn,3,"");
   double tabn = atof(tn);

   lsname(Find_Full_TN(tabn),ls1);
   FreeSpaceString(ls1,3,"");
   lsread(ls1,0);                   // инициализация ТН

   char str1[255];
   kch_from("data_r",str1);
   FreeSpaceString(str1,3,"");

   int ddd = Str_Cmp(d2,str1," ");
   if ( ddd != 0 ) ddd = 1;
   return ddd;
   }
}


ContrOt(d1,tab,nov)
{
   char nn[91];
   sprintf(nn,"%.90s",static_cast_to_string(nov));
   FreeSpaceString(nn,3,"");

   if ( atoi(nn) != 1  )
   {

   char d2[91];
   sprintf(d2,"%.90s",static_cast_to_string(d1));
   FreeSpaceString(d2,3,"");

   char tn[91], ls1[255];
   sprintf(tn,"%.90s",static_cast_to_string(tab));
   FreeSpaceString(tn,3,"");
   double tabn = atof(tn);

   lsname(Find_Full_TN(tabn),ls1);
   FreeSpaceString(ls1,3,"");
   lsread(ls1,0);                   // инициализация ТН

   char str1[255];
   kch_from("o",str1);
   FreeSpaceString(str1,3,"");

   int ddd = Str_Cmp(d2,str1," ");
   if ( ddd != 0 ) ddd = 1;
   return ddd;
   }
}


ContrIm(d1,tab,nov)
{
   char nn[91];
   sprintf(nn,"%.90s",static_cast_to_string(nov));
   FreeSpaceString(nn,3,"");

   if ( atoi(nn) != 1  )
   {

   char d2[91];
   sprintf(d2,"%.90s",static_cast_to_string(d1));
   FreeSpaceString(d2,3,"");

   char tn[91], ls1[255];
   sprintf(tn,"%.90s",static_cast_to_string(tab));
   FreeSpaceString(tn,3,"");
   double tabn = atof(tn);

   lsname(Find_Full_TN(tabn),ls1);
   FreeSpaceString(ls1,3,"");
   lsread(ls1,0);                   // инициализация ТН

   char str1[255];
   kch_from("i",str1);
   FreeSpaceString(str1,3,"");

   int ddd = Str_Cmp(d2,str1," ");
   if ( ddd != 0 ) ddd = 1;
   return ddd;
   }
}


ContrFa(d1,tab,nov)
{
   char nn[91];
   sprintf(nn,"%.90s",static_cast_to_string(nov));
   FreeSpaceString(nn,3,"");

   if ( atoi(nn) != 1  )
   {

   char d2[91];
   sprintf(d2,"%.90s",static_cast_to_string(d1));
   FreeSpaceString(d2,3,"");

   char tn[91], ls1[255];
   sprintf(tn,"%.90s",static_cast_to_string(tab));
   FreeSpaceString(tn,3,"");
   double tabn = atof(tn);

   lsname(Find_Full_TN(tabn),ls1);
   FreeSpaceString(ls1,3,"");
   lsread(ls1,0);                   // инициализация ТН

   char str1[255];
   kch_from("f",str1);
   FreeSpaceString(str1,3,"");

   int ddd = Str_Cmp(d2,str1," ");
   if ( ddd != 0 ) ddd = 1;
   return ddd;
   }
}


ContrPSP(d1,tab,nov)
{
   char nn[91];
   sprintf(nn,"%.90s",static_cast_to_string(nov));
   FreeSpaceString(nn,3,"");

   if ( atoi(nn) != 1  )
   {

   char d2[91];
   sprintf(d2,"%.90s",static_cast_to_string(d1));
   FreeSpaceString(d2,3,"");

   char tn[91], ls1[255];
   sprintf(tn,"%.90s",static_cast_to_string(tab));
   FreeSpaceString(tn,3,"");
   double tabn = atof(tn);

   lsname(Find_Full_TN(tabn),ls1);
   FreeSpaceString(ls1,3,"");
   lsread(ls1,0);                   // инициализация ТН

   char str1[255];
   kch_from("pasport",str1);
   FreeSpaceString(str1,3,"");

   int ddd = Str_Cmp(d2,str1," ");
   if ( ddd != 0 ) ddd = 1;
   return ddd;
   }
}



ContPSP(d1,tab)
{
   char d2[91];
   sprintf(d2,"%.90s",static_cast_to_string(d1));
   FreeSpaceString(d2,3,"");

   char tn[91], ls1[255];
   sprintf(tn,"%.90s",static_cast_to_string(tab));
   FreeSpaceString(tn,3,"");
   double tabn = atof(tn);

   lsname(Find_Full_TN(tabn),ls1);
   FreeSpaceString(ls1,3,"");
   double llss = atof(ls1);
   lsread(ls1,0);                   // инициализация ТН

   char str1[91];
   kch_from("pasport",str1);
   FreeSpaceString(str1,3,"");

   return str1;

}

KOR(d1)   
{
      char d2[91];
      sprintf(d2,"%.90s",static_cast_to_string(d1));

      var AdrParam = CreateObject("ParamFuncRW");
      AdrParam.IInitial(static_cast_to_string(d2)," /",3);

      char d3[30];
      sprintf(d3,"%s", static_cast_to_string(AdrParam.Get(1)));

      FreeSpaceString(d3,3,"");

  return d3;
}


KVA(d1)   
{
      char d2[91];
      sprintf(d2,"%.90s",static_cast_to_string(d1));

      var AdrParam = CreateObject("ParamFuncRW");
      AdrParam.IInitial(static_cast_to_string(d2)," -",3);

      char d3[30];
      sprintf(d3,"%s", static_cast_to_string(AdrParam.Get(1)));

      FreeSpaceString(d3,3,"");

  return d3;
}


DOM(d1)   
{
      char d2[91];
      sprintf(d2,"%.90s",static_cast_to_string(d1));

      var AdrParam = CreateObject("ParamFuncRW");
      AdrParam.IInitial(static_cast_to_string(d2)," -",3);

      char d3[30];
      sprintf(d3,"%s", static_cast_to_string(AdrParam.Get(0)));

      FreeSpaceString(d3,3,"");

  return d3;
}


GUv(d1)   // ГОД УВОЛЬНЕНИЯ ИЗ P01_60
{
      char d2[91];
      sprintf(d2,"%.90s",static_cast_to_string(d1));

      var AdrParam = CreateObject("ParamFuncRW");
      AdrParam.IInitial(static_cast_to_string(d2),".",4);

      char d3[30];
      sprintf(d3,"%s", static_cast_to_string(AdrParam.Get(0)));

      FreeSpaceString(d3,3,"");

  return d3;
}


Fam(fam)  //исправление символов-хамелеонов
{
      char fa[91];
      sprintf(fa,"%.90s",static_cast_to_string(fam));
      FreeSpaceString(fa,3,"");
      unsigned len = strlen(fa);

      for (unsigned idx=0; idx<len; ++idx)  fa[idx]=To_Rus(fa[idx]);

      return fa;

}


AdrNP1(d1)
{
      char d2[91];
      sprintf(d2,"%s",static_cast_to_string(d1));

      var AdrParam = CreateObject("ParamFuncRW");
      AdrParam.IInitial(static_cast_to_string(d2),",",2);

      char d3[60];
      sprintf(d3,"%s", static_cast_to_string(AdrParam.Get(0)));

      FreeSpaceString(d3,3,"");

  return d3;
}


Adr1(d1,pr)
{
      char p1[9];
      sprintf(p1,"%s",static_cast_to_string(pr));
      int p2 = atoi(p1);

      char d2[91];
      sprintf(d2,"%s",static_cast_to_string(d1));

      var AdrParam = CreateObject("ParamFuncRW");
      AdrParam.IInitial(static_cast_to_string(d2),",",2);

      char d3[60];
      int p3=0;
      if(p2 != 1) p3=1;
      sprintf(d3,"%s", static_cast_to_string(AdrParam.Get(p3)));
     // sprintf(d3,"%s", static_cast_to_string(AdrParam.Get(0)));
      FreeSpaceString(d3,3,"");


  return d3;
}


Adr2(d1,pr)
{

      char p1[9];
      sprintf(p1,"%s",static_cast_to_string(pr));
      int p2 = atoi(p1);

      char d2[91];
      sprintf(d2,"%.90s",static_cast_to_string(d1));

      var AdrParam = CreateObject("ParamFuncRW");
      AdrParam.IInitial(static_cast_to_string(d2),",",3);

      char d3[60];
      int p3=1;
      if(p2 != 1) p3=2;
      sprintf(d3,"%s", static_cast_to_string(AdrParam.Get(p3)));
     // sprintf(d3,"%s", static_cast_to_string(AdrParam.Get(1)));
      FreeSpaceString(d3,3,"");

  return d3;
}


Adr3(d1)
{
      char d2[91];
      sprintf(d2,"%.90s",static_cast_to_string(d1));

      var AdrParam = CreateObject("ParamFuncRW");
      AdrParam.IInitial(static_cast_to_string(d2),",",4);

      char d3[60];
      sprintf(d3,"%s", static_cast_to_string(AdrParam.Get(2)));

      FreeSpaceString(d3,3,"");

  return d3;
}



Dat1(d1)
{
      char d2[91];
      sprintf(d2,"%.90s",static_cast_to_string(d1));

      var DatParam = CreateObject("ParamFuncRW");
      DatParam.IInitial(static_cast_to_string(d2)," .",4);

      char d3[10], d4[10], d5[10];
      sprintf(d3,"%.9s", static_cast_to_string(DatParam.Get(0)));
      sprintf(d4,"%.9s", static_cast_to_string(DatParam.Get(1)));
      sprintf(d5,"%.9s", static_cast_to_string(DatParam.Get(2)));

      FreeSpaceString(d3,3,"");
      FreeSpaceString(d4,3,"");
      FreeSpaceString(d5,3,"");

      char d6[20];
      sprintf(d6,"%s.%s.%s",d5,d4,d3);
      FreeSpaceString(d6,3,"");

  return d6;
}



Dat2(d1)   // замена  "_" на  " "
{
      char d2[20];
      sprintf(d2,"%s",static_cast_to_string(d1));
      FreeSpaceString(d2,3,"");
      unsigned len = strlen(d2);

      int izm=0;
      for (unsigned idx=0; idx<len; ++idx)
       {
         if ( d2[idx]=='-' )   
          {
            d2[idx]=' ';
            izm=1;
          }
       }                     

      if (izm==0) 
       {
        for (unsigned idx=0; idx<len; ++idx) d2[idx]=' ';
       }

  return d2;

}

DatInv(in1,in2)
{
      char i1[20];
      sprintf(i1,"%s",static_cast_to_string(in1));
      FreeSpaceString(i1,3,"");
      char i2[20];
      sprintf(i2,"%s",static_cast_to_string(in2));
      FreeSpaceString(i2,3,"");

      char i3[90];
      sprintf(i3,"%s,%s",i2,i1);
      FreeSpaceString(i3,3,"");

  return i3;
}

DatRab(dat1,dat2)
{
      char d1[20];
      sprintf(d1,"%s",static_cast_to_string(dat1));
      FreeSpaceString(d1,3,"");

      char d2[20];
      sprintf(d2,"%s",static_cast_to_string(dat2));
      FreeSpaceString(d2,3,"");
      unsigned len = strlen(d2);

      if (len>2)  return d2;
      else        return d1;
}

DatPSP(ser,kem,kog)
{
      char p2[90];
      sprintf(p2,"%s",static_cast_to_string(ser));
      FreeSpaceString(p2,3,"");
      unsigned len = strlen(p2);

      int izm=0;
      for (unsigned idx=0; idx<len; ++idx)
       {
         if ( p2[idx]==' ' )   
          {
            //d2[idx]=' ';
            izm++;
            if (izm==2) p2[idx]=',';  // заменяем пробел на запятую
          }
       }                     

      char p3[90];
      sprintf(p3,"%s",static_cast_to_string(kem));
      FreeSpaceString(p3,3,"");

      char p4[90];
      sprintf(p4,"%s",static_cast_to_string(kog));
      FreeSpaceString(p4,3,"");

      char p5[90];
      sprintf(p5,"%s,%s,%s",p2,p3,p4);  //sprintf(p5,"%s,%s,%s",p2,kem,kog);
      FreeSpaceString(p5,3,"");

      return p5;

}