﻿var commentsEnabled;  // this value changes inline for each blog post
var archiveLinks = [];

///////////////////////////////////////////////////////
function onloadHandler() {
	var manageBlogLink = $('manageBlogLink');
	var blogId = getBlogId();
	if (blogId) {
		//right now I've got the url hard-coded
		//manageBlogLink.href = 'http://www2.blogger.com/posts.g?blogID=' + blogId;
	}
}
///////////////////////////////////////////////////////
function isArchivePage() {
    return location.href.contains("archive");
}
///////////////////////////////////////////////////////
function addCommentsLink(allowComments, commentsCount, commentsUrl) {
  if (!allowComments) {
		document.writeln('Reader comments are not allowed on this entry.');
		return;
	}
	var countText, linkText;
	switch (commentsCount) {
		case 0: 
			countText = 'There are no comments.'; 
			linkText = 'Add comment';
			break;
		case 1:
			countText = 'There is 1 comment.'; 
			linkText = 'Add/view comments';
			break;
		default:
			countText = 'There are ' + commentsCount + ' comments.'; 
			linkText = 'Add/view comments';
	}
	document.writeln(countText + ' <a href="' + commentsUrl + '">' + linkText + '</a>');
}
///////////////////////////////////////////////////////
function writeArchiveLinks() {
	if (!archiveLinks || archiveLinks.length < 1) return;
	// var archivesList = $('archivesList');
	var outputString = '';

	// append LIs to list
	for (var i = archiveLinks.length - 1; i >= 0 ; i--) {
		var linkItem = archiveLinks[i];
		var url = linkItem[0];
		var name = linkItem[1];
		outputString += '<li><a href="' + url + '">' + name + '</a></li>\n';
	}
	document.writeln(outputString);
}
///////////////////////////////////////////////////////
function writeLinkToCurrentPosts(homeUrl) {
	if (isArchivePage()) {
		document.writeln('<li><a href="' + homeUrl + '" class="linkToCurrent">Go To Current Posts</a></li>');
	}
}
///////////////////////////////////////////////////////
// Find our blog ID by sniffing internal links
function getBlogId() {  
  for (var i = 0; i < document.links.length; i++) {
    var href = document.links[i].href;
    if (!href) continue;

    var matchResult = href.match('blogID=(\\d+)');
    if (matchResult && matchResult[1]) {
      return matchResult[1];
    }
  }
  return null;
}
///////////////////////////////////////////////////////

function $(id) {return document.getElementById(id)}
