(function () {
    function inject(id, url) {
        var target = document.getElementById(id);
        if (!target) {
            return;
        }

        var request = new XMLHttpRequest();
        request.open('GET', url, false);
        try {
            request.send(null);
        } catch (err) {
            console.error('Failed to load ' + url + ':', err);
            return;
        }

        if (request.status >= 200 && request.status < 300) {
            target.innerHTML = request.responseText;
        } else {
            console.error('Failed to load ' + url + ': ' + request.status);
        }
    }

    inject('site-header', '/includes/nav.php');
    inject('site-footer', '/partials/footer.html');
})();
