/**
 * Author - koder_alex
 * ISQ - 669906617
 * VK - https://vk.com/koder_alex
 * It is forbidden to give, sell, modify.
 */
function vnNow() {
    return +new Date
}

function parseJSON(obj) {
    try {
        return JSON.parse(obj)
    } catch (e) {
        return eval("(" + obj + ")")
    }
}

function bind() {
    var e = Array.prototype.slice.call(arguments), t = e.shift(), a = e.shift();
    return function () {
        var n = Array.prototype.slice.call(arguments);
        return t.apply(a, e.concat(n))
    }
}

(function () {
    var e = vnNow();
    window.clog = function () {
        if (false) try {
            if (window.console && console.log) {
                var t = Array.prototype.slice.call(arguments);
                t.unshift("[" + (vnNow() - e) / 1e3 + "] "), browser.msie || browser.mobile && !browser.safari_mobile ? console.log(t.join(" ")) : console.log.apply(console, t)
            }
        } catch (a) {
        }
    }
})();

function cssToJs(e, t) {
    return t ? t + (e || "").replace(/(?:^|-)([a-z])/g, function (e, t) {
        return (t || "").toUpperCase()
    }) : (e || "").replace(/-([a-z])/g, function (e, t) {
        return (t || "").toUpperCase()
    })
}

function getCssPropertyName(e, t, a) {
    e = ge(e) || ce("div");
    for (var n = ["webkit", "Moz", "ms", "O", ""], o = ["-webkit-", "-moz-", "-ms-", "-o-", ""], i = 0, r = n.length; r > i; i++) {
        var s = n[i], l = cssToJs(t, s);
        if (typeof e.style[l] != "undefined") return a ? o[i] + t : l
    }
    return !1
}

function cssValue(e, t) {
    if ("number" == typeof e) {
        var a = 1e7;
        e = Math.round(e * a) / a + (t || "")
    }
    return e
}

function getStyle(e, t, a) {
    if (e = ge(e), !e) return !1;
    if (isArray(t)) {
        var n = {};
        return each(t, function (t, a) {
            n[a] = getStyle(e, a)
        }), n
    }
    if (isUndefined(a) && (a = !0), /transform(-origin)?|transition(-duration)?/i.test(t) && (t = getCssPropertyName(e, t), !t)) return !1;
    if (!a && "opacity" == t && browser.msie) {
        var o = e.style.filter;
        return o ? o.indexOf("opacity=") >= 0 ? parseFloat(o.match(/opacity=([^)]*)/)[1]) / 100 + "" : "1" : ""
    }
    if (!a && e.style && (e.style[t] || "height" == t)) return e.style[t];
    var i, r = document.defaultView || window;
    if (r.getComputedStyle) {
        t = t.replace(/([A-Z])/g, "-$1").toLowerCase();
        var s = r.getComputedStyle(e, null);
        s && (i = s.getPropertyValue(t))
    } else if (e.currentStyle) {
        if ("opacity" == t && browser.msie) {
            var o = e.currentStyle.filter;
            return o && o.indexOf("opacity=") >= 0 ? parseFloat(o.match(/opacity=([^)]*)/)[1]) / 100 + "" : "1"
        }
        var l = t.replace(/\-(\w)/g, function (e, t) {
            return t.toUpperCase()
        });
        i = e.currentStyle[t] || e.currentStyle[l], "auto" == i && (i = 0), i = (i + "").split(" "), each(i, function (t, a) {
            if (!/^\d+(px)?$/i.test(a) && /^\d/.test(a)) {
                var n = e.style, o = n.left, r = e.runtimeStyle.left;
                e.runtimeStyle.left = e.currentStyle.left, n.left = a || 0, i[t] = n.pixelLeft + "px", n.left = o, e.runtimeStyle.left = r
            }
        }), i = i.join(" ")
    }
    if (a && ("width" == t || "height" == t)) {
        var c = "width" == t ? getW(e) : getH(e);
        i = (intval(i) ? Math.max(floatval(i), c) : c) + "px"
    }
    return i
}

extend(getStyle, {
    transform: function (e) {
        var t, a = getStyle(e, "transform");
        return a ? {
            scale: (t = a.match(/(^|\s+)scale\(([0-9.]+)\)(\s+|$)/)) && t[2] || 1,
            scale3d: (t = a.match(/(^|\s+)scale3d\(([0-9.]+,\s+([0-9.]+),\s+([0-9.]+))\)(\s+|$)/)) && t[2] || 1,
            rotate: (t = a.match(/(^|\s+)rotate\(([0-9.-]+)(deg)?\)(\s+|$)/)) && +t[2] || 0,
            translate: (t = a.match(/(^|\s+)translate\(([0-9.-]+)(px)?(?:,\s+([0-9.-]+)(px)?)\)(\s+|$)/)) && [+t[2], +t[4]] || [0, 0],
            translate3d: (t = a.match(/(^|\s+)translate3d\(([0-9.-]+)(px)?(?:,\s+([0-9.-]+)(px)?)(?:,\s+([0-9.-]+)(px)?)\)(\s+|$)/)) && [+t[2], +t[4], +t[6]] || [0, 0, 0]
        } : {scale: 1, rotate: 0, translate: [0, 0]}
    }
});

function setStyle(e, t, a) {
    if (e = ge(e), e && e.style) {
        if (isObject(t)) return each(t, function (t, a) {
            setStyle(e, t, a)
        });
        var n = "number" == typeof a;
        n && /height|width/i.test(t) && (a = Math.abs(a)), (!/transform(-origin)?|transition(-duration)?/i.test(t) || (t = getCssPropertyName(e, t))) && (e.style[t] = n && !/z-?index|font-?weight|opacity|zoom|line-?height/i.test(t) ? a + "px" : a)
    }
}

extend(setStyle, {
    animate: function (e, t, a, n) {
        var o = getCssPropertyName(e, "transition");
        if (o) {
            if (!t) return e.onAnimationEnd ? e.onAnimationEnd() : setStyle.transition(e), setStyle;
            var i = isObject(a), r = (i ? a.duration : a) || 200, s = a.func || "ease";
            setStyle.transition(e, t, r, s), e.onAnimationEnd && (browser.opera ? e.removeEventListener("oTransitionEnd", e.onAnimationEnd) : removeEvent(e, "transitionend webkitTransitionEnd oTransitionEnd otransitionend msTransitionEnd", e.onAnimationEnd)), e.onAnimationEnd = function () {
                return browser.opera ? e.removeEventListener("oTransitionEnd", e.onAnimationEnd) : removeEvent(e, "transitionend webkitTransitionEnd oTransitionEnd otransitionend msTransitionEnd", e.onAnimationEnd), e.onAnimationEnd = null, setStyle.transition(e), n && n(e), !1
            }, browser.opera ? e.addEventListener("oTransitionEnd", e.onAnimationEnd) : addEvent(e, "transitionend webkitTransitionEnd oTransitionEnd otransitionend msTransitionEnd", e.onAnimationEnd)
        }
        return setStyle
    }, transform: function (e, t, a, n) {
        var o = [];
        if (isObject(t)) {
            has3d && (t.scale3d = t.scale, t.translate3d = t.translate);
            var i = extend(getStyle.transform(e), t);
            t = has3d ? i.scale3d : i.scale, n = i.rotate, a = has3d ? i.translate3d : i.translate
        }
        return "undefined" != typeof t && (has3d ? o.push("scale3d(" + cssValue(t) + ", " + cssValue(t) + ", 1)") : o.push("scale(" + cssValue(t) + ")")), "undefined" != typeof n && o.push("rotate(" + cssValue(n, "deg") + ")"), "undefined" != typeof a && (has3d ? o.push("translate3d(" + cssValue(a[0], "px") + ", " + cssValue(a[1], "px") + ", 0)") : o.push("translate(" + cssValue(a[0], "px") + ", " + cssValue(a[1], "px") + ")")), o.length ? (setStyle(e, "transform", o.join(" ")), void 0) : setStyle(e, "transform", "none")
    }, transformOrigin: function (e, t, a) {
        isArray(t) && (a = t[1], t = t[0]), setStyle(e, "transform-origin", cssValue(t, "px") + " " + cssValue(a, "px"))
    }, transition: function (e, t, a, n) {
        var o = [];
        return t ? (isArray(t) || (t = t.split(/\s*,\s*/)), a = cssValue(a, "ms"), each(t, function () {
            var t = getCssPropertyName(e, this, !0), i = [];
            t && (i.push(t), i.push(a), n && i.push(n), o.push(i.join(" ")))
        }), setStyle(e, "transition", o.join(",")), void 0) : setStyle(e, "transition", "none")
    }
});

function ge(e) {
    return "string" == typeof e ? document.getElementById(e) : e
}

function geByClass1(e, t, a) {
    return geByClass(e, t, a)[0]
}

function gpeByClass(e, t) {
    if (t = ge(t), !t) return null;
    for (; t = t.parentNode;) if (hasClass(e, t)) return t;
    return null
}

function hasClass(e, t, a) {
    return (t = ge(t)) ? new RegExp("(^|\\s)" + (a ? e : escapeRE(e)) + "(\\s|$)").test(t.className) : void 0
}

function escapeRE(e) {
    return e ? e.replace(/([.*+?^${}()|[\]\/\\])/g, "\\$1") : ""
}

function append(e, t) {
    return e = ge(e), t = ge(t), e && t && t.appendChild(e) || !1
}

function before(e, t) {
    return t = ge(t), t && t.parentNode && t.parentNode.insertBefore(ge(e), t) || !1
}

function after(e, t) {
    return t = ge(t), t && t.parentNode && t.parentNode.insertBefore(ge(e), t.nextSibling) || !1
}

function replace(e, t) {
    before(e, t) && remove(t)
}

function remove(e) {
    return e = ge(e), e && e.parentNode ? e.parentNode.removeChild(e) : !1
}

function utf2win(e) {
    return unescape(encodeURIComponent(e))
}

var rf = function () {
    return !1
};

function addEvent(e, t, a) {
    if (e = ge(e), a = a || rf, e && e.nodeType != 3 && e.nodeType != 8) {
        e.setInterval && e != window && (e = window);
        for (var t = t.split(" "), n = 0, o = t.length; o > n; n++) {
            var i = t[n];
            e.addEventListener ? e.addEventListener(i, a, !1) : e.attachEvent && e.attachEvent("on" + i, a)
        }
    }
}

function removeEvent(e, t, a) {
    if (e = ge(e), a = a || rf, e && e.nodeType != 3 && e.nodeType != 8) for (var t = t.split(" "), n = 0, o = t.length; o > n; n++) {
        var i = t[n];
        e.removeEventListener ? e.removeEventListener(i, a, !1) : e.detachEvent && e.detachEvent("on" + i, a)
    }
}

function uploadFile(e, t, a) {
    var n = window.XDomainRequest || window.XMLHttpRequest, o = new n;
    o.open("POST", e, !0), o.upload.addEventListener("progress", a.onProgress || rf, !1), o.onload = a.onComplete || rf, o.onerror = a.onError || rf;
    var i = a.onStart || rf;
    if (window.FormData) {
        var r = new FormData;
        for (var s in t) r.append(s, t[s]);
        return o.send(r), i(o), o
    }
    /**
     * Для некоторых устарелых браузеров
     */
    try {
        if (n && !n.prototype.sendAsBinary && window.ArrayBuffer && window.Uint8Array) {
            var l = window.MozBlobBuilder || window.WebKitBlobBuilder || window.BlobBuilder;
            l && (n.prototype.sendAsBinary = function (e) {
                for (var t = new ArrayBuffer(e.length), a = new Uint8Array(t, 0), n = 0; n < e.length; n++) a[n] = e.charCodeAt(n) & 255;
                var o = new l;
                o.append(t);
                var i = o.getBlob();
                this.send(i)
            })
        }
        var c = "----" + srand(), u = "", d = 0, p = function (e, t, a) {
            a += "--" + t + "--", e.setRequestHeader("Content-type", 'multipart/form-data; boundary="' + t + '"'), e.sendAsBinary(a), i(e)
        };
        for (var s in t) if (typeof t[s].getAsBinary == "function") {
            d++;
            var v = new FileReader, f = t[s], h = f.fileName || f.name || "";
            v.onload = function () {
                u += "--" + c + "\r\n" + 'Content-Disposition: form-data; name="' + utf2win(s) + '"; filename="' + utf2win(h) + '"' + "\r\n" + "Content-Type: application/octet-stream\r\n", 0 + v.result + "\r\n", d--, d || p(o, c, u)
            }, v.readAsBinaryString(f)
        } else u += "--" + c + "\r\n" + 'Content-Disposition: form-data; name="' + utf2win(s) + '"\r\n' + "\r\n" + utf2win(t[s]) + "\r\n";
        return d || p(o, c, u), o
    } catch (_) {
        return !1
    }
    return !1
}

function readFile(e, t) {
    if (window.FileReader) {
        var a = new FileReader;
        a.onload = function () {
            t && t(a.result), a = null
        }, a.readAsDataURL(e)
    }
}

function show(e) {
    var t = ge(e);
    t && (t.style.display = t.oldstyle || (hasClass("_ib", t) ? "inline-block" : hasClass("_i", t) || tag(t) == "span" ? "inline" : "block"))
}

function hide(e) {
    var t = ge(e);
    t && (t.style.display != "none" && (t.oldstyle = t.style.display), t.style.display = "none")
}

function isVisible(e) {
    var t = ge(e);
    return t && t.style ? t.style.display != "none" : !1
}

function toggle(e, t) {
    "undefined" == typeof t && (t = !isVisible(e)), t && isVisible(e) || (t || isVisible(e)) && (t ? show : hide)(e)
}

function addClass(e, t) {
    (t = ge(t)) && !hasClass(e, t) && (t.className = (t.className ? t.className + " " : "") + e)
}

function removeClass(e, t, a) {
    (t = ge(t)) && hasClass(e, t, a) && (t.className = (t.className || "").replace(new RegExp("(^|\\s)" + (a ? e : escapeRE(e)) + "(\\s|$)"), function (e, t, a) {
        return t && a ? " " : ""
    }))
}

function toggleClass(e, t, a) {
    var n = "undefined" == typeof a ? hasClass(e, t) : !a;
    n ? removeClass(e, t) : addClass(e, t)
}

function cancelEvent(e) {
    return (e = e || window.event) ? (e = e.originalEvent || e, e.preventDefault && e.preventDefault(), e.stopPropagation && e.stopPropagation(), e.cancelBubble = !0, e.returnValue = !1, !1) : !1
}

function isObject(e) {
    return "object" === typeof e
}

function clone(e) {
    return e = ge(e), e ? e.cloneNode(!0) : !1
}

function reflow(e) {
    e = ge(e);
    try {
        e.offsetWidth + e.offsetHeight
    } catch (t) {
    }
}

function des2num(int, array) {
    var cases = [2, 0, 1, 1, 1, 2];
    return int + array[(int % 100 > 4 && int % 100 < 20) ? 2 : cases[Math.min(int % 10, 5)]]
}

(function ($) {
    var interVal = 5e3;
    var timerID = undefined;
    $.fn.AnimateHide = function (interval) {
        var self = this;
        if (interval !== undefined) {
            interVal = interval;
        } else {
            interVal = 5e3;
        }
        if (timerID !== undefined) {
            clearTimeout(timerID);
        }
        timerID = setTimeout(function () {
            return self.remove();
        }, interVal);
    };
})(jQuery);

function messageBox(type, text) {
    $('#service_msg_box').remove();
    var node = $('.vk_mail');
    node.prepend('<div id="service_msg_box" class="service_msg_box"><div class="service_msg service_msg_' + type + '">' + text + '</div></div>');
    $('#service_msg_box').AnimateHide();
    return node;
}

function srand() {
    return Math.random().toString(36).substr(2)
}

function each(e, t) {
    if (!e) return e;
    var a, n = 0, o = e.length;
    if ("undefined" == typeof o) {
        for (a in e) if (t.call(e[a], a, e[a]) === !1) break
    } else for (var i = e[0]; o > n && t.call(i, n, i) !== !1; i = e[++n]) ;
    return e
}

function isUndefined(e) {
    return "undefined" == typeof e
}

function intval(e) {
    return e === !0 ? 1 : parseInt(e) || 0
}

mediaUpload = function () {
    var countPhotoLoad = 5;
    return {
        _uploadData: {},
        _uploadQueue: [],
        _readerQueue: [],
        _processUploadQueue: !1,
        _processReaderQueue: !1,
        clearAttaches: function () {
            mediaUpload._uploadData = {};
            mediaUpload._uploadQueue = [];
            mediaUpload._readerQueue = [];
            mediaUpload._processUploadQueue = !1;
            mediaUpload._processReaderQueue = !1;
        }, getAttachesCount: function () {
            return (geByClass("medias_thumb", ge("attachments")) || []).length
        }, refreshUploadState: function (e) {
            isUndefined(e) && (e = mediaUpload.getAttachesCount());
            var a = ge("attach_photo_btn"),
                n = geByClass1("pi_medias", ge("attachments")), o = geByClass1("inline_upload", a),
                i = countPhotoLoad;
            toggle(n, e > 0), toggleClass("cp_attach_btn_sel", a, e > 0), o && (o.disabled = e >= i, toggleClass("ms_attachments_label_disabled", a, e >= i))
        }, checkUploading: function (e) {
            return mediaUpload._processUploadQueue ? cancelEvent(e) : !0
        }, start: function (e, t) {
            var c = mediaUpload.getAttachesCount(), r = attr(e, "data-upload");
            return (each(e.files, function () {
                var e = {upload_url: r, file: this, uploaded: !1, attached: !1};
                return c >= countPhotoLoad ? !1 : (mediaUpload.queueInsert(e), mediaUpload.addFile(e), c++, void 0)
            }), removeEvent(e, "click", mediaUpload.checkUploading), addEvent(e, "click", mediaUpload.checkUploading), mediaUpload.refreshUploadState(c), replace(clone(e), e), mediaUpload._processUploadQueue || mediaUpload.uploadQueueNext(), !1);
        }, attachedPhotoTpl: function (e) {
            return ce("div", {
                id: "upload_item_" + e,
                className: "medias_thumb thumb_item thumb_upload",
                innerHTML: '<div id="upload_image_' + e + '" class="tu_img"></div>' + '<div id="item_progress_wrap_' + e + '" class="tu_progress_wrap">' + '<div id="item_progress_' + e + '" class="tu_progress"></div>' + "</div>" + '<div id="item_cancel_wrap_' + e + '" class="tu_cancel_wrap" onclick="return mediaUpload.reset(this, event, \'' + e + "');\">" + '<div id="item_cancel_' + e + '" class="tu_cancel"></div>' + "</div>"
            })
        }, uploadQueueNext: function () {
            clog("next upload"), mediaUpload._processUploadQueue = !0;
            var e = mediaUpload.uploadQueueRemove();
            return e ? (mediaUpload.uploadFile(e),void 0) : (clog("empty upload"), mediaUpload._processUploadQueue = !1, val(geByClass1("inline_upload", ge("attach_photo_btn")), ""),  void 0)
        }, uploadQueueRemove: function () {
            var e = mediaUpload._uploadQueue.shift();
            return e ? mediaUpload.getUploadDataById(e) : !1
        }, queueInsert: function (e) {
            var t = srand();
            return mediaUpload.getUploadDataById(t) ? mediaUpload.queueInsert(e) : (mediaUpload._uploadData[t] = extend(e, {id: t}), mediaUpload._uploadQueue.push(t), mediaUpload._readerQueue.push(t), mediaUpload._uploadData[t])
        }, getUploadDataById: function (e) {
            return mediaUpload._uploadData[e] || !1
        }, addFile: function (e) {
            var t = ge("attachments"), a = geByClass1("pi_medias", t), n = a ? geByClass("medias_thumb", a) : [],
                o = a ? geByClass1("medias_row", a) : null, i = n[n.length - 1], r = mediaUpload.attachedPhotoTpl(e.id);
            t && (a || (a = ce("div", {className: "pi_medias"}), append(a, t)), i ? after(r, i) : o ? before(r, o) : append(r, a), mediaUpload._processReaderQueue || mediaUpload.readerQueueNext())
        }, readerQueueNext: function () {
            clog("next reader"), mediaUpload._processReaderQueue = !0;
            var e = mediaUpload.readerQueueRemove();
            return e ? (mediaUpload.readFile(e), void 0) : (clog("empty reader"), mediaUpload._processReaderQueue = !1, void 0)
        }, readerQueueRemove: function () {
            var e = mediaUpload._readerQueue.shift();
            return e ? mediaUpload.getUploadDataById(e) : !1
        }, delUploadDataById: function (e) {
            delete mediaUpload._uploadData[e]
        }, uploadFile: function (e) {
            e.xhr = uploadFile(e.upload_url, {photo: e.file}, {
                onProgress: bind(mediaUpload.onUploadProgress, e),
                onComplete: bind(mediaUpload.onUploadComplete, e),
                onError: bind(mediaUpload.onUploadError, e)
            })
        }, readFile: function (e) {
            readFile(e.file, function (t) {
                var a = ge("upload_image_" + e.id);
                if (a) var n = ce("img", {
                    id: "upload_image_" + e.id, className: "ph_img", onload: function () {
                        replace(n, a), e.iw = n.width, e.ih = n.height
                    }, src: t
                });
                mediaUpload.readerQueueNext()
            })
        }, onUploadProgress: function (e) {
            var t = this, a = (ge("upload_item_" + t.id), ge("item_progress_" + t.id));
            setStyle(a, {width: e.loaded / e.total * 100 + "%", visibility: "visible"})
        }, onUploadComplete: function (e) {
            var t = this, a = e.target.responseText, n = !1, u = ge("upload_image_" + t.id);
            try {
                n = parseJSON(a)
            } catch (o) {
                n = {error: "Ошибка при загрузке фото..."}
            }
            n.error ? (messageBox('warning', n.error), remove(ge("upload_item_" + t.id))) : (function () {
                var a = ge("item_progress_wrap_" + t.id);
                if (u) {
                    var i = ce("img", {
                        id: "upload_image_" + t.id, className: "ph_img", onload: function () {
                            replace(i, u), reflow(i), setStyle(i, "opacity", 1)
                        }, src: n.src
                    });
                }
                setStyle(a, "opacity", 0), t.attached = !0, t.delete_url = n.delete_url
            }(), addClass("tu_progress_request", "item_progress_wrap_" + t.id), t.uploaded = !0, mediaUpload.uploadQueueNext())
        }, onUploadError: function (e) {
            clog("upload error."), mediaUpload.uploadQueueNext()
        }, reset: function (e, t, a) {
            cancelEvent(t);
            if (a[0] == "/") {
                $.post(attr(e, 'href'), {im_ajax: true}, function (data) {
                    if (data.error) {
                        messageBox('error', data.error);
                    } else {
                        var n = gpeByClass("medias_thumb", e);
                        remove(n)
                        mediaUpload.refreshUploadState()
                    }
                });

            } else {
                var o = a, i = mediaUpload.getUploadDataById(o);
                if (!i) return !1;
                if (i.delete_url) {
                    $.post(i.delete_url, {im_ajax: true}, function (data) {
                        if (data.error) {
                            messageBox('error', data.error);
                        } else {
                            i.attached ? void 0 : (i.xhr && i.xhr.abort && i.xhr.abort(), i.loaded || mediaUpload.uploadQueueNext()), remove("upload_item_" + o), mediaUpload.delUploadDataById(o)
                            mediaUpload.refreshUploadState()
                        }
                    });
                }
            }
            return !1
        }
    }
}(), MessagesActions = function () {
    return {
        BoxClose: function (d) {
            d = $(d.parentNode);
            d.slideUp(400, function (e) {
                d.remove();
            })
        },
        actionsOpened: function (t, e) {
            cancelEvent(e);
            $(t.parentNode).toggleClass('head_actions_opened');
        }
    }
}(), mail = function () {
    var interval = (new Date).getTime() + request.update;
    var isLoad = false;
    return {
        keyup: function (e, t) {
            var a = $(e).val() || "";
            (a.length > 0) && (this.myTyping(t))
        },
        myTyping: function (peer_id) {
            var date = (new Date).getTime();
            if (interval <= date) {
                interval = date + 2e3;
                $.post('/mail/?act=dataSend&func=myTyping', {im_ajax: true, peer: peer_id});
                return false
            }
        },
        send: function (t, peer_id) {
            var config = $('#data-text'), attachments = $('#attachments'), text = $('textarea'), n = $('.vk_mail');
            var data = {min: config.attr('data-min'), max: config.attr('data-max'), textLength: text.val().length};
            if (attachments.length == 0 && data.textLength < data.min || data.textLength > data.max) {
                messageBox('warning', 'Сообщение должно быть длиной не менее ' + des2num(data.min, ['-го', '-х', '-ти']) + ' и не более ' + des2num(data.max, ['-го', '-х', '-ти']) + ' символов.');
                return false;
            }
            mediaUpload.clearAttaches();
            t = $(t);
            t.before(ce('button', {
                className: 'button',
                id: 'nowrite_submit',
                innerHTML: '<span class="button_locked"><b class="button_locked_label">Отправить</b></span>',
                disabled: "disabled"
            }));
            t.hide();
            $.post('/mail/?act=dataSend&func=dialog', {
                im_ajax: true,
                to: peer_id,
                from: 'dialog',
                message: text.val()
            }, function (data) {
                $('#nowrite_submit').remove();
                t.show();
                if (!data.mail) {
                    messageBox('error', 'Неизвестная ошибка.');
                }
                if (data.msg_box && data.type) {
                    messageBox(data.type, data.msg_box);
                }
                if ('ok' == data.type) {
                    text.val('');
                    attachments.length >= 1 && (attachments.slideUp(400, function (e) {
                        $(this).html('<div class="pi_medias"></div>').show();
                        $('.cp_attach_btn_sel').removeClass('cp_attach_btn_sel');
                    }));
                    n = $('#messages');
                    n.find('#show_msg_box').length > 0 && (n.find('#show_msg_box').remove());
                    n.prepend(data.mail);
                }
            }, 'json');
            return false;
        },
        updateMail: function (peer_id) {
            $.post('/mail/?act=dataSend&func=update', {im_ajax: true, peer: peer_id}, function (data) {
                if (isObject(data) === false || data.length === 0)
                    return false;
                var n = $('#messages');
                if (data.typing) {
                    $('.near_btn').addClass('di_typing_now di_typing_animated');
                } else {
                    $('.near_btn').removeClass('di_typing_now di_typing_animated');
                }
                if (data.read) {
                    n.find('.mi_unread').removeClass('mi_unread');
                }
                if (data.message.length > 0) {
                    for (var i = 0; i < data.message.length; i++) {
                        n.prepend($(data.message[i]).hide().fadeIn(400));
                    }
                    if (data.message.length > 0) {
                        n.find('#show_msg_box').length > 0 && (n.find('#show_msg_box').remove());
                    }
                }
            }, 'json');
        }, updateContact: function () {
            var n = $('#contactUpdate');
            $.post('/mail/?act=dataSend&func=contact', {im_ajax: true, page: n.attr('data-page')}, function (data) {
                if (isObject(data) === false || data.length === 0)
                    return false;
                if (data.contact.length > 0) {
                    n.empty();
                    for (var i = 0; i < data.contact.length; i++) {
                        n.prepend(data.contact[i]);
                    }
                }
            }, 'json');
        }, loadMess: function (peer_id) {
            if (isLoad) {
                return;
            }
            isLoad = true;
            $('#show_more').removeClass('show_more').addClass('show_more_loading').html('<span class="button_locked"></span>');
            var match = location.search.match(/p=(\d+)/i);
            if (match !== null && match[1] !== null)
                request.page = parseInt(match[1]) + 1;
            var node = $('#messages');
            $.ajax({
                url: '/mail/?act=dataSend&func=load_mess',
                type: 'post',
                data: {im_ajax: true, peer: peer_id, p: request.page},
                success: function (data) {
                    if (isObject(data) === false || data.length === 0)
                        return false;
                    if (data.message.length > 0) {
                        $('.show_more_wrap').remove();
                        node.append('<div class="di_activity">Страница: ' + request.page + '</div>');
                        for (var i = 0; i < data.message.length; i++) {
                            node.append(data.message[i]);
                        }
                        var link = '/mail/?act=show&peer=' + peer_id + '&p=' + request.page;
                        window.history.pushState({path: link}, null, link);
                        request.page++;
                    } else {
                        request.page = 2;
                        var link = '/mail/?act=show&peer=' + peer_id + '&p=' + request.page;
                        window.history.pushState({path: link}, null, link);
                    }
                },
                complete: function () {
                    isLoad = false;
                    $('.show_more_wrap').show();
                }
            })
        }
    }
}();
