
function Blog_AddStory(component_id, post_id)
{
	loadSmallOverlay('/widgets/blog/blog_addedit.php?post_id='+post_id+'&component_id='+component_id, 640, 480, 'Add Blog Entry');
}

function Blog_MoveUp(blog_id, post_id)
{
	var url = '/widgets/blog/blog_update.php?action=move_up&post_id='+post_id+'&blog_id='+blog_id;
	new Ajax.Request(url, { onComplete: function() {
		window.location = window.location;
	} } );
}

function Blog_MoveDown(blog_id, post_id)
{
	var url = '/widgets/blog/blog_update.php?action=move_down&post_id='+post_id+'&blog_id='+blog_id;
	new Ajax.Request(url, { onComplete: function() {
		window.location = window.location;
	} } );
}

function Blog_DeleteStory(blog_id, post_id)
{
	if (confirm('Are you sure you want to delete this post?'))
	{
		var url = '/widgets/blog/blog_update.php?action=delete_post&post_id='+post_id+'&blog_id='+blog_id;
		new Ajax.Request(url, { onComplete: function() {
			window.location = window.location;
		} } );
	}
}

function Blog_AddEdit()
{
	var form = document.getElementById('blog_form');
	form.content2.value=FCKeditorAPI.GetInstance('content').GetXHTML(true);
	new Ajax.Form(form, { onComplete: function() { window.location = window.location; } } );
}

function Blog_AddCategory(blog_id)
{
	var name = prompt("Enter category name");
	if (name != null)
	{
		var url = '/widgets/blog/blog_update.php?action=add_category&blog_id='+blog_id+'&category='+urlencode(name);
		new Ajax.Request(url, { onComplete: function(t) {
			var select = document.getElementById('category_drop');
			var newOption = document.createElement('option');
			newOption.text = name;
			newOption.value = t.responseText;
			
			try
			{
				select.add(newOption, null); // standards compliant; doesn't work in IE
			}
			catch(ex)
			{
				select.add(newOption); // IE only
			}
		} } );
	}
}

function Blog_DeleteCategory(blog_id)
{
	var obj = document.getElementById('category_drop');
	var cat_id = obj.value;
	
	if (cat_id != 0)
	{
		if (confirm('Are you sure you want to delete this category?'))
		{
			var url = '/widgets/blog/blog_update.php?action=delete_category&blog_id='+blog_id+'&category='+cat_id;
			new Ajax.Request(url, { onComplete: function(t) {
				var select = document.getElementById('category_drop');
				var i;
				for (i = select.length - 1; i>=0; i--)
				{
					if (select.options[i].selected)
					{
						select.remove(i);
					}
				}
			} } );
		}
	}
	else
	{
		alert('You cannot delete the "NONE" category');
	}
}

function Blog_EditCategory(blog_id)
{
	var obj = document.getElementById('category_drop');
	var cat_id = obj.value;
	var select = document.getElementById('category_drop');
	
	if (cat_id != 0)
	{
		var currentName = select.options[cat_id].text;
		var name = prompt("Enter category name", currentName);
		if (name != null)
		{
			var url = '/widgets/blog/blog_update.php?action=rename_category&blog_id='+blog_id+'&category='+urlencode(name)+'&cat_id='+cat_id;
			new Ajax.Request(url, { onComplete: function(t) {
				select.options[cat_id].text = name;
			} } );
		}
	}
	else
	{
		alert('You cannot rename the "NONE" category');
	}
}

function ShowBlogCategory(blog_id, category_id)
{
	var url = '/widgets/blog/show_category.php?blog_id='+blog_id+'&category='+category_id;
	new Ajax.Updater('blog_'+blog_id, url);
}

function Blog_ViewArchive(blog_id)
{
	var url = '/widgets/blog/show_archive.php?blog_id='+blog_id;
	new Ajax.Updater('blog_'+blog_id, url);
}

function ShowBlog(entry_id, container)
{
	var url = '/widgets/blog/print_story.php?id='+entry_id;
	new Ajax.Updater(container, url);
}

function ShowBlogMonth(blog_id, container, start_month)
{
	var url = '/widgets/blog/print_month.php?blog_id='+blog_id+'&start_month='+start_month;
	new Ajax.Updater(container, url);
}

function Blog_ShowCommentForm(blog_id)
{
	var comment_form = document.getElementById('blog_comment_entry_'+blog_id);
	comment_form.style.display = 'block';
}

function Blog_AddComment(form)
{
	new Ajax.Form(form, { onComplete: function(t) {		
		if (t.responseText.length == 0)
		{
			var blog_id = form.elements.entry.value;
			form.reset();
			var comment_form = document.getElementById('blog_comment_entry_'+blog_id);
			comment_form.style.display = 'none';
			//alert('Your comment has been added and sent for moderation. It will be displayed as soon as it is reviewed and approved by a member of our staff. Thank you.');
		}
		else
		{
			//alert(t.responseText);
		}
	} } );
}

function Blog_DeleteComment(entry_id)
{
	if (confirm('Are you sure you want to delete this comment?'))
	{
		var url = '/widgets/blog/delete_comment.php?id='+entry_id;
		new Ajax.Request(url, { onComplete: function() {
			window.location = window.location; // refresh window
		} } );
	}
}