function __checkSiteUrl (window) {
    window.$ && window.$.ajaxSetup && window.$.ajaxSetup({
        complete: function (XMLHttpRequest, textStatus) {

            __checkURL();

        }
    });

    var __orgin__window__open = window.open;

    window.open = function (href) {
        if (href.indexOf('http') > -1 && href.indexOf('gov.cn') === -1 && href.indexOf(window.location.host) === -1) {
            __open_modal(href);
        } else {
            __orgin__window__open(href);
        }
    };

    function __open_modal (href) {
        if (window.UI && window.UI.modal) {
            window.UI.modal.confirm({
                text: '您访问的链接即将离开本网站，是否继续？',
                button: ['确定', '取消'],
                okCallback: function () {
                    __orgin__window__open(href);
                }
            });
        } else {
            var res = window.confirm('您访问的链接即将离开本网站，是否继续？');
            if (res) {
                __orgin__window__open(href);
            }
        }

    }

    function __checkURL () {
        setTimeout(function () {
            $('a').each(function (idx, val) {
                var $this = $(val);
                var href = $this.prop('href');
                if (href) {
                    $this.off('click').on('click', function (e) {
                        var __this = $(this);

                        if (__this.hasClass('nfw-disable-jump')) {
                            e.preventDefault();
                            return;
                        }

                        var href = __this.prop('href');
                        if (href && (!href.indexOf('http') || !href.indexOf('//')) && href.indexOf('gov.cn') === -1 && href.indexOf(window.location.host) === -1) {
                            e.preventDefault();
                            __open_modal(href);
                        }

                    });
                }
            });
        }, 1500);
    }

    setTimeout(function () {
        var done = false;
        if (window.UI && window.UI.modal) {
            __checkURL();
        } else {
            var script = document.createElement('script');
            // script.src = '//cloudtest.southcn.com/static/footer/js/ui.js';
            script.src = '//app.gd.gov.cn/asset/publicui/ui.js';
            script.type = 'text/javascript';
            script.onload = script.onreadystatechange = function () {
                if (!done && (!this.readyState ||
                    this.readyState === 'loaded' || this.readyState === 'complete')) {
                    done = true;

                    script.onload = script.onreadystatechange = null;
                    __checkURL();
                }
            };
            document.body.appendChild(script);
        }
    });

    window.__orgin__window__open = __orgin__window__open;
    window.__open_modal = __open_modal;
    window.__checkURL = __checkURL;
}

__checkSiteUrl(window);
