PageSourceSearch

https://www.westgarden.com.tw/wp-content/themes/medicenter-child/js/add-reg.js?v=1790317523

js westgarden.com.tw collected 2026-09-25 06:25:33 UTC 28,732 bytes, 729 lines download raw bytes

1jQuery(function ($) {
2    jQuery(document).ready(function () {
3        $('#addRegBtn').on('click', function () {
4            $("body, input[type='button']").css('cursor', 'progress');
5            var url = window.location.protocol + '//' + window.location.host + (window.location.href.includes('/wes/') ? '/wes' : '') + '/recaptcha';
6            $.ajax({
7                url: url,
8                method: 'POST',
9                //data: {data: grecaptcha.getResponse()},
10                data: { data: $('#checkword').val() },
11            }).done(function (response) {
12                var result = JSON.parse(response);
13                if (result.success == true) {
14                    addReg(false);
15                } else {
16                    $('body').css('cursor', 'default');
17                    $("input[type='button']").css('cursor', 'pointer');
18                    alert('請輸入正確的驗證碼!');
19                    refresh_captcha();
20                }
21            });
22        });
23
24        $('#isFirst').on('click', function () {
25            console.log('isFirst click');
26
27            var phone = $('#txtPhone').val();
28            var name = $('#txtName').val();
29            var idNo = $('#txtId').val();
30
31            console.log(phone + name + idNo);
32
33            if (!checkNameAndPhone(name, phone)) {
34                resetCursor();
35                return;
36            }
37
38            $('#firstOrderError').css('display', 'none');
39            $("body, input[type='button']").css('cursor', 'progress');
40
41            // 先掛號,掛號成功(狀態碼 0 或 1)才建立初診資料
42            addReg(true, function (regStatus, xml) {
43                if (!isRegSuccess(regStatus)) {
44                    resetCursor();
45                    showFirstOrderError(getRegMessage(xml) || '初診預約失敗,請稍後再試!');
46                    return;
47                }
48
49                $.ajax({
50                    url: 'https://regweb.westgarden.com.tw/GetOrderV8/WebOrder.svc/FirstOrder',
51                    method: 'POST',
52                    // contentType: 'application/json',
53                    data: JSON.stringify({
54                        order: {
55                            IDNO: idNo,
56                            NAME: name,
57                            HTEL: phone,
58                        },
59                    }),
60                })
61                    .done(function (response) {
62                        displayAddResult(xml);
63                        // 掛號已成立,僅初診資料未建檔,保留掛號並提示至櫃檯補件
64                        if (!response || response.d !== 'OK') {
65                            appendFirstOrderNotice();
66                        }
67                        resetCursor();
68                    })
69                    .fail(function () {
70                        displayAddResult(xml);
71                        appendFirstOrderNotice();
72                        resetCursor();
73                    });
74            });
75        });
76
77        $('#queryRegBtn').on('click', function () {
78            $("body, input[type='button']").css('cursor', 'progress');
79            var url = window.location.protocol + '//' + window.location.host + (window.location.href.includes('/wes/') ? '/wes' : '') + '/recaptcha';
80            $.ajax({
81                url: url,
82                method: 'POST',
83                //data: {data: grecaptcha.getResponse()},
84                data: { data: $('#checkword').val() },
85            }).done(function (response) {
86                var result = JSON.parse(response);
87                if (result.success == true) {
88                    queryReg(false);
89                } else {
90                    $('body').css('cursor', 'default');
91                    $("input[type='button']").css('cursor', 'pointer');
92                    alert('請輸入正確的驗證碼!');
93                    refresh_captcha();
94                }
95            });
96        });
97
98        $('#isFirstQuery').on('click', function () {
99            $("body, input[type='button']").css('cursor', 'progress');
100            queryReg(true);
101        });
102
103        $('#notFirst').on('click', function () {
104            //grecaptcha.reset();
105            refresh_captcha();
106            $('#checkFirst').css('display', 'none');
107            $('#notFirstNote, #notFirstNote p').css('display', 'block');
108            $('#regSubmit').css('display', 'block');
109
110            scrollToMiddle('#notFirstNote');
111        });
112
113        $('#cancelRegBtn').on('click', function () {
114            $('#cancelRegBtn').css('display', 'none');
115            $('#confirmCancel').css('display', 'block');
116        });
117
118        $('#confirmNo').on('click', function () {
119            $('#cancelRegBtn').css('display', 'block');
120            $('#confirmCancel').css('display', 'none');
121        });
122
123        $('#confirmYes').on('click', function () {
124            $("body, input[type='button']").css('cursor', 'progress');
125            $.each($('.appointment:checked'), function (i, ap) {
126                var self = this;
127                var info = $(this).parent().parent();
128                var dr = info.attr('dr');
129                var dept = info.attr('dept');
130                var schAp = info.attr('schAp');
131                var schDate = info.attr('schDate');
132                var isFirst = info.attr('isFirst');
133                var patNo = info.attr('patNo');
134                var idNo = info.attr('idNo');
135                var birth = info.attr('birth');
136
137                $.ajax({
138                    url: window.location.protocol + '//' + window.location.host + (window.location.href.includes('/wes/') ? '/wes' : '') + '/process-reg',
139                    method: 'POST',
140                    data: {
141                        data: {
142                            type: 'cancel',
143                            patNo: patNo,
144                            idNo: idNo,
145                            birth: birth,
146                            schDate: schDate,
147                            schAp: schAp,
148                            dept: dept,
149                            dr: dr,
150                            isFirst: isFirst,
151                        },
152                    },
153                }).done(function (xml) {
154                    $.each($(xml).find('Appointment'), function (i, ap) {
155                        if (dr == $(ap).find('Dr')[0].innerHTML && dept == $(ap).find('Dept')[0].innerHTML && schAp == $(ap).find('SchAp')[0].innerHTML && schDate == $(ap).find('SchDateString')[0].innerHTML) {
156                            var text = $(ap).find('Message')[0].innerHTML;
157                            $(self)
158                                .parent()
159                                .html('<div>
159' + text + '</div>');
160                            return false;
161                        }
162                    });
163                    if ($(document).find('input.appointment').length == 0) {
164                        $('#cancelRegBtn').css('display', 'none');
165                    }
166                });
167            });
168            if ($(document).find('input.appointment').length > 0) {
169                $('#cancelRegBtn').css('display', 'block');
170            }
171            $('#confirmCancel').css('display', 'none');
172            $('body').css('cursor', 'default');
173            $("input[type='button']").css('cursor', 'pointer');
174        });
175
176        $('#refresh-captcha').on('click', function () {
177            refresh_captcha();
178        });
179    });
180
181    function addReg(isFirst, onBooked) {
182        var dr = $('#bookDr').text();
183        var dept = $('#bookDept').text();
184        var schDate = $('#bookSchDate').text();
185        var schAp = $('#bookSchAp').text();
186
187        var textBirth = $('#txtBirth').val();
188        var textId = $('#txtId').val();
189
190        if (checkIdAndBirth(textId, textBirth) == false) {
191            //grecaptcha.reset();
192            refresh_captcha();
193            $('body').css('cursor', 'default');
194            $("input[type='button']").css('cursor', 'pointer');
195            return;
196        }
197
198        var birth = verifyBirth(textBirth);
199        var isIdno = verifyId(textId);
200        var patNo = '',
201            idNo = '';
202        if (isIdno == false) {
203            patNo += textId;
204        } else {
205            idNo += textId;
206        }
207        let protocol = window.location.protocol; // 改為當前連線得通訊協定(避免內網無法掛號)
208        var url = protocol + '//regweb.westgarden.com.tw/Regsource/regws.asmx/Reg_Book?strPatno=' + patNo + '&strIdno=' + idNo + '&strBirth=' + birth + '&strWebword=&strSchdate=' + schDate + '&strSchap=' + schAp + '&strDept=' + dept + '&strDr=' + dr + '&strFirstvisit=';
209        // var url = "http://regweb.westgarden.com.tw/Regsource/regws.asmx/Reg_Book?strPatno=" + patNo + "&strIdno=" + idNo + "&strBirth=" + birth + "&strWebword=&strSchdate=" + schDate + "&strSchap=" + schAp + "&strDept=" + dept + "&strDr=" + dr + "&strFirstvisit=";
210
211        if (isFirst) url += 'true';
212        $.ajax({
213            url: url,
214            // url: window.location.protocol + "//" + window.location.host + (window.location.href.includes('/wes/')) ? '/wes' : '' + "/process-reg",
215            // method: "POST",
216            // data: {
217            // 	data: {
218            // 		"type":"add",
219            // 		"patNo":patNo,
220            // 		"idNo":idNo,
221            // 		"birth":birth,
222            // 		"schDate":schDate,
223            // 		"schAp":schAp,
224            // 		"dept":dept,
225            // 		"dr":dr,
226            // 		"isFirst":(isFirst)?"true":"",
227            // 	}
228            // }
229        })
230            .done(function (xml, status, jqXHR) {
231                xml = jqXHR.responseText;
232
233                // 初診掛號的結果交由呼叫端依狀態碼判斷
234                if (typeof onBooked === 'function') {
235                    onBooked(getRegStatus(xml), xml);
236                    return;
237                }
238
239                if ($(xml).find('Appointment').length == 0) {
240                    var msg = $(xml).find('Message')[0].innerHTML;
241                    if (msg.indexOf('無病歷號') >= 0) {
242                        $('#toSubmit').css('display', 'none');
243                        $('#regSubmit').css('display', 'none');
244                        $('#checkFirst').css('display', 'block');
245                        $('#first-fieldsets').css('display', 'block');
246                        $('#notFirstNote').css('display', 'none');
247                        $('input').prop('disabled', false);
248                        resetCursor();
249
250                        scrollToMiddle('#checkFirst');
251
252                        return;
253                    } else if (msg.indexOf('身分證號錯誤') >= 0 || msg.indexOf('病歷號碼錯誤') >= 0) {
254                        $('#invalidId').css('display', 'block');
255                        resetCursor();
256                        scrollToMiddle('#invalidId');
257                        return;
258                    }
259                    //grecaptcha.reset();
260                    refresh_captcha();
261                } else {
262                    if ($(xml).find('Appointment SchDate').length == 0) {
263                        refresh_captcha();
264                        $('#checkFirst').css('display', 'none');
265                        $('#notFirstNote, #notFirstNote p').css('display', 'block');
266                        $('#regSubmit').css('display', 'block');
267                        return;
268                    }
269                    displayAddResult(xml);
270                }
271                resetCursor();
272            })
273            .fail(function () {
274                resetCursor();
275                if (typeof onBooked === 'function') {
276                    onBooked('', '');
277                    return;
278                }
279                alert('掛號失敗,請稍後再試!');
280            });
281    }
282
283    function queryReg(isFirst) {
284        var textBirth = $('#txtBirth').val();
285        var textId = $('#txtId').val();
286
287        if (checkIdAndBirth(textId, textBirth) == false) {
288            //grecaptcha.reset();
289            refresh_captcha();
290            $('body').css('cursor', 'default');
291            $("input[type='button']").css('cursor', 'pointer');
292            return;
293        }
294
295        var birth = verifyBirth(textBirth);
296        var isIdno = verifyId(textId);
297        var patNo = '',
298            idNo = '';
299        if (isIdno == false) {
300            patNo += textId;
301        } else {
302            idNo += textId;
303        }
304        let queryRegUrl = window.location.protocol + '//' + window.location.host + (window.location.href.includes('/wes/') ? '/wes' : '') + '/process-reg';
305
306        $.ajax({
307            url: window.location.protocol + '//' + window.location.host + (window.location.href.includes('/wes/') ? '/wes' : '') + '/process-reg',
308            method: 'POST',
309            data: {
310                data: {
311                    type: 'query',
312                    patNo: patNo,
313                    idNo: idNo,
314                    birth: birth,
315                    isFirst: isFirst ? 'true' : '',
316                },
317            },
318        }).done(function (xml) {
319            if ($(xml).find('Appointment').length == 0) {
320                var msg = $(xml).find('Message')[0].innerHTML;
321                if (msg.indexOf('無病歷號') >= 0) {
322                    $('#regSubmit').css('display', 'none');
323                    $('#checkFirst').css('display', 'block');
324                    $('#notFirstNote').css('display', 'none');
325                    $('input').prop('disabled', false);
326                    $('body').css('cursor', 'default');
327                    $("input[type='button']").css('cursor', 'pointer');
328
329                    scrollToMiddle('#checkFirst');
330                    return;
331                } else if (msg.indexOf('身分證號錯誤') >= 0 || msg.indexOf('病歷號碼錯誤') >= 0) {
332                    $('#invalidId').css('display', 'block');
333                    $('body').css('cursor', 'default');
334                    $("input[type='button']").css('cursor', 'pointer');
335                    scrollToMiddle('#invalidId');
336                    return;
337                } else if (msg.indexOf('無預約資料') >= 0) {
338                    $('#patName').text($(xml).find('PatInfo Name')[0].innerHTML);
339                    $('#tblInput').css('display', 'none');
340                    $('#tblList').css('display', 'table');
341                    $('#queryMsg').css('display', 'block');
342                    scrollToMiddle('#tblInput');
343                }
344                //grecaptcha.reset();
345                refresh_captcha();
346            } else {
347                displayQueryResult(xml);
348            }
349            $('body').css('cursor', 'default');
350            $("input[type='button']").css('cursor', 'pointer');
351        });
352    }
353
354    function displayAddResult(xml) {
355        var name;
356        var resultMsg = '';
357        var isFirstVisit = $(xml).find('PatInfo FirstVisit').length > 0 && $(xml).find('PatInfo FirstVisit')[0].innerHTML === 'true';
358        var topNotice = '';
359        var num;
360        var isFail = false;
361
362        if (isFirstVisit) {
363            name = $('#txtName').val();
364            // 依掛號狀態碼判斷成敗,不能只看 Message 節點是否存在(失敗時同樣有該節點)
365            if (isRegSuccess(getRegStatus(xml))) {
366                resultMsg += '初診掛號 取號成功';
367                // 新增初診提醒訊息
368                topNotice = '<p>溫馨提醒:初診掛號 取號成功!</p>';
369                topNotice += '<p>請初診病患,看診當日先至1F櫃檯填寫初診資料,報到流程,請見下方說明。</p>';
370                topNotice += '<div class="yellow">初診報到流程:</br>(1) 1樓取號機【掛號】取號</br>(2) 依號至櫃檯填初診單查驗證件</br>(3) 診間報到機【插健保卡】報到</br></br>初診應備文件:</br>身分證、健保卡及相關身分文件</div>';
371            } else {
372                resultMsg += getRegMessage(xml) || '初診掛號失敗';
373                topNotice = '';
374                isFail = true;
375            }
376
377            num = '--';
378        } else {
379            name = $(xml).find('PatInfo Name').length > 0 ? $(xml).find('PatInfo Name')[0].innerHTML : '';
380            if ($(xml).find('Appointment Message').length > 0) {
381                resultMsg += $(xml).find('Appointment Message')[0].innerHTML;
382            }
383            num = $(xml).find('Appointment DigNo').length > 0 ? parseInt($(xml).find('Appointment DigNo')[0].innerHTML) + ' 號' : '';
384        }
385
386        $('#regTopNotes').html(topNotice);
387
388        // var num = $(xml).find('Appointment DigNo').length > 0 ? parseInt($(xml).find('Appointment DigNo')[0].innerHTML) + ' 號' : '';
389
390        var place = '';
391        if ($(xml).find('Appointment Location').length > 0) {
392            place = $(xml).find('Appointment Location')[0].innerHTML;
393        } else if ($(xml).find('Appointment Room').length > 0) {
394            var room = $(xml).find('Appointment Room')[0].innerHTML;
395            if (room >= '01' && room <= '11') {
396                place = '1 樓 ' + room + ' 診';
397            } else if (room >= '12' && room <= '24') {
398                place = '2 樓 ' + room + ' 診';
399            } else if (room === '27') {
400                place = '6 樓 ' + room + ' 診';
401            } else if (room === '28') {
402                place = 'B1 樓 ' + room + ' 診';
403            } else {
404                place = room + ' 室';
405            }
406        }
407
408        $('#regName').text(name);
409        $('#resultMsg').text(resultMsg); //掛號成功或失敗
410        $('#regNum').text(num);
411        $('#regPlace').text(place);
412
413        var notice = '<ul>';
414
415        $.each($(xml).find('Notice Notice'), function (i, value) {
416            notice += '<li>' + value.innerHTML + '</li>';
417        });
418
419        if ($(xml).find('Notice Notice').length == 0) {
420            notice += '<li>候診參考時間,常會因當日醫師看診狀況而異動,建議先以網路或電話查詢看診進度,選擇適當時間到院。</li>';
421        }
422        notice += '</ul>';
423
424        $('#regNotes').html(notice);
425        $('#regContentInput').css('display', 'none');
426        $('#regSubmit').css('display', 'none');
427        $('#tblInput').css('display', 'none');
428        $('#tblResult').css('display', 'block');
429        if (isFail || resultMsg.indexOf('失敗') >= 0) {
430            // 收合後只會留下第一列(#regTopNotes),失敗訊息原本寫在第七列的
431            // #resultMsg 會一併被藏起來,導致畫面全白。因此收合前先把訊息補進第一列。
432            if (resultMsg !== '') {
433                $('#regTopNotes').html('<p style="color:red;">' + resultMsg + '</p>');
434            }
435            $('#tblResult tr').css('display', 'none');
436            $('#tblResult tr:first-child').css('display', 'block');
437        }
438
439        $('#checkFirst').css('display', 'none');
440        scrollToMiddle('#tblResult');
441    }
442
443    function displayQueryResult(xml) {
444        var name = $(xml).find('PatInfo Name')[0].innerHTML;
445        var isFirst = $(xml).find('PatInfo FirstVisit')[0].innerHTML;
446        var patNo = $(xml).find('PatInfo PatNo')[0].innerHTML;
447        var IDNo = $(xml).find('PatInfo IDNo')[0].innerHTML;
448        var birth = $(xml).find('PatInfo BirthString')[0].innerHTML;
449        var arr = ['上午', '下午', '夜診'];
450
451        $.each($(xml).find('Appointment'), function (i, ap) {
452            var date = $(ap).find('SchDateString')[0].innerHTML;
453            var dept = $(ap).find('Dept')[0].innerHTML;
454            var deptName = $(ap).find('DeptName')[0].innerHTML;
455            var dr = $(ap).find('Dr')[0].innerHTML;
456            var drName = $(ap).find('DrName')[0].innerHTML;
457            var room = $(ap).find('Room')[0].innerHTML;
458            var digNo = $(ap).find('DigNo')[0].innerHTML;
459            var schAp = $(ap).find('SchAp')[0].innerHTML;
460
461            if (deptName === '內科') {
462                deptName = '胸腔' + deptName;
463            }
464
465            var html = '<tr schDate="' + date + '" schAp="' + schAp + '" dept="' + dept + '" dr="' + dr + '" isFirst="' + isFirst + '" patNo="' + patNo + '" idNo="' + IDNo + '" birth="' + birth + '">';
466            html += '<td width="12%"><input type="checkbox" name="cbx-' + (i + 1) + '" class="appointment"></td>';
467            html += '<td width="18%">' + transDate(date) + ' ' + arr[schAp - 1] + '</td>';
468            html += '<td width="18%">' + deptName + '(' + dept + ')</td>';
469            html += '<td width="18%">' + drName + '(' + dr + ')</td>';
470            html += '<td width="15%">' + room + '</td>';
471            html += '<td width="15%">' + digNo + '</td>';
472            html += '</tr>';
473
474            $('#tblList').append(html);
475        });
476        $('#patName').text(name);
477        $('#tblInput').css('display', 'none');
478        $('#tblList').css('display', 'table');
479        $('#cancelRegBtn').css('display', 'block');
480        scrollToMiddle('#tblList');
481    }
482
483    function scrollToMiddle(element) {
484        var offset = $(element).offset().top;
485        var elementHeight = $(element).height();
486        var headerHeight = $('header').height();
487        var windowHeight = $(window).height() - headerHeight;
488        var newOffset = offset - headerHeight;
489        if (elementHeight >= windowHeight) {
490            newOffset -= 50;
491        } else {
492            newOffset -= (windowHeight - elementHeight) / 2;
493        }
494        $('html, body').animate({ scrollTop: newOffset }, 500);
495    }
496
497    function checkIdAndBirth(textId, textBirth) {
498        var result = true;
499        var birth = verifyBirth(textBirth);
500        var target = '';
501        if (birth == 'error') {
502            $('#invalidBirth').css('display', 'inline');
503            result = false;
504            target += '#invalidBirth';
505        } else {
506            $('#invalidBirth').css('display', 'none');
507        }
508
509        if (textId == '') {
510            $('#invalidId').css('display', 'inline');
511            result = false;
512            if (target == '') {
513                target += '#invalidId';
514            }
515        } else {
516            $('#invalidId').css('display', 'none');
517        }
518
519        if (!result) scrollToMiddle(target);
520
521        return result;
522    }
523
524    function checkNameAndPhone(name, phone) {
525        var result = true;
526        var target = '';
527
528        if (!name) {
529            $('#invalidName').css('display', 'inline');
530            result = false;
531            target += '#invalidName';
532        } else {
533            $('#invalidName').css('display', 'none');
534        }
535
536        if (!phone) {
537            $('#invalidPhone').css('display', 'inline');
538            result = false;
539            if (target == '') {
540                target += '#invalidPhone';
541            }
542        } else {
543            $('#invalidPhone').css('display', 'none');
544        }
545
546        if (!result) scrollToMiddle(target);
547
548        return result;
549    }
550
551    // 還原等待中的游標狀態
552    function resetCursor() {
553        $('body').css('cursor', 'default');
554        $("input[type='button']").css('cursor', 'pointer');
555    }
556
557    // Reg_Book 回傳的掛號狀態碼(Appointment > Status)
558    function getRegStatus(xml) {
559        var node = $(xml).find('Appointment Status');
560        return node.length > 0 ? $.trim(node.first().text()) : '';
561    }
562
563    // 僅 0(預約掛號成功)與 1(預約掛號成功,代診)視為成功,其餘一律當失敗
564    function isRegSuccess(regStatus) {
565        return regStatus === '0' || regStatus === '1';
566    }
567
568    // 取可顯示給民眾的訊息,優先取掛號結果,其次取病患資料的訊息
569    // 以 text() 取值,訊息含 & 等字元時才不會顯示成 HTML 逸出字串
570    function getRegMessage(xml) {
571        var nodes = [$(xml).find('Appointment Message'), $(xml).find('Message')];
572
573        for (var i = 0; i < nodes.length; i++) {
574            if (nodes[i].length > 0 && $.trim(nodes[i].first().text()) !== '') {
575                return $.trim(nodes[i].first().text());
576            }
577        }
578
579        return '';
580    }
581
582    function showFirstOrderError(msg) {
583        $('#firstOrderError').text(msg).css('display', 'block');
584        scrollToMiddle('#firstOrderError');
585    }
586
587    // 掛號已成立、僅初診資料未建檔時的補件提示
588    function appendFirstOrderNotice() {
589        $('#regTopNotes').append('<p style="color:red;">掛號已成功,但初診資料建立失敗,請於看診當日提早至 1F 櫃檯填寫初診單。</p>');
590    }
591
592    function refresh_captcha() {
593        $('#imgcode').attr('src', (window.location.href.includes('/wes/') ? '/wes' : '') + '/generate-captcha?' + Math.floor(Math.random() * 10000 + 1) + '">');
594        $('#checkword').val('');
595    }
596});
597
598function verifyBirth(textBirth) {
599    if (/\D/.test(textBirth)) return 'error';
600    var day = textBirth.slice(-2);
601    var month = textBirth.slice(-4, -2);
602    var year = textBirth.slice(0, -4);
603    var num_d, num_m, num_y;
604
605    num_d = parseInt(day);
606    num_m = parseInt(month);
607    num_y = parseInt(year);
608
609    if (isNaN(num_d) || isNaN(num_m) || isNaN(num_y)) return 'error';
610    if (num_y < 0 || num_y > new Date().getFullYear() - 1911) return 'error';
611    if (num_m < 1 || num_m > 12) return 'error';
612    var days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
613    if (num_d > days[num_m - 1]) {
614        if (num_m !== 2 || num_d !== 29) return 'error';
615    }
616
617    var str = num_y + 1911 + '' + month + '' + day;
618    return str;
619}
620
621function verifyId(textId) {
622    /*
623	//建立字母分數陣列(A~Z)
624	var city = [
625		1,10,19,28,37,46,55,64,39,73,82, 2,11,
626		20,48,29,38,47,56,65,74,83,21, 3,12,30
627	];
628	var id = textId.toUpperCase();
629
630	// 使用「正規表達式」檢驗格式
631	if (id.search(/^[A-Z](1|2)\d{8}$/i) == -1) {
632		return false;
633	} else {
634		//將字串分割為陣列(IE必需這麼做才不會出錯)
635		id = id.split('');
636		//計算總分
637		var total = city[id[0].charCodeAt(0)-65];
638		for(var i = 1; i <= 8; i++){
639			total += eval(id[i]) * (9 - i);
640		}
641
642		//補上檢查碼(最後一碼)
643		total += eval(id[9]);
644
645		//檢查比對碼(餘數應為0);
646		return ((total%10 == 0 ));
647	}
648	*/
649
650    if (IdCardNumberCheck(textId) == false) {
651        if (IdTextNumberCheck(textId) == false) {
652            return false;
653        }
654    }
655    return true;
656}
657
658function IdCardNumberCheck(id) {
659    var city = new Array(1, 10, 19, 28, 37, 46, 55, 64, 39, 73, 82, 2, 11, 20, 48, 29, 38, 47, 56, 65, 74, 83, 21, 3, 12, 30);
660    id = id.toUpperCase();
661    // 使用「正規表達式」檢驗格式
662    if (!id.match(/^[A-Z]\d{9}$/) && !id.match(/^[A-Z][A-D]\d{8}$/)) {
663        return false;
664    } else {
665        var total = 0;
666        if (id.match(/^[A-Z]\d{9}$/)) {
667            //身分證字號
668            //將字串分割為陣列(IE必需這麼做才不會出錯)
669            id = id.split('');
670            //計算總分
671            total = city[id[0].charCodeAt(0) - 65];
672            for (var i = 1; i <= 8; i++) {
673                total += eval(id[i]) * (9 - i);
674            }
675        } else {
676            // 外來人口統一證號
677            //將字串分割為陣列(IE必需這麼做才不會出錯)
678            id = id.split('');
679            //計算總分
680            total = city[id[0].charCodeAt(0) - 65];
681            // 外來人口的第2碼為英文A-D(10~13),這裡把他轉為區碼並取個位數,之後就可以像一般身分證的計算方式一樣了。
682            id[1] = id[1].charCodeAt(0) - 65;
683            for (var i = 1; i <= 8; i++) {
684                total += eval(id[i]) * (9 - i);
685            }
686        }
687        //補上檢查碼(最後一碼)
688        total += eval(id[9]);
689        //檢查比對碼(餘數應為0);
690        if (total % 10 == 0) {
691            return true;
692        } else {
693            return false;
694        }
695    }
696}
697
698function IdTextNumberCheck(id) {
699    var invalidList = '00000000,11111111';
700    if (/^\d{8}$/.test(id) == false || invalidList.indexOf(id) != -1) {
701        return false;
702    }
703
704    var validateOperator = [1, 2, 1, 2, 1, 2, 4, 1],
705        sum = 0,
706        calculate = function (product) {
707            // 個位數 + 十位數
708            var ones = product % 10,
709                tens = (product - ones) / 10;
710            return ones + tens;
711        };
712    for (var i = 0; i < validateOperator.length; i++) {
713        sum += calculate(id[i] * validateOperator[i]);
714    }
715
716    if (sum % 10 == 0 || (id[6] == '7' && (sum + 1) % 10 == 0)) {
717        return true;
718    } else {
719        return false;
720    }
721}
722
723function transDate(date) {
724    var day = date.slice(-2);
725    var month = date.slice(-4, -2);
726    var year = date.slice(0, -4);
727
728    return parseInt(year) - 1911 + '/' + month + '/' + day;
729}

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.