﻿function validate(theform, previewpost, switcheditormode) {
    var message = !theform.parseurloff.checked ? parseurl(theform.message.value) : theform.message.value;

    if (theform.title.value == "" || message == "") {
        alert("请完成标题和内容栏。");
        $("postsubmit").disabled = false;
        return false;
    } else if (theform.title.value.length > 60) {
        alert("您的标题超过 60 个字符的限制。");
        theform.title.focus();
        $("postsubmit").disabled = false;
        return false;
    }

    if (!disablepostctrl && ((postminchars != 0 && mb_strlen(message) < postminchars) || (postmaxchars != 0 && mb_strlen(message) > postmaxchars))) {
        alert("您的帖子长度不符合要求。\n\n当前长度: " + mb_strlen(message) + " 字节\n系统限制: " + postminchars + " 到 " + postmaxchars + " 字节");
        return false;
    }

    if (!switcheditormode && !previewpost) {
        $("postsubmit").disabled = true;
    }

    theform.message.value = message;
    return true;
}

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 ShowStars(n, t) {
    var s = '';
    for (var i = 3; i > 0; i--) {
        level = parseInt(n / Math.pow(t, i - 1));
        n = n % Math.pow(t, i - 1);
        for (var j = 0; j < level; j++) {
            s += '<img src="templates/' + templatepath + '/images/star_level' + i + '.gif" />';
        }
    }
    document.write(s);
}


function imgzoom(o) {
    if (event.ctrlKey) {
        var zoom = parseInt(o.style.zoom, 10) || 100;
        zoom -= event.wheelDelta / 12;
        if (zoom > 0) {
            o.style.zoom = zoom + '%';
        }
        return false;
    }
    else {
        return true;
    }
}

function printinpostad(index) {
    try {
        if (inpostad) {
            document.write("<div class=\"line category\"><div style='float: left;'>[广告]&nbsp;</div><div>");
            var tempstr = inpostad[index];
            var ad = tempstr.split("\\r\\n");
            for (var i = 0; i < ad.length; i++) {
                document.writeln(ad[i]);
            }
            document.write("</div>");
            document.write("</div>");
        }
    }
    catch (e) {
    }
}
