function addBookmark() {
    if (window.sidebar) {
        window.sidebar.addPanel(top.document.title.toString(), top.location, "");
    }
    else if (document.all) {
        window.external.AddFavorite(top.location, top.document.title.toString());
    }
    else if (window.opera && window.print) {
        alert("press Ctrl+T to add a bookmark!");
    }
}

function homePage() {
    if (document.all) {
        document.body.style.behavior = 'url(#default#homepage)';
        document.body.setHomePage('http://wallpaper.876.tw');
    }
    else if (window.sidebar) {
        if (window.netscape) {
            try {
                netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
            }
            catch (e) {
                alert('please visite "about:config", and set the key "signed.applets.codebase_principal_support" value for true');
            }
        }
        var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
        prefs.setCharPref('browser.startup.homepage', 'http://wallpaper.876.tw');
    }
}

function setCookie(name, value) {
    var argv = setCookie.arguments;
    var argc = setCookie.arguments.length;
    var LargeExpDate = new Date();
    LargeExpDate.setTime(LargeExpDate.getTime() + (1000 * 3600 * 24));
    document.cookie = name + "=" + escape(value) + ";path=/;expires=" + LargeExpDate.toGMTString();
}

function getCookie(Name) {
    var search = Name + "="
    if (document.cookie.length > 0) {
        offset = document.cookie.indexOf(search)
        if (offset != -1) {
            offset += search.length
            end = document.cookie.indexOf(";", offset)
            if (end == -1) end = document.cookie.length
            return unescape(document.cookie.substring(offset, end))
        }
        else return ""
    }
}

var pid = 0;

function getyPixel() {
    return screen.width + 'X' + screen.height;
}

function getPixel() {
    var pixel;
    try {
        pixel = getCookie('mypixel');
        if (pixel.indexOf('X') < 0) {
            pixel = getyPixel();
            setCookie('mypixel', pixel);
        }
    }
    catch (err) {
        pixel = getyPixel();
        setCookie('mypixel', pixel);
    }
    return pixel;
}


function getPixelList(cpixel) {
    var ypixel = getyPixel();
    var nstr = "|480X272|640X480|800X600|1024X768|1152X864|1280X720|1280X768|1280X800|1280X960|1280X1024|1400X1050|1400X900|1600X1200|1680X1050|1366X768".split('|');
    var sstr = "<a style=\"line-height:21px;height:43px;\">您的螢幕解析度為:" + ypixel + "<br />選擇設定電腦桌布的解析度：</a>";
    var i;
    for (i = 1; i < nstr.length; i++) {
        if (cpixel != nstr[i]) sstr += "<a href=\"javascript:changePixel('" + nstr[i] + "')\">" + nstr[i] + "</a>";
        else sstr += "<strong>當前:" + cpixel + "</strong>";
        if (i == 9) sstr += "<br />";
    }
    sstr += "<a href=\"javascript:changePixel('" + ypixel + "');\">檢測適應螢幕解析度</a>";
    return sstr;
}

function showPixelList(cpixel) {
    document.getElementById("pixels").innerHTML = getPixelList(cpixel);
}

function showWPic(cpixel) {
    var px=cpixel.toString();
    document.getElementById("spic").src = "http://876.jcache.com/image.aspx?pid=" + pid + "&wh=" + cpixel;
    document.getElementById("spic").width = px.substring(0, px.indexOf("X"));
    document.getElementById("spic").height = px.substring(px.indexOf("X") + 1);
}

function changePixel(cpixel) {
    showPixelList(cpixel);
    setCookie('mypixel', cpixel);
    showWPic(cpixel);
}

function setKW() {
    var kws = document.title;
    if (kws.indexOf("搜尋結果") > 0) {
        kws = kws.substring(0, kws.indexOf("搜尋結果"));
        document.getElementById("tskw").value = kws;
    }
}


function showads(at) {
    switch (at) {
        case 1:
            ads160x600();
            break;
        case 2:
            ads468x60();
            break;
        case 3:
            ads300x250();
            break;
        case 4:
            ads728x15();
            break;
        case 5:
            ads728x90();
            break;
    }
}

function ads160x600() {
    google_ad_client = "pub-2766498197753827";
     /* Wallpaper876TW_160x600 */
    google_ad_slot = "0371114530";
    google_ad_width = 160;
    google_ad_height = 600;
    document.write('<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>');
}


function ads468x60() {
	document.write('<iframe id="baiduSpFrame" border="0" vspace="0" hspace="0" marginwidth="0" marginheight="0" framespacing="0" frameborder="0" scrolling="no" width="468" height="60" src="http://spcode.baidu.com/spcode/spstyle/style2960.jsp?tn=wapcn_sp&ctn=0&styleid=2960"></iframe>');
}

function ads300x250() {
    google_ad_client = "pub-2766498197753827";
    /* Wallpaper876TW_300x250 */
    google_ad_slot = "9538804334";
    google_ad_width = 300;
    google_ad_height = 250;
    document.write('<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>');
}

function ads728x15() {
    google_ad_client = "pub-2766498197753827";
    /* Wallpaper876TW_728x15 */
    google_ad_slot = "9181748311";
    google_ad_width = 728;
    google_ad_height = 15;
    document.write('<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>');
}

function ads728x90() {
    google_ad_client = "pub-2766498197753827";
    /* Wallpaper876TW_728x90 */
    google_ad_slot = "0681308003";
    google_ad_width = 728;
    google_ad_height = 90;
    document.write('<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>');
}

