﻿$(document).ready(function () {
    $("#comment-button").click(function (event) {
        $('#add-comment').show(600);
    });

    $("#comment-submit").click(function (event) {

        var commentText = escape($("#txtComment").val());

        $.ajax({
            type: "POST",
            url: "DataService.asmx/AddComment",
            data: "{'Text': '" + commentText + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                //                alert(msg.d);
                var jsonData = jQuery.parseJSON(msg.d);
                var CommentID = jsonData.CommentID;
                ErrorMessage = jsonData.Error;

                if (ErrorMessage.length == 0) {
                    $('#add-comment').hide();
                    alert('You comment has been successfully posted.');
                    window.location = 'Default.aspx';
                }
                else {
                    alert(ErrorMessage);
                    //                    $('#login-feedback').html(ErrorMessage);
                }
            },
            error: function (e) {
                alert(e.d);
                alert('You comment has been successfully posted.');
            }
        });

        event.preventDefault();


    });
});
