

function loadComments( id ) {
	
	$( '#commentsDiv'+id ).html( '<div class="baseSize contentLeftPadding contentRightPadding"><p class="marginTop"><strong>Loading...</strong></p></div>' );
	$( '#commentsDiv'+id ).slideDown();
	paramObject = new Object();
	paramObject['postId'] = id;
	ah.addMessage( 'view-blog-list', 'get-comments', paramObject, 'viewBlogListLoadCommentsRecieive' );
	
	return false;
}

function viewBlogListLoadCommentsRecieive( paramArray ) {
	$( '#commentsDiv'+paramArray['id'] ).html( '<div class="baseSize contentLeftPadding contentRightPadding">Done</div>' );
	$( '#commentsDiv'+paramArray['id'] ).slideUp( function() {
		$( '#commentsDiv'+paramArray['id'] ).html( paramArray['content'] );
		$( '#commentsDiv'+paramArray['id'] ).slideDown();
	});
	
}

function addComment( postId ) {
	if( $( '#newComment' ).val().length > 0 ) {
		paramObject = new Object();
		paramObject['post'] = postId;
		paramObject['comment'] = $( '#newComment' ).val();
		ah.addMessage( 'view-blog-list', 'add-comment', paramObject, 'viewBlogListAddCommentRecieive' );
	}
}

function viewBlogListAddCommentRecieive( paramArray ) {
	if( paramArray['status'] == 'ok' ) {
		$.growl("Success", 'Comment added successfuly.');
		$( '#newComment' ).val('');
		loadComments( paramArray['post'] )
	}
	else {
		$.growl("Error", 'There was a problem adding your comment. Please try again.');
	}
	
}

function deletePost( id ) {
	if( confirm('Are you sure that you want to remove this post?' ) ) {
		$( '#postDiv'+id ).slideUp();
		paramObject = new Object();
		paramObject['postId'] = id;
		ah.addMessage( 'profile-blog-list', 'delete-post', paramObject, 'profileBlogListDeletePostRecieive' );
	}
	return false;
}

function profileBlogListDeletePostRecieive( paramArray ) {
	
	if( paramArray['status'] != 'ok' ) {
		$( '#postDiv'+paramArray['id'] ).slideDown( function() {
			$.growl("Error", paramArray['status'] );
		});
	} else {
		$.growl("Success", 'Post deleted successfuly.' );
		$( '#postDiv'+paramArray['id'] ).remove();
	}
}
