﻿

function replaceUrl(url, key, value) {

    var Url = url
    var u, g, StrBack = '';

    u = Url.split("?");
    if (u.length == 1) g = '';
    else g = u[1];
    if (g != '') {
        gg = g.split("&");
        var MaxI = gg.length;
        str = key + "=";
        if (url.indexOf(str) == -1) {

            url = url + "&" + key + "=" + value;
        
            window.location.href = url;
        }
        else {
            for (i = 0; i < MaxI; i++) {
                if (gg[i].indexOf(str) == 0) {
                    StrBack = gg[i].replace(str, "");
                    break;
                }
            }
              url = url.replace(key + "=" + StrBack, key + "=" + value);
                window.location.href = url;
        }
      
      
    }
    else {
   
        url = url + "?" + key + "=" + value;
        window.location.href = url;
    }
}

function replaceUrl2(key, value) {
   
    var url = window.location.href;
    return replaceUrl(url, key, value);
}


function replaceUrlKey(key, value) {
    var url = window.location.href;
    return replaceUrl(url, key, value);

}

function AddFavorite(sURL, sTitle) {
    try {
        window.external.addFavorite(sURL, sTitle);
    }
    catch (e) {
        try {
            window.sidebar.addPanel(sTitle, sURL, "");
        }
        catch (e) {
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    }
}
function SetHome(obj, vrl) {
    try {
        obj.style.behavior = 'url(#default#homepage)'; obj.setHomePage(vrl);
    }
    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', vrl);
        }
    }
}
function search() {
    var text = $("#searchtext").val();
    window.location.href = "search.html?text=" + encodeURIComponent(text);
}


var _bdhm_top = 0;
var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://");
var _bdhm_tim = new Image(1,1);
_bdhm_tim.id = "bdhmPerimg";
_bdhm_tim.src = _bdhmProtocol + "hm.baidu.com/_tt.gif?si=2354a6fbf90508694f5e58fd7e4fdc72&rnd=" + Math.round(Math.random()*2147483647);
_bdhm_tim.onload=function(){_bdhm_top = 1;}

