// Author: Al Sierra
// Version: 8.03.2009
// Description: AJAX for Blog Functionality
tfy.blog = {};
tfy.blog.inDocumentRef = false;
tfy.blog.dataURL = false;
tfy.blog.Init = 
	function(inDocumentRef) { 
		tfy.blog.inDocumentRef = inDocumentRef;
		tfy.blog.dataURL='scripts/php/blog.php?';
	};
tfy.blog.Pagination = 
	function(pagenum,$extra){
		url = "blog.php?pagenum="+pagenum;
		window.location = url;
	};
tfy.blog.AddComment = 
	function(bg_post_id) { 
		var text = $('p_comment').value;
		if(!tfy.main.ValidateString(text)){
			alert('Sorry, Your comment is invalid.\nPlease check it over and try again.');
			return ;
		}
		var msg_data = {};
		msg_data.cmd = 'AddComment';
		msg_data.comment = text;
		msg_data.isAnon = $('p_anon').checked;
		msg_data.bg_post_id = bg_post_id;
		msg_data.session_timeout = 1800;
		new Ajax.Request(tfy.blog.dataURL, {
			parameters: $H(msg_data).toQueryString(),
			evalScripts: true,
			onSuccess: function(transport) {
				try {
					var JSON = eval("("+transport.responseText+")");
					if (JSON.emsg) {
						alert(JSON.emsg);
						if (JSON.timeout_redirect){
							window.location = JSON.timeout_redirect;
						}
						return false;
					} 
					$('comment_form').style.display = "none";
					$('comment_message').style.display = "block";
					$('p_anon').checked = false;
					$('p_comment').value = '';
					$('blog-comments_list').innerHTML = JSON.html;
					setTimeout("tfy.blog.ShowCommentBox();",5000)
				}catch(e) {
					alert("The server's response could not be understood.\nPlease try again.");
					return false;
				}
			},
			onComplete: function(){
				
			}			
		});
	};
tfy.blog.ShowCommentBox = 
	function(){
		$('comment_message').fade();
		$('comment_form').appear();
	};