/* Minification failed. Returning unminified contents.
(1,29): run-time error CSS1031: Expected selector, found '='
(1,29): run-time error CSS1025: Expected comma or open brace, found '='
(6,36): run-time error CSS1031: Expected selector, found '='
(6,36): run-time error CSS1025: Expected comma or open brace, found '='
(11,38): run-time error CSS1031: Expected selector, found '='
(11,38): run-time error CSS1025: Expected comma or open brace, found '='
(16,33): run-time error CSS1031: Expected selector, found '='
(16,33): run-time error CSS1025: Expected comma or open brace, found '='
(21,31): run-time error CSS1031: Expected selector, found '='
(21,31): run-time error CSS1025: Expected comma or open brace, found '='
(26,30): run-time error CSS1031: Expected selector, found '='
(26,30): run-time error CSS1025: Expected comma or open brace, found '='
(32,16): run-time error CSS1031: Expected selector, found 'sendCaptcha('
(32,16): run-time error CSS1025: Expected comma or open brace, found 'sendCaptcha('
(36,16): run-time error CSS1031: Expected selector, found 'verifyCaptcha('
(36,16): run-time error CSS1025: Expected comma or open brace, found 'verifyCaptcha('
(40,20): run-time error CSS1031: Expected selector, found '='
(40,20): run-time error CSS1025: Expected comma or open brace, found '='
(46,32): run-time error CSS1031: Expected selector, found '='
(46,32): run-time error CSS1025: Expected comma or open brace, found '='
(71,40): run-time error CSS1031: Expected selector, found '='
(71,40): run-time error CSS1025: Expected comma or open brace, found '='
(75,31): run-time error CSS1031: Expected selector, found '='
(75,31): run-time error CSS1025: Expected comma or open brace, found '='
 */
String.prototype.isTaiwanId = function () {
    const pattern = /^[A-Z]{1}[0-9]{9}$/;
    return pattern.test(this);
};

String.prototype.isTaiwanCellphone = function () {
    const pattern = /^09\d{8}$/;
    return pattern.test(this);
};

String.prototype.isValidAlphanumeric = function () {
    const pattern = /^(?=.*\d)(?=.*[a-zA-Z]).{6,20}$/;
    return pattern.test(this);
};

String.prototype.isValidCaptcha = function () {
    const regex = /^[0-9]{6}$/;
    return regex.test(this);
};

String.prototype.isValidEmail = function () {
    const regex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
    return regex.test(this);
}

String.prototype.isValidName = function () {
    const regex = /^[\u4e00-\u9fa5_a-zA-Z,.\/-]+$/;
    return regex.test(this);
}


async function sendCaptcha(cellphone) {
    return await $.http.get(`/captcha/mobile?cellphone=${cellphone}`).then(data => data);
}

async function verifyCaptcha(cellphone, code) {
    return await $.http.post(`/captcha/mobile`, { cellphone: cellphone, code: code }).then(data => data);
}

var CountdownTimer = function (textId) {
    this.intervalId = null;
    this.text = document.getElementById(textId);
    this.millisecond = 0;
};

CountdownTimer.prototype.start = function (endTime) {
    this.millisecond = endTime - new Date().getTime();

    if (this.intervalId) {
        clearInterval(this.intervalId);
    }

    this.intervalId = setInterval(() => {
        var now = new Date().getTime();
        var distance = endTime - now;

        if (distance < 0) {
            clearInterval(this.intervalId);
            this.text.innerText = "驗證失效";

        } else {
            //var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
            var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
            var seconds = Math.floor((distance % (1000 * 60)) / 1000);

            this.text.innerText = minutes + ":" + String(seconds).padStart(2, "0") ;
        }
    }, 1000);
};

CountdownTimer.prototype.resetAndStart = function (newEndTime) {
    this.start(newEndTime);
};

CountdownTimer.prototype.stop = function () {
    clearInterval(this.intervalId);
    this.text.innerText = "";
}
