function addComment(id)
{
	// Get the blog parameters
	var name = getValue("n1");
	var email = getValue("e1");
	var verify = getValue("verify");
	var message = getValue("m1");
	var hid = getValue("hid");
	
	if ( CommentDivVisible() && name != "" && email != "" && verify != "" && message != "" && hid != "" )
	{
		// add the comment
		var dsource = "main_src/php/blogajax.php";
		var params = "comment=" + hid;
		params += "&name=" + name;
		params += "&email=" + email;
		params += "&verify=" + verify;
		params += "&message=" + message;
		
		AjaxPostCallWithCallback(dsource, params, AddCommentDone);
	}
	else
	{
		var dsource = "main_src/php/blogajax.php?add=" + id;
		
		AjaxCallWithCallback(dsource, AddCommentReady);
	}
}
function AddCommentDone()
{
	if ( XMLHttpRequestObject.readyState == 4 )
	{		
		// Hide the div
		if ( XMLHttpRequestObject.responseText == "" )
			window.location.reload();
			//hideComment();
	}
}
function showComments(id)
{
	// do the loading of comments
	var dsource = "main_src/php/blogajax.php?showcomments=" + id;
	
	AjaxCallWithCallback(dsource, commentsLoaded);
}
function commentsLoaded()
{
	if ( XMLHttpRequestObject.readyState == 4 )
	{
		var div = document.getElementById("blog_content");
		if ( !div )
			return;
			
		div.innerHTML = XMLHttpRequestObject.responseText;
		document.getElementById("blog_buttons").style.display = "none";
		document.getElementById("blog_buttons").style.visibility = "hidden";

		ShowCommentDiv();
	}
}
function getValue(id)
{
	var elem = document.getElementById(id);
	if ( !elem )
		return "";
		
	return elem.value;
}
function CommentDivVisible()
{
	var div = document.getElementById("blog_comment");
	if ( !div )
		return false;
		
	return (div.style.display == "block" && div.style.visibility == ""); 
}
function AddCommentReady()
{	
	if ( XMLHttpRequestObject.readyState == 4 )
	{
		var response = XMLHttpRequestObject.responseText;
		
		// Setup the text
		var contentDiv = document.getElementById("blog_content");
		if ( contentDiv )
		{
			contentDiv.innerHTML = response;
		}
		
		document.getElementById("blog_buttons").style.display = "block";
		document.getElementById("blog_buttons").style.visibility = "";
		
		ShowCommentDiv();
	}
}
function hideComment()
{
	var div = document.getElementById("blog_comment");
	if ( !div )
		return;
	
	div.style.visibility = "hidden";
	div.style.display = "none";
}
function ShowCommentDiv()
{
	var div = document.getElementById("blog_comment");
	if ( !div )
		return;
		
		
	// works with chrome - not with firefox
	var pos = document.body.scrollTop;
	if ( window.pageYOffset )
		pos = window.pageYOffset; // works with firefox

	div.style.top = pos + "px";
	
	div.style.visibility = "";
	div.style.display = "block";
}	
function LoadCommentDiv(id)
{
}
function HideShowAddComment()
{
	var div = document.getElementById("blog_comment");
	if ( !div ) return;
	
	div.style.visibility = (div.style.visibility == "") ? "hidden" : "";
	div.style.display = (div.style.display == "block") ? "none" : "block";
}