
function BlogComment_Init(plngNodeFK, pstrUserName, pstrTitle, plngHeight, plngCurrentPage, pblnFirstCommentFirst) {
	BlogComment_Delete(plngNodeFK);
	var lngPageToGo = 1;
	if (pblnFirstCommentFirst) {
		// Goto last page if adding
		lngPageToGo = 9999;
	}
	BlogComment_Add(plngNodeFK, pstrUserName, pstrTitle, plngHeight, lngPageToGo);
	BlogComment_Edit(plngNodeFK, plngHeight, plngCurrentPage);
	BlogComment_Paging(plngNodeFK);
}

function AjaxUpdateComment(req) {
	$('.CommentList').remove();
	$('.BlogPostInfo').replaceWith($(req));
}

function AjaxCreateComment(req) {
	$('.CommentList').remove();
	$('.BlogPostInfo').replaceWith($(req));
}

function AjaxEditComment(plngCommentFK, plngNodeFK, plngHeight, plngCurrentPage) {
	jsOpenWindow('/qsPortal/Ajax/Get.asp?Ajax=Blog.Comment&id=' + plngCommentFK + '&lngNodeFK=' + plngNodeFK + '&Page=' + plngCurrentPage + '&CallBackFunc=AjaxUpdateComment', 420, plngHeight)
}

function AjaxAddComment(plngNodeFK, pstrName, pstrTitle, plngHeight, plngPageToGo) {
	jsOpenWindow('/qsPortal/Ajax/Get.asp?Ajax=Blog.Comment&id=-1&lngNodeFK=' + plngNodeFK + '&Page=' + plngPageToGo + '&strName=' + pstrName + '&strTitle=' + pstrTitle + '&CallBackFunc=AjaxCreateComment', 420, plngHeight);
}

function BlogComment_Paging(plngNodeFK) {
	$(".CommentList .pagination a").click(function() {
		Params = this.href.split('#');
		//Reload the page
		BlogComment_Display('Page=' + Params[1].substr(1) + '&lngNodeFK=' + plngNodeFK);
	});
}

function BlogComment_Add(plngNodeFK, pstrUserName, pstrTitle, plngHeight, plngPageToGo) {
	//Attach add command
	$('a.add_comment').click(function(){
		AjaxAddComment(plngNodeFK, pstrUserName, pstrTitle, plngHeight, plngPageToGo);
		return false;
	});
}

function BlogComment_Edit(plngNodeFK, plngHeight, plngCurrentPage) {
	//Attach edit command
	$('a.edit_comment').click(function(){
		//Extract the comment : edit_xxx
		var comment_id = $(this).attr('id').slice(5);
		AjaxEditComment(comment_id, plngNodeFK, plngHeight, plngCurrentPage);
		return false;	
	});
}		

function BlogComment_Delete(plngNodeFK) {
	//Attach comment delete action
	$('a.del_comment').click(function() {
		if (confirm(jsTrad("Delete this comment ?"))) {
			//Extract the comment : del_xxx
			var comment_id = $(this).attr('id').slice(4);
			//Call Ajax function to physically delete it
			$.ajax({
				type: 'POST',
				cache: false,
				async: false,
				dataType: 'html',
				data: 'id=' + comment_id + '&lngNodeFK=' + plngNodeFK,
				url: '/qsPortal/Blog/AjaxDelComment.asp',
				success: function(req) {
					$('.CommentList').remove();
					$('.BlogPostInfo').replaceWith($(req.responseText));
			}
			});
		}
		return false;
	});
}			

//Retrieves the Blog comment in ajax
function BlogComment_Display(pstrParams) {
	var strResult = '';
	
	strData = "Ajax=Blog.commentlist&" + pstrParams;

	$.ajax({
		type: 'GET',
		cache: false,
		async: false,
		dataType: 'html',
		url: '/qsPortal/Ajax/Get.asp',
		data: strData,
		beforeSend: function() {
		},
		success: function(req) {
			strResult = req;
		},
		error: function(req, err) {
			//						alert('Error!');
			strResult = req.responseText;
		}
	});

	//Replace the content
	$('.CommentList').remove();
	$('.BlogPostInfo').replaceWith($(strResult));
}

