﻿function JumpForm(fid, ext) {
    if (fid != '') {
        window.location = "showforum-" + fid + ext;
    }
}


function ShowFormatBytesStr(bytes) {
    if (bytes > 1073741824) {
        document.write((Math.round((bytes / 1073741824) * 100) / 100).toString() + ' G');
    }
    else if (bytes > 1048576) {
        document.write((Math.round((bytes / 1048576) * 100) / 100).toString() + ' M');
    }
    else if (bytes > 1024) {
        document.write((Math.round((bytes / 1024) * 100) / 100).toString() + ' K');
    }
    else {
        document.write(bytes.toString() + ' Bytes');
    }
}

function CheckAll(current) {
    var allCheckId = "";
    var allCheckBox = document.getElementsByTagName("input");
    var length = allCheckBox.length;
    for (var i = 0; i < length; i++) {
        var item = allCheckBox[i];
        if (!item.getAttribute("moderator")) {
            if (item.name) {
                if (item.name == "checktid" && !item.disabled) {
                    item.checked = !item.checked;
                }
            }
        }
    }
}

function getCheckValue() {
    var allCheckId = "";
    var allCheckBox = document.getElementsByTagName("input");
    var length = allCheckBox.length;
    for (var i = 0; i < length; i++) {
        var item = allCheckBox[i];
        if (item.name) {
            if (item.name == "checktid" && !item.disabled) {
                if (item.checked) {
                    allCheckId += item.value + ",";
                }
            }
        }
    }

    if (allCheckId.length > 0) {
        allCheckId = allCheckId.substring(0, allCheckId.length - 1);
    }
    document.getElementById("allcheckedid").value = allCheckId;
}

function submitForm() {
    getCheckValue();
    document.moderatorform.submit();
}

function setcopyext(text, addmsg, alertmsg) {
    var i = text.indexOf("#");
    if (i != -1) {
        text = text.substring(0, i);
    }
    text += addmsg;

    if (is_ie) {
        clipboardData.setData('Text', text);
        alert(alertmsg);
    } else if (prompt('Press Ctrl+C Copy to Clipboard', text)) {
        alert(alertmsg);
    }
}

function report(rowid, fid) {
    var location = window.location.href;
    var i = location.indexOf("#");
    if (i != -1) {
        location = location.substring(0, i);
    }
    location += "#" + rowid;

    
    j.post("tools/ajax.aspx",
    { type: "1", fid: fid, report_url: location },
    function(data) {
        j("#reportContainer_" + rowid).html("已举报");
    }
    );
    
    return false;
}

function expandoptions(id) {
    var a = document.getElementById(id);
    if (a.style.display == '') {
        a.style.display = 'none';
    }
    else {
        a.style.display = '';
    }
}

function clonePoll() {
    var newNode = cloneObj($('divPollItem'), $('polloptions'), parseInt(maxpoll));
    if (!newNode) {
        alert('投票项不能多于 ' + maxpoll + ' 个');
    }
    var inputs = findtags(newNode, 'input');
    var attach;
    for (i in inputs) {
        if (inputs[i].name == 'pollitemid') {
            inputs[i].value = "";
            inputs[i].id = "pollitemid";
        }
    }
}

function delObj(oParent, count) {
    if (oParent.childNodes.length > count) {
        oParent.removeChild(oParent.lastChild);
        return true;
    }
    return false;
}

function cloneObj(oClone, oParent, count) {
    if (oParent.childNodes.length < count) {
        var newNode = oClone.cloneNode(true);
        oParent.appendChild(newNode);

        return newNode;
    }
    return false;
}

function writeDocument(msg) {
    document.write(msg);
}