header.js

来自「用php编写的一个BBS 小程序」· JavaScript 代码 · 共 335 行

JS
335
字号
/**
 * header.js
 * 08.08.2007
 */
function loginSwitch(typeId) {
    if (typeId < 0 || typeId > 1) {
        typeId = 0;
    }
    var switchId = new Array("login_gut", "lostpassword_gut");
    var focusId = new Array("dl_user", "dl_email");
    var oldTypeId = typeId == 0 ? 1 : 0;
    window.document.getElementById(switchId[oldTypeId]).style.display = "none";
    window.document.getElementById(switchId[typeId]).style.display = "block";
    window.document.getElementById(focusId[typeId]).focus();
}

function checkUsername(unm, uhint) {
    var sL = strLength(unm.value);
    uhint = uhint == null ? "usernamehint" : uhint;
    if (unm.value == "") {
        setHint(uhint, "* 请输入您的用户名!");
        return false;
    } else if (sL < 5 || sL > 30) {
        setHint(uhint, "* 用户名必须大于4位!");
        return false;
    } else if (!checkStr(unm.value, "~!@$%^&*;:'\"/?.>,<{}\\|=+-")) {
        setHint(uhint, "* 用户名中含非法字符!");
        return false;
    } else {
        setHint(uhint);
        return true;
    }
}

function checkPassword(pwd, phint) {
    phint = phint == null ? "watchwordhint" : phint;
    if (pwd.value == "") {
        setHint(phint, "* 请输入您的密码!");
        return false;
    } else if (pwd.value.length < 5 || pwd.value.length > 30) {
        setHint(phint, "* 密码必须大于4位!");
        return false;
    } else if (!checkStr(pwd.value, ",'\"", true)) {
        setHint(phint, "* 非法密码,请重新输入!");
        return false;
    } else {
        setHint(phint);
        return true;
    }
}

function checkConfirmPassword(rpwd, pwd, phint) {
    phint = phint == null ? "regRPwdHint" : phint;
    if (rpwd.value == "") {
        setHint(phint, "* 请输入您的确认密码!");
        return false;
    } else if (rpwd.value.length < 5 || rpwd.value.length > 30) {
        setHint(phint, "* 确认密码必须大于4位!");
        return false;
    } else if (!checkStr(rpwd.value, ",'\"", true)) {
        setHint(phint, "* 非法确认密码,请重填!");
        return false;
    } else if (rpwd.value != pwd.value) {
        setHint(phint, "* 您的确认密码有误!");
        return false;
    } else {
        setHint(phint);
        return true;
    }
}

function loginCheck() {
    var unm = window.document.login.username;
    var pwd = window.document.login.watchword;
    var isLegality = true;
    if (!checkUsername(unm)) {
        isLegality = false;
    }
    if (!checkPassword(pwd)) {
        isLegality = false;
    }
    if (isLegality) {
        window.document.login.bNext.disabled = true;
        xajax_login(xajax.getFormValues("loginForm"));
    }
}

function loginReset() {
    setHint("usernamehint");
    setHint("watchwordhint");
    setHint("lostpwdhint");
    window.document.getElementById("unmStr").value = "";
    window.document.getElementById("loginForm").reset();
    window.document.getElementById("lostpwdForm").reset();
    window.document.getElementById("lostpassword_gut").style.display = "none";
    window.document.getElementById("login_gut").style.display = "block";
    window.document.getElementById("dl_user").focus();
}

function checkEmail(eml, emlhint) {
    var p = eml.value.indexOf('@');
    emlhint = emlhint == null ? "regEmlHint" : emlhint;
    if (eml.value == "") {
        setHint(emlhint, "* 请输入您的Email地址!");
        return false;
    } else if (strLength(eml.value) > 200) {
        setHint(emlhint, "* 您的Email太长了!");
        return false;
    } else if (p < 1 || p == (eml.value.length - 1)) {
        setHint(emlhint, "* 不是有效的Email地址!");
        return false;
    } else {
        setHint(emlhint);
        return true;
    }
}

function registerReset() {
    var obj = window.document.register;
    setHint("regUnmHint");
    setHint("regPwdHint");
    setHint("regRPwdHint");
    setHint("regEmlHint");
    window.document.getElementById("regUnmStr").value = "";
    obj.reset();
    obj.username.focus();
}

function registerSubmit() {
    var obj = window.document.register;
    var isLegality = true;
    if (!checkUsername(obj.username, "regUnmHint")) {
        isLegality = false;
    }
    if (!checkPassword(obj.password, "regPwdHint")) {
        isLegality = false;
    }
    if (!checkConfirmPassword(obj.rpassword, obj.password)) {
        isLegality = false;
    }
    if (!checkEmail(obj.email)) {
        isLegality = false;
    }
    if (isLegality) {
        obj.bRegNext.disabled = true;
        xajax_register(xajax.getFormValues("registerForm"));
    }
}

function changePasswordSubmit() {
    var opw = window.document.changePassword.oldpassword;
    var npw = window.document.changePassword.newpassword;
    var cpw = window.document.changePassword.confirmnewpassword;
    if (opw.value == "") {
        window.alert("请输入您的原密码!");
        opw.focus();
    } else if (opw.value.length < 5 || opw.value.length > 30) {
        window.alert("原密码位数必须大于4位!");
        opw.select();
    } else if (!checkStr(opw.value, ",'\"", true)) {
        window.alert("非法密码,请重新输入!");
        opw.value = "";
        opw.focus();
    } else if (npw.value == "") {
        window.alert("请输入您的新密码!");
        npw.focus();
    } else if (npw.value.length < 5 || npw.value.length > 20) {
        window.alert("新密码位数必须大于4位!");
        npw.select();
    } else if (!checkStr(npw.value, ",'\"", true)) {
        window.alert("非法新密码,请重新输入!");
        npw.value = cpw.value = "";
        npw.focus();
    } else if (cpw.value == "") {
        window.alert("请再输入一次您的新密码!");
        cpw.focus();
    } else if (cpw.value != npw.value) {
        window.alert("您的确认密码有误!");
        cpw.select();
    } else {
        window.document.changePassword.bChange.disabled = true;
        xajax_change_password(xajax.getFormValues("changePasswordForm"));
    }
}

function showDetails(uId) {
    window.document.getElementById("ods_usr").innerHTML = "&nbsp;";
    window.document.getElementById("ods_qq").href = "javascript:void(0)";
    window.document.getElementById("ods_qq").onmousedown = "javascript:void(0)";
    window.document.getElementById("ods_img").title = "";
    window.document.getElementById("ods_img").src = "images/avatar.gif";
    window.document.getElementById("ods_sce").innerHTML = "&nbsp;";
    window.document.getElementById("ods_mny").innerHTML = "&nbsp;";
    window.document.getElementById("ods_ts").innerHTML = "&nbsp;";
    window.document.getElementById("ods_ps").innerHTML = "&nbsp;";
    window.document.getElementById("ods_msg").innerHTML = "&nbsp;";
    window.document.getElementById("ods_eml").innerHTML = "&nbsp;";
    window.document.getElementById("ods_logd").innerHTML = "&nbsp;";
    window.document.getElementById("ods_regd").innerHTML = "&nbsp;";
    window.document.getElementById("ods_cmt").innerHTML = "&nbsp;";
    if (uId > 0) {
        xajax_details(uId);
    } else {
        hideDiv(2);
    }
}

function verifyProfilePwd(vType) {
    var obj = window.document.profile.rnewpassword;
    var aEnm = window.document.activeElement.name;
    vType = vType == null ? false : (vType ? true : false);
    if (!arrDivIsHide[0] && obj.value != window.document.profile.newpassword.value && aEnm != "newpassword" && aEnm != "bVPRefit" && (vType || aEnm != "bPVary")) {
        alert("确认密码和新密码不一致!\n不修改密码的话请留空!");
        obj.focus();
        return false;
    }
    return true;
}

function varyProfileImg() {
    var obj = window.document.profile.avatar;
    window.document.getElementById('opv_img').src = obj.value;
}

function modifyProfileRefit() {
    window.document.profile.bVPRefit.disabled = true;
    window.document.profile.bPVary.disabled = true;
    window.document.profile.reset();
    varyProfileImg();
    window.document.getElementById('opv_img').title = "";
    xajax_profile(2);
}

function profileSubmit() {
    var obj = window.document.profile;
    obj.bPVary.disabled = true;
    obj.bVPRefit.disabled = true;
    varyProfileImg();
    if (obj.oldpassword.value != "") {
        if (verifyProfilePwd(true)) {
            xajax_profile(1, xajax.getFormValues("profileForm"));
            return;
        }
    } else {
        alert("修改资料必须输入密码!");
        obj.oldpassword.focus();
    }
    obj.bPVary.disabled = obj.bVPRefit.disabled = false;
}

function verifySynchroDetails(usrnm, uId) {
    usrnm = usrnm == null ? "" : usrnm;
    uId = uId == null ? 0 : uId;
    if (!arrDivIsHide[2] && usrnm == window.document.getElementById("ods_usr").innerHTML) {
        showDetails(uId);
    }
}

function logout() {
    if (window.confirm("退出登录?")) {
        xajax_logout();
    }
}

var _tbML = window.document.getElementById("tbML");

function waitMemberList(state, clysis) {
    var j = _tbML.rows.length;
    for (var i = 1; i < j; i++) {
        _tbML.deleteRow(1);
    }
    state = state != null ? parseInt(state) : 0;
    if (state == 1) {
        var _tr = _tbML.insertRow(1);
        _tr.style.background = "#fafafa";
        _tr.setAttribute("align", "center");
        _tr.setAttribute("valign", "middle");
        var _td = _tr.insertCell(0);
        _td.setAttribute("className", "td1");
        _td.setAttribute("colSpan", "5");
        _td.setAttribute("onmouseover", new Function("this.style.background='#ffffff'"));
        _td.setAttribute("onmouseout", new Function("this.style.background='#fafafa'"));
        _td.style.padding = "5px";
        _td.innerHTML = clysis != null ? clysis : "请稍后,载入数据中...";
    }
}

function insertMember(mRow, mUsr, mLvl, mEml, mLindt, mRegdt) {
    if (mRow <= 0) {
        var spot = "没有任何会员!";
        if (mRow == -1) {
            spot = "请登录后浏览会员名单。";
            window.document.getElementById("totalrows").innerHTML = "共有0个会员";
            window.document.getElementById("pagerows").value = 0;
            window.document.getElementById("pageview").innerHTML = "&nbsp;";
        }
        waitMemberList(1, spot);
        return;
    }
    var mStuff = new Array(mUsr, mLvl, mEml, mLindt, mRegdt);
    var _tr = _tbML.insertRow(mRow);
    _tr.style.background = "#fafafa";
    _tr.setAttribute("align", "center");
    _tr.setAttribute("vAlign", "middle");
    var _td = new Array();
    for (var i = 0; i < 5; i++) {
        _td[i] = _tr.insertCell(i);
        _td[i].setAttribute("className", "td1");
        _td[i].setAttribute("onmouseover", new Function("this.style.background='#ffffff'"));
        _td[i].setAttribute("onmouseout", new Function("this.style.background='#fafafa'"));
        _td[i].style.padding = "5px";
        _td[i].innerHTML = mStuff[i];
    }
}

function updateMemberList(curPage) {
    var oldPage = parseInt(window.document.getElementById("mlCurPage").value);
    curPage = curPage == null ? oldPage : curPage;
    if (curPage <= 0 || curPage != oldPage) {
        waitMemberList(1);
        xajax_member_list(curPage);
    }
}

function updateUserStatus() {
    if (window.document.readyState == "complete") {
        window.document.getElementById("mlCurPage").value = "0";
        window.document.getElementById("navigation").innerHTML = "&nbsp;";
        hideAllDiv();
        xajax_get_user_status();
    } else {
        setTimeout(updateUserStatus, 30);
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?