function addComment(typeid,extid) {
	jQuery.get(base_dir+'/comment/data/edit/'+comment_type+'/'+extid,
		function(data) {
			jQuery('#comments_holder').append(jQuery(data));
			jQuery('.addcomment').hide();
			jQuery('#comment_edit').slideDown('normal');
			document.getElementById('comment_edit_name').focus();
		}
	);
}

function saveComment() {
	var nameid = jQuery('#comment_name').val();
	var emailid = jQuery('#comment_email').val();
	var textid = jQuery('#comment_text').val();
	var phrase = jQuery('#comment_phrase').val();
	jQuery.post(base_dir+'/comment/data/edit',
		{
			type:comment_type,
			external_id:comment_external_id,
			name:nameid,
			text:textid,
			email:emailid,
			comment_phrase:phrase
		},
		function(data) {
			jQuery('#comment_edit').remove();
			var d = jQuery('<div>'+data+'</div>');
			jQuery('#comments_holder').append(d);
			jQuery(d).slideDown('normal');
			jQuery('.addcomment').slideDown('normal');
		}
	);
}

function delComment(cid) {
	jQuery.get(base_dir+'/comment/data/delete/'+cid,
		function(data) {
			if(data == 'no') {
				alert('Could not delete comment.  Perhaps your login session has timed out.\nPlease go to the admin section and log in again.');
			} else {
				jQuery('#comment_'+data).slideUp('normal');
			}
		}
	);
}

jQuery(document).ready(
	function() {
		if(jQuery('#comments_holder')) {
			jQuery.get(base_dir+'/comment/data/view/'+comment_type+'/'+comment_external_id,
				function(data) {
					jQuery('#comments_holder').append(jQuery(data)).slideDown('normal');
				}
			);
			if(comment_type == 'blog') {
				addComment('blog',comment_external_id);
			}
		}
	}
);
