var default_comment_text = 'Post Your Comment';

$(document).ready(function() {
						   
	/* Keycode Box */
	if( $("#commentTextArea").val() == '' )
	{
		$("#commentTextArea").val(default_comment_text);
	}
	
	$("#commentTextArea").focus(function () {
		if( $(this).val() == default_comment_text )
		{
			$(this).val('');
		}
	});
	$("#commentTextArea").blur(function () {
		if( $(this).val() == '' )
		{
			$(this).val(default_comment_text);
		}
	});
	
	/* Blog Comments */
	$('#submitForm').ajaxForm({ 
			dataType: 'json',
			beforeSubmit: sendingForm,
			success: processForm
	}); 
	
	function sendingForm(formData, jqForm, options) {
		$('#formContainer').fadeTo("slow", 0.35);
	}

	function processForm(data) {
		if( data.status == "OK" )
		{
			$('#formErrorBox').hide();
			$('#formBg').css("background","transparent");
			$('#formContainer').slideUp();
			$('#postComment').hide();
			
			$('#formMessageBox').html(data.message);
			$('#formMessageBox').show();
			
			LoadComments(data.blogid, data.categoryid);
			$('#commentLink').html( data.commentcount );
		}
		else
		{
			$('#formErrorBox').html(data.message);
			$('#formErrorBox').slideDown("fast");

			$('#formBg').css("background","transparent");
			$('#formContainer').fadeTo("fast", 100);
		}
		window.location="#formMessage";
	}

	function LoadComments(id, category) {
		var url = $("#r").val();
		$("#commentListing").load(url+'/includes/blogs.php?comments&c='+category+'&b='+id);
	}
	
});
