﻿//加入收藏
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 doSearch(txtId, url) {
    var txt = "";
    var obj = document.getElementById(txtId);
    if (obj && obj.value) {
        txt = encodeURI(obj.value.replace(/[ ,;，；　]/g, "%"));
        window.open(url + '?s=' + txt);
    } else {
        alert("请输入要检索的关键词");
    }
}
//Tab切换效果 0:On Class 1:Off Class 2:On id 之后是Off的id
function TabChange() {
    var obj = document.getElementById(arguments[2]);
    if (obj) {
        if (obj.className == arguments[0]) {
            return;
        }
        obj.className = arguments[0];
    }
    for (i = 3; i < arguments.length; i++) {
        obj = document.getElementById(arguments[i]);
        if (obj) {
            obj.className = arguments[1];
        }
        obj = document.getElementById(arguments[i] + "More");
        if (obj) {
            obj.style.display = "none";
        }
        obj = document.getElementById(arguments[i] + "Div");
        if (obj) {
            obj.style.display = "none";
        }
    }
    obj = document.getElementById(arguments[2] + "More");
    if (obj) {
        obj.style.display = "";
    }
    obj = document.getElementById(arguments[2] + "Div");
    if (obj) {
        obj.style.display = "";
    }
}
//DIV切换效果 0:block 1:none id 之后是none的id
function DivClick() {
    var obj = document.getElementById(arguments[0]);
    if (obj) {
        if (obj.style.display == "none") {
            obj.style.display = "";
        } else {
            return;
        }
    }
    for (i = 1; i < arguments.length; i++) {
        obj = document.getElementById(arguments[i]);
        if (obj) {
            obj.style.display = "none";
        }
        obj = document.getElementById(arguments[i] + "Div");
        if (obj) {
            obj.style.display = "none";
        }
        obj = document.getElementById(arguments[i] + "More");
        if (obj) {
            obj.style.display = "none";
        }
    }
    obj = document.getElementById(arguments[0] + "Div");
    if (obj) {
        obj.style.display = "";
    }
    obj = document.getElementById(arguments[0] + "More");
    if (obj) {
        obj.style.display = "";
    }
}
//翻动按钮 -1向前 1向后
var arrowFirst = 1;
function ArrowClick(iarrow,amount) {
    if (arrowFirst + iarrow < 1) {
        alert("已经到头了");
        return;
    }
    var objShow = document.getElementById("tdArrow" + (iarrow > 0 ? (amount + arrowFirst + iarrow - 1) : (arrowFirst+iarrow)));
    if (!objShow) {
        alert("已经没有了");
        return;
    }
    var objHide = document.getElementById("tdArrow" + (iarrow > 0 ? arrowFirst : (amount + arrowFirst + iarrow)));
    if (objHide) {
        objHide.style.display = "none";
    }
    objShow.style.display = "";
    arrowFirst = arrowFirst + iarrow;
}
function doZoom(objid, size) {
    var obj = document.getElementById(objid);
    if (obj) {
        obj.style.fontSize = getFontSize(obj) + size + 'px';
    } else {
        var objs = getElementsByName("div", objid);
        if (objs) {
            for (i = 0; i <= objs.length; i++) {
                objs[i].style.fontSize = getFontSize(objs[i]) + size + 'px';
            }
        }
    }
}
//获得字体大小
function getFontSize(obj) {
    if (obj.style.fontSize) {
        return parseInt(obj.style.fontSize, 10);
    } else {
        return 18;
    }
}
 //设置字体大小
function setSize(objid, size) {
    var obj = document.getElementById(objid);
    if (obj) {
        obj.style.fontSize = size + 'px';
    } else {
        var objs = getElementsByName("div", objid);
        if (objs) {
            for (i = 0; i <= objs.length; i++) {
                objs[i].style.fontSize = size + 'px';
            }
        }
    }
}
//内容分页按钮
function PageShow(num) {
    var objs = getElementsByName("div", "divContent");
    if (objs) {
        for (i = 0; i <= objs.length; i++) {
            if (objs[i].id == "divContent" + num) {
                objs[i].style.display = "";
            } else {
                objs[i].style.display = "none";
            }
        }
    }
}

// 兼容IE FF的ByName方法
function getElementsByName(tag, name) {
    var returns = document.getElementsByName(name);
    if (returns.length > 0) return returns;
    returns = new Array();
    var e = document.getElementsByTagName(tag);
    for (var i = 0; i < e.length; i++) {
        if (e[i].getAttribute("name") == name) {
            returns[returns.length] = e[i];
        }
    }
    return returns;
}

//样式控制
function classShow(obj, objClass, tipClass) {
    obj.className = objClass;
    var objTip = document.getElementById("tip" + obj.id);
    if (objTip) {
        objTip.className = tipClass;
    }
}

//二级联动
function selectChange(obj, changeId, allinfo) {
    var selValue = obj.options[obj.selectedIndex].value; //得到select对象中当前被选中的值
    var objChange = document.getElementById(changeId);
    if (objChange) {
        objChange.options.length = 0;
        for (i = 0; i < allinfo.length; i++) {
            if (allinfo[i].substring(0, selValue.length) == selValue) {
                objChange.options.length++;
                var p = allinfo[i].indexOf("|");
                var text = allinfo[i].substr(p + 1);
                var value = allinfo[i].substr(0, p);
                objChange.options[objChange.options.length - 1] = new Option(text, value);
            }
        }
    }
}

