var dlSch = document.location.search
var rCommHeadStr1a = '<table style="width:99%;padding-bottom:8px;"><tr valign="top"><td id="rCommentsHead"><a name="readerComm"></a>READER COMMENTS (<span id="cmHeaderCount"></span>)</td><td align="right" id="rCommentsSort">';
var rCommHeadStr1b = '<table id="viewCommDiv"><tr valign="top"><td><img style="padding-right:4px;" src="http://cache.boston.com/jobs/i/comments.jpg"/></td><td id="rCommentsHead"><H4>READER COMMENTS &raquo;</h4><a href="http://' + document.location.host + document.location.pathname + '?comments=all#readerComm">View reader comments (<span id="cmHeaderCount">&nbsp;</span>) &raquo;</a> &nbsp; <a href="http://' + document.location.host + document.location.pathname + '?comments=all#addComm">Comment on this story &raquo;</a></td><td align="right" id="rCommentsSort">';
var rCommHeadStr2 = '</td></tr></table>';
if(dlSch.indexOf("comments=all")!=-1){
	if(dlSch.indexOf("csort=desc")!=-1){
		document.write(rCommHeadStr1a + 'Sort: <a href="http://' + document.location.host + document.location.pathname + '?comments=all">Chrono order</a> | Latest first | <a href="http://' + document.location.host + document.location.pathname + '?comments=all&csort=rec">Most recommended</a>' + rCommHeadStr2);
	}else{
  		if(dlSch.indexOf("csort=rec")!=-1){
  			document.write(rCommHeadStr1a + 'Sort: <a href="http://' + document.location.host + document.location.pathname + '?comments=all">Chrono order</a> | <a href="http://' + document.location.host + document.location.pathname + '?comments=all&csort=desc">Latest first</a> | Most recommended' + rCommHeadStr2);
  		}else{
  			document.write(rCommHeadStr1a + 'Sort: Chrono order | <a href="http://' + document.location.host + document.location.pathname + '?comments=all&csort=desc">Latest first</a> | <a href="http://' + document.location.host + document.location.pathname + '?comments=all&csort=rec">Most recommended</a>' + rCommHeadStr2);
  		}
	}
}else{document.write(rCommHeadStr1b + '&nbsp;' + rCommHeadStr2)}

if(dlSch.indexOf("comments=all")!=-1){
	if(dlSch.indexOf("csort=desc")!=-1){
		gSiteLife.CommentsOutput("ExternalResource", pluckID, true, commDisplayCount, "TimestampDescending");
	}else{
		if(dlSch.indexOf("csort=rec")!=-1){
			gSiteLife.CommentsOutput("ExternalResource", pluckID, true, commDisplayCount, "RecommendationsDescending");
		}else{
			gSiteLife.CommentsOutput("ExternalResource", pluckID, true, commDisplayCount, "TimestampAscending");
		}
	}
}
