﻿function showSwf_resize(obj) {
    var obj = $(obj);
    if (obj.attr('resize') == 'yes') {
        obj.css('background-image', 'url(http://img.fuwoo.com/images/swf_mini.gif)');
        obj.parents('.showSwf').width('420px').height('400px');
        obj.parents('.showSwf').find('embed').width('420px').height('400px');
        obj.attr('resize', 'no');
    } else if (obj.attr('resize') == 'no') {
        obj.css('background-image', 'url(http://img.fuwoo.com/images/swf_max.gif)');
        obj.parents('.showSwf').width('225px').height('200px');
        obj.parents('.showSwf').find('embed').width('225px').height('200px');
        obj.attr('resize', 'yes');
    }
    obj.parents('.showSwf');

}


function loadoneWordlist(id) {
    $.get("/OneWord/loadoneWordlist/", { userID: id,render:Math.random() }, function (result) {
        $("#onewordtimelist").html(result);
    });
}


function updateoneWordlist() {
    var se = $("#onewordtimelist>li:first");
    if (se != null) {
        $.get("/OneWord/loadoneWordlist/", { userID: 0, maxId: se.attr("time"), render: Math.random() }, function (result) {
            $(result).hide().prependTo("#onewordtimelist");
            $("#onewordtimelist>li:first").show("slow");
        });
    }

    var po = $("#OneWordIndexList_index>.dynamic-item:first");
    if (po != null) {
        $.get("/OneWord/loadoneWordlist_last/", { render: Math.random() }, function (result) {
            $(result).hide().prependTo("#OneWordIndexList_index");
            $("#OneWordIndexList_index>.dynamic-item:first").show("slow");
        });
    }

}

function showLargerPic(src) {
    //alert($(src).attr("ref"));
    return false;
}


function deloneWord(id) {
    if (confirm("确定要删除这条闲话吗？")) {
        $.ajax({
            type: "get",
            url: "/OneWord/DelOneWord/" + id,
            data: "rander=" + Math.random(),
            success: function (result) {
                if (result) {
                    $("#oneWord_" + id).remove();
                }
            }
        });
    }
}



function deloneWordD(id,userid) {
    if (confirm("确定要删除这条闲话吗？")) {
        $.ajax({
            type: "get",
            url: "/OneWord/DelOneWord/" + id,
            data: "rander=" + Math.random(),
            success: function (result) {
                if (result) {
                    location.href = "/OneWord/List/" + userid;
                }
            }
        });
    }
}


function oneWordReply(obj, id) {
    var reply_box = $("#oneWordreply_" + id);
    if (reply_box.css("display") == "none") {
        reply_box.show();
        reply_box.html('<img style="margin-left:250px;" src="http://img.fuwoo.com/images/ico_loading16.gif" />');
        getOneWordReplyList(id, reply_box);
    }
    else {
        reply_box.hide();
    }

}


function getOneWordReplyList(OneWordId,obj) {
    $.post("/OneWord/getOneWordReplyList",
    { id: OneWordId },
    function (result) {
        obj.html(result);
    });
}


function replyOneWordSubmit(obj, id) {
    var inputObj = $(obj).prev("textarea");
    var objid = inputObj.attr("id");
    var txt = trimTxt(inputObj.val());
    if (txt == "") {
        alert("回复内容不能为空");
        return false;
    }

    if (getInputNum(objid) > 140) {
        alert("对不起，你输入的字数已经超过140个限制！");
        return false
    }
    
    $(obj).attr("disabled", "disabled");

    $.post("/OneWord/postReplyComment", { id: id, text: txt, render: Math.round() }, function (result) {
        $("#reply_list_ul_" + id).prepend(result);
        inputObj.val("");
        $(obj).attr("disabled", "");
        inputObj.css("height","22px");
        clearPostNum("replyComment_input_Kcount_" + id);
    });
}

function oneWordkeypress(event,obj) {
    if (event.keyCode == 13) {
        var clickobj = $(obj).next(".btn_normal");
        if (clickobj)
            clickobj.click();
        $(obj).next(":button").click();

        if (event.stopPropagation) {
            event.preventDefault();
            event.stopPropagation();
        }
        return false;
    }
}


function delReplyComment(obj, leavewordId) {
    if (confirm("确定要删除该回复吗？")) {
        var url = "/leaveWord/deleteLeaveWord"
        $.ajax({
            type: "get",
            url: url,
            data: "id=" + leavewordId + "&render=" + Math.random(),
            success: function (result) {
                if (result > 0) {
                    $("#reply_comment_id_" + leavewordId).fadeOut("fast", function () {
                        $(this).remove();
                    });
                }
            }
        });
    }
}


function replyCommentTxt(objId, Kname, userId) {
    //$("#replyComment_hidden_" + objId).val(userId);
    document.getElementById(objId).focus();
    $("#" + objId).val("回复 " + Kname + "：");


}


function updateHeightNum(id) {
    $("#replyComment_input_HeightControl_" + id).html($("#replyComment_input_" + id).val());
    var words = $("#replyComment_input_HeightControl_" + id).html();
    words=words.replace(/\n/g,"<br />");
    $("#replyComment_input_HeightControl_" + id).html(words);
    var h = $("#replyComment_input_HeightControl_" + id).height();
    if (h >= 22) {
        $("#replyComment_input_" + id).css("height", h + "px");
    }
    updatePostNumCount('replyComment_input_' + id, 'replyComment_input_Kcount_' + id);
}


