﻿// JScript File
function Comment(){
    this.commentid = "";
}
function saveComment(pollid,parentcommentid,comment,url,objectid,savebyurl){
       if (parentcommentid) {
         showWaitDiv("oDivCommentZoneReply",true);  
       } else {
         showWaitDiv("oDivCommentZone",true);
       }
       savebyurl = savebyurl ? "savecommentbyurl" : "savecomment";
       new Ajax.Request("/ajaxservices/comments/comments.aspx", {method:'post',asynchronous:true,postBody:'parentcommentid=' + parentcommentid + '&pollid=' + pollid + '&comment=' + escape(comment)+ '&url=' + escape(url) + '&action=' + savebyurl, onSuccess:function(t){         
             if(parentcommentid.length>0){
                getComment(parentcommentid);
             }else{
               document.getElementById(objectid).innerHTML = t.responseText;                         
             }
             if (url.indexOf("#commtentTop") < 1)
             {
                document.location.href = url + "#commtentTop";
             }
             showSuccessfulMsg("");
             document.getElementById("oLeaveComment").innerHTML = ""; 
             document.getElementById("oLeaveComment").value = "";
        }, onFailure:function(t){
        alert(t.responseText);
    }}); 
}

function replyComment(commentid){
    var str = "<div style='padding:5px 5px 5px 5px;'><textarea id='oLeaveComment_" + commentid + "' class='textbox'></textarea></div>";
    str += "<div id='oDivCommentZoneReply'>&nbsp;<input type='button' class='buttonbig' value='"+ lexicon.LEX_SUBMIT_COMMENT +"' onclick='saveReplyComment(\"" + commentid + "\");' /></div>";
    
    document.getElementById("replycomment_" + commentid).innerHTML = str;
}

function rateComment(commentid, rating,readonly){ 
       showWaitDiv('oDivRateComment' + commentid,true,false,false); 
       if (readonly == 'readonly') {readonly = "&readonly=1";} else { readonly = ""; }        
       new Ajax.Request("/ajaxservices/comments/comments.aspx", {method:'post',asynchronous:true,postBody:'rating=' + rating + '&commentid=' + commentid + '&action=ratecomment' + readonly, onSuccess:function(t){         
            document.getElementById("comment_" + commentid).innerHTML = t.responseText;
            showSuccessfulMsg("");
        }, onFailure:function(t){
        alert(t.responseText);
    }}); 
}

function showComment(commentid){              
       new Ajax.Request("/ajaxservices/comments/comments.aspx", {method:'post',asynchronous:false,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.Requst("/ajaxservices/comments/comments.aspx", {method:'post',asynchronous:false,postBody:'commentid=' + commentid + '&action=getcomment', onSuccess:function(t){         
            document.getElementById("comment_" + commentid).innerHTML = t.responseText;
            document.getElementById("showcomment_" + commentid).innerHTML = "[<A href='javascript:hideComment(\"" +   commentid + "\");'>"+lexicon.LEX_HIDE_COMMENT+"</a>]";
        }, onFailure:function(t){
        alert(t.responseText);
    }}); 
}

function hideComment(commentid){
    getComment(commentid);    
    document.getElementById("showcomment_" + commentid).innerHTML = "[<A href='javascript:showComment(\"" +   commentid + "\");'>"+lexicon.LEX_SHOW_COMMENT+"</a>]";    
}

function getCommentsByPollId(pollid,page,amountperpage,objectid){
       showWaitDiv(document.getElementById(objectid),false,false,true);             
       new Ajax.Request("/ajaxservices/comments/comments.aspx", {method:'post',asynchronous:true,postBody:'pollid=' + pollid + '&page=' + page + '&amountperpage=' + amountperpage + '&action=getcommentsbypollid', onSuccess:function(t){         
            document.getElementById(objectid).innerHTML = t.responseText;
            showSuccessfulMsg("");
        }, onFailure:function(t){
        alert(t.responseText);
    }}); 
    
}

function getCommentsByUserID(userid,page,amountperpage,objectid,readonly){  
       if (readonly == 'readonly') {readonly = "&readonly=1";} else { readonly = ""; }
       new Ajax.Request("/ajaxservices/comments/comments.aspx", {method:'post',asynchronous:true,postBody:'userid=' + userid + '&page=' + page + '&amountperpage=' + amountperpage + '&action=getcommentsbyuserid' + readonly, onSuccess:function(t){         
            document.getElementById(objectid).innerHTML = t.responseText;  
            showSuccessfulMsg("");                  
        }, onFailure:function(t){
        alert(t.responseText);
    }}); 
}

function getCommentsByURL(url,page,amountperpage,objectid){
       showWaitDiv(document.getElementById(objectid),false,false,true);              
       new Ajax.Request("/ajaxservices/comments/comments.aspx", {method:'post',asynchronous:true,postBody:'url=' + escape(url) + '&page=' + page + '&amountperpage=' + amountperpage + '&action=getcommentsbyurl', onSuccess:function(t){         
            document.getElementById(objectid).innerHTML = t.responseText;  
            showSuccessfulMsg("");                  
        }, onFailure:function(t){
        alert(t.responseText);
    }}); 
}

Comment.prototype.savecomment = saveComment;
Comment.prototype.getcommentsbypollid = getCommentsByPollId;
Comment.prototype.getcommentsbyuserid = getCommentsByUserID;
Comment.prototype.ratecomment = rateComment;
Comment.prototype.getcommentsbyurl = getCommentsByURL;
