/*****
 * BSkyB Daily Specific Blog Comments
 * Requires: Pluck SiteLife
 * Dependencies: pluckBlogComments.js
 * About: skydaily specific stylistic and structural blog post comments functionality
 *****/
 
var skydailyBlogComments = {};

//returns header text for comments
skydailyBlogComments.writeHeaderText = function() {
	var commentsHeader = "Your Comments";
	return commentsHeader;
};

//returns no comments HTML
skydailyBlogComments.writeNoComments = function() {
	var noCommentsHTML = "<div id=\"commentContainer\" class=\"commentContainer\"><div class=\"commentsHeader\"><p>Your Comments<\/p><\/div><div id=\"noComments\" class=\"noComments\"><p>There are currently no comments for this blog. Be the first to comment below, and let us know what you are thinking.<\/p><\/div>";
	return noCommentsHTML;
};

//returns single comment HTML
skydailyBlogComments.writeCommentHTML = function(comment) {
	if (comment) {
		var commentHTML = "<div class='commentRow' id='"+ comment.CommentKey.Key +"'><span class='commentAuthorAvatar'>" + pluckProfile.linkedAvatar(comment.Author) + "</span><span class='commentAuthorInfo'>Posted by: "+ pluckProfile.linkedDisplayName(comment.Author) +"  <span class='comment-date'> "+ pluckUtils.formatDateStamp(comment.PostedAtTime) +"</span></span><blockquote class='comment-entry'>"+ comment.CommentBody +"</blockquote></div>";
	}
	return commentHTML;
};

//returns comments sort HTML
skydailyBlogComments.writeCommentSortHTML = function(_commentPage) {
	var sortHTML = "";
	return sortHTML;
};

//returns perma link to comment
skydailyBlogComments.addPermaLink = function(comment) {
	if (comment) {
		var permaLinkHTML = "";
		return permaLinkHTML;
	}
};

//pagination for blog comments
skydailyBlogComments.commentPagination = function(_commentPage) {
	var sortOrder = _commentPage.Sort;
	var currentPage = parseInt(_commentPage.OnPage);
	var pages = Math.ceil(_commentPage.NumberOfComments / _commentPage.NumberPerPage);
	var prevPage = (currentPage > 1) ? currentPage-1 : currentPage;
 	var nextPage = (currentPage < pages) ? currentPage+1 : currentPage;
	var pageNumbers = '';
	var pageNumber = '';
	var paginationHTML = "";
	if (pages !=1) {	
		var x = "";
		var y = "";
		var z = "";
		maxPagesShown = pages - 7;
		if(pages>8) {
			pagesShown = currentPage + 7;
		} else {
			pagesShown = pages;
		}
	
		if(currentPage<=maxPagesShown || maxPagesShown<0) {
			for (x=_commentPage.OnPage; x<=pagesShown; x++) {
				if(x==_commentPage.OnPage) {
					pageNumbers += '<strong>' + x + '<\/strong>';
				} else {
					pageNumbers += '<span class=\"pagingLinks\"><a href=\"#comment\" onclick=\"pluckBlogComments.getBlogPostComments(arguments[0], ' + x + ', true, \'' + sortOrder + '\');\">' + x + '</a></span>';
				}
			}
		}
			
		if(currentPage>maxPagesShown) {
			for (y=_commentPage.OnPage; y>=maxPagesShown; y--) {
				if(y==_commentPage.OnPage) {
					pageCurrent = '<strong>' + y + '<\/strong>';
				} else {
					if(y>0) {
						pageNumber = '<span class=\"pagingLinks\"><a href=\"#comment\" onclick=\"pluckBlogComments.getBlogPostComments(arguments[0], ' + y + ', true, \'' + sortOrder + '\');\">' + y + '</a></span>';
						pageNumber += pageNumbers;
					}
				}
				pageNumbers = pageNumber;
			}
			pageNumbers += pageCurrent;
			for (z=_commentPage.OnPage; z<=pages; z++) {
				if(z==_commentPage.OnPage) {
					pageNumbers = pageNumbers;
				} else {
					pageNumbers += '<span class=\"pagingLinks\"><a href=\"#comment\" onclick=\"pluckBlogComments.getBlogPostComments(arguments[0], ' + z + ', true, \'' + sortOrder + '\');\">' + z + '</a></span>';
				}
			}
		}		
		var firstComments = (currentPage > 1) ? '<span class=\"pagingLinks\"><a class=\"paginationPrevious\" href=\"#comment\" onclick=\"pluckBlogComments.getBlogPostComments(arguments[0], 1, true, \'' + sortOrder + '\');\">First</a></span>' : '';
		var prevComments = (currentPage > 1) ? '<span class=\"pagingLinks\"><a class=\"paginationPrevious\" href=\"#comment\" onclick=\"pluckBlogComments.getBlogPostComments(arguments[0], '+ prevPage+', true, \'' + sortOrder + '\');\">&lt;</a></span>' : '';
		var nextComments = (currentPage < pages) ? '<span class=\"pagingLinks\"><a href=\"#comment\" onclick=\"pluckBlogComments.getBlogPostComments(arguments[0], '+ nextPage +', true, \'' + sortOrder + '\');\">&gt;</a></span>' : '';
		var lastComments = (currentPage < pages) ? '<span class=\"pagingLinks\"><a class=\"paginationLast\" href=\"#comment\" onclick=\"pluckBlogComments.getBlogPostComments(arguments[0], '+ pages +', true, \'' + sortOrder + '\');\">Last</a></span>' : '';
		paginationHTML = "<div id=\"commentsPaging\" class=\"commentsPaging\">" + firstComments + prevComments + pageNumbers + nextComments + lastComments + "<\/div>";
	}
	return paginationHTML;
};

//return comments submission form HTML
skydailyBlogComments.writeCommentsSubmissionHTML = function() {
	var commentsSubHeadHTML = "<div id=\"commentForm\" class=\"commentForm\"><div class=\"commentsHeader\"><p>Add your comments<\/p><\/div><p id=\"postCommentPara\">By posting a comment you are agreeing to abide by our <a href=\"http://community.sky.com/about/house_rules.html\">House Rules</a> and <a href=\"http://www.sky.com/portal/site/skycom/terms\">Terms &amp; Conditions</a>. See our <a href=\"http://community.sky.com/faq.html\">FAQs</a> for help.<\/p>";
	return commentsSubHeadHTML;	
};

//return HTML for comments textarea
skydailyBlogComments.writeCommentsTextareaHTML = function(isMsgLeft) {
	//if comment has just been left, leave thanks message visible
	if(document.getElementById('commentMessage')) {
		if(document.getElementById('commentMessage').style.visibility === "visible") {
			var commentsTextareaHTML = "<div id=\"commentMessage\" style=\"visibility: visible\">Thank you for your comment.<\/div><div class=\"textareaContainer\"><textarea id=\"commentText\" maxlength=\"1000\"><\/textarea>";
		} else {
			var commentsTextareaHTML = "<div id=\"commentMessage\"><\/div><div class=\"textareaContainer\"><textarea id=\"commentText\" maxlength=\"1000\"><\/textarea>";
		}
	} else {
		var commentsTextareaHTML = "<div id=\"commentMessage\"><\/div><div class=\"textareaContainer\"><textarea id=\"commentText\" maxlength=\"1000\"><\/textarea>";
	}
	var commentsSubmitButton = "<input id=\"btnSubmitComment\" class=\"btn_ok\" type=\"button\" value=\"SUBMIT\" alt=\"Submit\" onclick=\"pluckBlogComments.submitComment(1000)\" \/>";
	commentsTextareaHTML = commentsTextareaHTML + commentsSubmitButton + "<\/div><\/div>";
	return commentsTextareaHTML;
};

//show comments message - error
skydailyBlogComments.commentsMessageShowFail = function() {
	document.getElementById('commentMessage').style.visibility = "visible";
};

//show comments message - success
skydailyBlogComments.commentsMessageShowSuccess = function() {
	document.getElementById('commentMessage').style.visibility = "visible";
};

//return login / register links HTML
skydailyBlogComments.writeCommentsLoginHTML = function() {
	var commentsLoginHTML = "<div id=\"loginLink\" class=\"commentsLogIn\"><p>To comment on this story you must be <a href=\"" + pluckUtils.WIDGET_LOGIN_BASE + '/' + pluckUtils.setPartialURL() + "\">logged in<\/a>. If you are not a member then you can <a href=\"" + pluckUtils.WIDGET_REGISTER_BASE + '/' + pluckUtils.setPartialURL() + "\">register to our community<\/a> now.<\/p>";
	commentsLoginHTML += "<ul class=\"interactions\"><li id=\"liLogin\"><img alt=\"\" src=\"" + pluckUtils.IMAGEPATH + "/more_icon.gif\" \/><a class=\"reportLink\" href=\"" + pluckUtils.WIDGET_LOGIN_BASE + '/' + pluckUtils.setPartialURL() + "\">Log In<\/a><\/li><li id=\"liRegister\"><img alt=\"\" src=\"" + pluckUtils.IMAGEPATH + "/more_icon.gif\" \/><a class=\"reportLink\" href=\"" + pluckUtils.WIDGET_REGISTER_BASE + '/' + pluckUtils.setPartialURL() + "\">Register<\/a><\/li><\/ul><\/div><\/div>";
	return commentsLoginHTML;
};

//return participate link HTML
skydailyBlogComments.writeCommentsParticipateHTML = function() {
	var commentsParticipateHTML = "<div id=\"loginLink\" class=\"commentsLogIn\"><p>To comment on this story you must provide <a href=\"" + pluckUtils.WIDGET_LOGIN_BASE + '/' + pluckUtils.setPartialURL() + "\">additional registration details</a>.<\/p>";
	commentsParticipateHTML += "<ul class=\"interactions\"><li id=\"liParticipate\"><img alt=\"\" src=\"" + pluckUtils.IMAGEPATH + "/more_icon.gif\" \/><a class=\"reportLink\" href=\"" + pluckUtils.WIDGET_LOGIN_BASE + '/' + pluckUtils.setPartialURL() + "\">Participate<\/a><\/li><\/ul><\/div><\/div>";
	return commentsParticipateHTML;
}