;$(function()
{
    setTimeout(showSpugConfig, 100);
});

window.osChange = function()
{
    const osName = $('[name="osName"]').val();
    if(typeof osName === 'undefined') return;

    toggleLoading('#osVersion', true);
    const $picker = $('[name="osVersion"]').zui('picker');
    if(typeof $picker === 'undefined') return;

    $picker.$.clear();
    if(!osName)
    {
        $picker.render({items: []});
        toggleLoading('#osVersion', false);
        return;
    }

    $.getJSON($.createLink('host', 'ajaxGetOS', 'type=' + osName), function(items)
    {
        $picker.render({items: items});
        if(typeof(host) !== 'undefined') $picker.$.setValue(host.osVersion);
        toggleLoading('#osVersion', false);
    });
};

window.showSpugConfig = function()
{
    const CD = $('[name="CD"]');
    if(typeof(CD) == 'undefined') return;

    const type = $('[name="CD"]').val();
    const edit = $('#hostEditForm');
    if(type == 'spug')
    {
        $('.spugConfig').removeClass('hidden');
        $('#remoteIP').find('input').removeAttr('disabled');
        $('#extranetID').find('input').attr('disabled', true);
        $('#osRow').addClass('hidden');
        if(!edit.length)
        {
            $('#ipRow').addClass('hidden');
            $('#cpuRow').addClass('hidden');
            $('#diskRow').addClass('hidden');
        }
        $('#status').closest('.form-group').addClass('hidden');
    }
    else
    {
        $('.spugConfig').addClass('hidden');
        $('#remoteIP').find('input').attr('disabled', true);
        $('#extranetID').find('input').removeAttr('disabled');
        $('#osRow').removeClass('hidden');
        $('#ipRow').removeClass('hidden');
        $('#cpuRow').removeClass('hidden');
        $('#diskRow').removeClass('hidden');
        $('#status').closest('.form-group').removeClass('hidden');
    }
};
