
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);
}
