﻿$(document).ready(function() {
    $("a.add").click(function() {
        var divElement = $(this).parent("p").parent("div.add_comment_inner");
        var text = divElement.find("textarea:first").val();
        if (text == "") {
            alert("Введите текст комментария");
        } else if (text.length > 2500) {
            alert("Текст комментария не должен превышать 2500 символов");
        } else {
            var newID = divElement.find("input#newid").val();
            var result = AddComment.ClientAddComment(newID, text).value;
            divElement.find("textarea:first").val("");
            alert(result);

            if (result == "Спасибо за Ваш комментарий!") {
                document.location.reload();
            }

            var blockID = divElement.parent("div.add_comment").attr("id");
            show_hide(blockID);
        }
        return false;
    });

    $("img.smarttag").click(function() {
        var textarea = $(this).parent("div.add_comment").find("textarea:first");
        if (textarea) {

            var text = prompt("Введите адрес URL ссылки, которую Вы хотите добавить:", "");
            if (text != null && text != "") {
                var text2 = prompt("Введите текст ссылки:", "");
                if (text2 != null) {
                    var result = "";
                    if (text2 == "") {
                        result = "[url=" + text + "]" + text + "[/url]";
                    }
                    else {
                        result = "[url=" + text + "]" + text2 + "[/url]";
                    }
                    textarea.replaceSelection(result, true);
                }
            }
        }
    });
    $("a.link").click(function() {
        var textarea = $(this).parent("div.add_comment").find("textarea:first");
        if (textarea) {

            var text = prompt("Введите адрес URL ссылки, которую Вы хотите добавить:", "");
            if (text != null && text != "") {
                var text2 = prompt("Введите текст ссылки:", "");
                if (text2 != null) {
                    var result = "";
                    if (text2 == "") {
                        result = "[url=" + text + "]" + text + "[/url]";
                    }
                    else {
                        result = "[url=" + text + "]" + text2 + "[/url]";
                    }
                    textarea.replaceSelection(result, true);
                }
            }
        }
    });
});
