﻿// JScript File
function Comment(){
    this.commentid = "";
    this.nforumtopic = "";
}

function saveTopic(user_pk, forum_fk, subject,comment){
       new Ajax.Request("/library/ajaxservices/comments/comments.aspx", {method:'post',asynchronous:true,postBody:'forum_fk=' + forum_fk + '&user_pk=' + user_pk + '&subject=' + escape(subject) + '&comment=' + escape(comment) + '&action=savetopic', onSuccess:function(t){                    
            var nforumtopic = t.responseText;
            window.opener.document.location = t.responseText;
            window.close();
                        
        }, onFailure:function(t){
        alert(t.responseText);
    }}); 
    
}
function saveComment(url,parentcommentid,comment,objectid,sort){                      
       new Ajax.Request("/library/ajaxservices/comments/comments.aspx", {method:'post',asynchronous:true,postBody:'sort=' + sort + '&parentcommentid=' + parentcommentid + '&comment=' + escape(comment)+ '&url=' + escape(url) + '&action=savecomment', onSuccess:function(t){         
             if(parentcommentid.length>0){
                getComment(parentcommentid);
             }else{
                document.getElementById(objectid).innerHTML = t.responseText;     
                try{
                    document.getElementById("oStatus").innerHTML = "";
                }catch(e){}
                                
             }       
        }, onFailure:function(t){
         
        alert(t.responseText);
    }}); 
}
function replyComment(commentid){
    var str = "<div style='padding:5px 5px 5px 5px;' id='oReplyCommentTextBox" + commentid + "'><textarea id='oLeaveComment_" + commentid + "' class='textbox'></textarea></div>";
    str += "<input type='button' class='buttonbig' value='Submit Comment' onclick='savereplycomment(\"" + commentid + "\");' />"
    document.getElementById("replycomment_" + commentid).innerHTML = str;
     var div = document.getElementById("oLeaveComment_" + commentid);
     var fck2 = new FCKeditor("oLeaveComment_" + commentid);
     fck2.ToolbarSet = "Basic";                              
     fck2.BasePath = "/fckeditor/" ;  
     fck2.ReplaceTextarea() ;
}

function getCommentsByURL(url, objectid, sort,page,amountperpage){    
      
      
       document.getElementById("oComments").innerHTML = "<img src='/images/loading.gif' width='120' height='20'>Loading comments...";          
       new Ajax.Request("/library/ajaxservices/comments/comments.aspx", {method:'post',asynchronous:true,postBody:'amountperpage=' + amountperpage + '&page=' + page + '&url=' + url + '&sort=' + sort + '&action=getcommentsbyurl', onSuccess:function(t){         
            document.getElementById(objectid).innerHTML = t.responseText;
                    
                    
        }, onFailure:function(t){
        alert(t.responseText);
    }}); 
    
}
function rateComment(commentid, rating){     
      document.getElementById("comment_" + commentid).style.cursor = "wait";
         
       new Ajax.Request("/library/ajaxservices/comments/comments.aspx", {method:'post',asynchronous:true,postBody:'rating=' + rating + '&commentid=' + commentid + '&action=ratecomment', onSuccess:function(t){         
            document.getElementById("comment_" + commentid).innerHTML = t.responseText;
            document.getElementById("comment_" + commentid).style.cursor = "default";
      
        }, onFailure:function(t){
        alert(t.responseText);
    }}); 
}

function showComment(commentid){              
       new Ajax.Request("/library/ajaxservices/comments/comments.aspx", {method:'post',asynchronous:true,postBody:'commentid=' + commentid + '&action=showcomment', onSuccess:function(t){         
            document.getElementById("comment_" + commentid).innerHTML = t.responseText;
            document.getElementById("showcomment_" + commentid).innerHTML = "[<A href='javascript:hideComment(" +   commentid + ");'>hide comment</a>]";
        }, onFailure:function(t){
        alert(t.responseText);
    }}); 
}

function getComment(commentid){              
       new Ajax.Request("/library/ajaxservices/comments/comments.aspx", {method:'post',asynchronous:true,postBody:'commentid=' + commentid + '&action=getcomment', onSuccess:function(t){         
            
            document.getElementById("commentholder_" + commentid).innerHTML = t.responseText;
            document.getElementById("showcomment_" + commentid).innerHTML = "[<A href='javascript:hideComment(" +   commentid + ");'>hide comment</a>]";
        }, onFailure:function(t){
        alert(t.responseText);
    }}); 
}

function hideComment(commentid){
    getComment(commentid);    
    document.getElementById("showcomment_" + commentid).innerHTML = "[<A href='javascript:showComment(" +   commentid + ");'>show comment</a>]";    
}


function getCommentsByUserID(userid, objectid, sort,page,amountperpage){              
       new Ajax.Request("/library/ajaxservices/comments/comments.aspx", {method:'post',asynchronous:true,postBody:'userid=' + userid + '&sort=' + sort +'&page=' + page+ '&amountperpage=' + amountperpage + '&action=getcommentsbyuserid', onSuccess:function(t){         
            document.getElementById(objectid).innerHTML = t.responseText;                    
        }, onFailure:function(t){
        alert(t.responseText);
    }}); 
}

function incrementtopic(ntopicid,nforumid){              
       new Ajax.Request("/library/ajaxservices/comments/comments.aspx", {method:'post',asynchronous:true,postBody:'ntopicid=' + ntopicid + '&nforumid=' + nforumid + '&action=incrementtopic', onSuccess:function(t){         
           // document.getElementById(objectid).innerHTML = t.responseText;                    
        }, onFailure:function(t){
        alert(t.responseText);
    }}); 
}

Comment.prototype.savetopic = saveTopic;
Comment.prototype.incrementtopic = incrementtopic;            
Comment.prototype.savecomment = saveComment;
Comment.prototype.getcommentsbyurl = getCommentsByURL;
Comment.prototype.getcommentsbyuserid = getCommentsByUserID;
Comment.prototype.ratecomment = rateComment;
