﻿
var sjson = new jsonHandler();
var spaceid = $("#spaceID").val();
$(function() {
    //增加访问次数
    //if (spaceid != gUserID)
    sjson.addSpaceViewCount(spaceid, gUserID);
    $(".html").each(function() {
        $(this).html($(this).text()).show();
    });
    $(".formatRemark").each(function() {
        $(this).height(this.scrollHeight + 10);
        $(this).parent().html($(this).parent().html());
    });
    seteasydrag('EditUserIconBox', '编辑个人照片');
});
function addBlogViewCount() {
    var blgid = $("#blogid").val();
    if (blgid < 0) return;
    sjson.addBlogViewCount(blgid);
}
function addType() {
    if (isblank($("#newTypeName").val())) {
        alert("分类名称不能为空");
        return false;
    }
    if ($("#tblType tr").length > 40) {
        alert("最多可以添加20个分类");
        return false;
    }
    $.blockUI({ message: "操作提交中..." });
    sjson.dealBlogType(gUserID, -1, entityType.add, $("#newTypeName").val(), function(response) {
        var data = response.result;
        if (data.state) {
            $.blockUI({ message: "添加分类成功。" });
            var newHtml = '<tr id="' + data.newID + '"><td>' + $("#newTypeName").val() + '</td><td><a href="javascript:;" onclick="editType(' + data.newID + ');">编辑</a></td><td><a href="javascript:;" onclick="delType(' + data.newID + ');">删除</a></td></tr>' +
            '<tr id="' + data.newID + '_E" class="cur n"><td colspan="3"><input type="text" maxLength="10" value="' + $("#newTypeName").val() + '" class="mr20"/><button class="bt_tx2 mr20" onclick="editType(' + data.newID + ',this);">确定</button><button class="bt_tx2" onclick=$(this).parents("tr").hide();$("#' + data.newID + '").show(); >取消</button></td></tr>';
            $("#tblType").append(newHtml);
            $('#newType').fadeOut();
        }
        else {
            $.blockUI({ message: "网络繁忙，请刷新本页面或稍候重试。" });
        }
    });
}

function editType(typeid, obj) {
    var typename = gtrim($(obj).prev("input").val());
    if (gtrim($("#" + typeid).find("td:first").text()) == typename) {
        $("#" + typeid + "_E").hide();
        $("#" + typeid).show();
        return;
    }

    $.blockUI({ message: "操作提交中..." });
    sjson.dealBlogType(gUserID, typeid, entityType.modify, typename, function(response) {
        var data = response.result;
        if (data.state) {
            $.blockUI({ message: "编辑分类成功。" });
            $.unblockUI();
            $("#" + typeid + "_E").hide();
            $("#" + typeid).show().find("td:eq(0)").text(typename);
        }
        else {
            $.blockUI({ message: "网络繁忙，请刷新本页面或稍候重试。" });
        }
    });
}
function delType(typeid) {
    if (confirm("确定删除该分类？")) {
        $.blockUI({ message: "操作提交中..." });
        sjson.dealBlogType(gUserID, typeid, entityType.remove, '', function(response) {
            var data = response.result;
            if (data.state) {
                $.blockUI({ message: "删除分类成功。" });
                $.unblockUI();
                $("#" + typeid + "_E").hide();
                $("#" + typeid).hide();
            }
            else {
                $.blockUI({ message: "网络繁忙，请刷新本页面或稍候重试。" });
            }
        });
    }
}

function addBlog() {
    if (isblank($("#__BlogTitle").val())) {
        alert("标题不能为空，请填写");
        return;
    }
//    if ($("textarea[name='__BlogContent']").val().length > 4000) {
//        alert("日志内容太多，请精简后发布");
//        return;
//    }
    var idlist = "";
    $("input[name=__BlogType][@checked]").each(function() {
        idlist += isblank(idlist) ? this.value : "," + this.value;
    });
    $("#__BlogTypeIDList").val(idlist);
    $("#formAdd").submit();
}
function delBlog(blogid) {
    if (confirm("确定删除该日志？")) {
        $("#formDel").submit();
    }
}
function addReview() {
    if (isblank($("#__BlogReviewContent").val())) {
        alert("请填写评论内容");
        return false;
    }
    if ($("#__BlogReviewContent").val().length > 500) {
        alert("评论内容超出长度限制");
        return false;
    }
    $("#formReview").submit();
}
/*
function setPuriew(state) {
$("#__BlogPurview").val($("input[name=blogPurv][@checked]:first").val());
$("#formPurview").ajaxsubmit({
type: "POST",
cache: false,
success: function() {
},
error: function() { 
            
}
});
}*/
function delReview(revid) {
    $("#__delReviewID").val(revid);
    $("#formDelReview").submit();
}
function addSpaceMsg() {
    if (isblank($("#__SpaceMsgContent").val())) {
        alert("内容不能为空，请填写");
        return;
    }
    if ($("#__SpaceMsgContent").val().length > 500) {
        alert("留言内容太多，请精简后发布");
        return;
    }
    $("#formAddMsg").submit();
}
function showReply(id) {
    $("#ReplySpaceMsgID").val(id);
    $('#replyDiv').appendTo("#" + id + "_d").show();
    $("#__SpaceMsgReplyContent").val("").focus();
}
function replySpaceMsg() {

    if (isblank($("#__SpaceMsgReplyContent").val())) {
        alert("内容不能为空，请填写");
        $("#__SpaceMsgReplyContent").focus();
        return;
    }
    if ($("#__SpaceMsgReplyContent").val().length > 500) {
        alert("内容太多，请精简后发布");
        $("#__SpaceMsgReplyContent").focus();
        return;
    }
    $("#formReplyMsg").submit();
}
function delSpaceMsg(id) {
    if (confirm("确定删除该回复？")) {
        $("#DelSpaceMsgID").val(id);
        $("#formDelMsg").submit();
    }
}

function replySysMsg() {

    if (isblank($("#__MsgReplyContent").val())) {
        alert("内容不能为空，请填写");
        $("#__MsgReplyContent").focus();
        return;
    }
    if ($("#__MsgReplyContent").val().length > 500) {
        alert("内容太多，请精简后发布");
        $("#__MsgReplyContent").focus();
        return;
    }
    $("#formReplyMsg").submit();
}
function showReplyMail(id,toid) {
    $("#ReplySysMsgID").val(id);
    $("#ToUserID").val(toid);
    $('#replyDiv').appendTo("#" + id + "_d").show();
    $("#__MsgReplyContent").val("").focus();
}

function removeFavQues(qid, fid) {
    $("#remFavQuestionID").val(fid);
    $("#remQuestionID").val(qid);
    $("#removeFavQuestion").submit();
}
function delMail(id) {
    if (confirm("删除消息？")) {
        $("#__SysMsgID").val(id);
        $("#formGrid").submit();
    }
}
function modifyFavClass() {

    var idlist = "";
    $("input[name=qclass][@checked]").each(function() {
        idlist += isblank(idlist) ? this.value : "," + this.value;
    });
    if (isblank($("#favListid").val()))
        $("#favListid").val(-1);
    $("#modQuestionList").val(idlist);
    $("#removeFavQuestion").submit();
}
function sendMsg() {
    if ($("input[name=__MsgUserID][@checked]").length == 0) {
        alert("请至少选择一个好友");
        return false;
    }
//    if (isblank($("#__MsgTitle").val())) {
//        alert("标题不能为空，请填写");
//        $("#__MsgTitle").focus();
//        return false;
    //    }
    if (isblank($("#__MsgContent").val())) { 
        alert("内容不能为空");
        $("#__MsgContent").focus();
        return false;
    }
    if ($("#__MsgContent").val().length > 500) {
        alert("内容太多，请精简后发布");
        $("#__MsgContent").focus();
        return false;
    }
    $("#formSend").submit();
}
function sendMsgR() {
    if (isblank($("#__MsgTitle").val())) {
        alert("标题不能为空，请填写");
        $("#__MsgTitle").focus();
        return false;
    }
    if ($("#__MsgContent").val().length > 500) {
        alert("内容太多，请精简后发布");
        $("#__MsgContent").focus();
        return false;
    }
    $("#formSend").submit();
}
function editUserIcon() {
    //$('#EditUserIconBox .easydrag_content').html("<iframe name=EditUserIconFrame width=530 height=400px frameborder=0 src=/EditUserIcon.axml scrolling=no></iframe>");
    $('#EditUserIconFrame').attr('src','/EditUserIcon.axml');
    showeasydrag('EditUserIconBox');
    
}
