﻿function UpdateCommentsCountLeadIn(key) 
{  
    log('in UpdateCommentsCountLeadIn');
    // create a request batch
    var requestBatchComments = new RequestBatch();
    var articleKey = new ArticleKey(key);

    // add the userKey to the request
    requestBatchComments.AddToRequest(new CommentPage(articleKey, 1, 1, "TimeStampDescending")); 
    
    // initiate the request.  The response will be passed to the renderUserData() method.
    requestBatchComments.BeginRequest(serverUrl, getCommentsCountData); 
}

function getCommentsCountData(responseBatch) 
{             
    log('in getCommentsCountData'); 
    logobj(responseBatch);
     
     if(responseBatch.Messages[0].Message == 'ok')
     {
        var response = responseBatch.Responses[0];
        if(response.CommentPage != null)
        {
            if(response.CommentPage.NumberOfComments == 0)
            {
                document.getElementById('span_CommentsLeadIn').style.display = 'none';
                document.getElementById('span_CommentsLeadIn_BeFirstToComment').style.display = '';
            }
            else if(response.CommentPage.NumberOfComments == 1)
            {
                if(language == "EN")
                    document.getElementById('a_CommentsLeadIn_Count').innerHTML = '1 Comment';
                else
                    document.getElementById('a_CommentsLeadIn_Count').innerHTML = '1 Comentario';
            }
            else
            {
               if(language == "EN")
                    document.getElementById('a_CommentsLeadIn_Count').innerHTML = response.CommentPage.NumberOfComments + ' Comments';
                else
                    document.getElementById('a_CommentsLeadIn_Count').innerHTML = response.CommentPage.NumberOfComments + ' Comentarios';
            }
        }
     }
}