(defun _dialogPodwojnyNumer  (/ _typy _comments plik_dcl dcl_id l_typ wnext find lstPoints filter _find _end _dr makeDcl)
  (defun makeDcl  (/ result _c lCol i)
    (setq result nil
          _c     (chr 34))
    (if (and (setq plik_dcl (vl-filename-mktemp "" "" ".dcl"))
             (msg_open_fle plik_dcl "w")
             (include_baseDcl #fle))
      (progn (setq i    0
                   lCol (+ (msg_div (length _typy) 2) (msg_mod (length _typy) 2)))
             (write-line
               (strcat "msg_sel_pkt:boxed_row{label=" _c "Typy punktów" _c ";fixed_height=true;key=" _c "typyp" _c ";:column{")
               #fle)
             (repeat lCol
               (write-line (strcat ":toggle{label=" _c (nth i _comments) _c ";key=" _c (nth i _typy) _c ";}") #fle)
               (setq i (1+ i)))
             (write-line "}:column{" #fle)
             (repeat lCol
               (if (= i (length _typy))
                 (write-line ":spacer{height=1.2;}" #fle)
                 (write-line (strcat ":toggle{label=" _c (nth i _comments) _c ";key=" _c (nth i _typy) _c ";}") #fle))
               (setq i (1+ i)))
             (write-line "}invert_all;}" #fle)
             (write-line
               (strcat "podwojnyNumer:dialog{label=" _c "Podwójne numery punktów" _c ";:boxed_radio_row{label=" _c "Odszukaj punkt" _c ";key=" _c "find" _c ";:radio_button{label=" _c "Roboczy" _c
                       ";key=" _c "0" _c ";}")
               #fle)
             (write-line
               (strcat ":radio_button{label=" _c "Załamania granicy" _c ";key=" _c "1" _c ";}}msg_sel_pkt;:row{:list_box{label=" _c "Odnalezione podwójne numery:" _c ";key=" _c "points" _c
                       ";width=18;height=10;fixed_width_font=true;}" ":column{fixed_height=true;spacer;spacer;spacer;:button{label=" _c "Szukaj" _c ";key=" _c "accept" _c
                       ";is_default=true;height=6;}}}spacer;:row{button_drukuj;button_zapisz;" ":button{label=" _c "Zamknij" _c ";key=" _c "cancel" _c ";is_cancel=true;}}errtile;}")
               #fle)
             (msg_close_fle)
             (setq result T)))
    result)
  (defun _dr  (_isdr / marg where clinia)
    (cond (_isdr
           (setq clinia '("WYKAZ PODWÓJNYCH NUMERÓW PUNKTÓW")
                 marg   (_strings " " 5)
                 where  (okno_data 'clinia nil)
                 clinia (append clinia '(" "))))
          (T
           (setq clinia '()
                 marg   ""
                 where  (getfiled "Podaj nazwę pliku" (strcat (_getFullDwgName) ".pnp") "pnp" 7))))
    (if (and where (setq #fle (open where "w")))
      (progn (foreach & clinia (write-line (strcat marg &) #fle))
             (foreach & lstPoints (write-line (strcat marg &) #fle))
             (msg_close_fle)
             (if _isdr
               (progn (arx_drukuj_plik where) (vl-file-delete where))))))
  (defun _end  (var)
    (setq find (get_tile "find"))
    (cond ((equal find "0") (ustal_typy 'l_typ 'filter))
          (T (setq filter '((0 . "INSERT") (2 . "EGPG_?")))))
    (setq #scr-fnd (done_dialog var)))
  (defun _find  ()
    (mode_tile "typyp"
               (if (equal find "0")
                 0
                 1)))
  (ReadTypes '_typy '_comments)
  (if (and (makeDcl) (>= (setq dcl_id (load_dialog plik_dcl)) 0))
    (progn (setq l_typ     '()
                 wnext     2
                 lstPoints '()
                 find      (msg_getcfg "POINT_FIND" "0"))
           (var_initialize '#scr-fnd '(-1 -1))
           (foreach & _typy (setq l_typ (append l_typ (list (stan_warstwy &)))))
           (while (and (> wnext 0) (new_dialog "podwojnyNumer" dcl_id "" #scr-fnd))
             (invertButtons _typy)
             (set_tile "find" find)
             (mapcar '(lambda (var dat) (set_tile var dat)) _typy l_typ)
             (_find)
             (start_list "points")
             (mapcar 'add_list lstPoints)
             (end_list)
             (cond ((> (length lstPoints) 0) (mode_tile "drukuj" 0) (mode_tile "zapisz" 0))
                   (T (mode_tile "drukuj" 1) (mode_tile "zapisz" 1)))
             (action_tile "find" "(setq find $value)(_find)")
             (action_tile "invert" "(do_invert 2 _typy)")
             (action_tile "selall" "(do_invert 1 _typy)")
             (action_tile "unsel" "(do_invert 0 _typy)")
             (action_tile "zapisz" "(_end 2)")
             (action_tile "drukuj" "(_end 3)")
             (action_tile "accept" "(_end 1)")
             (action_tile "cancel" "(_end 0)")
             (setq wnext (start_dialog))
             (cond ((equal wnext 1) (setq lstPoints (_listaPodwojnychNumerow filter)))
                   ((equal wnext 2) (_dr nil))
                   ((equal wnext 3) (_dr T))))
           (unload_dialog dcl_id)
           (vl-file-delete plik_dcl)
           (msg_setcfg "POINT_FIND" find))))

(defun _dialogWolnyNumer  (/ _typy _comments plik_dcl dcl_int wnext find l_typ filter numer lstPoints int_end _find _dr makeDcl)
  (defun makeDcl  (/ result _c lCol i)
    (setq result nil
          _c     (chr 34))
    (if (and (setq plik_dcl (vl-filename-mktemp "" "" ".dcl"))
             (msg_open_fle plik_dcl "w")
             (include_baseDcl #fle))
      (progn (setq i    0
                   lCol (+ (msg_div (length _typy) 2) (msg_mod (length _typy) 2)))
             (write-line
               (strcat "msg_sel_pkt:boxed_row{label=" _c "Typy punktów" _c ";fixed_height=true;key=" _c "typyp" _c ";:column{")
               #fle)
             (repeat lCol
               (write-line (strcat ":toggle{label=" _c (nth i _comments) _c ";key=" _c (nth i _typy) _c ";}") #fle)
               (setq i (1+ i)))
             (write-line "}:column{" #fle)
             (repeat lCol
               (if (= i (length _typy))
                 (write-line ":spacer{height=1.2;}" #fle)
                 (write-line (strcat ":toggle{label=" _c (nth i _comments) _c ";key=" _c (nth i _typy) _c ";}") #fle))
               (setq i (1+ i)))
             (write-line "}invert_all;}" #fle)
             (write-line
               (strcat "find_pkt :dialog{label=" _c "Wolne numery punktów" _c ";:boxed_radio_row{label=" _c "Odszukaj punkt" _c ";key=" _c "find" _c ";:radio_button{label=" _c "Roboczy" _c ";key=" _c
                       "0" _c ";}" ":radio_button{label=" _c "Załamania granicy" _c ";key=" _c "1" _c ";}}msg_sel_pkt;:row{:list_box{label=" _c "Wolne numery:" _c ";key=" _c "points" _c
                       ";width=25; height=10;fixed_width_font=true;}")
               #fle)
             (write-line
               (strcat ":column{fixed_height=true;:text{value=" _c "Wybrany numer:" _c ";}:edit_box{label=" _c "" _c ";key=" _c "numer" _c ";fixed_width_font=true;edit_width=10;}spacer;spacer;spacer;"
                       ":button{label=" _c "Szukaj" _c ";key=" _c "accept" _c ";is_default=true;height=6;}}}spacer;:row{button_drukuj;button_zapisz;:button{label=" _c "Zamknij" _c ";key=" _c "cancel"
                       _c ";is_cancel=true;}}errtile;}")
               #fle)
             (msg_close_fle)
             (setq result T)))
    result)
  (defun int_end  (var)
    (cond ((null (check_real "numer" "Numer" nil)))
          (T
           (setq find  (get_tile "find")
                 numer (get_tile "numer"))
           (cond ((equal find "0") (ustal_typy 'l_typ 'filter))
                 (T (setq filter '((0 . "INSERT") (2 . "EGPG_?")))))
           (setq #scr-fnd (done_dialog var)))))
  (defun _find  ()
    (mode_tile "typyp"
               (if (equal find "0")
                 0
                 1)))
  (defun _dr  (_isdr / marg where clinia)
    (cond (_isdr
           (setq clinia '("WYKAZ WOLNYCH NUMERÓW PUNKTÓW")
                 marg   (_strings " " 5)
                 where  (okno_data 'clinia nil)
                 clinia (append clinia '(" "))))
          (T
           (setq clinia '()
                 marg   ""
                 where  (getfiled "Podaj nazwę pliku" (strcat (_getFullDwgName) ".wnr") "wnr" 7))))
    (if (and where (setq #fle (open where "w")))
      (progn (foreach & clinia (write-line (strcat marg &) #fle))
             (foreach &  lstPoints
               (write-line
                 (strcat (_add (itoa (car &)) #max_nr T)
                         (if (equal (car &) (cadr &))
                           ""
                           (strcat " - "
                                   (if (cadr &)
                                     (itoa (cadr &))
                                     ""))))
                 #fle))
             (msg_close_fle)
             (if _isdr
               (progn (arx_drukuj_plik where) (vl-file-delete where))))))
  (ReadTypes '_typy '_comments)
  (if (and (makeDcl) (>= (setq dcl_int (load_dialog plik_dcl)) 0))
    (progn (setq l_typ     '()
                 wnext     2
                 numer     ""
                 lstPoints '()
                 find      (msg_getcfg "POINT_FIND" "0"))
           (var_initialize '#scr-fnd '(-1 -1))
           (foreach & _typy (setq l_typ (append l_typ (list (stan_warstwy &)))))
           (while (and (> wnext 0) (new_dialog "find_pkt" dcl_int "" #scr-fnd))
             (invertButtons #lst_pkt)
             (set_tile "find" find)
             (mapcar '(lambda (var dat) (set_tile var dat)) _typy l_typ)
             (_find)
             (start_list "points")
             (foreach &  lstPoints
               (add_list (strcat (itoa (car &))
                                 (if (equal (car &) (cadr &))
                                   ""
                                   (strcat "-"
                                           (if (cadr &)
                                             (itoa (cadr &))
                                             ""))))))
             (end_list)
             (set_tile "numer" numer)
             (cond ((> (length lstPoints) 0) (mode_tile "drukuj" 0) (mode_tile "zapisz" 0))
                   (T (mode_tile "drukuj" 1) (mode_tile "zapisz" 1)))
             (action_tile "find" "(setq find $value)(_find)")
             (action_tile "invert" "(do_invert 2 _typy)")
             (action_tile "selall" "(do_invert 1 _typy)")
             (action_tile "unsel" "(do_invert 0 _typy)")
             (action_tile
               "points"
               "(if (and lstPoints (equal $reason 1))(progn(setq numer (itoa (car (nth (atoi $value) lstPoints))))
	                           (set_tile \"numer\" numer)))")
             (action_tile "zapisz" "(int_end 2)")
             (action_tile "drukuj" "(int_end 3)")
             (action_tile "accept" "(int_end 1)")
             (action_tile "cancel" "(int_end 0)")
             (setq wnext (start_dialog))
             (cond ((equal wnext 1) (setq lstPoints (_listaWolnychNumerow filter)))
                   ((equal wnext 2) (_dr nil))
                   ((equal wnext 3) (_dr T))))
           (unload_dialog dcl_int)
           (vl-file-delete plik_dcl)
           (msg_setcfg "POINT_FIND" find)))
  (cond ((equal (strlen numer) 0) 1)
        (T (atoi numer))))

