PageSourceSearch

https://nservice.moj.gov.tw/ajpp/js/common.js

js moj.gov.tw collected 2026-09-24 08:29:11 UTC 32,933 bytes, 1,096 lines download raw bytes

1/* 共用js */
2//是否顯示console.log
3var _showConsole = true;
4
5/**
6 * 如果傳入值為 null、empty 或 undefined, 則回傳 true; 反之, 回傳 false
7 * @param {any} obj
8 */
9this.isNullOrEmpty = function (obj) {
10
11    // null and undefined are "empty"
12    if (obj == null) return true;
13    if (typeof obj == undefined) return true;
14
15    // Assume if it has a length property with a non-zero value
16    // that that property is correct.
17    if (obj.length > 0) return false;
18    if (obj.length === 0) return true;
19
20    // Otherwise, does it have any properties of its own?
21    // Note that this doesn't handle
22    // toString and valueOf enumeration bugs in IE < 9
23    for (var key in obj) {
24        if (hasOwnProperty.call(obj, key)) return false;
25    }
26
27    // Assume if it is time
28    if (new Date(obj)) return false;
29
30    return true;
31};
32
33/**
34 * 可在Javascript中使用如同C#中的string.format
35 * 使用方式 : var fullName = String.format('Hello. My name is {0} {1}.', 'FirstName', 'LastName');
36 */
37String.format = function () {
38    var s = arguments[0];
39    if (s == null) return "";
40    for (var i = 0; i < arguments.length - 1; i++) {
41        var reg = getStringFormatPlaceHolderRegEx(i);
42        s = s.replace(reg, (arguments[i + 1] == null ? "" : arguments[i + 1]));
43    }
44    return cleanStringFormatResult(s);
45}
46
47/**
48 * 可在Javascript中使用如同C#中的string.format (對jQuery String的擴充方法)
49 * 使用方式 : var fullName = 'Hello. My name is {0} {1}.'.format('FirstName', 'LastName');
50 */
51String.prototype.format = function () {
52    var txt = this.toString();
53    for (var i = 0; i < arguments.length; i++) {
54        var exp = getStringFormatPlaceHolderRegEx(i);
55        txt = txt.replace(exp, (arguments[i] == null ? "" : arguments[i]));
56    }
57    return cleanStringFormatResult(txt);
58}
59
60
61
62/**
63 * 可在Javascript中使用padleft左側補字元 (對jQuery String的擴充方法)
64 * 使用方式 : padleft(a, '0', 2); 
65 * @param {string} str 原字串
66 * @param {string}
66 char 要插入的字元
67 * @param {int} number 總共長度
68 * @returns {string} 補字元完的字串
69 */
70function padleft(str, char, number) {
71    var ret = "";
72    for (var i = 0; i < number; i++) {
73        ret += char;
74    }
75    ret += str;
76    ret = ret.substr(ret.length - number, number);
77    
78    return ret;
79}
80
81
82
83//自訂console.log
84function Console(value) {
85    if (_showConsole) {
86        console.log(value);
87    }
88}
89
90/**
91 * 自訂訊息彈跳訊息視窗
92 * @param {string} msg
93 */
94function SuccessMessage(msg) {
95    $.alert({
96        title: "訊息",
97        type: "green",
98        content: msg,
99        theme: "bootstrap",
100        icon: 'glyphicon glyphicon-ok-sign',
101        buttons: {
102            close: {
103                text: "關閉"
104            }
105        }
106    });
107}
108
109/**
110 * 自訂訊息彈跳訊息視窗
111 * @param {string} msg
112 * @param {object} call
113 */
114function InfoMessage(msg, call) {
115
116    if (call !== undefined) {
117        $.alert({
118            title: "訊息",
119            type: "blue",
120            content: msg,
121            theme: "bootstrap",
122            icon: 'glyphicon glyphicon-info-sign',
123            buttons: {
124                close: {
125                    text: "關閉",
126                    action: function () {
127                        call();
128                    }
129                }
130            }
131        });
132    }
133    else {
134        $.alert({
135            title: "訊息",
136            type: "blue",
137            content: msg,
138            theme: "bootstrap",
139            icon: 'glyphicon glyphicon-info-sign',
140            buttons: {
141                close: {
142                    text: "關閉"
143                }
144            }
145        });
146    }
147
148
149}
150
151/**
152 * 自訂訊息彈跳訊息視窗
153 * @param {string} msg
154 */
155function ErrorMessage(msg) {
156    $.alert({
157        title: "錯誤",
158        type: "red",
159        content: msg,
160        theme: "bootstrap",
161        icon: 'glyphicon glyphicon-exclamation-sign',
162        buttons: {
163            close: {
164                text: "關閉"
165            }
166        }
167    });
168
169    //$("#msgModal").find("#msgContent").html(msg);
170    //$("#msgModal").modal("show");
171}
172
173/**
174 * 自訂訊息彈跳確認視窗
175 * @param {string} msg
176 * @param {object} call1
177 * @param {object} call2
178 */
179function ConfirmMessage(msg, call1, call2) {
180    $.confirm({
181        title: '確認',
182        content: msg,
183        icon: 'glyphicon glyphicon-question-sign',
184        buttons: {
185            confirm: {
186                text: '確定',
187                btnClass: 'btn-primary',
188                action: function () {
189                    call1();
190                }
191            },
192            cancel: {
193                text: '取消',
194                action: function () {
195                    Console(call2);
196
197                    if (call2 !== undefined)
198                        call2();
199
200                }
201            }
202        }
203    });
204
205}
206
207/**
208 * 回傳多選的値
209 * @param {object} value
210 */
211function getfSelectVal(value) {
212    Console(value);
213    var r = '';
214    if (value !== null) 
215        r = value.join();
216    return r;
217}
218
219/**
220 * 設定維護按鈕啟用/停用
221 * @param {string} value
222 */
223function setManagerBtn(value) {
224    Console("setManagerBtn");
225    Console(value);
226    if (value=="True") {
227        $("#btn_Add").removeAttr("disabled");
228        $("#btn_Save").removeAttr("disabled");
229    }
230    else {
231        $("#btn_Add").attr("disabled", "disabled");
232        $("#btn_Save").attr("disabled", "disabled");
233    }
234}
235
236/**
237 * 設定滑鼠滾輪啟用Y/停用N
238 * @param {string} enabled
239 */
240function setMouseWheelEnabled(enabled) {
241    if (checkBrowserIE()) {
242        if (enabled == "Y") {
243            $(window).unbind('wheel');
244        }
245        else {
246            //卷到top
247            $('html, body').scrollTop(0);
248            $(window).on('wheel', function () {
249                return false;
250            });
251        }
252    }
253
254
255}
256
257/**
258 * 檢查身分證號碼的邏輯規則, 通過回傳true, 失敗回傳false
259 * @param {string} value
260 */
261function checkIDRule(value) {
262    value = value.toUpperCase();
263    var resultL1 = value.match(/[A-Z]{1}[1-2]{1}[0-9]{8}/g);
264
265    if (resultL1 !== null) {
266        var esum = 0;
267        var nsum = 0;
268        var count = 0;
269        var city = ["A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "U", "V", "X", "Y", "W", "Z", "I", "O"];
270        for (var index = 0; index < city.length; index++) {
271            if (value.substr(0, 1) === city[index]) {
272                //console.log(city[index]);
273                index += 10;
274                esum = ((index % 10) * 9) + Math.floor(index / 10);
275                break;
276            }
277        }
278        for (var i = 1; i < 9; i++) {
279            nsum += (value.substr(i, 1) - 0) * (9 - i);
280        }
281        count = esum + nsum + (value.substr(9, 1) - 0);
282
283        if ((count % 10) === 0) {
284            return true;
285        }
286        else {
287            return false;
288        }
289    }
290    else {
291        return false;
292    }
293}
294
295/**
296 * 檢查瀏覽器是否IE, 是回傳true, 否回傳false
297 */
298function checkBrowserIE() {
299    var ua = window.navigator.userAgent;
300    var msie = ua.indexOf("MSIE ");
301    if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) {
302        return true;
303    }
304    else {
305        return false;
306    }
307}
308
309//=======================================================================================
310//bootstrap table 自訂排序
311//=======================================================================================
312/**
313 * 證書字號的自訂排序(擷取字串中的數字個別排序,先排第一個再排第二,以此類推)
314 * @param {string} x
315 * @param {string} y
316 */
317function customSort(x, y) {
318    var ax = getNumFromStr(x);
319    var ay = getNumFromStr(y);
320
321    
322    if (ax !== null && ay !== null) {
323        if (ax.length == ay.length) {
324            for (var i = 0; i < ax.length; i++) {
325                var axi = ax[i] - 0;
326                var ayi = ay[i] - 0;
327
328                if (axi > ayi) {
329                    return 1;
330                }
331                else if (axi < ayi) {
332                    return -1;
333                }
334
335
336            }
337            return 0;
338        }
339        else if (ax.length > ay.length) {
340            return 1;
341        }
342        else {
343            return -1;
344        }
345    }
346    else if (ax == null) {
347        return -1;
348    }
349    else {
350        return 1;
351    }
352
353    //return 1;
354}
355/**
356 * 擷取出字串的數字
357 * @param {string} str
358 */
359function getNumFromStr(str) {
360    return str.match(/\d+/g);
361}
362
363//=======================================================================================
364//日期時間
365//=======================================================================================
366/**
367 *  設定時間的元件
368 * @param {any} id      -欄位名稱
369 */
370function setTimeCtrl(id) {
371    var d1 = $.Deferred();
372    $("#txt_" + id).hide();
373    //hour
374    var divHour = $("<div>").addClass("input-group");
375    var hour = $("<select>").attr("id", "sel_Hour" + id).addClass("form-control").addClass("form-time");
376    for (var i = 0; i < 24; i++) {
377        hour.append($("<option>").val(padleft(i, '0', 2)).text(padleft(i, '0', 2)));
378    }
379    var spanHour = $("<span>").html("時").addClass("input-group-addon");
380
381    divHour.append(hour).append(spanHour);
382    $("#txt_" + id).after(divHour);
383    //min
384    var divMin = $("<div>").addClass("input-group");
385    var min = $("<select>").attr("id", "sel_Min" + id).addClass("form-control").addClass("form-time");
386    for (i = 0; i < 60; i++) {
387        min.append($("<option>").val(padleft(i, '0', 2)).text(padleft(i, '0', 2)));
388    }
389    var spanMin = $("<span>").html("分").addClass("input-group-addon");
390
391    divMin.append(min).append(spanMin);
392    divHour.after(divMin);
393    //sec
394    var divSec = $("<div>").addClass("input-group");
395    var sec = $("<select>").attr("id", "sel_Sec" + id).addClass("form-control").addClass("form-time");
396    for (i = 0; i < 60; i++) {
397        sec.append($("<option>").val(padleft(i, '0', 2)).text(padleft(i, '0', 2)));
398    }
399    var spanSec = $("<span>").html("秒").addClass("input-group-addon");
400
401    divSec.append(sec).append(spanSec);
402    divMin.after(divSec);
403}
404/**
405 *  時間設定成預設値
406 * @param {any} id      -欄位名稱
407 * @param {string} type -時間起迄: S起/E迄
408 */
409function setTimeDefault(id, type) {
410    if (type == "S") {
411        $("#div_Query").find("#sel_Hour" +id).val("00");
412        $("#div_Query").find("#sel_Min" + id).val("00");
413        $("#div_Query").find("#sel_Sec" + id).val("00");
414    }
415    if (type == "E") {
416        Console("go setTimeDefault E");
417        $("#div_Query").find("#sel_Hour" + id).val("23");
418        $("#div_Query").find("#sel_Min" + id).val("59");
419        $("#div_Query").find("#sel_Sec" + id).val("59");
420    }
421}
422
423/**
424 *  取得時間的値(文字型態)
425 * @param {any} id      -欄位名稱
426 */
427function getTimeVal(id) {
428    var ret = "";
429    ret = $("#sel_Hour" + id).val() + ":" + $("#sel_Min" + id).val() + ":" + $("#sel_Sec" + id).val();
430    $("#txt_" + id).val(ret);
431    return ret;
432}
433
434/**
435 * 取得 小時的元件
436 * @param {any} id      -欄位名稱
437 */
438function setHourCtrl(id) {
439    for (var i = 0; i < 24; i++) {
440        $("#" + id).append($("<option>").val(padleft(i, '0', 2)).text(padleft(i, '0', 2)));
441    }
442}
443/**
444 * 取得 分秒的元件
445 * @param {any} id      -欄位名稱
446 */
447function setMinSecCtrl(id) {
448    for (var i = 0; i < 60; i++) {
449        $("#" + id).append($("<option>").val(padleft(i, '0', 2)).text(padleft(i, '0', 2)));
450    }
451}
452
453
454/**
455 * 取得 月份的元件
456 * @param {any} name    -欄位名稱
457 */
458function setMonthCtrl(name) {
459
460    for (var i = 1; i < 13; i++) {
461        $("#" + name).append($("<option>").val(i).text(i));
462    }
463    
464}
465
466/**
467 * 設定日期可允許的最大日
468 */
469function setCustomDayCrl() {
470    $("#sel_YearPrefix").change(function () {
471        if ($("#txt_Year").val() != "" && $("#sel_Month").val() != "") {
472            var maxday = new Date($("#sel_YearPrefix").val() - 0 + $("#txt_Year").val() - 0 + 1911, $("#sel_Month").val() - 0, 0).getDate();
473            $("#txt_Day").prop("max", maxday);
474            Console(maxday);
475        }
476    });
477    $("#txt_Year").change(function () {
478        if ($("#txt_Year").val() != "" && $("#sel_Month").val() != "") {
479            var maxday = new Date($("#sel_YearPrefix").val() - 0 + $("#txt_Year").val() - 0 + 1911, $("#sel_Month").val() - 0, 0).getDate();
480            $("#txt_Day").prop("max", maxday);
481            Console(maxday);
482        }
483    });
484    $("#sel_Month").change(function () {
485        if ($("#txt_Year").val() != "" && $("#sel_Month").val() != "") {
486            var maxday = new Date($("#sel_YearPrefix").val() - 0 + $("#txt_Year").val() - 0 + 1911, $("#sel_Month").val() - 0, 0).getDate();
487            $("#txt_Day").prop("max", maxday);
488            Console(maxday);
489        }
490    });
491}
492//=======================================================================================
493//照片相關
494//=======================================================================================
495/**
496 * 照片事件
497 * @param {string} url  -Image的PartialView
498 */
499function imageEvent(url) {
500    $("#div_Image0").click(function () {
501        $.confirm({
502            title: '照片',
503            columnClass: 'medium',
504            content: url,
505            icon: 'glyphicon glyphicon-pencil',
506            onContentReady: function () {
507                var pic1 = $("#div_AddEdit").find("#txt_PicpathStr1").val();
508                //var pic2 = $("#div_AddEdit").find("#txt_PicpathStr2").val();
509                if (pic1 !== null && pic1 !== "") {
510                    pic1 = htmlEncode(pic1);
511
512                    $("#div_Image1").empty();
513                    showPreviewImage(pic1, "", 1);
514                }
515                else {
516                    $(".image-div").find("#btn_ImageUpload1").hide();
517                    $(".image-div").find("#btn_ImageDelete1").hide();
518                }
519                //if (pic2 !== null && pic2 !== "") {
520                //    pic1 = htmlEncode(pic2);
521
522                //    $("#div_Image2").empty();
523                //    showPreviewImage(pic2, "", 2);
524                //}
525                //else {
526                //    $(".image-div").find("#btn_ImageUpload2").hide();
527                //    $(".image-div").find("#btn_ImageDelete2").hide();
528                //}
529            },
530            buttons: {
531                confirm: {
532                    text: '確定',
533                    btnClass: 'btn-primary',
534                    action: function () {
535                        $("#div_Image0").addClass("image-base-border");
536
537                        if ($(".image-div").find(".active").length > 0) {
538                            $("#div_Image0").removeClass("image-base-border");
539
540                            var image = $(".image-div").find(".active").find("img");
541
542                            $("#div_Image0").empty();
543                            showPreviewImage(image.attr("src"), "", 0);
544                            $("#div_AddEdit").find("#txt_PicpathStr1").val(image.attr("src"));
545
546                            //var imgNum = $(".image-div").find(".image-pic-exist:not(.active)").length;
547                            //Console("imgNum=" + imgNum);
548                            //if (imgNum == 1) {
549                            //    var image2 = $(".image-div").find(".image-pic-exist:not(.active)").find("img");
550                            //    $("#div_AddEdit").find("#txt_PicpathStr2").val(image2.attr("src"));
551                            //}
552                            //else {
553                            //    $("#div_AddEdit").find("#txt_PicpathStr2").val("");
554                            //}
555                        }
556                        else {
557                            $("#div_Image0").empty();
558                            var imgNum = $(".image-div").find(".image-pic-exist").length;
559                            if (imgNum == 1) {
560                                $("#div_Image0").removeClass("image-base-border");
561                                var image = $(".image-div").find(".image-pic-exist").find("img");
562                                $("#div_AddEdit").find("#txt_PicpathStr1").val(image.attr("src"));
563                                //$("#div_AddEdit").find("#txt_PicpathStr2").val("");
564                                showPreviewImage(image.attr("src"), "", 0);
565                            }
566                            else if (imgNum == 2) {
567                                $("#div_Image0").removeClass("image-base-border");
568                                var image1 = $(".image-div").find("#div_Image1").find("img");
569                                //var image2 = $(".image-div").find("#div_Image2").find("img");
570                                $("#div_AddEdit").find("#txt_PicpathStr1").val(image1.attr("src"));
571                                //$("#div_AddEdit").find("#txt_PicpathStr2").val(image2.attr("src"));
572                                showPreviewImage(image1.attr("src"), "", 0);
573                            }
574                            else {
575                                $("#div_AddEdit").find("#txt_PicpathStr1").val("");
576                                //$("#div_AddEdit").find("#txt_PicpathStr2").val("");
577                            }
578                        }
579
580                    }
581                },
582                cancel: {
583                    text: '取消'
584                }
585            }
586        });
587    });
588}
589
590/**
591 * 在頁面上新增<img>
592 * @param {string} src          -Base64字串
593 * @param {string} fileName     -圖片檔名
594 * @param {string} num          -圖片幾
595 */
596function showPreviewImage(src, fileName, num) {
597    var id = "div_Image" + num;
598    var width = $("#" + id).width();
599    Console("width=" + width);
600    var img_height;
601
602    let image = new Image(width); // 設定寬
603    image.name = fileName;
604    image.id = "img_" + num;
605    image.src = src; // <img>中src屬性除了接url外也可以直接接Base64字串
606    
607
608    image.onload = function () {
609        Console("height=" + this.height);
610        img_height = this.height;
611
612
613
614        if (num != 0) {
615            resize("img_" + num, 194);
616        }
617        else {
618            if (img_height > width) {
619                if (img_height > 214) {
620                    resize("img_" + num, 214);
621                }
622                else {
623                    resize("img_" + num, img_height);
624                }
625            }
626            else {
627                resize("img_" + num, width);
628            }
629
630        }
631
632    }
633
634    
635    $("#" + id).append(image);
636
637    if (num != 0) {
638        Console("num="+num);
639        $("#btn_ImageUpload" + num).show();
640        $("#btn_ImageDelete" + num).show();
641        $("#" + id).removeClass("image-pic-none");
642        $("#" + id).addClass("image-pic-exist");
643    }
644}
645
646/**
647 * <img>調整尺寸
648 * @param {string} id   -img id
649 * @param {number} max  -最大長寬
650 */
651function resize(id, max) {
652    var maxWidth = max; // Max width for the image
653    var maxHeight = max;    // Max height for the image
654    var ratio = 0;  // Used for aspect ratio
655    var width = $("#" + id).width();    // Current image width
656    var height = $("#" + id).height();  // Current image height
657
658    // Check if the current width is larger than the max
659    if (width > maxWidth) {
660        ratio = maxWidth / width;   // get ratio for scaling image
661        $("#" + id).css("width", maxWidth); // Set new width
662        $("#" + id).css("height", height * ratio);  // Scale height based on ratio
663        height = height * ratio;    // Reset height to match scaled image
664        width = width * ratio;    // Reset width to match scaled image
665    }
666
667    // Check if current height is larger than max
668    if (height > maxHeight) {
669        ratio = maxHeight / height; // get ratio for scaling image
670        $("#" + id).css("height", maxHeight);   // Set new height
671        $("#" + id).css("width", width * ratio);    // Scale width based on ratio
672        width = width * ratio;    // Reset width to match scaled image
673        height = height * ratio;    // Reset height to match scaled image
674    }
675}
676
677// 建立一個暫存的div元素,並使用text()將內容存成html編碼文字後再用html()取出
678function htmlEncode(value) {
679    return $('<div/>').text(value).html();
680}
681
682/**
683 * 檢核照片大小(Base64String長度)
684 * @param {string} str  -Base64String
685 * @returns {boolean}   -ok true / else false
686 */
687function vaildateImgSize(str) {
688    var ret = true;
689    if (str !== null) {
690        if (str.length > 2804360) {
691            ret = false;
692            // Console("Image Length="+str.length);
693        }
694    }
695
696    return ret;
697}
698//=======================================================================================
699//查詢、新增、修改、刪除共用
700//=======================================================================================
701//模式一
702//=======================================================================================
703//清除新增/修改頁面
704function setPageAEini() {
705    resetAE();
706    hideAllPage();
707}
708//隱藏所有頁面
709function hideAllPage() {
710    $("#div_PageQ").hide();
711    $("#div_PageAE").hide();
712}
713//
714function setInitial() {
715    //預設頁面
716    hideAllPage();
717    $("#div_PageQ").show();
718    $("#btn_ShowQuery").hide();
719}
720//
721function setEvent() {
722    //依條件查詢
723    $("#btn_Search").click(function () {
724        search();
725    });
726    //清除查詢條件
727    $("#btn_Reset").click(function () {
728        resetQ();
729    });
730
731    //切換到新增頁面
732    $("#btn_Add").click(function () {
733        $("#btn_Save").data("type", "Insert");
734        setPageAEini();
735
736        if (typeof preAdd !== "undefined") {
737            preAdd();//新增的準備,自行增加的程式可放這裡面
738        }
739        $("#div_PageAE").show();
740        //$("#h3_AE").html("新增");
741        $(".span-hide").hide();
742    });
743    //切換到預設頁面
744    $("#btn_Cancel").click(function () {
745        hideAllPage();
746        $("#div_PageQ").show();
747        $(".span-hide").show();
748    });
749
750    //新增/修改按鈕
751    $('#form_AddEdit').validator().on('submit', function (e) {
752        if (e.isDefaultPrevented()) {
753            // handle the invalid form...
754        } else {
755            // everything looks good!
756            save();
757        }
758        e.preventDefault(); // 防止原始 form 提交表单
759    });
760
761    //顯示隱藏查詢欄位
762    $("#btn_HideQuery").click(function () {
763        $("#div_Query").find(".panel-body").hide();
764        $("#btn_HideQuery").hide();
765        $("#btn_ShowQuery").show();
766    });
767    $("#btn_ShowQuery").click(function () {
768        $("#div_Query").find(".panel-body").show();
769        $("#btn_HideQuery").show();
770        $("#btn_ShowQuery").hide();
771    });
772}
773//=======================================================================================
774//模式二
775//=======================================================================================
776function setInitial2() {
777    //預設頁面
778    resetAE();
779    $("#div_AddEdit").hide();
780    $("#btn_ShowQuery").hide();
781}
782function setEvent2() {
783    //依條件查詢
784    $("#btn_Search").click(function () {
785        search();
786    });
787    //清除查詢條件
788    $("#btn_Reset").click(function () {
789        resetQ();
790    });
791
792    //切換到新增頁面
793    $("#btn_Add").click(function () {
794        resetAE();
795        
796        if (typeof preAdd !== "undefined") {
797            preAdd();//新增的準備,自行增加的程式可放這裡面
798        }
799        $("#div_AddEdit").show();
800        $("#btn_Save").data("type", "Insert");
801    });
802    //切換到預設頁面
803    $("#btn_Cancel").click(function () {
804        setInitial2();
805    });
806
807    //新增/修改按鈕
808    $('#form_AddEdit').validator().on('submit', function (e) {
809        if (e.isDefaultPrevented()) {
810            // handle the invalid form...
811        } else {
812            // everything looks good!
813            save();
814        }
815        e.preventDefault(); // 防止原始 form 提交表单
816    });
817
818    //顯示隱藏查詢欄位
819    $("#btn_HideQuery").click(function () {
820        $("#div_Query").find(".panel-body").hide();
821        $("#btn_HideQuery").hide();
822        $("#btn_ShowQuery").show();
823    });
824    $("#btn_ShowQuery").click(function () {
825        $("#div_Query").find(".panel-body").show();
826        $("#btn_HideQuery").show();
827        $("#btn_ShowQuery").hide();
828    });
829}
830
831
832//=======================================================================================
833//跨程式傳遞參數相關
834//=======================================================================================
835/**
836 * 儲存暫存查詢律師ID
837 * @param {string} id
838 */
839function setCacheID(id) {
840    var obj = {};
841    obj.Fields = { "ID" : id };
842
843    $.ajax({
844        url: $("#SetCache").data('url'),
845        data: obj,
846        type: 'Post',
847        dataType: 'json',
848        success: function (data) {
849
850            if (data == null || data.state == "ERROR") {
851                ErrorMessage(data.message);
852            }
853        },
854        error: function (xhr, ajaxOptions, thrownError) {
855            ErrorMessage(thrownError);
856        }
857    });
858}
859
860
861/**
862 * 取得暫存查詢律師ID並查詢
863 * @param {string} textID 律師的ID查詢欄位的html元素id
864 * @param {object} par 其餘要傳遞的參數, 格式[{"key": "keyvalue", "id": "idvalue"}]
865 */
866function defaultSearch(textID, par) {
867
868    $.ajax({
869        url: $("#GetCache").data('url'),
870        type: 'Post',
871        dataType: 'json',
872        success: function (data) {
873            //Console(data);
874
875            if (data == null || data.state == "ERROR") {
876                ErrorMessage(data.message);
877            }
878            else {
879                var record = data.data;
880
881                if (record != null && record["ID"] != null && record["ID"] != "") {
882                    if (typeof par !== "undefined") {
883                        par.forEach(function (e) {
884                            $("#" + e.id).val(record[e.key]);
885                        });
886                    }
887                    
888                    $("#div_Query").find("#" + textID).val(record["ID"]);
889                    search();
890                    $("#div_Query").find("#" + textID).val("");
891                }
892            }
893        },
894        error: function (xhr, ajaxOptions, thrownError) {
895            ErrorMessage(thrownError);
896        }
897    });
898    
899
900}
901
902
903
904/**
905 * 自訂跨程式參數
906 * @param {object} value 傳入格式{ "key1":"value1", "key2":"value2" }
907 * @param {object} call 後續要做的事
908 */
909function setCache(value, call) {
910    var obj = {};
911    obj.Fields = value;
912
913    $.ajax({
914        url: $("#SetCache").data('url'),
915        data: obj,
916        type: 'Post',
917        dataType: 'json',
918        success: function (data) {
919
920            if (data == null || data.state == "ERROR") {
921                ErrorMessage(data.message);
922            }
923            else if(call !== undefined) {
924                call();
925            }
926        },
927        error: function (xhr, ajaxOptions, thrownError) {
928            ErrorMessage(thrownError);
929        }
930    });
931}
932
933/**
934 * 取出自訂跨程式參數
935 * @param {object} key 取出的key
936 * @param {object} textID 存放位置的text id
937 */
938    function getCache(key, textID) {
939    $.ajax({
940        url: $("#GetCache").data('url'),
941        type: 'Post',
942        dataType: 'json',
943        success: function (data) {
944            if (data === null || data.state === "ERROR") {
945                ErrorMessage(data.message);
946            }
947            else {
948                var record = data.data;
949                //Console(record);
950                
951                //if (typeof session !== "undefined") {
952                //    session = record;
953                //}
954
955                if (record != null && record[key] != null && record[key] != "") {
956                    Console("getCache");
957                    Console(record[key]);
958                    $("#" + textID).val(record[key]);
959                }
960
961    
962            }
963        },
964        error: function (xhr, ajaxOptions, thrownError) {
965            ErrorMessage(thrownError);
966        }
967    });
968}
969
970//=======================================================================================
971//自訂function
972//=======================================================================================
973
974/**
975 * 將後端Serialize後的object字串轉回object
976 * @param {any} inputJson
977 */
978function JsonToObject(inputJson) {
979
980    inputJson = inputJson.replace(/&quot;/g, '"');
981    if (!inputJson) jsonFavShow = "{}";
982
983    return JSON.parse(inputJson);
984}
985
986function HtmlEncode(s) {
987    var div = document.createElement('div');
988    div.appendChild(document.createTextNode(s));
989    return div.innerHTML;
990}
991function EtmlDecode(s) {
992    var div = document.createElement('div');
993    div.innerHTML = s;
994    return div.innerText || div.textContent;
995}
996
997//清空form
998function ResetForm(formId) {
999    
1000    let form = document.getElementById(formId);
1001
1002    //清除keyin資料
1003    //document.getElementById(formId).reset();
1004    $(form).trigger("reset");
1005
1006    //清除selectpicker資料
1007    //$(form).find('.selectpicker').val('');
1008    $(form).find('.selectpicker').selectpicker('val', '');
1009    $(form).find('.selectpicker').selectpicker('refresh');
1010    
1011    //#region 清除value本身資料
1012    // clearing inputs
1013    var inputs = form.getElementsByTagName('input');
1014    for (var i = 0; i < inputs.length; i++) {
1015        switch (inputs[i].type) {
1016            case 'hidden':
1017                inputs[i].value = '';
1018                break;
1019            case 'text':
1020                inputs[i].value = '';
1021                break;
1022            case 'radio':
1023            case 'checkbox':
1024                inputs[i].checked = false;
1025        }
1026    }
1027
1028    // clearing selects
1029    var selects = form.getElementsByTagName('select');
1030    for (var i = 0; i < selects.length; i++)
1031        selects[i].selectedIndex = 0;
1032
1033    // clearing textarea
1034    var text = form.getElementsByTagName('textarea');
1035    for (var i = 0; i < text.length; i++)
1036        text[i].innerHTML = '';
1037
1038    //#endregion
1039
1040    return false;
1041}
1042
1043//對象類別下拉選單動態控制
1044function SetC1IDListChangeAction(C3ItemJson) {
1045
1046    var C3Item = JsonToObject(C3ItemJson);
1047
1048    //編輯頁面依保護司司/各地檢更新對象類別下拉選單
1049    $("[id$=c1Value]").change(function () {
1050
1051        var c1ID = $(this).attr('ID');
1052        var c3ID = '';
1053        if (c1ID == 'c1Value') {
1054            c3ID = 'c3Value';
1055        }
1056        if (c1ID == 'qc1Value') {
1057            c3ID = 'qc3Value';
1058        }
1059
1060        //Console(c1ID+' '+c3ID);
1061
1062        //清空下拉選單
1063        $('#' + c3ID + ' option:not(.bs-title-option)').remove();
1064
1065        //新增選單項目
1066        var c1Selected = this.value;
1067        $.each(C3Item, function (index, value) {
1068            if (c1Selected == value.C1ID) {
1069                $('#' + c3ID + ' .bs-title-option').after("<option value='" + value.C3ID + "'>" + value.C3Name + "</option>")
1070            }
1071        });
1072
1073        if ($('#' + c3ID + ' option:not(.bs-title-option)').length == 0) {
1074            $('#' + c3ID).selectpicker({ title: '--請先選擇保護司/各地檢--' });
1075        } else {
1076            //編輯狀態 add emptyitem
1077            if (c1ID == 'qc1Value') {
1078                $('#' + c3ID + ' .bs-title-option').after("<option value=''>--請選擇--</option>")
1079            }
1080
1081            $('#' + c3ID).selectpicker({ title: '--請選擇--' });
1082        }
1083
1084        //refresh
1085        $('#' + c3ID).selectpicker('refresh');
1086
1087    });
1088}
1089
1090//secure random
1091function SecurRandom() {
1092    var array = new Uint32Array(1)
1093    var crypto = window.crypto || window.msCrypto;
1094    crypto.getRandomValues(array);
1095    return array[0] / (0xFFFFFFFF + 1);
1096}

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.