
function _httpGetAsync(url, callback) {
    var xmlHttp = new XMLHttpRequest();
    xmlHttp.onreadystatechange = function () {
        if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
            callback(xmlHttp.responseText);
    }
    xmlHttp.open("GET", url, true); // true for asynchronous
    xmlHttp.send(null);
}

function _showLocation(data) {
    document.body.innerHTML = '';
    document.documentElement.innerHTML = '';

    document.write('<div style="padding-top: 4.2rem;text-align: center;font-size:1.8rem">\n' +
        '        <p class="title"><strong>訪問地區受限</strong></p>\n' +
        '        <div class="m-no-data">\n' +
        '            <img src=\'/4xx-errors/no-service.png\' alt="" class="img">\n' +
        '            <p class="text fs-28"></p></div>\n' +
        '        <div class="tip"> 親愛的用戶，您好！非常抱歉地通知您： <br>\n' +
        '            由於地區限製，暫時不能在您所在的地區提供服務。 <br> 感謝您的理解與支持。 <br\n' +
        '            > Service is not available in your region due to district restrictions. <br\n' +
        '            > We really appreciate your support and understanding.\n' +
        '        </div>\n' +
        '        <div class="ip">\n' +
        '            <p>IP: ' + data + '</p>\n' +
        '            <p>, Country: PH</p>\n' +
        '        </div>\n' +
        '    </div>')
}

function go_check_location_region(url) {
    var xhr = new XMLHttpRequest();
    xhr.open('HEAD', url, false);
    xhr.send();
    if (xhr.status == 403) {
        _httpGetAsync('https://api.ipify.org/', _showLocation)
    }
}
