$(document).ready(function() {
    communityNoteSetup();
    memberNoteSetup();
});


function submitMemberNote()
{
    $.ajax({
        type: 'POST',
        dataType: 'json',
        url: '/member/message-new/id/' + $('#member_note_dialog').data('member_id'),
        data: { note: $('#member_note').val() },
        success: function(data) {
            if(data['success'] == false)
            {
                return false;
            }
        },
        error: function() {
            //alert('error');
        }
    });
    $(this).dialog('close');
}


function submitCommunityNote()
{
    $.ajax({
        type: 'POST',
        dataType: 'json',
        url: '/community/message-new/id/' + $('#community_note_dialog').data('community_id'),
        data: { note: $('#community_note').val() },
        success: function(data) {
            if(data['success'] == false)
            {
                return false;
            }
        },
        error: function() {
            //alert('error');
        }
    });
    $(this).dialog('close');
}


function memberNoteStart(member_id, member_name)
{
    $('#member_note').val('');
    $('#note_member_name').text(member_name);
    $('#member_note_dialog').dialog('open')
    $('#member_note').trigger('focus');
    $('#member_note_dialog').data('member_id', member_id);
    return false;
}

function communityNoteStart(community_id, community_name)
{
    $('#community_note').val('');
    $('#note_community_name').text(community_name);
    $('#community_note_dialog').dialog('open')
    $('#community_note').trigger('focus');
    $('#community_note_dialog').data('community_id', community_id);
    return false;
}

function memberNoteSetup()
{
    var member_options = {
                          autoOpen: false,
                          modal: true,
                          draggable: false,
                          title: 'Member to member messaging',
                          buttons: {
                                    'Cancel': function() { $(this).dialog('close'); },
                                    'Submit': submitMemberNote
                                   }
                         };
    $('#member_note_dialog').dialog(member_options);
    $('#member_note').maxLength(140);  //maxlength plugin
}

function communityNoteSetup()
{
    var community_options = {
                             autoOpen: false,
                             modal: true,
                             draggable: false,
                             title: 'Member to community messaging',
                             buttons: {
                                       'Cancel': function() { $(this).dialog('close'); },
                                       'Submit': submitCommunityNote
                                      }
                            };

    $('#community_note_dialog').dialog(community_options);
    $('#community_note').maxLength(140);  //maxlength plugin
}
