var msgSelection; function htmlMarkItem(thread_id, status) { if (status == 'new') { $('#msgU' + thread_id).attr('class', 'bold'); $('#msgD' + thread_id).attr('class', 'bold'); } else { $('#msgU' + thread_id).attr('class', ''); $('#msgD' + thread_id).attr('class', ''); } }; function markSelected(folder, status) { if (msgSelection.length == 0) return false; var ajaxSelection = msgSelection[0]; for(var l = 1; l < msgSelection.length; l++) ajaxSelection = ajaxSelection + ',' + msgSelection[l]; if (status == 'new') { $.getJSON( '/ajax.php', {page:'messages', action:'markSelected', msgStatus: status, folderId:folder, threads: ajaxSelection }, function(json){ if (json.result) { window.location.reload(); for(var l = 0; l < msgSelection.length; l++) htmlMarkItem(msgSelection[l], status);} }); } if (status == 'read') { $.getJSON( '/ajax.php', {page:'messages', action:'markSelected', msgStatus: status, folderId:folder, threads: ajaxSelection }, function(json){ if (json.result){window.location.reload(); for(var l = 0; l < msgSelection.length; l++) htmlMarkItem(msgSelection[l], status);} }); } }; function selectAll() { var c = 0; msgSelection = new Array(); $(':checkbox[id=checkMsg]').each(function(i){ $(this).attr('checked', true); msgSelection[c++] = $(this).val(); }); toggleActionMsgBlock(); }; function selectRead() { selectNothing() var c = 0; msgSelection = new Array(); $(':checkbox[id=checkMsg][lang=read]').each(function(i){ $(this).attr('checked', true); msgSelection[c++] = $(this).val(); }); toggleActionMsgBlock(); }; function selectNew() { selectNothing(); var c = 0; msgSelection = new Array(); $(':checkbox[id=checkMsg][lang=new]').each(function(i){ $(this).attr('checked', true); msgSelection[c++] = $(this).val(); }); toggleActionMsgBlock(); }; function selectAnswered() { selectNothing(); var c = 0; msgSelection = new Array(); $(':checkbox[id=checkMsg][lang=answered]').each(function(i){ $(this).attr('checked', true); msgSelection[c++] = $(this).val(); }); toggleActionMsgBlock(); }; function selectNothing() { $(':checkbox[id=checkMsg]').each(function(i){ $(this).attr('checked', false); }); msgSelection = new Array(); toggleActionMsgBlock(); }; function getMsgSelection() { var c = 0; msgSelection = new Array(); $(':checkbox[id=checkMsg]').each(function(i){ if ($(this).attr('checked')) { msgSelection[c++] = $(this).val(); } }); toggleActionMsgBlock(); }; function toggleActionMsgBlock() { if (typeof(msgSelection) != 'undefined' && msgSelection.length > 0) { $('#actionMsgBlock').show(); } else { $('#actionMsgBlock').hide(); } }; /******************************************************************************* * DELETE *******************************************************************************/ function htmlDeleteItem(thread_id) { $('#msg'+thread_id).hide(); $('#msg'+thread_id).html(''); $('#msgFull'+thread_id).hide(); $('#msgFull'+thread_id).html(''); $('#d'+thread_id).hide(); }; function deleteMessage(folder_id, thread_id, owner) { if (!confirm(Q_JS_DELETE_MESSAGE)) return false; $.getJSON( '/ajax.php', {page:'messages', action:'delete', folderId: folder_id, messageId:thread_id}, function(json){ htmlDeleteItem(thread_id); }); toggleActionMsgBlock(); if(folder_id){ location.href = '/profile/messenger_outbox/?owner=' + owner; } else{ location.href = '/profile/messenger_inbox/?owner=' + owner; } }; function deleteSelected(folder_id) { if (!confirm("Вы уверенны, что хотите удалить выбранные сообщения?")) return false; var ajaxSelection = msgSelection[0]; for(var l = 1; l < msgSelection.length; l++) ajaxSelection = ajaxSelection + ',' + msgSelection[l]; $.getJSON( '/ajax.php', {page:'messages', action:'deleteSelected', t: ajaxSelection }, function(json){ if (json.result) for(var l = 0; l < msgSelection.length; l++) htmlDeleteItem(msgSelection[l]); }); $('#actionMsgBlock').hide(); }; function removeRecipient(ids) { $('#rcp'+ids).hide(); recipients.removeItems(ids); }; function sendMessage() { if (recipients.length == 0) { alert(N_JS_ADD_RECIPIENTS); return; } if ($('textarea[id=msg_content]').val() == '') { alert(N_JS_ENTER_TEXT); return; } $.post( '/ajax.php', {page:'messages', action:'create', recipients: recipients.toString(), subject: $('#msg_subject').val(), content: $('textarea[id=msg_content]').val() }, function(response){ eval("var data = "+response+';'); if (data['result']) { showNotification(data['message']); history.back(); } else { $('#msgError').html(data['message']); $('#msgError').fadeIn(600); $('#modalBox').css('display','block'); } }); }; function replyMessage() { if ($('textarea[id=msg_content]').val() == '') { alert(N_JS_ENTER_TEXT); return; } $.post( '/ajax.php', {page:'messages', action:'reply', threadId: $('#thread_id').val(), content: $('textarea[id=msg_content]').val() }, function(response){ eval("var data = "+response+';'); if (data['result']) { showNotification(N_JS_SENT); window.location.reload(); } else { $('#msgError').html(data['message']); $('#msgError').fadeIn(600); //$('#modalBox').css('display','none'); } }); }; function closeThread() { $.post( '/ajax.php', {page:'messages', action:'closeThread', threadId: $('#thread_id').val()}, function(response){ showNotification(OK_CLOSE_THREAD); window.location.reload(); }); }; function formatFriend(row, i, num, searchValue) { var mystr = row; re = new RegExp("("+searchValue+")", "i"); return row[0].replace(re, "$1"); }; function onSelectFriend(value) { var userIds = value.extra[1]; var userName = value.extra[0]; $('#rcp').val(''); if (recipients.inArray(userIds)) { return; } var ins = '
  • '+userName+'
    [ '+LB_JS_DELETE+' ]
  • '; recipients[recipients.length] = userIds; $('#rcps').append(ins); $("ul.postnav a").nifty("small transparent"); }; function getDialogAllFriends (user_id) { $.getJSON( '/ajax.php', {page:'dialogs', action:'getFriends', userId: user_id}, function(json){ completeDialogBox(json); }); }; function getFriendSelection() { var c = 0; friendSelection = new Array(); $(':checkbox[id=checkFr]').each(function(i){ if ($(this).attr('checked')) { friendSelection[c++] = $(this).val(); } }); }; function addMail (friend_count) { var c = 0; friendSelection = new Array(); for (var i = 1; i <= friend_count; i++) if ($('#friend_ids'+i).attr('checked')) { friendSelection[c++] = $('#friend_ids'+i).val(); // строка в виде str = $('#friend_ids'+i).val(); var userName = str.substring(0,str.indexOf("|")); var userIds = str.substring(str.indexOf("|")+1, str.length); $('#rcp').val(''); if (recipients.inArray(userIds)) { return; } var ins = '
  • '+userName+'
    [ '+LB_JS_DELETE+' ]
  • '; recipients[recipients.length] = userIds; $('#rcps').append(ins); $("ul.postnav a").nifty("small transparent"); } if (friendSelection.length == 0) { closeDialog(); showNotification(N_JS_ADD_RECIPIENTS); } else { closeDialog(); showNotification(N_JS_SAVED); } }; function getInnerMail (user_id_to, isSup, objectIds) { $.getJSON( '/ajax.php', {page:'dialogs', action:'getInnerMail', userIdTo: user_id_to, isSup: isSup, objectIds: objectIds}, function(json){ completeDialogBox(json); }); }; function sendMessageToOne(recipient_id, displayType, isSup, objectIds) { if ($('textarea[id=msg_content]').val() == '') { alert(N_JS_ENTER_TEXT); return; } $.post( '/ajax.php', {page:'messages', action:'create', recipients: recipient_id.toString(), subject: 'Письмо', content: $('textarea[id=msg_content]').val(), isSup: isSup, objectIds: objectIds }, function(response){ eval("var data = "+response+';'); if (data['result']) { if (displayType) { showNotification(data['message']); window.history.back(); } else { closeDialog(); showNotification(data['message']); } //window.location.reload(); } else { $('#msgError').html(data['message']); $('#msgError').fadeIn(600); $('#modalBox').css('display','block'); } }); };