﻿$(document).ready(function() {
    InitSendMessage();
});

function InitSendMessage() {
    //发消息
    $('.btnSendMessage').unbind().hover(function() {
        if ($(this).attr('class').indexOf('messagebutton') == -1)
            $(this).addClass('over');
    }, function() {
        if ($(this).attr('class').indexOf('messagebutton') == -1)
            $(this).removeClass('over');
    }).click(function() {
        if (userID <= 0) {
            ShowLogin();
            return;
        }
        var sendType = $(this).attr('sendtype'); //0:查看消息 1:写消息 2:回复消息
        var currMessageID = $(this).attr('usermessageid');
        var toUserID = $(this).attr('userid');
        if (toUserID != undefined && toUserID != null && toUserID.length > 0 && userID == parseInt(toUserID)) {
            AlertTips('系统提示：', '不能给自己发消息！');
            return;
        } else if (toUserID == undefined || toUserID == null || toUserID.length == 0) {
            toUserID = 0;
        }
        if (currMessageID == undefined || currMessageID == null || currMessageID.length == 0) {
            currMessageID = 0;
        }
        $.ajax({
            type: "POST",
            url: commonControllerUrl + '/GetOtherControlHtmlAjax/',
            data: { 'paramStr': 'sendType|' + sendType + ',toUserID|' + toUserID + ',currMessageID|' + currMessageID, 'viewName': 'SendMessage' },
            success: function(data) {
                if ($.trim(data) == 'NoFriend') {
                    AlertTips("系统提示：", "他（她）不是您的好友或粉丝，不能给他（她）发消息！");
                } else if ($.trim(data) == '') {
                    AlertTips("系统提示：", "您目前没有好友或粉丝，不能发消息！");
                } else {
                    $('#ShowLayerContainer').html(data);
                    ShowSendMessage();
                }
            },
            error: function(xmlHttpRequest, error) { }
        });
    });
}
