﻿//document.oncontextmenu=new Function("event.returnValue=false;");
//document.onselectstart=new Function("event.returnValue=false;");

$(document).ready(function () {
    favorite();
    homepage();

    if (getCookie()[0] != "" && getCookie()[1] != "") {
        $("#t_username").val(decodeURIComponent(getCookie()[0]));
        $("#t_password").val(getCookie()[1]);
        $("#cb_remember").attr("checked", true);
    }
});

/*================================收藏及加入首页===============================================*/

function favorite() {
    $("a[rel='favorite']").click(function () {
        var ctrl = (navigator.userAgent.toLowerCase()).indexOf('mac') != -1 ? 'Command/Cmd' : 'CTRL';
        if (document.all) {
            window.external.addFavorite('http://www.fzvogue.com', '服装灵感在线')
        } else if (window.sidebar) {
            window.sidebar.addPanel('前端笔记', 'http://www.fzvogue.com', "")
        } else {
            alert('您可以尝试通过快捷键' + ctrl + ' + D 加入到收藏夹~')
        }
    });
}

function homepage() {
    $("a[rel='homepage']").click(function () {
        if (document.all) {
            document.body.style.behavior = 'url(#default#homepage)';
            document.body.setHomePage(window.location.href);
        }
        else if (window.sidebar) {
            if (window.netscape) {
                try {
                    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
                }
                catch (e) {
                    alert("该操作被浏览器拒绝，如果想启用该功能，请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true");
                    history.go(-1);   //这里我用firefox测试的时候出错，我把它注释掉，改成 return false;
                }

            }
            var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
            prefs.setCharPref('browser.startup.homepage', window.location.href);
        }
    });
}
/*==============================收藏及加入首页结束=============================================*/


function getCookie(name)//取cookies函数        
{
    var password = "", username = "";
    var arr = document.cookie.match(new RegExp("(^| )lg_username=([^;]*)(;|$)"));
    if (arr != null && arr != "") username = arr[2];
    arr = document.cookie.match(new RegExp("(^| )lg_password=([^;]*)(;|$)"));
    if (arr != null && arr != "") password = arr[2];

    return [username, password];
}
