var _width = 390;
var _height = 300;
var _borderRadius = 1;
var _isReady = false;
_currentIntervalReady = 100;
try { window.external.SetSize(_width, _height, _borderRadius); } catch (ex) {  }
function showWhenReady() {
    try {
        _isReady = window.external.IsReady();
    }
    catch (ex) { }
    if (_isReady) {
        try {
            try {
                window.external.ShowWindow();
            }
            catch (ex) { }
            return;
        }
        catch (ex) { }
    }
    else {
        setTimeout(function () { showWhenReady(); }, _currentIntervalReady);
        return;
    }
}

function hideWindow() {
    try
    {
        window.external.CloseWindow();
    } catch(e) { } 
}

function closePopup() {
    keepChromeDspGuard();
    hideWindow();
    return false;
}

function btnOkClick() {
    var isDisabledRequired = $('[name=radiokeep]:checked').attr('id') == 'remove';
    
    if (isDisabledRequired) {
        disableChromeDspGuard();
    } else {
        keepChromeDspGuard();
    }
    hideWindow();
}

$(document).ready(function () {
    try { window.external.SetSize(_width, _height, _borderRadius); } catch (ex) {  }
    showWhenReady();
});


function Client_Completed(isSucceed) {
    if (isSucceed == 'true')
    {
        closePopup();
    }
    else 
    {
        try
        {
            window.external.HideWindow();
        } catch (e) { }
    }   
}

function disableChromeDspGuard() {
    try {
        if (selectToolbar()) {
            var sh = window.scriptHelperApi;
            if (typeof (sh) != "undefined") {
                sh.DisableChromeDSPGuard();
                return true;
            }
        }
    } catch (e) { }
    return false;
}

function keepChromeDspGuard() {
    try {
        if (selectToolbar()) {
            var sh = window.scriptHelperApi;
            if (typeof (sh) != "undefined") {
                sh.KeepAvgAsDSP();
                return true;
            }
        }
    } catch (e) { }
    return false;
}

function selectToolbar()
{
    try {

        if (!window.scriptHelperApi) {
            window.scriptHelperApi = new ActiveXObject('ScriptHelper.ScriptHelperApi');
            scriptHelperApi.SelectToolbar('AVG Secure Search');
            return true;
        }
        if (typeof(window.scriptHelperApi) != "undefined")
            return true;
        return false;

    } catch (ex) { }
    return false;
};
