﻿// JScript File
var _CommentMaxLimit = 500;
var http_request = false;

var frmreplyprefix ="comment_form_id_";
var btnpostprefix="imgPostComment";
var btndiscardprefix="imgDiscardComment";
var txtCommentPrefix= "txtComment";
var watchcommentbody="watch-comment-body";
var commentbody ="comment_body_";
var lblMessagePrefix = "lblMessage";
var lblCountPrefix = "lblCount";
var spamvotecountPrefix="span_votecount";
var spamvoteactionPrefix="span_voteaction";
var spamprefix ="markasspam";
var showlink="showlink";
var hidelink="hidelink";
var replylink = "replylink";
var removelink="removelink";
var approvelink="approvelink";
var deletelink="deletelink";

//For Edit Funtionality
var btnEditprefix="imgEditComment";
var txtEditCommentPrefix = "txtEditComment";

   
   
/**************************************************************************************************/
function updateCharCount(textArea, label_id,bLimit,event) 
{
//ValidateText(event, textArea);

if(bLimit=="True")
{

    var currentVal
    if (textArea.value.length > _CommentMaxLimit) 
        textArea.value= textArea.value.substring(0, _CommentMaxLimit);
    else
        document.getElementById(label_id).innerHTML = _CommentMaxLimit - textArea.value.length;
}
}
//For reset the comment textbox
function discard(textArea, label_id,bLimit)
{

try{    
    document.getElementById(textArea).value ="";
    document.getElementById(textArea).focus();
    if(bLimit=="True")
        document.getElementById(label_id).innerHTML = 500;
    }catch(e){}

}
function discardSub(commentid,bLimit)
{

try{    
if(document.getElementById(txtEditCommentPrefix+commentid))
    document.getElementById(txtEditCommentPrefix+commentid).value =document.getElementById(watchcommentbody+commentid).innerHTML.replace(/<br>/g, ''); ;
    document.getElementById(txtCommentPrefix+commentid).value ="";
    document.getElementById("lblMessage"+commentid).innerHTML ="";
    document.getElementById(txtCommentPrefix+commentid).disabled = false;
    document.getElementById(btnpostprefix+commentid).disabled = false;
    document.getElementById(btnpostprefix+commentid).src = "/images/site/pHion/common/Post.Comment.Button_Up.gif";
    if(bLimit=="True")
        document.getElementById(lblCountPrefix +commentid).innerHTML =_CommentMaxLimit;
    document.getElementById(frmreplyprefix+commentid).style.display ="none";
    }catch(e){}

}

function validcomment(textArea)
{

    var txt = document.getElementById(textArea).value.trim();
    if(txt.length < 1)
    {
        alert("You must enter a comment.");
        return false;
    }
}

function showCommentReplyForm(comment_form_id, id)
{

var frm = document.getElementById(comment_form_id);
if(frm!=null)
 {
    
    frm.style.display = "";
    //show edit object
    if(document.getElementById(btnEditprefix+id))
        document.getElementById(btnEditprefix+id).style.display="none";
    if(document.getElementById(txtEditCommentPrefix+id))
        document.getElementById(txtEditCommentPrefix+id).style.display="none";
        
    //hide add objects    
     if(document.getElementById(txtCommentPrefix+id))
        document.getElementById(txtCommentPrefix+id).style.display="";
    if(document.getElementById(btnpostprefix+id))
        document.getElementById(btnpostprefix+id).style.display="";    
 }

    
}

function postCommentReplyForm(textArea, productid, parentid,active)
{
    vComment = document.getElementById(textArea).value.trim();
   vComment=vComment.replace(/&/g, '%26'); 
  
        if(vComment.length < 1)
        {
            alert("You must enter a comment.");
            document.getElementById(textArea).focus();
            return false;
        }
        else
        {
          var poststr = "txtcomment=" + encodeURI( vComment ) +
                    "&productid=" + productid +"&parentid="+parentid+"&active="+active ;
              makePOSTRequest('/App_UI/site/pHion/Public/postComment.aspx', poststr);
            
            document.getElementById(textArea).disabled = true;
            
            document.getElementById(btnpostprefix+parentid).src = "/images/site/pHion/v2/btn_post_comment_disabled.gif";
            document.getElementById(btndiscardprefix+parentid).src = "/images/site/pHion/v2/btn_discard_disable.gif";
            document.getElementById(btnpostprefix+parentid).disabled = true;
            document.getElementById(btndiscardprefix+parentid).disabled = true;
            document.getElementById("lblMessage"+parentid).innerHTML ="Thanks for comment." ;
        }
  }


function voteComment(commentid, productid, rate)
{
    var poststr = "rate="+rate+"&productid=" + productid +"&commentid="+commentid ;
    var currentrate = document.getElementById(spamvotecountPrefix+commentid).innerHTML;
    currentrate =parseInt(currentrate.trim(),0)+ parseInt(rate,0) ;
    makePOSTRequest('/App_UI/site/pHion/Public/postComment.aspx', poststr);
    document.getElementById(spamvotecountPrefix+commentid).innerHTML =currentrate+"&#160;&#160;" ; 
    if(rate == 1)
    {
    document.getElementById(spamvotecountPrefix+commentid).className="watch-comment-score watch-comment-green";
    var voteaction="<span id='span_voteaction"+commentid+"'><img src='/images/site/pHion/common/Thumbs.Down_Up.gif' class='watch-comment-down-hover' title='Poor comment' alt='Poor comment' />"+
    "&#160;<img src='/images/site/pHion/common/Thumbs.Up_Over.gif' class='watch-comment-down-hover' title='Good comment' alt='Good comment'/> </span>";          
   
    }
    else
    {
    document.getElementById(spamvotecountPrefix+commentid).className="watch-comment-score watch-comment-red";
    var voteaction="<span id='span_voteaction"+commentid+"'><img src='/images/site/pHion/common/Thumbs.Down_Over.gif' class='watch-comment-down-hover' title='Poor comment' alt='Poor comment'>"+
    "&#160;<img src='/images/site/pHion/common/Thumbs.Up_Up.gif' class='watch-comment-down-hover' title='Good comment' alt='Good comment'/> </span>";          
    
    }
     
    document.getElementById(spamvoteactionPrefix+commentid).innerHTML =voteaction;            
    
    
}

function spam(commentid)
{
   var poststr = "spam=1&commentid="+commentid+"&admin=1" ;
   makePOSTRequest('/App_UI/site/pHion/Public/postComment.aspx', poststr);
    document.getElementById("reply_comment_form_id_"+commentid).innerHTML ="<span class='watch-comment-spam-bug'>Marked as spam</span>" ; 
    
    var voteaction="<span id='span_voteaction"+commentid+"'></span>";          
    document.getElementById(spamvoteactionPrefix+commentid).innerHTML =voteaction;            
    var scomment = document.getElementById(watchcommentbody+commentid).innerHTML;
    document.getElementById(watchcommentbody+commentid).innerHTML = scomment.replace('<strong>New Comment (Pending Approval)<br></strong>','');
    
}

function spamapproval(commentid, isspam)
{

//if(isspam =="1")
//{
//    if(!confirm("Are you sure you want to mark this comment as spam?"))
//    {
//        return false;
//    }
//}
   var poststr = "spamapp="+isspam+"&commentid="+commentid ;
   makePOSTRequest('/App_UI/site/pHion/Public/postComment.aspx', poststr);
   if(isspam =="1")
   {
    document.getElementById(spamprefix+commentid).innerHTML ="Marked as spam" ; 
    document.getElementById(spamprefix+commentid).className ="watch-comment-spam-bug" ; 
    document.getElementById(replylink+commentid).style.display= "none";
    //displayShowCommentLink(commentid);
   }
   else
   {
      document.getElementById(spamprefix+commentid).innerHTML ="<a onclick=\"spam('"+commentid+"');\">Mark as spam</a>&#160</span>" ; 
   }
    
}

function spambyuser(commentid, productid)
{
   var poststr = "spam=1&productid=" + productid +"&commentid="+commentid ;
   makePOSTRequest('/App_UI/site/pHion/Public/postComment.aspx', poststr);
    document.getElementById(spamprefix+commentid).innerHTML ="Marked as spam" ; 
    document.getElementById(spamprefix+commentid).className ="watch-comment-spam-bug" ; 
    document.getElementById(replylink+commentid).style.display= "none";
    //displayShowCommentLink(commentid);
}


function displayHideCommentLink(commentid,productid, voted, active)
{
    document.getElementById(hidelink+commentid).style.display= "inline";
    document.getElementById(hidelink+commentid).style.visibility= "visible";

    document.getElementById(showlink+commentid).style.display= "none";
    document.getElementById(showlink+commentid).style.visibility= "hidden";     
    document.getElementById(commentbody+commentid).style.display= "inline";

if((voted == "0" || voted == "False") && (active == "1" || active == "True") )
    var voteaction="<span id=\"span_voteaction"+commentid+"\"><a onclick=\"voteComment('"+commentid+"', '"+productid+"', '-1');\"><img src=\"/images/site/pHion/common/Thumbs.Down_Up.gif\" class=\"watch-comment-down-hover\" title=\"Poor comment\" alt=\"Poor comment\" onmouseover=\"this.src='/images/site/pHion/common/Thumbs.Down_Over.gif'\" onmouseout=\"this.src='/images/site/pHion/common/Thumbs.Down_Up.gif'\"></a>"+
            "&#160;<a onclick=\"voteComment('"+commentid+"', '"+commentid+"', '1');\"><img src=\"/images/site/pHion/common/Thumbs.Up_Up.gif\" class=\"watch-comment-down-hover\" title=\"Good comment\" alt=\"Good comment\" onmouseover=\"this.src='/images/site/pHion/common/Thumbs.Up_Over.gif'\" onmouseout=\"this.src='/images/site/pHion/common/Thumbs.Up_Up.gif'\"></a></span>";       
else
    var voteaction="<span id=\"span_voteaction"+commentid+"\"><img src=\"/images/site/pHion/common/Thumbs.Down_Up.gif\" class=\"watch-comment-down-hover\" title=\"Poor comment\" alt=\"Poor comment\" >"+
            "&#160;<img src=\"/images/site/pHion/common/Thumbs.Up_Up.gif\" class=\"watch-comment-down-hover\" title=\"Good comment\" alt=\"Good comment\"></span>";
    document.getElementById(spamvoteactionPrefix+commentid).innerHTML =voteaction;  

}
function displayShowCommentLink(commentid)
{
    document.getElementById(showlink+commentid).style.display= "inline";
    document.getElementById(showlink+commentid).style.visibility= "visible";

    document.getElementById(hidelink+commentid).style.display= "none";
    document.getElementById(hidelink+commentid).style.visibility= "hidden";     

    document.getElementById(commentbody+commentid).style.display= "none";
    var voteaction="<span id=\"span_voteaction"+commentid+"\"><img src=\"/images/site/pHion/common/Thumbs.Down_Up.gif\" class=\"watch-comment-down-hover\" title=\"Poor comment\" alt=\"Poor comment\" >"+
            "&#160;<img src=\"/images/site/pHion/common/Thumbs.Up_Up.gif\" class=\"watch-comment-down-hover\" title=\"Good comment\" alt=\"Good comment\"></span>";
            document.getElementById(spamvoteactionPrefix+commentid).innerHTML =voteaction;  
}

function removecomment(commentid)
{
if(confirm("Do you really want to remove this comment?"))
{
    var poststr = "remove=1&commentid="+commentid ;
    makePOSTRequest('/App_UI/site/pHion/Public/postComment.aspx', poststr);
     document.getElementById("reply_comment_form_id_"+commentid).innerHTML ="<span class='watch-comment-spam-bug'>Removed</span>" ; 
    
    var voteaction="<span id='span_voteaction"+commentid+"'><img src='/images/site/pHion/common/Thumbs.Down_Up.gif' class='watch-comment-down-hover' title='Poor comment' alt='Poor comment'>"+
    "&#160;<img src='/images/site/pHion/common/Thumbs.Up_Up.gif' class='watch-comment-down-hover' title='Good comment' alt='Good comment'/> </span>";          
    if(document.getElementById(spamvoteactionPrefix+commentid) !=null)
    document.getElementById(spamvoteactionPrefix+commentid).innerHTML =voteaction;            
 }
}

function approvecomment(commentid,productid)
{
    var poststr = "approve=1&commentid="+commentid ;
    makePOSTRequest('/App_UI/site/pHion/Public/postComment.aspx', poststr);
    document.getElementById(approvelink+commentid).innerHTML ="Approved" ; 
    document.getElementById(approvelink+commentid).className ="watch-comment-spam-bug" ; 
     var voteaction="<span id=\"span_voteaction"+commentid+"\"><a onclick=\"voteComment('"+commentid+"', '"+productid+"', '-1');\"><img src=\"/images/site/pHion/common/Thumbs.Down_Up.gif\" class=\"watch-comment-down-hover\" title=\"Poor comment\" alt=\"Poor comment\" onmouseover=\"this.src='/images/site/pHion/common/Thumbs.Down_Over.gif'\" onmouseout=\"this.src='/images/site/pHion/common/Thumbs.Down_Up.gif'\"></a>"+
            "&#160;<a onclick=\"voteComment('"+commentid+"', '"+commentid+"', '1');\"><img src=\"/images/site/pHion/common/Thumbs.Up_Up.gif\" class=\"watch-comment-down-hover\" title=\"Good comment\" alt=\"Good comment\" onmouseover=\"this.src='/images/site/pHion/common/Thumbs.Up_Over.gif'\" onmouseout=\"this.src='/images/site/pHion/common/Thumbs.Up_Up.gif'\"></a></span>";       
     document.getElementById(spamvoteactionPrefix+commentid).innerHTML =voteaction;    
     var scomment = document.getElementById(watchcommentbody+commentid).innerHTML;
     document.getElementById(watchcommentbody+commentid).innerHTML = scomment.replace('<strong>New Comment (Pending Approval)<br></strong>','');
     
}

function ValidateText (e,txt)
{
    var evt=(e)?e:(window.event)?window.event:null;
    if(evt)
    { 
        var key=(evt.charCode)?evt.charCode: ((evt.keyCode)?evt.keyCode:((evt.which)?evt.which:0)); 
        if(key!="8" && key!="35" && key!="36" && key!="37" && key!="39"  && key!="46"   && key!="50"  && !( key>="51" && key <= "56")&& !( key>="65" && key <= "90") )
        {

	        var str=txt;	
	        var SearchTxt=str.value;				

	        SearchTxt=SearchTxt.replace('<','');
            SearchTxt=SearchTxt.replace('>','');
	        str.value=SearchTxt;				
	       
        } 
    }
}


/*Edit Funtionality*/
function showCommentEditForm(comment_form_id, id)
{
var frm = document.getElementById(comment_form_id);
if(frm!=null)
 {
    
    frm.style.display = "";
    //show edit object
    if(document.getElementById(btnEditprefix+id))
        document.getElementById(btnEditprefix+id).style.display="";
    if(document.getElementById(txtEditCommentPrefix+id))
        document.getElementById(txtEditCommentPrefix+id).style.display="";
        
    //hide add objects    
     if(document.getElementById(txtCommentPrefix+id))
        document.getElementById(txtCommentPrefix+id).style.display="none";
    if(document.getElementById(btnpostprefix+id))
        document.getElementById(btnpostprefix+id).style.display="none";    
 }
}

function postCommentEditForm(textArea, commentid)
{
    vComment = document.getElementById(textArea).value.trim();
   vComment=vComment.replace(/&/g, '%26'); 
  
        if(vComment.length < 1)
        {
            alert("You must enter a comment.");
            document.getElementById(textArea).focus();
            return false;
        }
        else
        {
          var poststr = "edit=1&txtcomment=" + encodeURI( vComment ) +
                    "&commentid="+commentid;
              makePOSTRequest('/App_UI/site/pHion/Public/postComment.aspx', poststr);
            
            document.getElementById(textArea).disabled = true;
            
            document.getElementById(btnEditprefix+commentid).src = "/images/site/pHion/v2/btn_post_comment_disabled.gif";
            document.getElementById(btndiscardprefix+commentid).src = "/images/site/pHion/v2/btn_discard_disable.gif";
            document.getElementById(btnEditprefix+commentid).disabled = true;
            document.getElementById(btndiscardprefix+commentid).disabled = true;
            document.getElementById("lblMessage"+commentid).innerHTML ="Comment has been updated." ;
        }
  }

