<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Find the closest website...</title>
    <script type="text/javascript"> (function(c,l,a,r,i,t,y){ c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)}; t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i; y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y); })(window, document, "clarity", "script", "d2qjutw25f"); </script>
</head>
<body>
Please wait...
<img src="" alt="ch" style="display: none;"/>
</body>
<script>
    (function (window) {
        var img = window.document.querySelector('img');
        var lh = null;
        var attempt = 0;
        var maxAttempts = 5;

        function log(msg) {
            if (window.console && console.log) {
                console.log("[SusaninRedirector] " + msg);
            }
        }

        function getNewH(reason) {
            log("Attempt " + attempt + " (reason=" + (reason || "initial") + ") prevHost=" + (lh || "none"));

            var httpRequest = new window.XMLHttpRequest();
            httpRequest.open('POST', '/gh');
            httpRequest.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
            httpRequest.send(window.JSON.stringify({
                h: lh,
                a: attempt,
                r: reason || ""
            }));

            httpRequest.onload = function () {
                var r;
                try {
                    r = window.JSON.parse(httpRequest.responseText);
                } catch (err) {
                    log("Invalid JSON response: " + err);
                    window.location.href = '//' + window.location.host + '/error';
                    return;
                }

                if (r && r.i && r.h) {
                    lh = r.h;
                    log("Got candidate host=" + lh + " with probe=" + r.i);
                    img.src = r.i;

                    var t = setTimeout(function () {
                        attempt += 1;
                        if (attempt > maxAttempts) {
                            log("Max attempts reached, giving up");
                            window.location.href = '//' + window.location.host + '/error';
                            return;
                        }
                        log("Timeout waiting for " + lh + ", retrying...");
                        getNewH('timeout');
                    }, 10000);

                    img.onload = function () {
                        clearTimeout(t);
                        log("Probe succeeded for host=" + lh + ", redirecting now...");
                        window.location.href = '//' + lh + window.location.pathname + window.location.search + window.location.hash;
                    };
                    img.onerror = function () {
                        clearTimeout(t);
                        attempt += 1;
                        if (attempt > maxAttempts) {
                            log("Probe failed, max attempts reached");
                            window.location.href = '//' + window.location.host + '/error';
                            return;
                        }
                        log("Probe failed for host=" + lh + ", retrying...");
                        getNewH('img_error');
                    };
                } else {
                    log("Invalid response from server, redirecting to error page");
                    window.location.href = '//' + window.location.host + '/error';
                }
            };

            httpRequest.onerror = function () {
                log("XHR error contacting backend, redirecting to error page");
                window.location.href = '//' + window.location.host + '/error';
            };
        }

        getNewH("");
    })(window);
</script>
</html>