function deleteData(type, id) {
	var del = confirm('Are you sure you wish to delete this ' + type + '?');
	if(del) {
	new Ajax.Request('/administration/index.php?section=delete', {
		method: 'post',
		parameters: { content_type: type, content_id: id},
		onSuccess: function(transport) {
			var response = transport.responseText;
			if(response==1) {
				Effect.Fade(type+id);
			} else {
				alert('Deletion could not be completed. Please refresh the page and try again.\nError: ' + response);
			}
		},
		onFailure: function() {
			alert('Deletion could not be completed. Please refresh the page and try again.');
		}
	});
	}	
}

function editComment(id) {
	$('comment_username_'+id).innerHTML = '<input size="15" type="text" id="comment_username_value_' + id + '" value="' + $('comment_username_'+id).innerHTML + '" />';
	$('comment_comment_'+id).innerHTML = '<textarea rows="8" cols="40" id="comment_comment_value_' + id + '">' + $('comment_comment_'+id).innerHTML + '</textarea>';
	$('editControl'+id).href = 'javascript:saveComment(\'' + id + '\');';
	$('editControl'+id).innerHTML = '<img src="/administration/icons/save_comment.png" alt="Save Comment" />';
}

function saveComment(id) {
	new Ajax.Request('/administration/index.php?section=save_comment', {
		method: 'post',
		parameters: { comment_id: id, username: $('comment_username_value_'+id).value, comment:  $('comment_comment_value_'+id).value },
		onSuccess: function(transport) {
			var response = transport.responseText;
			if(response==1) {
				$('editControl'+id).href = 'javascript:editComment(\'' + id + '\');';
				$('comment_username_'+id).innerHTML = $('comment_username_value_'+id).value;
				$('comment_comment_'+id).innerHTML = $('comment_comment_value_'+id).value;
				$('editControl'+id).innerHTML = '<img src="/administration/icons/edit.png" alt="Edit Comment" />';
			} else {
				alert('Comment could not be saved.\nError: ' + response);
			}
		},
		onFailure: function() {
			alert('Comment could not be saved.');
		}
	});
}

function editArticleComment(id) {
	$('comment_username_'+id).innerHTML = '<input size="15" type="text" id="comment_username_value_' + id + '" value="' + $('comment_username_'+id).innerHTML + '" />';
	$('comment_comment_'+id).innerHTML = '<textarea rows="8" cols="40" id="comment_comment_value_' + id + '">' + $('comment_comment_'+id).innerHTML + '</textarea>';
	$('editControl'+id).href = 'javascript:saveArticleComment(\'' + id + '\');';
	$('editControl'+id).innerHTML = '<img src="/administration/icons/save_comment.png" alt="Save Comment" />';
}

function saveArticleComment(id) {
	new Ajax.Request('/administration/index.php?section=save_article_comment', {
		method: 'post',
		parameters: { comment_id: id, username: $('comment_username_value_'+id).value, comment:  $('comment_comment_value_'+id).value },
		onSuccess: function(transport) {
			var response = transport.responseText;
			if(response==1) {
				$('editControl'+id).href = 'javascript:editComment(\'' + id + '\');';
				$('comment_username_'+id).innerHTML = $('comment_username_value_'+id).value;
				$('comment_comment_'+id).innerHTML = $('comment_comment_value_'+id).value;
				$('editControl'+id).innerHTML = '<img src="/administration/icons/edit.png" alt="Edit Comment" />';
			} else {
				alert('Comment could not be saved.\nError: ' + response);
			}
		},
		onFailure: function() {
			alert('Comment could not be saved.');
		}
	});
}

function denyFact(type,id) {
	new Ajax.Request('/administration/index.php?section=deny_fact', {
		method: 'post',
		parameters: { type: type, fact_id: id },
		onSuccess: function(transport) {
			var response = transport.responseText;
			if(response==1) {
				Effect.Fade(type+id);
			} else if(response==2) {
				Effect.Fade('fact'+id);
			} else {
				alert('Fact could not be deleted.\nError: ' + response);
			}
		},
		onFailure: function() {
			alert('Fact could not be deleted.');
		}
	});
}

function acceptFact(type,id) {
	new Ajax.Request('/administration/index.php?section=accept_fact', {
		method: 'post',
		parameters: { type: type, fact_id: id },
		onSuccess: function(transport) {
			var response = transport.responseText;
			if(response==1) {
				Effect.Fade(type+id);
			} else if(response==2) {
				Effect.Fade('fact'+id);
			} else {
				alert('Fact could not be accepted.\nError: ' + response);
			}
		},
		onFailure: function() {
			alert('Fact could not be accepted.');
		}
	});
}

function selectDate(date) {
	window.location = "/administration/index.php?date=" + date;
}

function editArticlePage(n, i) {
	for(var j=1; j<=i; j++) {
		$('content_'+j).hide();
		$('edit_content_'+j).setStyle({color: '#000', fontWeight: 'normal', textDecoration: 'none'});
		$('title_'+j).hide();
	}
	$('content_'+n).show();
	$('edit_content_'+n).setStyle({color: '#0000ff', fontWeight: 'bold', textDecoration: 'underline'});
	$('title_'+n).show();
	$('page_title').update('Page ' + n + ' Title:');
}

function editArticleImage(i) {
	for(var j=1; j<=i; j++) {
		$('image_title_'+j).hide();
	}
	n = $('image_title').getValue();
	$('image_title_'+n).show();
}

function populateLink(linkNum) {
	new Ajax.Request('/administration/index.php?section=retrieve_rss_item', {
		method: 'get',
		onSuccess: function(transport) {
			var response = transport.responseText;
			if(response==0) {
				alert('RSS item could not be retrieved.');
			} else {
				var rss_item = response.split('|');
				$('post_link_text_'+linkNum).value=rss_item[0];
				$('post_link_url_'+linkNum).value=rss_item[1];
				$('post_link_title_'+linkNum).value=rss_item[2];				
			}
		},
		onFailure: function() {
			alert('RSS item could not be retrieved.');
		}
	});
}