﻿// JScript File

function CommentPoster()
{
    this.parentid = 0;
    this.text = '';
    this.sessionid = '';
    
    this.PostProfileComment = PostProfileComment;
    this.PostProfileCommentReply = PostProfileCommentReply;
}

function ReplyPoster()
{
    this.parentid = 0;
    this.text = '';
    this.sessionid = '';
    
    this.PostProfileCommentReply = PostProfileCommentReply;
}

function PostProfileComment(ResultFunction)
{
    if(this.text.length == 0) return;
    
    var vars = new Array();
    vars[0] = 'text=' + this.text;
    vars[1] = 'item-id=' + this.parentid;
    
    var a = new AjaxCall('profile.comment.save', vars);
    var ta = document.getElementById('profile-comment-ta');

    a.sessionid = this.sessionid;
    
    ta.disabled = true;
    a.Send(ResultFunction);
}

function PostProfileCommentReply(ResultFunction)
{
    if(this.text.length == 0) return;
    
    var vars = new Array();
    vars[0] = 'text=' + this.text;
    vars[1] = 'item-id=' + this.parentid;
    
    var a = new AjaxCall('profile.comment.reply.save', vars);
    var ta = document.getElementById('profile-comment-ta');

    a.sessionid = this.sessionid;
    
    ta.disabled = true;
    a.Send(ResultFunction);
}

function PostMyComment(sessionid, itemid)
{
    var c = new CommentPoster();
    var ta = document.getElementById('profile-comment-ta');
    
    c.sessionid = sessionid;
    c.text = ta.value;
    c.parentid = itemid;
    
    c.PostProfileComment(function (txt) {
    
        $('#profile-comment-form-div').fadeOut(200);
        $('#pcr-text').html(c.text);

        txt = $('#profile-comment-result').html();
        
        $('#NewCommentsDiv').html(txt + $('#NewCommentsDiv').html()) ;
        ta.value = '';
        ta.disabled = false;
    });
}

function PostMyReply(sessionid, commentid)
{
    var c = new CommentPoster();
    var ta = document.getElementById('ReplyTextArea' + commentid.toString());
    
    c.sessionid = sessionid;
    c.text = ta.value;
    c.parentid = commentid;
    
    c.PostProfileCommentReply(function (txt) {
        $('#pcrr-text').html(c.text);
        txt = $('#profile-reply-result').html();
        
        $('#NewCommentReplies' + commentid.toString()).html(txt + $('#NewCommentReplies' + commentid.toString()).html()) ;
        ta.value = '';
        ta.disabled = false;
        $('#reply-form-div-' + commentid).fadeOut(200)
        $('#reply-box-' + commentid).show();
    });
}
