// Set up jQuery to not cache requests
$.ajaxSetup({ cache: false });

// Get the host info, used by the main page
function GetHostInfo() {
    // There has to be a better way to do this :D
    $('#ipv4-spin').show();
    $('#ipv6-spin').show();
    $('#ipv4-reload').hide();
    $('#ipv6-reload').hide();

    $.getJSON("/Home/GetHostInfo/", null, function(data) {
        if (!data.CE) {
            $('#pe').text("You need to enable cookies to view this site, you could alternatively try the <a href='http://old.myip.dk'>old verison of site</a>");
            $('#pe').show();
        }
        else
        { $('#pe').hide(); }        
        if (!data.IPV6) {
            $('#ipv4').show();
            $('#ipv6').hide();
            document.title = data.HA4;
            $('.ha4').text(data.HA4);
            $('.hn4').text(data.HN4);
        }
        else {
            $('#ipv4').hide();
            $('#ipv6').show();
            document.title = data.HA6;
            $('.ha6').text(data.HA6);
            $('.hn6').text(data.HN6);
        }

        $('#ipv4-spin').hide();
        $('#ipv6-spin').hide();
        $('#ipv4-reload').show();
        $('#ipv6-reload').show();
    });
}

// Used for XHTML 1.0 Strict, _target compat. links
$(function() {
    $('a.new-window').click(function() {
        window.open(this.href);
        return false;
    });
});

// Bind the reload ipv4 button on the main page
$(document).ready(function() {
    $('#ipv4-reload').click(function() {
        $('#ipv4-reload').hide();
        $('#ipv4').hide();
        $('#ipv4-spin').show();

        $.getJSON("/Home/GetHostInfo4/", null, function(data) {
            $('.ha4').text(data.HA);
            $('.hn4').text(data.HN);

            $('#ipv4-spin').hide();
            $('#ipv4-reload').show();

            if (data.VA) {
                $('#ipv4').show();
                document.title = data.HA;
            }
        });
    });
});

// Bind the reload ipv6 button on the main page
$(document).ready(function() {
    $('#ipv6-reload').click(function() {
        $('#ipv6-reload').hide();
        $('#ipv6').hide();
        $('#ipv6-spin').show();

        $.getJSON("/Home/GetHostInfo6/", null, function(data) {
            $('.ha6').text(data.HA);
            $('.hn6').text(data.HN);

            $('#ipv6-spin').hide();
            $('#ipv6-reload').show();

            if (data.VA) {
                $('#ipv6').show();
                document.title = data.HA;
            }
        });
    });
});
