PageSourceSearch

https://zan.kz/js/DocumentHelper.js?q=4&nocache=639258787932267155

js zan.kz collected 2026-09-24 15:35:23 UTC 112,934 bytes, 2,771 lines download raw bytes

1var Cookies = new function () {
2    this.Create = function (name, value, days) {
3        var expires = "";
4        if (days) {
5            var date = new Date();
6            date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
7            expires = "; expires=" + date.toGMTString();
8        }
9        document.cookie = name + "=" + value + expires + "; path=/";
10    }
11
12    this.Read = function (name) {
13        var nameEQ = name + "=";
14        var ca = document.cookie.split(";");
15
16        for (var i = 0; i < ca.length; i++) {
17            var c = ca[i];
18            while (c.charAt(0) == " ") c = c.substring(1, c.length);
19            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
20        }
21        return null;
22    }
23
24    this.Erase = function (name) {
25        Cookie.create(name, "", -1);
26    }
27};
28
29var DocumentHelper = new function () {
30    //TODO: check document status
31    this.Status23 = function (windowNumber, statusId) {
32        if (statusId === 2 || statusId === 3) {
33            if ($('.doc-window doc-window-' + windowNumber).find('.doc-body').hasClass('doc-expired') === false) {
34                $('#doc-body-' + windowNumber).addClass('doc-expired');
35            }
36        }
37        else {
38            $('#doc-body-' + windowNumber).css("background-image", "");
39            $('#doc-body-' + windowNumber).removeClass('doc-expired');
40            }
41        var currLang = $('#docLang').val();
42        if (statusId === 2) {
43            var imgNameExp = "expired_ru";
44            if (currLang === "kk")
45                imgNameExp = "expired_kz";
46            if (currLang === "en")
47                imgNameExp = "expired_en";
48
49            var urlExp = '/images/' + imgNameExp + '.png';
50            $('.doc-expired').css("background-image", "url('" + urlExp + "')");
51        }
52        else if (statusId === 3) {
53            var imgNameIsexp = "isexpired_ru";
54            if (currLang === "kk")
55                imgNameIsexp = "isexpired_kz";
56            if (currLang === "en")
57                imgNameIsexp = "isexpired_en";
58
59            var urlIsexp = '/images/' + imgNameIsexp + '.png';
60            $('.doc-expired').css("background-image", "url('" + urlIsexp + "')");
61        }
62    }
63
64    this.ShowModalLogin = function () {
65        $("#modalLogin").modal();
66        return false;
67    }
68
69    this.SelectIsNew = function (isNew) {
70        $(".is-new").val(isNew);
71        $(".lastdoc-form").submit();
72        return false;
73    }
74
75    this.RemoveFromList = function (docId) {
76        $("#docId" + docId).slideUp();
77        var exDocs = $("#excludeDocuments").val();
78        $("#excludeDocuments").val(exDocs + "'" + docId + "',");
79    }
80
81    this.FastOpen = function (id) {
82        $(".doc-info-right .doc-info-right-body").html('Загрузка...');
83        var data = { id: id };
84
85        CommonHelper.ShowLoader();
86        $.ajax({
87            url: "/" + languageUI + "/Document/GetBodyById/",
88            method: "GET",
89            data: data
90        }).done(function (result) {
91            $(".search-result-container").addClass("search-result-container-half");
92            $(".doc-info-right").show();
93            if (result.isCanView == false)
94                $(".doc-info-right .doc-info-right-body").addClass("doctype-not-free-ru");
95            else
96                $(".doc-info-right .doc-info-right-body").removeClass("doctype-not-free-ru");
97            $(".doc-info-right .doc-info-right-body").html(result.body);
98            CommonHelper.HideLoader();
99        });
100    }
101
102    this.SudSearch = function () {
103        DocumentHelper.ResetParameters();
104        $(".selectedNpaTypes").val("СУПР");
105        $(".form-search-doc").submit();
106        return false;
107    }
108
109    this.FreeSearch = function () {
110        DocumentHelper.ResetParameters();
111        $(".selectedNpaTypes").val("КОНС,ЗАК,КОД");
112        $(".form-search-doc").submit();
113        return false;
114    }
115
116    this.SectionsSearch = function (code) {
117        DocumentHelper.ResetParameters();
118        $(".selectedSections").val(code);
119        $(".selectedRegionActions").val("100000000000");
120        $(".form-search-doc").submit();
121        return false;
122    }
123
124    this.ClassifiersSearch = function (code) {
125        DocumentHelper.ResetParameters();
126        $(".selectedClassifiers").val(code + ",");
127        $(".selectedRegionActions").val("100000000000,");
128        $(".form-search-doc").submit();
129        return false;
130    }
131
132    this.TSSearch = function () {
133        DocumentHelper.ResetParameters();
134        $(".selectedSections").val("3500");
135        $(".form-search-doc").submit();
136        return false;
137    }
138
139    this.AdvancedSearch = function () {
140        $(".isRewriteFilterPanel").val("true");
141        DocumentHelper.AddFilterParametrValue();
142        DocumentHelper.RefreshFilter();
143        $(".form-search-doc").submit();
144        return false;
145    }
146
147    this.ResetParameters = function () {
148        $(".selected-hidden").val('');
149        $(".form-search input[type=text]").val('');
150        $(".form-search input[type=checkbox]").iCheck('uncheck');
151
152        $(".selected-div").html('');
153        $(".aciTreeUl li").removeClass("aciTreeChecked");
154        $("#excludeDocuments").val('');
155        DocumentHelper.UpdateTrees();
156    }
157
158    this.ErrorMessage = function () {
159        $(".selected-error-message").val($("#selectedFullText").val());
160        $window = $(".doc-window-" + 1);
161        var id = $window.find(".id").val();
162
163        $(".error-document-id").val(id);
164        $("#modalError").modal();
165    }
166
167    this.SearchDic = function (windowNumber) {
168        $('.selection-menu-content').toggle(false);
169        var fullText = $("#selectedFullText").val();
170        var truncatedText = fullText.length > 30 ? fullText.slice(0, 30) + '...' : fullText;
171        document.getElementById("selectedFullText").value = fullText;
172        document.getElementById("selectText").innerHTML = '"' + truncatedText.replace(/\s+/g, ' ') + '"';
173        $(".words").html('');
174
175        $.ajax({
176            url: '/' + languageUI + '/Dictionary/Search/',
177            data: { searchText: truncatedText, size: 3, sortByDesc: true }
178        }).done(function (words) {
179            $('.selection-menu-content').toggle();
180            if (words.words[0] != null) {
181                var dic = 1;
182                $.each(words.words, function (key, value) {
183                    var desc = $.parseHTML(value.description);
184                    var html = ' <div class="dictionary-title"><a href="' + '/' + languageUI + '/Dictionary/Detail/?id=' + value.id + '">' + value.title + '</a></div>';
185                    html += ' <div class="dictionary-descr"> Словарь: ' + value.dictionaryType.name + '</div>';
186                    html += ' <div class="dictionary-text desc-' + dic + '"></div>';
187                    $(".words").append(html);
188                    $('.desc-' + dic).append(desc[0].textContent);
189                    dic = dic + 1;
190                });
191            } else {
192                $(".words").html('Ничего не найдено: <br/><a href="#" id="openModalDic" class="btn btn-success btn-zakon" style="font-size: 12px; margin-left: 15px" data-toggle="modal" data-target="#modalAddWordToDic">Добавить в словарь</a>');
193                $('input[name="DictionaryText"]').val(document.getElementById("selectedFullText").value);
194            }              
195        });
196        return false;
197    }
198
199    this.ThematicSearch = function (windowNumber) {
200        $('.selection-menu-content').toggle(false);
201        var isbytheme = 7;
202        var fullText = $("#selectedFullText").val();
203        var truncatedText = fullText.length > 30 ? fullText.slice(0, 30) + '...' : fullText;
204        document.getElementById("selectedFullText").value = fullText;
205        document.getElementById("selectText").innerHTML = '"' + truncatedText.replace(/\s+/g, ' ') + '"';
206        $(".words").html('');
207        $('.words').empty();
208        $('.words').append('<div class="words-tree aciTree aciTree0" style="opacity:1;"></div>');
209        $('.words-tree').css({ height: 200 });
210        var isAlfa = false;
211        $('.words-tree').aciTree({
212            ajax: {
213                async: true,
214                //cache: false,
215                url: '/' + languageUI + '/dictionary/GetTree?isbytheme=' + isbytheme + '&alpha=' + isAlfa + '&searchText=' + encodeURI(truncatedText) + '&id='
216            },
217            checkbox: false,
218            selectable: true,
219            itemHook: function (parent, item, itemData, level) {
220                
221            }
222        });
223        $('.selection-menu-content').toggle(true);
224        return false;
225    }
226
227    this.SynonymSearch = function (windowNumber) {
228        $('.selection-menu-content').toggle(false);
229        var fullText = $("#selectedFullText").val();
230        var truncatedText = fullText.length > 30 ? fullText.slice(0, 30) + '...' : fullText;
231        document.getElementById("selectedFullText").value = fullText;
232        document.getElementById("selectText").innerHTML = '"' + truncatedText.replace(/\s+/g, ' ') + '"';
233        $(".words").html('');
234
235        $.ajax({
236            url: '/' + languageUI + '/Dictionary/Search/',
237            data: { searchText: truncatedText, size: 3, sortByDesc: true }
238        }).done(function (words) {
239            $('.selection-menu-content').toggle();
240            if (words.words[0] != null) {
241                var dic = 1;
242                $.each(words.words, function (key, value) {
243                    var desc = $.parseHTML(value.description);
244                    var html = ' <div class="dictionary-title"><a href="' + '/' + languageUI + '/Dictionary/Detail/?id=' + value.id + '">' + value.title + '</a></div>';
245                    html += ' <div class="dictionary-descr"> Словарь: ' + value.dictionaryType.name + '</div>';
246                    html += ' <div class="dictionary-text desc-' + dic + '"></div>';
247                    $(".words").append(html);
248                    $('.desc-' + dic).append(desc[0].textContent);
249                    dic = dic + 1;
250                });
251            } else {
252                $(".words").html('Ничего не найдено: <br/><a href="#" id="openModalDic" class="btn btn-success btn-zakon" style="font-size: 12px; margin-left: 15px" data-toggle="modal" data-target="#modalAddWordToDic">Добавить в словарь</a>');
253                $('input[name="DictionaryText"]').val(document.getElementById("selectedFullText").value);
254            }
255        });
256        return false;
257    }
258
259    this.ErrorMessageSubmit = function () {
260        $.ajax({
261            url: '/' + languageUI + '/Document/Error',
262            method: "POST",
263            data: { comment: $(".error-comment").val(), documentId: $(".error-document-id").val(), email: $(".error-email").val(), errorMessage: $(".selected-error-message").val() }
264        }).done(function (output) {
265
266            $("#modalError").modal('toggle');
267            toastr["success"]("Сообщение отправлено");
268        });
269        return false;
270    }
271
272    this.FastCard = function (ngr, dateEdition, language) {
273        $(".doc-info-right .doc-info-right-body").html('Загрузка...');
274        CommonHelper.ShowLoader();
275
276        $.ajax({
277            url: "/" + languageUI + "/document/card/",
278            type: "GET",
279            data: { langId: language, ngr: ngr, dateEdition: dateEdition }
280        }).done(function (output) {
281            $(".search-result-container").addClass("search-result-container-half");
282            $(".doc-info-right").show();
283
284            $(".doc-info-right .doc-info-right-body").html(output);
285            CommonHelper.HideLoader();
286
287        });
288    }
289
290    this.HideRightCard = function () {
291        $(".doc-info-right").hide();
292        $(".search-result-container").removeClass("search-result-container-half");
293    }
294
295    this.Remove = function () {
296        CommonHelper.ShowLoader();
297        var removeItems = [];
298        $(".fav-doc-checkbox").each(function () {
299            if ($(this).prop('checked'))
300                removeItems.push($(this).val());
301        });
302        //console.info(removeItems);
303        $.ajax({
304            url: '/' + languageUI + '/Document/RemoveFavorite',
305            data: { docs: removeItems },
306            method: "POST"
307        }).done(function (output) {
308            window.location.reload();
309        });
310    }
311
312    this.ToScrollToStart = function () {
313        if ($(".doc-detail").length < 1)
314            return false;
315        $('body').animate({
316            scrollTop: $(".doc-work-space").offset().top - 50
317        }, 500);
318    }
319
320    this.HideComments = function () {
321        $stateHide = $(".hide-comment").attr('state');
322        if ($stateHide == 'false') {
323            $(".hide-comment").attr('state', 'true');
324            $(".body-comment").hide();
325            $(".body-bookmark").hide();
326            $(".hide-comment").find('i').removeClass('fa-commenting');
327            $(".hide-comment").find('i').addClass('fa-commenting-o');
328            toastr["success"]("Коментарии и закладки отключены");
329
330        }
331        else {
332            $(".hide-comment").attr('state', 'false');
333            $(".body-comment").show();
334            $(".body-bookmark").show();
335            $(".hide-comment").find('i').removeClass('fa-commenting-o');
336            $(".hide-comment").find('i').addClass('fa-commenting');
337            toastr["success"]("Коментарии и закладки включены");
338        }
339    }
340
341    this.HideCommentsRcpi = function () {
342        $stateHide = $(".hide-comment-rcpi").attr('state');
343        if ($stateHide == 'false') {
344            $(".hide-comment-rcpi").attr('state', 'true');
345            $(".doc-body").children('a').hide();
346            $('font[color="#FF0000"]').parent('p').hide();
347            $('font[color="FF0000"]').parent('p').hide();
348            $('font[color="#800000"]').parent('p').hide();
349            $('font[color="800000"]').parent('p').hide();
350            $('font[color="#FF0000"]').hide();
351            $('font[color="FF0000"]').hide();
352            $('font[color="#800000"]').hide();
353            $('font[color="800000"]').hide();
354            $(".hide-comment-rcpi").find('i').removeClass('fa-toggle-on');
355            $(".hide-comment-rcpi").find('i').addClass('fa-toggle-off');
356            toastr["success"]("Примечания ИЗПИ отключены");
357
358        }
359        else {
360            $(".hide-comment-rcpi").attr('state', 'false');
361            $(".doc-body").children('a').show();
362            $('font[color="#FF0000"]').parent('p').show();
363            $('font[color="FF0000"]').parent('p').show();
364            $('font[color="#800000"]').parent('p').show();
365            $('font[color="800000"]').parent('p').show();
366            $('font[color="#FF0000"]').show();
367            $('font[color="FF0000"]').show();
368            $('font[color="#800000"]').show();
369            $('font[color="800000"]').show();
370            $(".hide-comment-rcpi").find('i').removeClass('fa-toggle-off');
371            $(".hide-comment-rcpi").find('i').addClass('fa-toggle-on');
372            toastr["success"]("Примечания ИЗПИ включены");
373        }
374    }
375
376    this.CheckTree = function (treeObject, selectedElements) {
377        if ($("." + selectedElements).length < 1) {
378            //console.log(false);
379            return false;
380        }
381        var npaTypes = $("." + selectedElements).val().split(',');
382        $.each(npaTypes, function (index, value) {
383            var api = $('.' + treeObject).aciTree('api');
384            if (api != null) {
385                var leaves = $("." + treeObject + " .aciTreeLi");
386                if (leaves.length > 0) {
387                    //console.info(leaves); 
388                    var checked = api.checkboxes(leaves, false);
389                    checked.each(function (index, item) {
390                        var $item = $(item);
391                        if (api.getId($item) == value)
392                            api.check($item);
393                    });
394                }
395            }
396        });
397        //console.log(true);
398    }
399
400    this.ScrollLockClick = function (isToaster) {
401        if ($(".doc-window-2").length > 0) {
402            var rightDiv = $(".doc-window-2").get(0);
403            if (rightDiv.style.display != "none") {
404                var $scrollBtn = $(".btn-scroll-lock");
405                if ($scrollBtn.attr('lock') == 'true') {
406                    $(".btn-scroll-lock").find("i").removeClass("fa-lock");
407                    $(".btn-scroll-lock").find("i").addClass("fa-unlock");
408                    $scrollBtn.attr('lock', false);
409                    DocumentHelper.SyncScroll(false);
410                    if (isToaster == undefined)
411                        toastr["success"]("Режим одновременной прокрутки двух окон отключился");
412                }
413                else {
414                    $(".btn-scroll-lock").find("i").addClass("fa-lock");
415                    $(".btn-scroll-lock").find("i").removeClass("fa-unlock");
416                    $scrollBtn.attr('lock', true);
417                    DocumentHelper.SyncScroll(true);
418                    if (isToaster == undefined)
419                        toastr["success"]("Режим одновременной прокрутки двух окон включился");
420                }
421            }
422        }
423    }
424
425    this.HideScrollLock = function (show) {
426        if (!show) {
427            $(".doc-scrolllock").css("display", "none");
428        }
429        else {
430            $(".doc-scrolllock").css("display", "block");
431        }
432    }
433
434    this.LockEditationLanguage = function (flag) {
435        if (flag) {
436            $("#bodyLanguages1").attr("disabled", true);
437            $("#bodyLanguages2").attr("disabled", true);
438            $("#bodySelectEditions1").attr("disabled", true);
439            $("#bodySelectEditions2").attr("disabled", true);
440            $("#bodySelectEditions1").attr("disabled", true);
441        }
442        else {
443            $("#bodyLanguages1").prop("disabled", false);
444            $("#bodyLanguages2").prop("disabled", false);
445            $("#bodySelectEditions1").prop("disabled", false);
446            $("#bodySelectEditions2").prop("disabled", false);
447        }
448    }
449
450    this.SyncScroll = function (sync) {
451        if (sync) {
452            $(".btn-scroll-lock").show();
453        }
454        var isSyncingLeftScroll = sync;
455        var isSyncingRightScroll = sync;
456        var leftDiv = document.getElementById('doc-body-1');
457        var rightDiv = document.getElementById('doc-body-2');
458        if (sync) {
459            leftDiv.onscroll = function () {
460                if (!isSyncingLeftScroll) {
461                    isSyncingRightScroll = true;
462                    rightDiv.scrollTop = this.scrollTop;
463                }
464                isSyncingLeftScroll = false;
465            }
466
467            rightDiv.onscroll = function () {
468                if (!isSyncingRightScroll) {
469                    isSyncingLeftScroll = true;
470                    leftDiv.scrollTop = this.scrollTop;
471                }
472                isSyncingRightScroll = false;
473            }
474        }
475        else {
476            leftDiv.onscroll = function () {
477            }
478
479            rightDiv.onscroll = function () {
480            }
481        }
482    }
483
484    this.CheckTreeLanguages = function (delay) {
485        setTimeout(function () {
486            DocumentHelper.CheckTree("language-tree", "selectedLanguage")
487        }, delay);
488    }
489
490    this.CheckTreeNpaTypes = function (delay) {
491        setTimeout(function () {
492            DocumentHelper.CheckTree("npa-types-tree", "selectedNpaTypes")
493        }, delay);
494    }
495
496    this.CheckTreeClassifiers = function (delay) {
497        setTimeout(function () {
498            DocumentHelper.CheckTree("classifiers-tree", "extselectedClassifiers")
499        }, delay);
500    }
501
502    this.CheckTreeDepartments = function (delay) {
503        setTimeout(function () {
504            DocumentHelper.CheckTree("departments-tree", "extselectedDepartments")
505        }, delay);
506    }
507
508    this.CheckTreeActionRegions = function (delay) {
509        setTimeout(function () {
510            DocumentHelper.CheckTree("regions-tree", "extselectedRegionActions")
511        }, delay);
512    }
513
514    this.CheckTreeInitRegions = function (delay) {
515        setTimeout(function () {
516            DocumentHelper.CheckTree("initregions-tree", "extselectedRegionInits")
517        }, delay);
518    }
519
520    this.CheckTreeSources = function (delay) {
521        setTimeout(function () {
522            DocumentHelper.CheckTree("sources-tree", "extselectedSources")
523        }, delay);
524    }
525
526    this.CheckTreeSections = function (delay) {
527        setTimeout(function () {
528            DocumentHelper.CheckTree("sections-tree", "extselectedSections")
529        }, delay);
530    }
531
532    this.CheckTreeRegAgencies = function (delay) {
533        setTimeout(function () {
534            DocumentHelper.CheckTree("regagencies-tree", "extselectedRegAgencies")
535        }, delay);
536    }
537
538    this.CheckTreeDevAgencies = function (delay) {
539        setTimeout(function () {
540            DocumentHelper.CheckTree("dev-agencies-tree", "extselectedDevAgencies")
541        }, delay);
542    }
543
544    this.CheckTreeTitlePrefixes = function (delay) {
545        setTimeout(function () {
546            DocumentHelper.CheckTree("title-prefixes-tree", "selectedTitlePrefixes")
547        }, delay);
548    }
549
550    this.UpdateTrees = function () {
551        DocumentHelper.CheckTreeNpaTypes(4000);
552        DocumentHelper.CheckTreeLanguages(4000);
553        DocumentHelper.CheckTreeActionRegions(6000);
554        DocumentHelper.CheckTreeClassifiers(6000);
555        DocumentHelper.CheckTreeDepartments(6000);
556        DocumentHelper.CheckTreeSources(6000);
557        DocumentHelper.CheckTreeRegAgencies(6000);
558        DocumentHelper.CheckTreeDevAgencies(6000);
559        DocumentHelper.CheckTreeSections(6000);
560        DocumentHelper.CheckTreeInitRegions(6000);
561        DocumentHelper.CheckTreeTitlePrefixes(6000);
562    }
563
564    this.IfExistCard = function () {
565        var id = $("#documentCardId").val();
566        $.ajax({
567            url: '/' + languageUI + '/Document/OfficalPublic?id=' + id,
568            type: 'HEAD',
569            error: function () {
570                $("#officalPublic").hide();
571            },
572            success: function () {
573                $("#officalPublic").show();
574            }
575        });
576    }
577
578    this.SelectRange = function (rangeType) {
579        $(".range-type").val(rangeType);
580        $(".lastdoc-form").submit();
581        return false;
582    }
583
584    this.SelectLastDocumentsLanguage = function (language) {
585        $(".language").val(language);
586        $(".lastdoc-form").submit();
587        return false;
588    }
589
590    this.SaveList = function () {
591        if (!authorized) {
592            $("#modalLogin").modal();
593            return false;
594        }
595        //var total = $(".total").html();
596        var listName = $("#favoriteListName").val();
597
598        if (listName.length < 3) {
599            $('#favoriteListNameMessage').show();
600            return false;
601        }
602        $('#favoriteListNameMessage').hide();
603        $('#favoriteListNameForm').val(listName);
604        $(".is-save-list").val('true');
605        DocumentHelper.SearchSubmit();
606    }
607
608    this.LocationToFavorite = function () {
609        if (!authorized) {
610            $("#modalLogin").modal();
611            return false;
612        }
613        window.location.href = "/" + languageUI + "/Cabinet/Favorites";
614    }
615
616    this.ChangeYearOrRegion = function () {
617        var year = $('#docyear').val();
618        var region = $('#docregion').val();
619        window.location.href = "/" + languageUI + "/Document/LastDocuments?year=" + year + "&regionCode=" + region + "&rangeType=0";
620    }
621
622    this.OnClickSort = function (sortType) {
623        var $sortItem = $('#sortPanel li[type=' + sortType + ']');
624        var desc = $sortItem.find('a').attr('desc');
625        if (desc == 'True') {
626            $sortItem.find('a').attr('desc', 'False');
627            $sortItem.find('.sort-icon').find('i').removeClass('fa-sort-amount-desc');
628            $sortItem.find('.sort-icon').find('i').addClass('fa-sort-amount-asc');
629        }
630        else {
631            $sortItem.find('a').attr('desc', 'True');
632            $sortItem.find('.sort-icon').find('i').removeClass('fa-sort-amount-asc');
633            $sortItem.find('.sort-icon').find('i').addClass('fa-sort-amount-desc');
634        }
635        DocumentHelper.OnMoveSort();
636        return false;
637        //Click Sort Icon 
638    }
639
640    this.OnMoveSort = function () {
641        var sortList = '';
642        var descList = '';
643        $('#sortPanel li').each(function (index, element) {
644            sortList += $(element).find('a').attr('type');
645            descList += $(element).find('a').attr('desc');
646            if (index < 3) {
647                sortList += ',';
648                descList += ',';
649            }
650        });
651        $('#descList').val(descList);
652        $('#sortList').val(sortList);
653        DocumentHelper.SearchSubmit();
654    }
655
656    this.RemoveTag = function (treeObject, selectedObject, unselectedObject, id) {
657        $("." + id).remove();
658        if ($("." + unselectedObject).val().indexOf(id) == -1)
659            $("." + unselectedObject).val($("." + unselectedObject).val() + id + ',');
660        var str = $("." + selectedObject).val();
661        $("." + selectedObject).val(str.replace(id + ',', ''));
662        var api = $("." + treeObject).aciTree('api');
663        api.searchId(true, true, {
664            success: function (item, options) {
665                api.uncheck(item, null);
666            },
667            fai: function (item, options) {
668
669            },
670            id: id
671        });
672    }
673
674    this.ShowAllComments = function () {
675        $.ajax({
676            url: "/" + languageUI + "/Document/CommentsAll?id=" + $(".document-id").val()
677        }).done(function (output) {
678            $(".comments-container").html(output);
679            $(".comments-container").toggle(400);
680        });
681    }
682
683    this.RefreshFilter = function () {
684        $(".selectedNpaTypes").val($(".extselectedNpaTypes").val());
685        $(".unselectedNpaTypes").val($(".extunselectedNpaTypes").val());
686
687        $(".selectedRegionActions").val($(".extselectedRegionActions").val());
688        $(".unselectedRegionActions").val($(".extunselectedRegionActions").val());
689
690        $(".selectedRegionInits").val($(".extselectedRegionInits").val());
691        $(".unselectedRegionInits").val($(".extunselectedRegionInits").val());
692
693        $(".selectedRegAgencies").val($(".extselectedRegAgencies").val());
694        $(".unselectedRegAgencies").val($(".extunselectedRegAgencies").val());
695
696        $(".selectedDevAgencies").val($(".extselectedDevAgencies").val());
697        $(".unselectedDevAgencies").val($(".extunselectedDevAgencies").val());
698
699        $(".selectedClassifiers").val($(".extselectedClassifiers").val());
700        $(".unselectedClassifiers").val($(".extunselectedClassifiers").val());
701
702        $(".selectedDepartments").val($(".extselectedDepartments").val());
703        $(".unselectedDepartments").val($(".extunselectedDepartments").val());
704
705        $(".selectedSources").val($(".extselectedSources").val());
706        $(".unselectedSources").val($(".extunselectedSources").val());
707
708        $(".selectedSections").val($(".extselectedSections").val());
709        $(".unselectedSections").val($(".extunselectedSections").val());
710        return false;
711    }
712
713    this.SearchSubmitClick = function () {
714        $(".isRewriteFilterPanel").val("true");
715        DocumentHelper.AddFilterParametrValue();
716        DocumentHelper.RefreshFilter();
717        $(".form-search-doc").submit();
718        return false;
719    }
720
721    this.RefreshFilterPanel = function () {
722        $('.filter-container').addClass('disabledbutton');
723        var formData = $(".form-search-doc").serialize();
724        $("#filterLoader").show();
725        $.ajax({
726            url: '/' + languageUI + '/Document/SearchFilter',
727            method: 'post',
728            data: formData
729        }).done(function (filter) {
730            DocumentHelper.FilterInsert(filter.languages, 'filter-language', 'language', filter.unselectedLanguage);
731            DocumentHelper.FilterInsert(filter.statuses, 'filter-statuses', 'status-ext', filter.unselectedStatuses);
732            DocumentHelper.FilterInsert(filter.regionsAction, 'filter-regions', 'region', filter.unselectedRegionActions);
733            DocumentHelper.FilterInsert(filter.classifiers, 'filter-classifiers', 'classifier', filter.unselectedClassifiers);
734            $(".isRewriteFilterPanel").val("false");
735            $('.i-checks').iCheck({
736                checkboxClass: 'icheckbox_square-green',
737                radioClass: 'iradio_square-green',
738            });
739            $('.near-check').on('ifChecked', function (event) {
740                $(".every-word-and").iCheck('check');
741                $(".every-word-or").iCheck('uncheck');
742                $(".every-word-or").iCheck('disable');
743            });
744            $('.near-check').on('ifUnchecked', function (event) {
745                $(".every-word-or").iCheck('enable');
746            });
747            $('.showTranslateCheckbox').on('ifChecked', function (event) {
748                $("#showTranslate").val(true);
749                DocumentHelper.SearchSubmit();
750            });
751            $('.showTranslateCheckbox').on('ifUnchecked', function (event) {
752                $("#showTranslate").val(false);
753                DocumentHelper.SearchSubmit();
754            });
755            $('#onlyFree').on('ifChecked', function (event) {
756                $("#onlyFreeInput").val(true);
757                DocumentHelper.SearchSubmit();
758            });
759            $('#onlyFree').on('ifUnchecked', function (event) {
760                $("#onlyFreeInput").val(false);
761                DocumentHelper.SearchSubmit();
762            });
763            CommonHelper.CheckOnSelect('check-language', 'selectedLanguage', 'unselectedLanguage', true, true, DocumentHelper.SearchSubmit, DocumentHelper.RefreshFilterPanel);
764            CommonHelper.CheckOnSelect('check-status-ext', 'selectedStatuses', 'unselectedStatuses', true, true, DocumentHelper.SearchSubmit, DocumentHelper.RefreshFilterPanel);
765            CommonHelper.CheckOnSelect('check-region', 'filterSelectedRegionActions', 'unselectedRegionActions', true, true, DocumentHelper.SearchSubmit, DocumentHelper.RefreshFilterPanel);
766            CommonHelper.CheckOnSelect('check-classifier', 'filterSelectedClassifiers', 'unselectedClassifiers', true, true, DocumentHelper.SearchSubmit, DocumentHelper.RefreshFilterPanel);
767            $("#filterLoader").hide();
768            $('.filter-container').removeClass('disabledbutton');
769        });
770    }
771
772    this.ResetLeftFilters = function () {
773        $('.filter-container input').iCheck('uncheck');
774        DocumentHelper.SearchSubmit();
775    }
776
777    this.SearchInDocument = function (windowNumber) {
778        CommonHelper.ShowLoader();
779        var $window = $(".doc-window-" + windowNumber);
780        $window.find('.body-links').remove();
781        $window.find(".find-text-active").replaceWith(function () { return $(this).contents(); });
782        $window.find(".find-text").replaceWith(function () { return $(this).contents(); });
783        var searchString = $window.find(".doc-search-text").val().trim();
784        if (searchString == "")
785            return false;
786        var html = $("#doc-body-" + windowNumber).html();
787        $window.find('.find-pos').html('0');
788        var multiWordsParam = $("#docFindMultiWords" + windowNumber).val();
789        if (multiWordsParam === '1') {
790            var searchWords = searchString.split(' ');
791            searchString = "";
792            for (i = 0; i < searchWords.length; i++) {
793                var word = searchWords[i].replaceAll(',', '').replaceAll('.', '').replaceAll('"', '').replaceAll('\'', '').replaceAll('(').replaceAll(')').trim();
794                if (word.length > 0) {
795                    searchString += "(" + searchWords[i].replaceAll(',', ' ') + ")";
796                    if (i != searchWords.length - 1) {
797                        searchString += '|';
798                    }
799                }
800            }
801            searchString = searchString.trim();
802        }
803        console.log(html);
804        var reg = new RegExp(searchString, 'gi');
805        var result = html.replace(reg, function (str) {
806            return '<span class=\'find-text\'>' + str + '</span>'
807        });
808
809        html = $(result);
810        $.each(html.find('a'), function (i, el) {
811            var href = $(this).attr('href');
812            if (href != undefined)
813                $(this).attr('href', href.replace('<span class=\'find-text\'>', '').replace('</span>', ''));
814        });
815        $("#doc-body-" + windowNumber).html(html);
816        $("#doc-body-" + windowNumber).scrollTop(0);
817        $window.find('.find-element-coord').val('');
818        var i = 0;
819        $("#doc-body-" + windowNumber).find(".find-text").each(function (index, element) {
820            i++;
821            $window.find('.find-element-coord').val($window.find('.find-element-coord').val() + ($(element).offset().top - 300) + ',');
822        });
823        $window.find('.find-count').html(i);
824        $window.find('.need-search').val('');
825        CommonHelper.HideLoader();
826    }
827
828    this.SearchInDocumentCount = function (windowNumber) {
829        CommonHelper.ShowLoader();
830        var $window = $(".doc-window-" + windowNumber);
831        $window.find('.body-links').remove();
832        $window.find(".find-text-active").replaceWith(function () { return $(this).contents(); });
833        $window.find(".find-text").replaceWith(function () { return $(this).contents(); });
834        var searchString = $window.find(".doc-search-text").val().trim();
835        if (searchString == "")
836            return false;
837
838        var html = $("#doc-body-" + windowNumber).html();
839        $window.find('.find-pos').html('0');
840        var multiWordsParam = $("#docFindMultiWords" + windowNumber).val();
841        if (multiWordsParam === '1') {
842            var searchWords = searchString.split(' ');
843            searchString = "";
844            for (i = 0; i < searchWords.length; i++) {
845                var word = searchWords[i].replaceAll(',', '').replaceAll('.', '').replaceAll('"', '').replaceAll('\'', '').replaceAll('(').replaceAll(')').trim();
846                if (word.length > 0) {
847                    searchString += "(" + searchWords[i].replaceAll(',', ' ') + ")";
848                    if (i != searchWords.length - 1) {
849                        searchString += '|';
850                    }
851                }
852            }
853            searchString = searchString.trim();
854        }
855        var reg = new RegExp(searchString, 'gi');
856        var result = html.replace(reg, function (str) {
857            return '<span class=\'find-text\'>' + str + '</span>';
858        });
859        html = $(result);
860        $.each(html.find('a'), function (i, el) {
861            var href = $(this).attr('href');
862            if (href != undefined)
863                $(this).attr('href', href.replace('<span class=\'find-text\'>', '').replace('</span>', ''));
864        });
865        $("#doc-body-" + windowNumber).html(html);
866        $window.find('.find-element-coord').val('');
867        var i = 0;
868        i = $("#doc-body-" + windowNumber).find(".find-text").length;
869        $window.find('.find-count').html(i);
870        CommonHelper.HideLoader();
871    }
872
873    this.NeedSearch = function (windowNumber, event) {
874        var $window = $(".doc-window-" + windowNumber);
875        if (event == null) {
876            $window.find('.need-search').val('true');
877            return;
878        }
879        if (event.keyCode == 13) {
880            DocumentHelper.FindElementRight(windowNumber);
881        } else if (event.ctrlKey || event.altKey) {
882            return false;
883        }
884        else {
885            $window.find('.need-search').val('true');
886        }
887    }
888
889    this.VisibleDocSearchPanel = function (windowNumber, visible) {
890        var $window = $(".doc-window-" + windowNumber);
891        if (visible) {
892            $window.find('.doc-search-panel').show();
893            $window.find('.doc-search-text').focus();
894        }
895        else
896            $window.find('.doc-search-panel').hide();
897    }
898
899    this.ReturnSearchUrl = function () {
900        var searchUrl = Cookies.Read("searchUrl");
901        if (searchUrl == null) {
902            alert('Параметры поиска не найдены');
903            return false;
904        } else {
905            window.location.href = searchUrl;
906        }
907    }
908
909    this.UpdateShortBodies = function () {
910        if ($('#searchContext').val() != "0") {
911            $(".doc-fragment").hide();
912            return false;
913        }
914        $(".doc-fragment").show();
915        var _data = "ids=" + $("#docIds").val() + '&searchText=' + $("#searchText").val();
916        $.ajax({
917            url: "/" + languageUI + "/Document/GetBodySearch",
918            data: _data,
919            method: 'post',
920            async: true
921        }).done(function (docs) {
922            $.each(docs, function (index) {
923                $(".doc-fragment").eq(index).html(this);
924
925            });
926        });
927    }
928
929    this.SearchSubmit = function () {
930        if ($(".sample-search").length < 1)
931            return false;
932
933        if ($('.first-search').length > 0)
934            return true;
935
936        $(".find-arrows").hide();
937
938        if ($(".search-context").val() == "2") {
939            return false;
940        }
941        if ($('.second-search').length < 1)
942            return false;
943
944        $("#size").val($("#sizeSelect").val());
945        CommonHelper.ShowLoader();
946        $(".ui-autocomplete").css('display', 'none');
947        $('.search-result-container').addClass('disabledbutton');
948        $('.pagination').html('');
949        var formData = $(".form-search-doc").serialize();
950
951        $.ajax({
952            url: '/' + languageUI + '/Document/Search',
953            method: 'post',
954            data: formData,
955            async: true
956        }).done(function (output) {
957            $(".search-result-docs").html(output);
958            CommonHelper.HideLoader();
959            DocumentHelper.SortClick();
960            $('.search-result-container').removeClass('disabledbutton');
961        });
962
963        $.ajax({
964            url: '/' + languageUI + '/Document/SearchCount',
965            method: 'post',
966            data: formData,
967            async: true
968        }).done(function (output) {
969            $(".current-page").val(output.page);
970            $(".total-pages").val(output.totalPages);
971            $(".total").html(output.total);
972
973            if (output.currentPage == 1)
974                toastr["success"]("Поиск выполнен. Результат поиска: " + output.total + " записей");
975
976            $('.pagination').pagination({
977                prevText: '<',
978                nextText: '>',
979                currentPage: output.page,
980                items: output.total,
981                itemsOnPage: output.size,
982                cssStyle: 'light-theme',
983                onPageClick: function (pageNumber, event) {
984                    $(".current-page").val(pageNumber);
985                    DocumentHelper.SearchSubmit();
986                }
987            });
988        });
989        Cookies.Create("searchUrl", '/' + languageUI + '/Document/Search?' + formData, 1);
990        DocumentHelper.RefreshFilterPanel();
991        $(".advanced-search").hide("slow");
992        return false;
993    }
994
995    this.FilterInsert = function (items, containerClassName, itemClassName, unSelectedItems) {
996        var unArr = (unSelectedItems != null && unSelectedItems != "") ? unSelectedItems.split(',') : [];
997
998        var isRewrite = $(".isRewriteFilterPanel").val();
999        if (isRewrite == "true") {
1000            $("." + containerClassName).html("");
1001        }
1002        else {
1003            $("." + containerClassName).find("span[class*=-count-]").html("0");
1004        }
1005
1006        $.each(items, function (index, item) {
1007            var $countItem = $("." + containerClassName).find(".check-" + itemClassName + "-count-" + item.code);
1008
1009            if ($countItem.length > 0) {
1010                $countItem.html(item.count);
1011            }
1012            else {
1013                //checked
1014                var _checked = "";
1015                var ischecked = $.grep(unArr, function (row) { return row == item.code; });
1016                if (unArr.length > 0 && ischecked.length > 0)
1017                    _checked = "";
1018                if (item.code == '' && item.nameRu == '') {
1019                    $("." + containerClassName).append('<label><input type="checkbox" value="' + item.code + '" class="i-checks check-' + itemClassName + '" ' + _checked + ' /> Без раздела (<span class="check-' + itemClassName + '-count-' + item.code + '">' + item.count + '</span>)</label><br />');
1020                } else {
1021                    $("." + containerClassName).append('<label><input type="checkbox" value="' + item.code + '" class="i-checks check-' + itemClassName + '" ' + _checked + ' /> ' + item.nameRu + ' (<span class="check-' + itemClassName + '-count-' + item.code + '">' + item.count + '</span>)</label><br />');
1022                }
1023
1024            }
1025        });
1026    }
1027
1028    this.FilterInsertNoClick = function (items, containerClassName, itemClassName, unSelectedItems) {
1029        var unArr = (unSelectedItems != null && unSelectedItems != "") ? unSelectedItems.split(',') : [];
1030
1031        $("." + containerClassName).html('');
1032
1033        var isRewrite = $(".isRewriteFilterPanel").val();
1034        if (isRewrite == "true") {
1035            $("." + containerClassName).html("");
1036        }
1037        else {
1038            $("." + containerClassName).find("span[class*=-count-]").html("0");
1039        }
1040
1041        $.each(items, function (index, item) {
1042            var $countItem = $("." + containerClassName).find(".check-" + itemClassName + "-count-" + item.code);
1043
1044            if ($countItem.length > 0) {
1045                $countItem.html(item.count);
1046            }
1047            else {
1048                //checked
1049                var _checked = "";
1050                var ischecked = $.grep(unArr, function (row) { return row == item.code; });
1051                if (unArr.length > 0 && ischecked.length > 0)
1052                    _checked = "";
1053                $("." + containerClassName).append('<label>' + item.nameRu + ' (<span class="check-' + itemClassName + '-count-' + item.code + '">' + item.count + '</span>)</label><br />');
1054            }
1055        });
1056    }
1057
1058    this.AddFilterParametrValue = function () {
1059        $(".selectedStatuses").val('')
1060        $.each($(".icheckbox_square-green").find(".check-s-status-ext"), function (key, value) {
1061            if (value.parentNode.className.indexOf('checked') >= 0) {
1062                if ($(".selectedStatuses").val() == '') {
1063                    $(".selectedStatuses").val(value.value);
1064                }
1065                else {
1066                    if ($(".selectedStatuses").val().indexOf(value.value) == -1)
1067                        $(".selectedStatuses").val($(".selectedStatuses").val() + ',' + value.value);
1068                }
1069            }
1070        });
1071        $(".selectedRegistered").val('');
1072        $.each($(".icheckbox_square-green").find(".check-reg-ext"), function (key, value) {
1073            if (value.parentNode.className.indexOf('checked') >= 0) {
1074                if ($(".selectedRegistered").val() == '') {
1075                    $(".selectedRegistered").val(value.value);
1076                }
1077                else {
1078                    if ($(".selectedRegistered").val().indexOf(value.value) == -1)
1079                        $(".selectedRegistered").val($(".selectedRegistered").val() + ',' + value.value);
1080                }
1081            }
1082        });
1083
1084        if ($(".search-check-current-region:checked").length > 0) {
1085            $(".search-check-region").val("true");
1086        }
1087        else {
1088            $(".search-check-region").val("false");
1089        }
1090        var search = $(".search-context").val();
1091        return false;
1092    }
1093
1094    this.UpdateSearchInDoc = function (windowNumber) {
1095        var $window = $(".doc-window-" + windowNumber);
1096        var searchText = $window.find('.doc-search-text').val();
1097        if (searchText.trim().length > 0) {
1098            DocumentHelper.SearchInDocumentCount(windowNumber);
1099            DocumentHelper.VisibleDocSearchPanel(windowNumber, true);
1100            $window.find('.need-search').val('true')
1101        }
1102    }
1103
1104    this.CloseSearchInDoc = function (windowNumber) {
1105        var $window = $(".doc-window-" + windowNumber);
1106        $window.find(".doc-search-text").val('');
1107        DocumentHelper.FindElementRight(windowNumber);
1108        DocumentHelper.VisibleDocSearchPanel(windowNumber, false);
1109    }
1110
1111    this.FindElementRight = function (windowNumber) {
1112        var $window = $(".doc-window-" + windowNumber);
1113        var searchString = $window.find(".doc-search-text").val().trim();
1114        if (searchString == "") {
1115            $window.find(".find-text-active").replaceWith(function () { return $(this).contents(); });
1116            $window.find(".find-text").replaceWith(function () { return $(this).contents(); });
1117            $window.find('.find-count').html("0");
1118            $window.find('.find-pos').html("0");
1119            return false;
1120        }
1121        if ($window.find('.need-search').val() != '') {
1122            DocumentHelper.SearchInDocument(windowNumber);
1123        }
1124        $window.find(".find-text").removeClass("find-text-active");
1125        var arr = $window.find('.find-element-coord').val().split(',');
1126        if ($window.find('.find-element-coord').val().trim() == '')
1127            return;
1128        var pos = parseInt($window.find('.find-pos').html()) - 1;
1129        if (arr.length - 2 == pos)
1130            pos = 0;
1131        else
1132            pos++;
1133        $window.find('.find-pos').html(parseInt(pos) + 1);
1134        var $findElement = $window.find(".find-text").eq(pos);
1135        $findElement.addClass("find-text-active");
1136        $("#doc-body-" + windowNumber).scrollTop(arr[pos]);
1137    }
1138
1139    this.FindElementLeft = function (windowNumber) {
1140        var $window = $(".doc-window-" + windowNumber);
1141        var searchString = $window.find(".doc-search-text").val().trim();
1142        if (searchString == "") {
1143            $window.find(".find-text-active").replaceWith(function () { return $(this).contents(); });
1144            $window.find(".find-text").replaceWith(function () { return $(this).contents(); });
1145            $window.find('.find-count').html("0");
1146            $window.find('.find-pos').html("0");
1147            return false;
1148        }
1149        if ($window.find('.need-search').val() != '') {
1150            DocumentHelper.SearchInDocument(windowNumber);
1151        }
1152        $window.find(".find-text").removeClass("find-text-active");
1153        var arr = $window.find('.find-element-coord').val().split(',');
1154        if ($window.find('.find-element-coord').val().trim() == '')
1155            return;
1156        var pos = parseInt($window.find('.find-pos').html()) - 1;
1157        if (pos == 0)
1158            pos = (arr.length - 2);
1159        else pos--;
1160        $window.find('.find-pos').html(parseInt(pos) + 1);
1161        var $findElement = $window.find(".find-text").eq(pos);
1162        $findElement.addClass("find-text-active");
1163        $("#doc-body-" + windowNumber).scrollTop(arr[pos]);
1164    }
1165
1166    this.ClearPage = function (windowNumber) {
1167        var $window = $(".doc-window-" + windowNumber);
1168        $stateHide = $window.find(".is-clear-doc").attr('state');
1169        if ($stateHide == 'false') {
1170            $window.find(".is-clear-doc").attr('state', 'true');
1171            $window.find(".body-comment").hide();
1172            $window.find(".body-bookmark").hide();
1173            $window.find('.link-button').hide();
1174            $window.find('.body-links').hide();
1175            $window.find('.bookmark-buttons').hide();
1176            $window.find(".doc-body").children('a').hide();
1177            $window.find('font[color="#FF0000"]').parent('p').hide();
1178            $window.find('font[color="#800000"]').parent('p').hide();
1179            $window.find('font[color="#FF0000"]').hide();
1180            $window.find('font[color="#800000"]').hide();
1181            toastr["success"]("Режим \"Чистый лист\" включен");
1182        }
1183        else {
1184            $window.find(".is-clear-doc").attr('state', 'false');
1185            $window.find(".body-comment").show();
1186            $window.find(".body-bookmark").show();
1187            $window.find('.link-button').show();
1188            $window.find('.body-links').show();
1189            $window.find('.bookmark-buttons').show();
1190            $window.find(".doc-body").children('a').show();
1191            $window.find('font[color="#FF0000"]').parent('p').show();
1192            $window.find('font[color="#800000"]').parent('p').show();
1193            $window.find('font[color="#FF0000"]').show();
1194            $window.find('font[color="#800000"]').show();
1195            toastr["success"]("Режим \"Чистый лист\" отключен");
1196        }
1197    }
1198
1199    this.HideLeftMenu = function () {
1200        $(".show-left-menu").find("i").addClass("fa-reorder");
1201        $(".show-left-menu").find("i").removeClass("fa-angle-double-right");
1202        var left = parseInt($('.doc-left-menu-container').position().left);
1203        var width = parseInt($('.doc-left-menu-container').css('width'));
1204        var widthH = parseInt($(".doc-left-menu-hint").css('width'));
1205        $(".doc-left-menu-hint").animate({
1206            left: "-=" + parseInt(width + widthH + left) + "px",
1207            opacity: 0,
1208        }, 50);
1209        $(".doc-left-menu-hint").hide();
1210    }
1211
1212    this.ShowLeftMenu = function () {
1213        if ($(".show-left-menu").find("i").hasClass("fa-angle-double-right")) {
1214            DocumentHelper.HideLeftMenu();
1215        } else {
1216            $(".hint-body").hide();
1217            $(".search-panel").hide();
1218            $(".doc-info-cont").hide();
1219            $(".show-left-menu").find("i").removeClass("fa-reorder");
1220            $(".show-left-menu").find("i").addClass("fa-angle-double-right");
1221            $(".doc-left-menu-hint").show();
1222            var left = parseInt($('.doc-left-menu-container').position().left);
1223            var width = parseInt($('.doc-left-menu-container').css('width'));
1224            var widthH = parseInt($(".doc-left-menu-hint").css('width'));
1225            $(".doc-left-menu-hint").animate({
1226                left: "+=" + parseInt(width + widthH + left) + "px",
1227                opacity: 1
1228            }, 700);
1229        }
1230
1231    }
1232
1233    this.PrintFragment = function (windowNumber) {
1234        CommonHelper.ShowLoader();
1235        $window = $(".doc-window-1");
1236        var id = $window.find('.id').val();
1237        var ftext = $("#selectedFullText").val();
1238        $.ajax({
1239            url: "/" + languageUI + "/Document/GetFragmentForPrint/",
1240            method: "GET",
1241            async: true,
1242            data: { documentId: id }
1243        }).done(function (output) {
1244            CommonHelper.HideLoader();
1245            var mywindow = window.open('', 'PRINT', '');
1246            mywindow.document.write(output.replaceAll("<pre></pre>", "<pre>" + ftext + "</pre>"));
1247            mywindow.document.close();
1248            mywindow.focus();
1249            setTimeout(function () {
1250                mywindow.print();
1251                mywindow.close();
1252            }, 200);
1253        });
1254        return false;
1255    }
1256
1257    this.PrintCard = function (windowNumber) {
1258        CommonHelper.ShowLoader();
1259        var id = $("#documentCardId").val();
1260        var ftext = $(".hint-card").html();
1261        $.ajax({
1262            url: "/" + languageUI + "/Document/GetCardForPrint/",
1263            method: "GET",
1264            async: true,
1265            data: { documentId: id }
1266        }).done(function (output) {
1267            CommonHelper.HideLoader();
1268            var mywindow = window.open('', 'PRINT', '');
1269            mywindow.document.write(output.replaceAll("<pre></pre>", "<pre>" + ftext + "</pre>"));
1270            mywindow.document.close();
1271            mywindow.focus();
1272            setTimeout(function () {
1273                mywindow.print();
1274                mywindow.close();
1275            }, 200);
1276        });
1277        return false;
1278    }
1279
1280    this.Print = function (windowNumber) {
1281        CommonHelper.ShowLoader();
1282        $window = $(".doc-window-" + windowNumber);
1283        var id = $window.find('.id').val();
1284        var isLat = $window.find(".isLat").val();
1285        $.ajax({
1286            url: isLat === 'false' ? "/" + languageUI + "/Document/GetBodyForPrint/" : "/" + languageUI + "/Document/GetBodyForPrintLatin/",
1287            method: "GET",
1288            async: true,
1289            data: { documentId: id }
1290        }).done(function (output) {
1291            CommonHelper.HideLoader();
1292            var title = $(".doc-detail-title_").html();
1293            var mywindow = window.open('', '_BLANK', '');
1294            mywindow.document.write(output);
1295            mywindow.document.close();
1296            mywindow.focus();
1297            setTimeout(function () {
1298                mywindow.print();
1299                mywindow.close();
1300            }, 200);
1301        });
1302        return true;
1303    }
1304
1305    this.PrintFavorites = function (id) {
1306        CommonHelper.ShowLoader();
1307        $.ajax({
1308            url: "/" + languageUI + "/Cabinet/FavoritesForPrint/",
1309            method: "GET",
1310            async: true,
1311            data: { id: id }
1312        }).done(function (output) {
1313            CommonHelper.HideLoader();
1314            var mywindow = window.open('', 'PRINT', '');
1315            mywindow.document.write(output);
1316            mywindow.document.close();
1317            mywindow.focus();
1318            setTimeout(function () {
1319                mywindow.print();
1320                mywindow.close();
1321            }, 200);
1322        });
1323        return false;
1324    }
1325
1326    this.PrintUpdates = function () {
1327        var list = $(".doc-print").html();
1328        CommonHelper.ShowLoader();
1329        $.ajax({
1330            url: "/" + languageUI + "/Document/GetListForPrint/",
1331            method: "GET",
1332            async: true
1333        }).done(function (output) {
1334            CommonHelper.HideLoader();
1335            var mywindow = window.open('', 'PRINT', '');
1336            mywindow.document.write(output.replace("<pre></pre>", list));
1337            mywindow.document.close();
1338            mywindow.focus();
1339            setTimeout(function () {
1340                mywindow.print();
1341                mywindow.close();
1342            }, 200);
1343        });
1344        return false;
1345    }
1346
1347    this.ChangeLink = function (string) {
1348        if (!isSubscribed) {
1349            $("#modalTarif").modal();
1350            return false;
1351        }
1352        if (string.indexOf(".htm") > 0)
1353            return false;
1354        var link = string.split('#');
1355        var ngr = link[0];
1356        var lang = $("#bodyLang1").val();
1357        if (ngr == $('#bodyNgr1').val()) {
1358            DocumentHelper.ToParagraphScroll_(1, link[1]);
1359            DocumentHelper.ToBookMarkSrcoll(1, link[1]);
1360            return false;
1361        }
1362        $("#modalLinkNgr").val(ngr);
1363        $("#modalLinkLang").val(lang);
1364        if (link.length > 1)
1365            $("#modalLinkParagraph").val(link[1]);
1366        if (ngr == $('#bodyNgr2').val()) {
1367            DocumentHelper.OpenLinkOnNearWindow();
1368            return false;
1369        }
1370        $.ajax({
1371            url: "/" + languageUI + "/Document/GetTitle?ngr=" + ngr + "&langId=" + lang
1372        }).done(function (output) {
1373            $("#modalLinkId").val(output.id);
1374            $("#modalLinkTitle").html(output.title);
1375            $("#modalLinkDateEdition").val(output.dateEditionStr);
1376        });
1377        $('#modalLink').modal('toggle');
1378    }
1379
1380    this.DownloadPdf = function (windowNumber) {
1381        $window = $(".doc-window-" + windowNumber);
1382        var id = $window.find(".id").val();
1383        var isLat = $window.find(".isLat").val();
1384        if (isLat === 'false') {
1385            window.location.href = '/' + languageUI + '/Document/DownloadPdf?documentId=' + id;
1386        } else {
1387            window.location.href = '/' + languageUI + '/Document/DownloadPdfLatin?documentId=' + id;
1388        }
1389    }
1390
1391    this.SendEmail = function (windowNumber, isauthorized) {
1392        $window = $(".doc-window-" + windowNumber);
1393        var id = $window.find(".id").val();
1394        $('.sendDocId').val(id);
1395        if (isauthorized) {
1396            $.ajax({
1397                dataType: "json",
1398                url: '/' + languageUI + '/Cabinet/GetEmail',
1399                success: function (data) {
1400                    $('.email').val(data);
1401                }
1402            });
1403        }
1404    }
1405
1406    this.RewriteEmail = function () {
1407        $('.email').prop('readonly', false);
1408    }
1409
1410    this.DownloadWord = function (windowNumber) {
1411        $window = $(".doc-window-" + windowNumber);
1412        var id = $window.find(".id").val();
1413        var isLat = $window.find(".isLat").val();
1414        if (isLat === 'false') {
1415            window.location.href = '/' + languageUI + '/Document/DownloadWord?documentId=' + id;
1416        } else {
1417            window.location.href = '/' + languageUI + '/Document/DownloadWordLatin?documentId=' + id;
1418        }
1419    }
1420
1421    this.ExportFragmentToPdf = function () {
1422        var $form = $(".export-fragment-pdf");
1423        $form.find(".fragmentDocId").val($(".doc-window-1 .id").val());
1424        $form.find(".text").val($("#selectedFullText").val());
1425        $form.submit();
1426    }
1427
1428    this.ExportFragmentToWord = function () {
1429        var $form = $(".export-fragment-word");
1430        $form.find(".fragmentDocId").val($(".doc-window-1 .id").val());
1431        $form.find(".text").val($("#selectedFullText").val());
1432        $form.submit();
1433    }
1434
1435    this.ToParagraphScroll = function (windowNumber) {
1436        $window = $(".doc-window-" + windowNumber);
1437        var paragraph = $window.find(".doc-paragraph-number").val();
1438        DocumentHelper.ToParagraphScroll_(windowNumber, paragraph);
1439        DocumentHelper.ToBookMarkSrcoll(windowNumber, paragraph);
1440    }
1441
1442    this.ToBookMarkSrcoll = function (windowNumber, bookmark) {
1443        var $window = $(".doc-window-" + windowNumber);
1444        if (bookmark != '') {
1445            var $mark = $window.find('a[name="' + bookmark + '"]');
1446            if ($mark.length > 0) {
1447                $window.find('.doc-body').animate({
1448                    scrollTop: $('.doc-body').scrollTop() + $mark.offset().top - $('.doc-body').offset().top - 100
1449                }, 400);
1450                //tag structure: p>>font>>b>>a or p>>a
1451                var $p;
1452                if ($mark.parent().get(0).tagName == "P")
1453                    $p = $mark.parent();
1454                else {
1455                    //b
1456                    var $item = $mark.parent();
1457                    //font
1458                    if ($item.get(0).tagName != "P") {
1459                        $item = $item.parent();
1460                    }
1461                    //p
1462                    if ($item.get(0).tagName != "P") {
1463                        $item = $item.parent();
1464                    }
1465                    $p = $item;
1466                }
1467                if ($p.length > 0) {
1468                    $p.css({
1469                        'background-color': '#5C6F7C',
1470                        'color': 'black'
1471                    });
1472                    //todo: hide timeout
1473                    $p.animate({
1474                        'background-color': 'white',
1475                        'color': 'black'
1476                    }, 7000);
1477                }
1478            }
1479        }
1480    }
1481
1482    this.ToParagraphScroll_ = function (windowNumber, paragraph) {
1483        var $window = $(".doc-window-" + windowNumber);
1484        if (paragraph != '') {
1485            var $paragraph = $("#" + windowNumber + 'paragraph' + paragraph);
1486            if ($paragraph.length == 0) {
1487                $paragraph = $window.find('[name="' + paragraph + '"]');
1488            }
1489            if ($paragraph.length > 0) {
1490                $window.find('.doc-body').animate({
1491                    scrollTop: $('.doc-body').scrollTop() + $paragraph.offset().top - $('.doc-body').offset().top - 500
1492                }, 400);
1493                var $p = $paragraph.parents('font').length > 0 ? $paragraph.parent().parent().next() : $paragraph.next();
1494                if ($p.length > 0) {
1495                    $p.css({
1496                        'background-color': '#5C6F7C',
1497                        'color': 'black'
1498                    });
1499                    //todo: hide timeout
1500                    $p.animate({
1501                        'background-color': 'white',
1502                        'color': 'black'
1503                    }, 7000);
1504                }
1505            }
1506        }
1507    }
1508
1509    this.OpenLinkOnNewWindow = function () {
1510        var ngr = $(".modal-link-ngr").val();
1511        var lang = $(".modal-link-lang").val();
1512        var paragraph = $(".modal-link-paragraph").val();
1513        window.open("/" + languageUI + "/Document/Detail?ngr=" + ngr + "&langId=" + lang + "&paragraphNumber=" + paragraph);
1514    }
1515
1516    this.VisibilityTabTitle = function (show) {
1517        if (show === true)
1518            $(".tab-title").show();
1519        else
1520            $(".tab-title").hide();
1521    }
1522
1523    this.StretchToggle = function (windowNumber) {
1524        var $window = $(".doc-window-" + windowNumber);
1525        var $tabTitle = $window.find(".tab-title");
1526        var $icon = $tabTitle.find(".fa");
1527
1528        if ($icon.hasClass("fa-caret-down")) {
1529            $tabTitle.css('height', 'auto');
1530            $icon.removeClass("fa-caret-down");
1531            $icon.addClass("fa-caret-up");
1532        } else {
1533            $tabTitle.css('height', '25px');
1534            $icon.removeClass("fa-caret-up");
1535            $icon.addClass("fa-caret-down");
1536        }
1537    }
1538
1539    this.OpenLinkOnNearWindow = function () {
1540        DocumentHelper.TextWidth(true);
1541        DocumentHelper.VisibilityTabTitle(true);
1542        var $window = $(".doc-window-2");
1543        var id = $("#modalLinkId").val();
1544        var ngr = $("#modalLinkNgr").val();
1545        var lang = $("#modalLinkLang").val();
1546        var paragraph = $("#modalLinkParagraph").val();
1547        var dateEdition = $('#modalLinkDateEdition').val();
1548
1549        $("#bodyId2").val(id);
1550        $("#bodyNgr2").val(ngr);
1551        $("#bodyLang2").val(lang);
1552        $("#bodyDocParagraphNumber2").val(paragraph);
1553        $("#bodyDateEdition2").val(dateEdition);
1554        DocumentHelper.InitSelectEditions(2);
1555        $(".doc-window").addClass("doc-window-half");
1556        $window.show();
1557        $('#modalLink').modal('hide');
1558
1559        //TODO: показать скрол
1560        DocumentHelper.HideScrollLock(false);
1561        DocumentHelper.SyncScroll(false);
1562    }
1563
1564    this.ChangeEditionDate = function (windowNumber,isSelected) {
1565
1566        CommonHelper.ShowLoader();
1567        var $window = $(".doc-window-" + windowNumber);
1568        var date = $window.find(".select-editions").val();
1569
1570        if (isSelected) {
1571            var sdate = $('#SelectEditionLeft').val();
1572            if (windowNumber == 1) {
1573                var list = JSON.parse(localStorage.getItem("doc-version"));
1574                let findIndex = -1;
1575                let flag = false;
1576                
1577                var textEdit = "Редакция от ";
1578                if (languageUI == "kk")
1579                    textEdit = "Басылым ";
1580                else if (languageUI == "en")
1581                    textEdit = "Edition ";
1582
1583                $('#SelectEditionRight').empty();
1584                $.each(list, function (key, value) {
1585                    if (value.dateEditionStr === sdate) {
1586                        findIndex = key;
1587                    }
1588
1589                    if (findIndex > -1 && findIndex < key) {
1590
1591                        if (!flag) {
1592                            $('#SelectEditionRight').append('<option value="' + value.dateEditionStr + '" selected>' + textEdit + value.dateEditionStr2 + '</option>');
1593                            flag = true;
1594                        }
1595                        else {
1596                            $('#SelectEditionRight').append('<option value="' + value.dateEditionStr + '">' + textEdit + value.dateEditionStr2 + '</option>');
1597                        }
1598                    }
1599                });
1600            }
1601        }
1602        
1603        if (date == "Выберите редакцию" || date == "Басылымды таңдаңыз" || date == "Compare redactions") {
1604            CommonHelper.HideLoader();
1605            return false;
1606        }
1607        $window.find('.date-edition').val(date);
1608        DocumentHelper.InitSelectLangauges(windowNumber, true);
1609        CommonHelper.HideLoader();
1610
1611    }
1612
1613    this.ChangeLanguage = function (windowNumber, withButtons) {
1614        var $window = $(".doc-window-" + windowNumber);
1615        var $select = $window.find(".select-languages");
1616        var $selectedOption = $window.find(".select-languages option:selected");
1617        var lang_ = $select.val();
1618        $window.find('.id').val($selectedOption.attr('docId'));
1619        $window_.find(".tab-title-content").html($selectedOption.attr('title'));
1620        if (windowNumber == 2 && lang_ == null) {
1621            var lang1 = $(".doc-window-1").find('.lang').val();
1622            $window.find(".lang").val(lang1);
1623        }
1624        else {
1625            $window.find(".lang").val(lang_);
1626        }
1627
1628        if (windowNumber == 1 && $("#isCompare").val() == 'false' && $('#isTranslate').val() == 'false') {
1629            $(".doc-window-2").find(".lang").val(lang_);
1630        }
1631        var id = $window.find(".id").val();
1632        DocumentHelper.GetBody(windowNumber, id, true);
1633    }
1634
1635    this.SpellClick = function (str) {
1636        $(".search-text").val(str);
1637        DocumentHelper.SearchSubmit();
1638        return false;
1639    }
1640
1641    this.InitSelectLangauges = function (windowNumber, withButtons) {
1642        var $window = $(".doc-window-" + windowNumber);
1643        if ($window.find('.select-languages').length > 0) {
1644            var dateEdition = $window.find('.date-edition').val();
1645            var ngr = $window.find('.ngr').val();
1646            var lang = $window.find('.lang').val();
1647            $window.find('.select-languages').html('');
1648            $.ajax({
1649                url: "/" + languageUI + "/document/GetByDateEdition",
1650                method: "GET",
1651                async: true,
1652                data: { ngr: ngr, dateEdition: dateEdition, windowNumber: windowNumber }
1653            }).done(function (languages) {
1654                var languages_ = languages.objects;
1655                $window_ = $(".doc-window-" + languages.windowNumber);
1656                $.each(languages_, function (key, value) {
1657                    var language = value.language;
1658                    $window_.find('.select-languages').append('<option docId="' + value.id + '" title="' + value.title + '" value="' + language.idInt + '">' + language.nameRu + '</option>')
1659                });
1660                $window_.find('.select-languages').val($window_.find(".lang").val());
1661                DocumentHelper.ChangeLanguage(windowNumber, true)
1662            });
1663        }
1664    }
1665
1666    this.InitSelectEditions = function (windowNumber) {
1667        var $window = $(".doc-window-" + windowNumber);
1668        if ($window.find('.select-editions').length > 0) {
1669            //TODO: 
1670            var lang = $window.find('.lang').val();
1671            var ngr = $window.find('.ngr').val();
1672            $('#bodySelectEditions' + windowNumber).html('');
1673            var textEdit = "Редакция от ";
1674            if (languageUI == "kk")
1675                textEdit = "Басылым ";
1676            else if (languageUI == "en")
1677                textEdit = "Edition ";
1678            $.ajax({
1679                url: "/" + languageUI + "/document/GetByLanguage",
1680                method: "GET",
1681                async: false,
1682                data: { ngr: ngr, langId: lang, windowNumber: windowNumber }
1683            }).done(function (editions) {
1684                var $window = $(".doc-window-" + editions.windowNumber);
1685                var editions_ = editions.objects;
1686                var lastEdition;
1687                $.each(editions_, function (key, value) {
1688                    if (key == editions_.length - 1)
1689                        lastEdition = value.dateEditionStr;
1690                    $('#bodySelectEditions' + editions.windowNumber).append('<option value="' + value.dateEditionStr + '">' + textEdit + value.dateEditionStr2 + '</option>')
1691                });
1692
1693                if ($("#isCompare").val() == "true") {
1694                    if ($window.find(".select-editions > option").length > 1) {
1695                        $window.find(".select-editions > option").eq($window.find(".select-editions > option").length - 2).prop("selected", true);
1696                    }
1697
1698                } else {
1699                    var dateEdition = $("#bodyDateEdition" + editions.windowNumber).val();
1700                    if (dateEdition == '')
1701                        dateEdition = lastEdition;
1702                    $('#bodySelectEditions' + editions.windowNumber).val(dateEdition);
1703                }
1704                DocumentHelper.ChangeEditionDate(editions.windowNumber);
1705            });
1706
1707        }
1708    }
1709
1710    this.CloseWindow2 = function () {
1711        DocumentHelper.VisibilityTabTitle(false);
1712        $docWindow1 = $(".doc-window-1");
1713        $docWindow2 = $(".doc-window-2");
1714        $('.compare-div').addClass("hide");
1715
1716        if ($("#isCompare").val() == "true") {
1717            $(".doc-window").removeClass("doc-window-half");
1718            $docWindow2.hide();
1719            $("#isCompare").val(false);
1720
1721            //TODO: показать скрол
1722            DocumentHelper.HideScrollLock(false);
1723            DocumentHelper.SyncScroll(false);
1724            DocumentHelper.LockEditationLanguage(false);
1725            DocumentHelper.TextWidth(false);
1726
1727            var id = $window.find(".id").val();
1728            DocumentHelper.GetBody(1, id, false);
1729            return false;
1730        }
1731
1732        $(".doc-window").removeClass("doc-window-half");
1733        $docWindow2.hide();
1734        $("#isTranslate").val(false);
1735
1736        $docWindow2.find(".id").val($docWindow1.find(".id").val());
1737        $docWindow2.find(".ngr").val($docWindow1.find(".ngr").val());
1738        $docWindow2.find(".lang").val($docWindow1.find(".lang").val());
1739
1740        //TODO:compare text
1741        $('.showChangedDef').addClass('hide');
1742        $('#diffCount').text('0');
1743        $('#indexDiff').text('0');
1744
1745        //TODO: показать скрол
1746        DocumentHelper.HideScrollLock(false);
1747        DocumentHelper.SyncScroll(false);
1748        DocumentHelper.TextWidth(false);
1749        return false;
1750    }
1751
1752    String.prototype.replaceAll = function (str1, str2, ignore) {
1753        return this.replace(new RegExp(str1.replace(/([\/\,\!\\\^\$\{\}\[\]\(\)\.\*\+\?\|\<\>\-\&])/g, "\\$&"), (ignore ? "gi" : "g")), (typeof (str2) == "string") ? str2.replace(/\$/g, "$$$$") : str2);
1754    }
1755
1756    this.SetLinkCounts = function (windowNumber, ngr, lang) {
1757        $.ajax({
1758            url: "/" + languageUI + "/Document/InputLinksGroup/",
1759            method: "GET",
1760            async: true,
1761            data: { langId: lang, ngr: ngr }
1762        }).done(function (output) {
1763            if (output == null || output == "") {
1764                return;
1765            }
1766            $.each(output, function (key, value) {
1767                var $window = $(".doc-window-" + windowNumber);
1768                var $p = $window.find("a[name='" + value.paragraph + "']").closest('.paragraph');
1769                var html = $(".link-counts-sample").html();
1770                $(html).insertAfter($p);
1771                $p.next().attr('onclick', "DocumentHelper.ShowLinksByParagraph(" + windowNumber + ",'" + ngr + "', '" + lang + "','" + value.paragraph + "')");
1772                $p.next().find('.link-count').html(value.count);
1773            });
1774        });
1775    }
1776
1777    this.SetCommentsToBody = function (windowNumber, documentId, isBookmark) {
1778        $.ajax({
1779            url: "/" + languageUI + "/Document/CommentsJson",
1780            data: { documentId: documentId, isBookmark: isBookmark }
1781        }).done(function (comments) {
1782            $.each(comments, function (key, value) {
1783                var $window = $(".doc-window-" + windowNumber);
1784                var commentClass = isBookmark === false ? 'bookmark' : 'comment';
1785                var $p = $window.find("a[name='" + value.paragraphNumber + "']").parent();
1786                $p.append('<div class="body-' + commentClass + ' comment-' + value.id + '"><div class="remove-comment" onclick="DocumentHelper.RemoveComment(\'' + windowNumber + '\', \'' + value.id + '\')"><i class="fa fa-remove"></i></div>' + value.comment + '</div>');
1787            });
1788        });
1789    }
1790
1791    this.RemoveComment = function (windowNumber, commentId) {
1792        $.ajax({
1793            url: "/" + languageUI + "/Document/RemoveCommentJson",
1794            data: { commentId: commentId }
1795        }).done(function (success) {
1796            if (success) {
1797                var $window = $(".doc-window-" + windowNumber);
1798                var commentClass = '.comment-' + commentId;
1799                $window.find(commentClass).remove();
1800                toastr["success"]("Комментарий успешно удален. ");
1801                window.location.reload();
1802            }
1803            else {
1804                toastr["error"]("Не получилось удалить коментарий. Попробуйте позднее.");
1805            }
1806        });
1807    }
1808
1809    this.ShowLinksByParagraph = function (windowNumber, ngr, lang, paragraph) {
1810        var $window = $(".doc-window-" + windowNumber);
1811        var $p = $window.find("a[name='" + paragraph + "']").parent();
1812        if ($p.find('.body-links').length > 0) {
1813            $p.find('.body-links').remove();
1814            return false;
1815        }
1816        $.ajax({
1817            url: "/" + languageUI + "/Document/GetLinksByParagraph",
1818            data: { ngr: ngr, langId: lang, paragraph: paragraph }
1819        }).done(function (links) {
1820            var $window = $(".doc-window-" + windowNumber);
1821            var message = "Ссылки на абзац";
1822            if (languageUI == "kk")
1823                message = "Абзацқа сілтеме";
1824            else if (languageUI == "en")
1825                message = "Link to paragraph";
1826            var html = '<div class="body-links url-tooltip" onclick="return DocumentHelper.HideLinksParagraph(' + windowNumber + ',' + paragraph + ')"><div class="body-links-title" onclick="return DocumentHelper.HideLinksParagraph(' + windowNumber + ',' + paragraph + ')">' + message + '</div>';
1827            var $p = $window.find("a[name='" + paragraph + "']").parent();
1828            $.each(links, function (key, value) {
1829                html += '<a onclick="return DocumentHelper.ChangeLink(\'' + value.document.ngr + '#' + value.paragraph + '\')" href="/' + languageUI + '/Document/Detail/?ngr=' + value.document.ngr + '&langId=' + value.document.language.idInt + '&paragraphNumber=' + value.paragraph + '">' + (key + 1) + '. ' + value.document.title + ' (абзац ' + value.paragraph + ')</a><hr style="margin-top:5px;margin-bottom:5px;">';
1830            });
1831            $p.append(html + '</div>');
1832        });
1833    }
1834
1835    this.HideLinksParagraph = function (windowNumber, paragraph) {
1836        var $window = $(".doc-window-" + windowNumber);
1837        var $p = $window.find("a[name='" + paragraph + "']").parent();
1838        if ($p.find('.body-links').length > 0) {
1839            $p.find('.body-links').remove();
1840            return false;
1841        }
1842    }
1843
1844    this.AutoHeight = function () {
1845        var windowH = $(window).height();
1846        $(".doc-body").css('height', (windowH - 190) + 'px');
1847        $(".doc-body").css('min-height', (windowH - 190) + 'px');
1848        $("#page-wrapper").css('min-height', '200px');
1849    }
1850
1851    this.GetBody = function (windowNumber, id, withButtons) {
1852        var data = { id: id };
1853        CommonHelper.ShowLoader();
1854        $.ajax({
1855            url: "/" + languageUI + "/Document/GetBodyById",
1856            method: "GET",
1857            async: true,
1858            data: data
1859        }).done(function (result) {
1860            DocumentHelper.Status23(windowNumber, result.status.idInt);
1861            if (windowNumber == 1) {
1862                $('#docDetailTitle').html(result.title);
1863                $('#docInfo').html(result.info);
1864                $('#docDateEdition').html(result.dateEditionStr2);
1865                $('#docStatusName').html(result.status.name);
1866                $('#docCommentsCount').html(result.commentsCount);
1867                $('#docClicksCount').html(result.clicksCount);
1868                $('#docPrintDepartment').html(result.printDepartment);
1869                if (result.isArchive == false) {
1870                    if ($(".doc-is-archive").hasClass("hide") == false) {
1871                        $(".doc-is-archive").addClass("hide");
1872                    }
1873                }
1874                else {
1875                    $(".doc-is-archive").removeClass("hide");
1876                }
1877            }
1878            var output = result.body;
1879            var $window = $(".doc-window-" + windowNumber);
1880            var $docBody = $window.find(".doc-body");
1881            var isSetFormatting = 1;
1882            var doclenght = output.length;
1883            if (doclenght > 450000) {
1884                isSetFormatting = 0;
1885            }
1886            $docBody.html("");
1887            $docBody.html(output);
1888            if (result.isCanView == false) {
1889                $docBody.addClass("doctype-not-free-ru");
1890                $window.find('.price').html(result.priceString);
1891                $window.find('.doc-payment-line').show();
1892                $window.find('.doc-payment-line .btn-purchase').attr('onclick', "window.location='/" + languageUI + "/Cabinet/Purchase?documentId=" + result.id + "'");
1893            }
1894            else {
1895                $docBody.removeClass("doctype-not-free-ru");
1896                $window.find('.doc-payment-line').hide();
1897            }
1898            $window.find(".id").val(result.id);
1899            $window.find(".ngr").val(result.ngr);
1900            $window.find(".lang").val(result.language.idInt);
1901            $window.find('.tab-title-content').html(result.title);
1902            $window.find(".dateEdition").val(result.dateEdition);
1903            DocumentHelper.AutoHeight();
1904            CommonHelper.HideLoader();
1905            setTimeout(function () {
1906                if ($("#isCompare").val() == "false" && isSetFormatting == 1) {
1907                    DocumentHelper.FormattingParagraphs(windowNumber, withButtons, result);
1908                }
1909                if ($("#isTranslate").val() == "false" && $("#isCompare").val() == "false") {
1910                    DocumentHelper.ToParagraphScroll(windowNumber);
1911                }
1912                DocumentHelper.UpdateSearchInDoc(windowNumber);
1913            }, 1000);
1914
1915            if (result.language.idInt != 3) {
1916                $window.find(".button-icon-latin").addClass("hide");
1917                $(".doc-voice").removeClass("hide");
1918            }
1919            else {
1920                $window.find(".button-icon-latin").removeClass("hide");
1921                $(".doc-voice").addClass("hide");
1922            }
1923        });
1924    }
1925
1926    this.FormattingParagraphs = function (windowNumber, withButtons, docInfo) {
1927        var $window = $(".doc-window-" + windowNumber);
1928        var $docBody = $window.find(".doc-body");
1929        if (withButtons) {
1930            $docBody.find("p").each(function (index) {
1931                $(this).find("a").each(function (indexA) {
1932                    if ($(this).attr('name') != null) {
1933                        var bookmark = $(".bookmark-sample").html();
1934                        var attr = $(this).attr('name');
1935                        bookmark = bookmark.replaceAll('paragraph-number=""', 'paragraph-number="' + attr + '"');
1936                        var nofirst = (indexA > 0 ? 'notfirst' : '');
1937                        //console.log(indexA);
1938                        var div = "<div class='bookmark-buttons' " + nofirst + " id='" + windowNumber + "paragraph" + attr + "' paragraph=' " + attr + "'>" + bookmark + "</div><div class='paragraph'>";
1939                        div = (indexA > 0 ? '</div>' : '') + div;
1940                        $(div).insertBefore($(this));
1941                    }
1942                });
1943                var html = $(this).html();
1944                html = html.replaceAll('<div class="paragraph"></div>', '<div class="paragraph">').replaceAll('<div class="bookmark-buttons" notfirst=""', '</div><div class="bookmark-buttons" ') + '</div>';
1945                $(this).html(html);
1946            });
1947            $(".paragraph").parent().css('margin-left', '0px');
1948            $(".paragraph").parent().css('margin-right', '0px');
1949            $("font").css('margin-left', "20px;").css('overflow', 'hidden ');
1950
1951            DocumentHelper.SetLinkCounts(windowNumber, docInfo.ngr, docInfo.language.idInt);
1952            var documentId = $window.find('.id').val();
1953            DocumentHelper.SetCommentsToBody(windowNumber, documentId, true);
1954            DocumentHelper.SetCommentsToBody(windowNumber, documentId, false);
1955        }
1956    }
1957
1958    this.TelegramAdd = function () {
1959        $(".telegram-form").show();
1960        $(".phone-number").inputmask({ "mask": "9(999)999 9999" });
1961        return false;
1962    }
1963
1964    this.DocInfoToggle = function () {
1965        $(".doc-info-cont").slideToggle();
1966        DocumentHelper.LeftMenuHintEnabled();
1967    }
1968
1969    this.KeyPress = function (e) {
1970        var keycode;
1971        if (window.event)
1972            keycode = window.event.keyCode;
1973        else if (e)
1974            keycode = e.which;
1975
1976        // Mozilla firefox
1977        //ctrl+F
1978        //if (e.ctrlKey && keycode == 70) {
1979        //    DocumentHelper.VisibleDocSearchPanel("1", true);
1980        //    if (e.preventDefault) {
1981        //        e.preventDefault();
1982        //        e.stopPropagation();
1983        //    }
1984        //}
1985        //ctrl+Left
1986        if (e.ctrlKey && keycode == 37) {
1987            DocumentHelper.FindElementLeft(1);
1988            if (e.preventDefault) {
1989                e.preventDefault();
1990                e.stopPropagation();
1991            }
1992        }
1993        //ctrl+right
1994        if (e.ctrlKey && keycode == 39) {
1995            DocumentHelper.FindElementRight(1);
1996            if (e.preventDefault) {
1997                e.preventDefault();
1998                e.stopPropagation();
1999            }
2000        }
2001        //alt+Left
2002        if (e.altKey && keycode == 37) {
2003            DocumentHelper.FindElementLeft(2);
2004            if (e.preventDefault) {
2005                e.preventDefault();
2006                e.stopPropagation();
2007            }
2008        }
2009        //alt+right
2010        if (e.altKey && keycode == 39) {
2011            DocumentHelper.FindElementRight(2);
2012            if (e.preventDefault) {
2013                e.preventDefault();
2014                e.stopPropagation();
2015            }
2016        }
2017        //ctrl+M
2018        if (e.ctrlKey && keycode == 77) {
2019            DocumentHelper.ShowLeftMenu();
2020            if (e.preventDefault) {
2021                e.preventDefault();
2022                e.stopPropagation();
2023            }
2024        }
2025        //ctrl+K
2026        if (e.ctrlKey && keycode == 75) {
2027            DocumentHelper.Card();
2028            if (e.preventDefault) {
2029                e.preventDefault();
2030                e.stopPropagation();
2031            }
2032        }
2033        //ctrl+I
2034        if (e.ctrlKey && keycode == 73) {
2035            DocumentHelper.Map();
2036            if (e.preventDefault) {
2037                e.preventDefault();
2038                e.stopPropagation();
2039            }
2040        }
2041        //ctrl+L
2042        if (e.ctrlKey && keycode == 76) {
2043            DocumentHelper.Links();
2044            if (e.preventDefault) {
2045                e.preventDefault();
2046                e.stopPropagation();
2047            }
2048        }
2049        //ctrl+Y
2050        if (e.ctrlKey && keycode == 89) {
2051            DocumentHelper.MyComments();
2052            if (e.preventDefault) {
2053                e.preventDefault();
2054                e.stopPropagation();
2055            }
2056        }
2057        //ctrl+T
2058        if (e.ctrlKey && keycode == 84) {
2059            DocumentHelper.HideComments();
2060            if (e.preventDefault) {
2061                e.preventDefault();
2062                e.stopPropagation();
2063            }
2064        }
2065
2066        //ctrl+R
2067        if (e.ctrlKey && keycode == 82) {
2068            DocumentHelper.HideCommentsRcpi();
2069            if (e.preventDefault) {
2070                e.preventDefault();
2071                e.stopPropagation();
2072            }
2073        }
2074        //ctrl+U
2075        if (e.ctrlKey && keycode == 85) {
2076            DocumentHelper.MyBookmarks();
2077            if (e.preventDefault) {
2078                e.preventDefault();
2079                e.stopPropagation();
2080            }
2081        }
2082        //ctrl+B
2083        if (e.ctrlKey && keycode == 66) {
2084            DocumentHelper.Favotire();
2085            if (e.preventDefault) {
2086                e.preventDefault();
2087                e.stopPropagation();
2088            }
2089        }
2090
2091        //Ctrl+H
2092        if (e.ctrlKey && keycode == 72) {
2093            DocumentHelper.History();
2094            if (e.preventDefault) {
2095                e.preventDefault();
2096                e.stopPropagation();
2097            }
2098        }
2099
2100        //Ctrl+G
2101        if (e.ctrlKey && keycode == 71) {
2102            DocumentHelper.Audio();
2103            if (e.preventDefault) {
2104                e.preventDefault();
2105                e.stopPropagation();
2106            }
2107        }
2108
2109        //Alt+T
2110        if (e.altKey && keycode == 84) {
2111            DocumentHelper.Translate();
2112            if (e.preventDefault) {
2113                e.preventDefault();
2114                e.stopPropagation();
2115            }
2116        }
2117        //Alt+G
2118        if (e.altKey && keycode == 71) {
2119            DocumentHelper.GoogleTranslate();
2120            if (e.preventDefault) {
2121                e.preventDefault();
2122                e.stopPropagation();
2123            }
2124        }
2125    }
2126
2127    this.OpenAttDocument = function (href) {
2128        var id = $(".document-id").val();
2129        $.ajax({
2130            url: "/" + languageUI + "/Document/GetAttBody",
2131            data: { id: id, href: href }
2132        }).done(function (output) {
2133            DocumentHelper.ScrollLockClick();
2134            var $window = $(".doc-window-2");
2135            $window.find(".doc-body").html(output);
2136            $window.show();
2137            $(".doc-window ").addClass("doc-window-half");
2138            DocumentHelper.TextWidth(true);
2139        });
2140    }
2141
2142    this.SearchToggle = function () {
2143        $(".search-panel").slideToggle();
2144
2145    }
2146
2147    this.ShowBookmarkButtons = function ($object, isShow, isParagraph) {
2148        if (isShow) {
2149            $(".bookmark").hide();
2150            if (isParagraph)
2151                $object.prev().find(".bookmark").show();
2152            else
2153                $object.find(".bookmark").show();
2154        }
2155        else {
2156            if (isParagraph)
2157                $object.prev().find(".bookmark").hide();
2158            else
2159                $object.find(".bookmark").hide();
2160        }
2161    }
2162
2163    this.Init2Windows = function (isShow) {
2164
2165    }
2166
2167    this.TextWidth = function (isFullWidth) {
2168        var $div = $(".doc-detail");
2169        var textWidth = isFullWidth == true ? "80" : isFullWidth == false ? "100" : $("#textWidth").val();
2170        if (textWidth == "100") {
2171            $div.addClass('default-doc');
2172            $("#textWidth").val('80');
2173        }
2174        else {
2175            $div.removeClass('default-doc');
2176            $("#textWidth").val('100');
2177        }
2178    }
2179
2180    this.FullScreen = function (windowNumber) {
2181        var isFullScreen = ($("#isFullScreen").val() == 'true');
2182        if (!isFullScreen) {
2183            $(".doc-body-container").addClass("full-screen");
2184            $(".search-panel").hide();
2185            $(".navbar").hide();
2186            $(".doc-left-menu").hide();
2187            $(".comment-add").hide();
2188            $(".footer").hide();
2189            DocumentHelper.TextWidth(true);
2190            $("#page-wrapper").addClass("full-wrapper");
2191            toastr["success"]("Режим полного экрана включился");
2192        }
2193        else {
2194            $(".doc-body-container").removeClass("full-screen");
2195            $(".search-panel").show();
2196            $(".navbar").show();
2197            $(".doc-left-menu").show();
2198            $(".comment-add").show();
2199            $(".footer").show();
2200            DocumentHelper.TextWidth(false);
2201            $("#page-wrapper").removeClass("full-wrapper");
2202            toastr["success"]("Режим полного экрана отключился");
2203        }
2204        $("#isFullScreen").val(!isFullScreen);
2205    }
2206
2207    this.ShowHintBody = function (newFlag) {
2208        DocumentHelper.HideLeftMenu();
2209        var currentFlag = $("#flag").val();
2210        var displayState = $(".hint-body").css('display');
2211        $("#flag").val(newFlag);
2212        if (currentFlag != newFlag) {
2213            $(".search-panel").hide();
2214            $(".doc-info-cont").hide();
2215            $(".hint-body").show();
2216        }
2217        if (currentFlag == newFlag) {
2218            $(".hint-body").hide();
2219            $("#flag").val('');
2220        }
2221    }
2222
2223    this.Map = function () {
2224        var $window = $(".doc-window-1");
2225        $hint = $(".hint-body");
2226        var id = $(".document-id").val();
2227        $.ajax({
2228            url: "/" + languageUI + "/document/map/?id=" + id,
2229            type: "GET"
2230        }).done(function (output) {
2231            $(".hint-body").html(output);
2232            $(".hint-body").find("a").each(function () {
2233                var href = $(this).attr('href');
2234                if (href) {
2235                    $(this).removeAttr('href');
2236                    var paragraph = href.split("#");
2237                    $(this).attr('onclick', 'DocumentHelper.ToParagraphScroll_(1,' + paragraph[1] + ')');
2238                    $(this).attr('onclick', 'DocumentHelper.ToBookMarkSrcoll(1,' + paragraph[1] + ')');
2239                }
2240            });
2241            DocumentHelper.ShowHintBody('map');
2242        });
2243    }
2244
2245    this.History = function () {
2246        CommonHelper.ShowLoader();
2247        var $window = $(".doc-window-1");
2248        var lang = $window.find('.lang').val();
2249        var ngr = $window.find('.ngr').val();
2250        $hint = $(".hint-body");
2251        $.ajax({
2252            url: "/" + languageUI + "/document/history/" + lang + "/" + ngr,
2253            type: "GET"
2254        }).done(function (output) {
2255            $(".hint-body").html(output);
2256            DocumentHelper.ShowHintBody('history');
2257            CommonHelper.HideLoader();
2258        });
2259    }
2260
2261    this.Card = function () {
2262        CommonHelper.HideLoader();
2263        var $window = $(".doc-window-1");
2264        var lang = $window.find('.lang').val();
2265        var ngr = $window.find('.ngr').val();
2266        var dateEdition = $window.find('.date-edition').val();
2267        $hint = $(".hint-body");
2268        $.post("/" + languageUI + "/document/card/", {
2269            langId: lang, ngr: ngr, dateEdition: dateEdition
2270        }, function (output) {
2271            $(".hint-body").html(output);
2272            DocumentHelper.ShowHintBody('card');
2273            CommonHelper.HideLoader();
2274        });
2275    }
2276
2277    this.MyComments = function (ngr, lang, dateEdition) {
2278        if (!authorized) {
2279            $("#modalLogin").modal();
2280            return false;
2281        }
2282        var $window = $(".doc-window-1");
2283        var documentId = $window.find('.id').val();
2284        var isBookmark = true;
2285        var isAll = false;
2286        $hint = $(".hint-body");
2287        $.ajax({
2288            url: "/" + languageUI + "/document/comments/",
2289            type: "GET",
2290            data: { documentId: documentId, isBookmark: isBookmark, isAll: isAll }
2291        }).done(function (output) {
2292            $(".hint-body").html(output);
2293            DocumentHelper.ShowHintBody('mycomments');
2294        });
2295    }
2296
2297    this.MyBookmarks = function (ngr, lang, dateEdition) {
2298        if (!authorized) {
2299            $("#modalLogin").modal();
2300            return false;
2301        }
2302        var $window = $(".doc-window-1");
2303        var documentId = $window.find('.id').val();
2304        var isBookmark = false;
2305        var isAll = false;
2306        $hint = $(".hint-body");
2307        $.ajax({
2308            url: "/" + languageUI + "/document/bookmarks/",
2309            type: "GET",
2310            data: { documentId: documentId, isBookmark: isBookmark, isAll: isAll }
2311        }).done(function (output) {
2312            $(".hint-body").html(output);
2313            DocumentHelper.ShowHintBody('mybookarks');
2314        });
2315    }
2316
2317    this.ComparePretty = function (original, change) {
2318
2319    }
2320
2321    this.CompareClick = function () {
2322        var newId = $("#bodyId1").val();
2323        var oldId = $("#bodyId2").val();
2324        if (languageUI == "ru") {
2325            toastr["success"]("Процесс сравнения занимает несколько минут. Дождитесь завершения операции.");
2326        }
2327        else if (languageUI == "kk") {
2328            toastr["success"]("Салыстыру үдерісі бірнеше минутқа созылады. Операцияның аяқталуын күтіңіз.");
2329        }
2330        else if (languageUI == "en") {
2331            toastr["success"]("The comparison process takes several minutes. Wait for the operation to complete.");
2332        }
2333        CommonHelper.ShowLoader();
2334        setTimeout(function () {
2335            $.ajax({
2336                url: "/" + languageUI + "/Document/GetDiffBody",
2337                method: "GET",
2338                //async: false,
2339                data: { newId: newId, oldId: oldId, windowId: 1 }
2340            }).done(function (result) {
2341                $('.diff').html(result.body);
2342            });
2343
2344            $.ajax({
2345                url: "/" + languageUI + "/Document/GetDiffBody",
2346                method: "GET",
2347                //async: false,
2348                data: { newId: newId, oldId: oldId, windowId: 2 }
2349            }).done(function (result) {
2350                $('.original').html(result.body);
2351                //TODO: new
2352                DocumentHelper.FindAllCount();
2353                CommonHelper.HideLoader();
2354                toastr["success"]("Сравнение редакции успешно завершено!");
2355                $('.btn-compare-ins').removeClass('hide');
2356                $('.btn-compare-del').removeClass('hide');
2357                $('.changePrevious').removeClass('hide');
2358                $('.changeNext').removeClass('hide');
2359            });
2360        }, 1000);
2361    }
2362
2363    this.FontSizeInc = function (windowNumber) {
2364        var $window = $(".doc-window-" + windowNumber);
2365        var $p = $window.find("#doc-body-" + windowNumber);
2366        var fontSize = parseInt($p.css("font-size")) + 1;
2367        $p.css("font-size", fontSize + "px");
2368        toastr["success"]("Размер шрифта текста увеличен");
2369    }
2370
2371    this.FontSizeDec = function (windowNumber) {
2372        var $window = $(".doc-window-" + windowNumber);
2373        var $p = $window.find("#doc-body-" + windowNumber);
2374        var fontSize = parseInt($p.css("font-size")) - 1;
2375        $p.css("font-size", fontSize + "px");
2376        toastr["success"]("Размер шрифта текста уменьшен");
2377    }
2378
2379    this.Translate = function () {
2380        DocumentHelper.TextWidth(true);
2381        DocumentHelper.VisibilityTabTitle(true);
2382        $docWindow2 = $(".doc-window-2");
2383        $docWindow1 = $(".doc-window-1");
2384        if ($docWindow1.find(".select-languages > option").length < 2) {
2385            $("#modalMessage").find("h3").html("Уведомление");
2386            $("#modalMessage").find(".modal-message").html('У данного документа не имеется перевода.');
2387            $("#modalMessage").modal('toggle');
2388            return false;
2389        }
2390        if ($("#isTranslate").val() == "true") {
2391            $(".doc-window").removeClass("doc-window-half");
2392            $docWindow2.hide();
2393            $("#isTranslate").val(false);
2394            return false;
2395        }
2396        $("#isTranslate").val(true);
2397        $(".doc-window").addClass("doc-window-half");
2398        var dateEdition1 = $docWindow1.find(".date-edition").val();
2399        $docWindow2.find(".date-edition").val(dateEdition1);
2400        $docWindow2.find(".select-editions").val(dateEdition1);
2401        $docWindow2.find(".select-languages").html($docWindow1.find(".select-languages").html());
2402        $docWindow2.show();
2403        var lang = $docWindow1.find(".select-languages").val();
2404        if (lang == "1") {
2405            $docWindow2.find(".select-languages").val("3");
2406            $docWindow2.find(".lang").val("3");
2407        }
2408        else if (lang == 3) {
2409            $docWindow2.find(".select-languages").val("1");
2410            $docWindow2.find(".lang").val("1");
2411        }
2412        DocumentHelper.InitSelectEditions(2);
2413        toastr["success"]("Двухоконный режим включен");
2414        DocumentHelper.HideScrollLock(true);
2415        DocumentHelper.SyncScroll(true);
2416        DocumentHelper.TextWidth(true);
2417    }
2418
2419    this.Transcription = function (windowNumber) {
2420        var $window = $(".doc-window-" + windowNumber);
2421        var lang = $window.find(".select-languages").val();
2422        if (lang == 3) {
2423            var isLat = $window.find(".isLat").val();
2424            if (isLat === 'false') {
2425                var trans = StringHelper.Translit($window.find(".doc-body").html());
2426                $window.find(".doc-body").html(trans);
2427                toastr["success"]("Транскрипция на латиницу успешно выполнена");
2428                $window.find(".isLat").val('true');
2429            }
2430            else {
2431                var id = $window.find(".id").val();
2432                DocumentHelper.GetBody(windowNumber, id, false);
2433                $window.find(".isLat").val('false');
2434            }
2435        }
2436    }
2437
2438    this.GetAllComments = function (ngr, lang, dateEdition) {
2439
2440    }
2441
2442    this.Bookmarks = function (ngr, lang, dateEdition) {
2443
2444    }
2445
2446    this.Audio = function () {
2447        var $window = $(".doc-window-1");
2448        var id = $window.find(".id").val();
2449        $('.sendDocId').val(id);
2450        if (authorized) {
2451            $.ajax({
2452                dataType: "json",
2453                url: '/' + languageUI + '/Cabinet/GetEmail',
2454                success: function (data) {
2455                    $('.email').val(data);
2456                }
2457            });
2458        }
2459        var lang = $window.find(".select-languages").val();
2460        if (lang == 1) {
2461            $("#modalAudio").modal('toggle');
2462        }
2463        return false;
2464    }
2465
2466    this.Favotire = function () {
2467        if (!authorized) {
2468            $("#modalLogin").modal();
2469            return false;
2470        }
2471        CommonHelper.ShowLoader();
2472        var $window = $(".doc-window-1");
2473        var documentId = $window.find(".id").val();
2474        var docNgr = $window.find(".ngr").val();
2475
2476        $.ajax({
2477            url: "/" + languageUI + "/Document/ToFavorite",
2478            data: { documentId: documentId, ngr: docNgr }
2479        }).done(function (output) {
2480            CommonHelper.HideLoader();
2481            toastr["success"](output.message);
2482        });
2483    }
2484
2485    this.SaveToFavoriteList = function () {
2486        if (!authorized) {
2487            $("#modalLogin").modal();
2488            return false;
2489        }
2490        $("#modalSaveToList").modal('toggle');
2491        var select = $("#favoriteListGroup");
2492
2493        $.ajax({
2494            url: "/" + languageUI + "/Document/GetFavoriteGroups"
2495        }).done(function (output) {
2496            //var htmlOptions = [];
2497            var appendOptions = '<option selected="true" disabled="disabled" style="display:none"></option>';
2498            if (output.length) {
2499                for (item in output) {
2500                    appendOptions += '<option value="' + output[item].id + '">' + output[item].title + '</option>';
2501                }
2502                select.empty().append(appendOptions);
2503            }
2504        });
2505    }
2506
2507    this.SaveDocToFavList = function () {
2508        var $window = $(".doc-window-1");
2509        var documentId = $window.find(".id").val();
2510        var groupId = $("#modalSaveToList").find("#FavGroupId").val();
2511        //console.log(groupId);
2512        $.ajax({
2513            url: "/" + languageUI + "/Document/DocSaveToList",
2514            data: { groupId: groupId, documentId: documentId }
2515        }).done(function (output) {
2516            $("#modalSaveToList").modal('toggle');
2517            toastr["success"](output.message);
2518        });
2519    }
2520
2521    this.GoogleTranslate = function () {
2522        $("#modalTranslate").modal('toggle');
2523    }
2524
2525    this.Links = function () {
2526        CommonHelper.ShowLoader();
2527        var lang = $('.lang').val();
2528        var ngr = $('.ngr').val();
2529        $hint = $(".hint-body");
2530        $.ajax({
2531            url: "/" + languageUI + "/document/links/" + lang + "/" + ngr,
2532            type: "GET"
2533        }).done(function (links) {
2534            $(".hint-body").html(links);
2535            DocumentHelper.ShowHintBody('links');
2536            CommonHelper.HideLoader();
2537        });
2538    }
2539
2540    this.HintBodyEnabled = function () {
2541        var pos = $(".doc-left-menu-container").position();
2542        var w = parseInt($(".doc-left-menu-container").css('width'));
2543        var mt = parseInt($(".doc-left-menu-container").css('margin-top'));
2544        if ($(".hint-body").length > 0) {
2545            $(".hint-body").css('top', parseInt(pos.top) + mt + 'px');
2546            $(".hint-body").css('left', parseInt(pos.left) + w + 'px');
2547        }
2548    }
2549
2550    this.LeftMenuHintEnabled = function () {
2551        var pos = $(".doc-left-menu-container").position();
2552        var w = parseInt($(".doc-left-menu-container").css('width'));
2553        var mt = parseInt($(".doc-left-menu-container").css('margin-top'));
2554        if ($(".doc-left-menu-hint").length > 0) {
2555            var widthH = parseInt($(".doc-left-menu-hint").css('width'));
2556            $(".doc-left-menu-hint").css('top', parseInt(pos.top) + mt + 'px');
2557            $(".doc-left-menu-hint").css('left', parseInt(- widthH) + 'px');
2558            $(".hint-body").css('top', parseInt(pos.top) + mt + 'px');
2559            $(".hint-body").css('left', parseInt(pos.left) + w + 'px');
2560        }
2561    }
2562
2563    this.SortClick = function () {
2564        //Click Sort Icon 
2565        var desc = $(".desc").val();
2566        var sortType = $(".sort").val();
2567        $(".sort-icon").html('');
2568        if (desc == 'true')
2569            $('.doc-sort[type="' + sortType + '"]').find(".sort-icon").html(' <i class="fa fa-sort-amount-asc"></i>');
2570        else $('.doc-sort[type="' + sortType + '"]').find(".sort-icon").html(' <i class="fa fa-sort-amount-desc"></i>');
2571    }
2572
2573    this.GetLast = function (href, hrefClassName) {
2574        if ($(".last-docs").length < 1)
2575            return false;
2576        $.ajax({
2577            url: '/' + languageUI + href
2578        }).done(function (output) {
2579            $(".last-docs").html(output);
2580            $(".last-docs-links").find(".underline").removeClass("underline-active-blue");
2581            $("." + hrefClassName).addClass("underline-active-blue");
2582            var owlDocument = $('.document-carousel');
2583            owlDocument.owlCarousel({
2584                items: 1,
2585                dots: false,
2586                margin: 0,
2587                loop: true,
2588                autoplay: true,
2589                autoplayTimeout: 14000,
2590                autoplayHoverPause: true
2591            });
2592        });
2593    }
2594
2595    this.SearchSettingsToggle = function () {
2596        $(".search-settings-modal").toggle();
2597    }
2598
2599    this.SelectCompareEdition = function () {
2600        $docWindow1 = $(".doc-window-1");
2601        if ($docWindow1.find(".select-editions > option").length < 2) {
2602            $("#modalMessage").find("h3").html("Уведомление");
2603            $("#modalMessage").find(".modal-message").html('У данного документа нет других редакции.');
2604            $("#modalMessage").modal('toggle');
2605            return false;
2606        }
2607        this.SetEditions();
2608        $("#modalChooseCompare").modal();
2609    }
2610
2611    this.CompareOk = function () {
2612        if ($("#isCompare").val() == "true") {
2613            $('.compare-div').addClass("hide");
2614            $(".doc-window").removeClass("doc-window-half");
2615            $docWindow2.hide();
2616            $("#isCompare").val(false);
2617            location.reload();
2618            return false;
2619        }
2620        var leftEdition = $('#SelectEditionLeft').val();
2621        var rightEdition = $('#SelectEditionRight').val();
2622        $('#bodySelectEditions1').val(leftEdition);
2623        $('#bodySelectEditions2').val(rightEdition);
2624        DocumentHelper.VisibilityTabTitle(true);
2625        $docWindow2 = $(".doc-window-2");
2626        $docWindow1 = $(".doc-window-1");
2627
2628        $("#isCompare").val(true);
2629        $(".doc-window").addClass("doc-window-half");
2630        $docWindow2.show();
2631
2632        //TODO:
2633        $('.compare-div').removeClass("hide");
2634        toastr["success"]("Режим сравнения документов включен");
2635
2636        //TODO: показать скрол
2637        DocumentHelper.HideScrollLock(true);
2638        //TODO: крутить скрол по умолчанию
2639        DocumentHelper.SyncScroll(true);
2640        //TODO: отключить второе окно
2641        DocumentHelper.LockEditationLanguage(true);
2642        DocumentHelper.TextWidth(true);
2643        DocumentHelper.ChangeEditionDate(2);
2644    }
2645
2646    this.SetEditions = function (windowNumber) {
2647        var lang = $window.find('.lang').val();
2648        var ngr = $window.find('.ngr').val();
2649        $('#SelectEditionLeft').html('');
2650        $('#SelectEditionRight').html('');
2651
2652        var textEdit = "Редакция от ";
2653        if (languageUI == "kk")
2654            textEdit = "Басылым ";
2655        else if (languageUI == "en")
2656            textEdit = "Edition ";
2657
2658        $.ajax({
2659            url: "/" + languageUI + "/document/GetByLanguage",
2660            method: "GET",
2661            async: false,
2662            data: { ngr: ngr, langId: lang, windowNumber: windowNumber }
2663        }).done(function (editions) {
2664            var editions_ = editions.objects;
2665            localStorage.setItem("doc-version", JSON.stringify(editions_));
2666
2667            $.each(editions_, function (key, value) {
2668
2669                if (editions_.length > 1) {
2670
2671                    if (key == 0) {
2672                        $('#SelectEditionLeft').append('<option value="' + value.dateEditionStr + '" selected>' + textEdit + value.dateEditionStr2 + '</option>');
2673                    }
2674                    else {
2675                        $('#SelectEditionLeft').append('<option value="' + value.dateEditionStr + '">' + textEdit + value.dateEditionStr2 + '</option>');
2676                    }
2677
2678                    if (key == 1) {
2679                        $('#SelectEditionRight').append('<option value="' + value.dateEditionStr + '" selected>' + textEdit + value.dateEditionStr2 + '</option>');
2680                    }
2681                    else if (key > 1) {
2682                        $('#SelectEditionRight').append('<option value="' + value.dateEditionStr + '">' + textEdit + value.dateEditionStr2 + '</option>');
2683                    }
2684
2685                    $('#bodySelectEditions2').append('<option value="' + value.dateEditionStr + '">' + textEdit + value.dateEditionStr2 + '</option>');
2686                }
2687            });
2688        });
2689    }
2690
2691    this.myIns = -1;
2692    this.TempData = [];
2693    this.EditedData = [];
2694    this.EditedDataDel = [];
2695    this.outerHeightDel = 0;
2696    this.outerHeightIns = 0;
2697    this.type = "";
2698
2699    this.FindAllCount = function () {
2700
2701        if (DocumentHelper.EditedData.length == 0) {
2702            var _diff = $('.diff').find('p');
2703            var _original = $('.original').find('p');
2704
2705            DocumentHelper.EditedData = $.grep(_diff, function (p) {
2706                return (($(p).html().indexOf("del") != -1) || ($(p).html().indexOf("ins") != -1));
2707            });
2708
2709            DocumentHelper.EditedDataDel = $.grep(_original, function (p) {
2710                return (($(p).html().indexOf("del") != -1) || ($(p).html().indexOf("ins") != -1));
2711            });
2712        }
2713        DocumentHelper.TempData = DocumentHelper.EditedData;
2714        //console.log('editData=', DocumentHelper.EditedData);
2715        $('.showChangedDef').removeClass('hide');
2716        $('#diffCount').text(DocumentHelper.TempData.length);
2717    }
2718
2719    //try 
2720    this.FindAllChanges = function (type) {
2721
2722        DocumentHelper.ScrollLockClick(false);
2723        if (type === 'next') {
2724            if (DocumentHelper.myIns < DocumentHelper.TempData.length - 1) {
2725                DocumentHelper.myIns++;
2726                DocumentHelper.ScrollTopMove();
2727            } else {
2728                toastr["success"]("Поиск изменений в документе завершен");
2729            }
2730        } else {
2731            if (DocumentHelper.myIns > 0) {
2732                DocumentHelper.myIns--;
2733                DocumentHelper.ScrollTopMove();
2734            } else {
2735                toastr["success"]("Поиск изменений в документе завершен");
2736            }
2737        }
2738    }
2739
2740    this.ScrollTopMove = function () {
2741        var $window1 = $(".doc-window-1");
2742        var $window2 = $(".doc-window-2");
2743
2744        //TODO:
2745        $window1.find('.doc-body').scrollTop(0);
2746        $window2.find('.doc-body').scrollTop(0);
2747
2748        $('#indexDiff').text(DocumentHelper.myIns + 1);
2749        $('.showChangeCount').removeClass('hide');
2750
2751        $.map(DocumentHelper.TempData, function (item, indx) {
2752            if ($(item).text().trim() != "") {
2753                if (DocumentHelper.myIns == indx) {
2754
2755                    var _height = $(item).outerHeight();
2756
2757                    DocumentHelper.outerHeightIns += _height;
2758                    DocumentHelper.outerHeightDel += _height;
2759
2760                    var del_item = DocumentHelper.EditedDataDel[indx];
2761                    var _topIns = ($window1.find($(item)).offset().top);
2762                    var _topDel = ($window2.find($(del_item)).offset().top);
2763
2764                    $window1.find('.doc-body').scrollTop(_topIns - 300);
2765                    $window2.find('.doc-body').scrollTop(_topDel - 300);
2766                    DocumentHelper.ScrollLockClick(false);
2767                }
2768            }
2769        });
2770    }
2771}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.