// common DIV control
function hideIt(obj) {
	$(obj).style.display = 'none';
}
function showIt(obj) {
	$(obj).style.display = '';
}
function switchContents(hideItem,showItem) {
	$(hideItem).style.display = 'none';
	Effect.Appear(showItem,{duration:0.5});
}
function autoContents(boxContent) {
	if ($(boxContent).style.display=="none") {
		$(boxContent).style.display = "";
	} else {
		$(boxContent).style.display = "none";
	}
}

// remove all special characters
function stripMessage(message) {
	message = encodeURIComponent(message);
	message = message.replace(/\+/ig, "%2B");
	return message;
}

var nestID=0;
var loadBox = 'bottom';

// get blog list
function getBlogList(username,group) {
	new Ajax.Updater("blogListContents", "http://blog.aw8.net/b2-ajax-getBlogList.php", {
		method: 'POST',
		parameters: {
			username: username,
			group: group
		},
		onCreate: function() {
			$("blogListContents").update('Retrieving list, please wait...');
		}
	});
}
// get blog
function getBlog(username,blogID) {
	new Ajax.Request("http://blog.aw8.net/b2-ajax-getBlog.php", {
		method: 'POST',
		parameters: {
			username: username,
			blogID: blogID
		},
		onCreate: function() {
			new Effect.Fade("b_"+blogID, { duration: 0 , to: 0.3 });
		},
		onSuccess: function(transport) {
			$("b_"+blogID).update(transport.responseText);
			new Effect.Appear("b_"+blogID, { duration: 0.2 , to: 1 });
		}
	});
}

// for commenting
function postBlogComment(blogID,blogOwner,nestID) {
	username = $("bc_Form").username.value;
	comment = $("bc_Form").comment.value;
	new Ajax.Request("http://blog.aw8.net/b2-ajax-commentPost.php", {
		method: 'POST',
		parameters: {
			blogID: blogID,
			blogOwner: blogOwner,
			nestID: nestID,
			message: comment,
			username: username
		},
		onCreate: function() {
			$("progressLine").update('Posting your comment...');
		},
		onSuccess: function(transport) {
			if (transport.responseText=='error') {
				$("progressLine").update('An error has occurred. Please try again.');
			} else {
				$("progressLine").update('');
				if ($("commentEntryPoint")) {
					$("commentEntryPoint").insert({ 'before' : transport.responseText });
				} else {
					$("composeBox").insert({ 'top' : transport.responseText });
				};
				$("bc_Form").comment.value = '';
			};
		}
	});
}

// getting comments
function getComment(blogID,commentID) {
	new Ajax.Updater("commentArea","http://blog.aw8.net/b2-ajax-comment.php", {
		method: 'GET',
		parameters: {
			blogID: blogID,
			commentID: commentID
		},
		onCreate: function() {
			$("commentArea").update('<div align="center">Retrieving comments...</div>');
		}
	});
}

// add blogmark
function addBlogmark(blogID) {
	new Ajax.Request("http://blog.aw8.net/b2-ajax-blogmark.php", {
		method: 'GET',
		parameters: { id: blogID },
		onSuccess: function(transport) {
			if (transport.responseText=='Added') {
				alert('Blogmarking successful!');
			} else {
				alert('Error! Please try again later.');
			};
		}
	});
}