var pluckBlogID = "";
function blogIndexCheckComm()
{
	cPlaceHolder = getElementsByClassName(document.body, "blogIndexComments");
	for(i = 0; i<pluckEntries.length; i++)
	{
		cPlaceHolder[i].innerHTML = "0";
		getPageCcount(pluckEntries[i]);
	}
}

function getPageCcount(indPluckID)
{
	var articleKey = new ArticleKey(indPluckID);
	var requestBatch = new RequestBatch();
	requestBatch.AddToRequest(articleKey);
	requestBatch.BeginRequest(serverUrl, pageCallback);
}

function pageCallback(responseBatch)
{
	if(responseBatch.Messages[0].Message=="ok")
	{
		numPlComments = responseBatch.Responses[0].Article.Comments.NumberOfComments;
		pluckBlogID = "entry" + responseBatch.Responses[0].Article.ArticleKey.Key;
		getEl(pluckBlogID).innerHTML=numPlComments;
	}
}

function blogEntryCheckComm()
{
	if(document.location.href.indexOf("workbench")==-1){
		if(comments_global){
			if(commDisplayCount != 25){
				/*
				getEl("relatedContent").innerHTML='<div class="relatedBox" style="padding-bottom:4px;"><table id="commentInviteBox" cellpadding="0" cellspacing="0"><tr><td rowspan="2" style="width:auto"><a href="http://' + document.location.host + document.location.pathname + '?comments=all" id="commentCount"><img style="padding-right:4px;" src="http://cache.boston.com/jobs/i/comments.jpg"/></a></td><td class="commentInvite">Discuss</td></tr><tr><td><a href="http://' + document.location.host + document.location.pathname + '?comments=all" id="commentCount">COMMENTS (<span id="cCount"></span>)</a></td></tr></table></div>' + getEl("relatedContent").innerHTML
				getEl("articleEmbed").style.display="block";
				*/
				getCcount();
				// if(document.location.search.indexOf("comments=all")!=-1){getCcount()};
			}else{
				fGraph = getElementsByClassName(document.body,"firstGraph");
				fGraph[0].innerHTML+="<div id='viewFulArt'><a href='http://" + document.location.host + document.location.pathname + "'>< Read Full Article</a></div>";
				if(document.location.search.indexOf("comments=all")!=-1){getCcountForRepos()};
			}

			if(document.location.search.indexOf("comments=all")==-1){
				aObj = new JSONscriptRequest("http://sitelife.boston.com/ver1.0/Direct/Jsonp?r={%22Requests%22%3A[{%22ArticleKey%22%3A{%22Key%22%3A%22" + pluckID + "%22}}]%2C%22UniqueId%22%3A0}&cb=bcOverCom");
		    	aObj.buildScriptTag();
		    	aObj.addScriptTag();
		    }


		}
	}
}

function articleCallback(responseBatch) {
	if(responseBatch.Messages[0].Message=="ok"){
		numPlComments = responseBatch.Responses[0].Article.Comments.NumberOfComments;
		getEl("cmBlogCount").innerHTML = numPlComments;
		//getEl("cmHeaderCount").innerHTML=getEl("cCount").innerHTML=numPlComments;
		getEl("cmHeaderCount").innerHTML = numPlComments;
		if(commDisplayCount == 4){getEl("cCount2").innerHTML=numPlComments}
	}else{
		getEl("cmBlogCount").innerHTML = "0";
		// getEl("cmHeaderCount").innerHTML=getEl("cCount").innerHTML="0";
		getEl("cmHeaderCount").innerHTML = "0";
		if(pluckAccess==0){
			var articleKey = new ArticleKey(pluckID);
			var requestBatch = new RequestBatch();
			var uaAction = new UpdateArticleAction(articleKey, ("http://" + document.location.host + document.location.pathname), escape(pluckTitle), new Section(pluckSection), pluckCats);
			requestBatch.AddToRequest(uaAction);
			requestBatch.BeginRequest(serverUrl,articleOk);
			getEl("seeAllComm").style.display="none";
		}
	}
	//comLogForm();
}

function bcOverCom(lData){
	if(lData.ResponseBatch){
		if(lData.ResponseBatch.Messages[0].Message=="ok"){
			numPlComments = lData.ResponseBatch.Responses[0].Article.Comments.NumberOfComments;
			getEl("cmHeaderCount").innerHTML = numPlComments;
			getEl("cmBlogCount").innerHTML = numPlComments;
			// getEl("cCount").innerHTML=numPlComments;
			if(commDisplayCount == 4){getEl("cCount2").innerHTML=numPlComments}
		}
	}
}

function articleCallbackRepos(responseBatch) {
	if(responseBatch.Messages[0].Message=="ok"){
		numPlComments = responseBatch.Responses[0].Article.Comments.NumberOfComments;
		getEl("cmHeaderCount").innerHTML = numPlComments;
		getEl("cmBlogCount").innerHTML = numPlComments;
	}
	comLogForm();
}