﻿
var Li = {};

Li.Win = {
    /* 设为首页 */
    setHomePage: function () {
        var url = 'http://' + document.location.host;
        if (document.all) {
            xa = $('a').get(0)
            xa.style.behavior = 'url(#default#homepage)';
            xa.setHomePage(url);
        }
        else if (window.sidebar) {
            try {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            } catch (e) {
                alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将[signed.applets.codebase_principal_support]设置为'true'");
            }
            var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
            prefs.setCharPref('browser.startup.homepage', url);
        }
    },

    /* 添加收藏 */
    addBookmark: function () {
        var title = $("title").html();
        title = $.trim(title)
        var url = 'http://' + document.location.host;
        if (document.all) {
            window.external.AddFavorite(url, title);
        } else if (window.sidebar) {
            window.sidebar.addPanel(title, url, "");
        } else if (window.opera && window.print) {
            return true;
        }
    },

    /* 取得页面的宽高信息 */
    getBodySize: function () {
        return { width: $(window).width(), height: $(window).height() }
    },

    /* 页面重定向 */
    redirect: function () {
        var len = arguments.length;
        if (len == 1) {
            window.location.href = url;
        } else {
            window.setTimeout('window.location.href = "' + arguments[0] + '"', arguments[1] * 1000);
        }
    },

    /* 弹出提示框,跳转页面 */
    alertRedirect: function (str, src) {
        alert(str);
        redirect(src);
    },

    /* 设置状态栏文字 */
    setStatusBarTxt: function (str) {
        window.status = txt;
    },

    /* 弹出确认对话框后跳转 */
    _confirm: function (str, src) {
        var r = confirm(str);
        if (r) {
            redirect(src);
        }
    },

    /* 关闭窗口 */
    closeWin: function () {
        window.open("", "_self");
        window.top.opener = null;
        window.top.close();
    },

    /* 弹出新窗口
    url 窗口地址
    name 窗口名称
    w 窗口宽
    h 窗口高 */
    openWinx: function (url, name, w, h) {
        window.open(url, name, "top=100,left=400,width=" + w + ",height=" + h + ",toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no");
    },

    /* 弹出模式窗口
    url 窗口地址
    name 窗口名称
    w 窗口宽
    h 窗口高 */
    dialog: function (url, name, w, h) {
        return showModalDialog(url, name, 'dialogWidth:' + w + 'px; dialogHeight:' + h + 'px; help: no; scroll: yes; status: no');
    }
};
