﻿function addFavorite()
{
try { window.external.addFavorite(window.location, document.title);}catch (e){try { window.sidebar.addPanel(document.title, window.location, ""); } catch (e) { alert("加入收藏失败，请使用Ctrl+D进行添加"); } } }

function setHome(obj)
{
    var url = window.location.href;
    try
    {
        obj.style.behavior = 'url(#default#homepage)'; obj.setHomePage(url);
    }
    catch (e)
    {
        if (window.netscape)
        {
            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);
        }
        else { alert("该浏览器不支持脚本设为首页。为了获得更好的体验，建议您使用 IE 9、Firefox(火狐)、Chrome(谷歌浏览器) 等现代浏览器！"); }
    } 
}

function query(k, au)
{
    au = au || true; var reg = new RegExp("(^|&)" + k + "=([^&]*)(&|$)", "i"); var r = window.location.search.substr(1).match(reg);
    if (r) { if (au && (au == true)) { return unescape(r[2]); } else { return r[2]; } } return null;
}

function isIE()
{
    return ! +"\v1";
}

function mask(maskID)
{
    //隐藏滚动条
    document.body.style.overflow = "hidden";
    if (document.getElementById(maskID))
    {
        document.getElementById(maskID).style.display = "";
    }
    else
    {
        //不存在该遮罩层
        if (isIE())
        {
            //如果是IE，就创建iframe以遮住dropdownlist
            var d = document.createElement("iframe");
            d.id = maskID;
            with (d.style)
            {
                position = "absolute";
                width = (document.body.scrollWidth + 20) + "px";
                height = document.body.scrollHeight + "px";
                top = "0px";
                left = "0px";
                zIndex = "90";
                filter = "Alpha(opacity=50)";
            }
            document.body.appendChild(d);
            d.contentWindow.document.write("<html><head></head><body style=\"background:#666\"></body></html>");
            d.contentWindow.document.close();
        }
        else
        {
            var d = document.createElement("div");
            d.id = maskID;
            with (d.style)
            {
                width = (document.body.scrollWidth + 20) + "px";
                height = document.body.scrollHeight + "px";
                position = "absolute";
                top = "0px";
                left = "0px";
                zIndex = "90";
                backgroundColor = "#666";
                opacity = 0.5;
            }
            document.body.appendChild(d);
        } //else end


    }
}

/*
关闭遮罩层
说明：maskClose(名称);
示例：maskClose("mask");
*/
function maskClose(maskID)
{
    document.getElementById(maskID).style.display = "none";
    document.body.style.overflow = "auto";
}

function showLogin()
{
    mask("mask");

    var d = document.getElementById("loginform");
    //对于scrollTop，safari有自己的方法，但对于滚动条在最顶端，IE下是0||undefined,此时会得到undefined，所以pageYOffset 要放在前面。
    var _top = window.pageYOffset || document.documentElement.scrollTop;
    d.style.top = ((document.documentElement.clientHeight - parseInt(d.currentStyle.height)) / 2 + _top) + "px";
    d.style.left = ((document.documentElement.clientWidth - parseInt(d.currentStyle.width)) / 2 + document.documentElement.scrollLeft) + "px";

    //显示登录框
    $("#loginform").show();
    $("#loginform input:eq(0)").focus();
}

function winopen(url)
{
    window.open(url);
}

