function deleteArticle(type, id) {
	
	this.postDelete = function(resp, callback) {
		if(resp != 'failed') {
			var theTag = $('mainPanelText');
			theTag.innerHTML='';
			alert('item deleted, hit F5 to refresh the page');
		}
	}
	
	if(type == "news") {
		aj_postLoadResponse('opts_news.php', this.postDelete, 'delete=1&id='+id, type);
	}
	if(type == "events") {
		aj_postLoadResponse('opts_events.php', this.postDelete, 'delete=1&id='+id, type);
	}
}

function commitAdd(type, text, title, date) {
	
	this.postAdd = function(resp, callback) {
		if(resp != 'failed') {
			var id = resp;
			getArticle(type, id);
			alert('article added, hit F5 to refresh the page');
		}
	}
	
	if(type == "news") {
		aj_postLoadResponse('opts_news.php', this.postAdd, 'add=1&text='+text.replace(/&/g,'%26')+'&title='+title.replace(/&/g,'%26')+'&date='+date, type);
	}
	if(type == "events") {
		aj_postLoadResponse('opts_events.php', this.postAdd, 'add=1&text='+text.replace(/&/g,'%26')+'&title='+title.replace(/&/g,'%26')+'&date='+date, type);
	}
}

function getArticle(type, id) {
	this.postGetArticle = function(resp, params) {
		if(resp != 'failed') {
			var theTag = $('mainPanelText');
			theTag.innerHTML='';
			theTag.insert(resp);
		}
	}

	arr = new Array();
	arr[0] = id;
	arr[1] = type;
	$('mainPanelText').innerHTML = '';
	$('mainPanelText').insert('<br /><br /><br /><br /><div align="center"><img src="images/loader.white.gif" /><br /> Loading...</div>');
	aj_postLoadResponse('opts_getHTML.php', this.postGetArticle, 'getArticle=1&id='+id+'&type='+type, arr);
}

function editArticle(type, id) {
	this.postEditArticle = function(resp, params) {
		if(resp != 'failed') {
			var theTag = $('mainPanelText');
			theTag.innerHTML='';
			theTag.insert(resp);
		}
	}

	arr = new Array();
	arr[0] = id;
	arr[1] = type;
	$('mainPanelText').innerHTML = '';
	$('mainPanelText').insert('<br /><br /><br /><br /><div align="center"><img src="images/loader.white.gif" /><br /> Loading...</div>');
	aj_postLoadResponse('opts_getHTML.php', this.postEditArticle, 'editArticle=1&id='+id+'&type='+type, arr);
}

function saveArticle(id, date, title, text, type) {
	this.postSaveArticle = function(resp, arr) {
		if(resp == 'success') {
			alert("Article saved OK.\n\nPlease refresh your page by hitting F5");
			getArticle(arr[0], arr[1]);
		} else {
			alert("Article save FAILED\n\nWe have left the text on the screen\n\nNOTE: You may try hitting the save button again,\nor copy and paste the edited text to another place and trying again later\n\nIf you still have problems, --Sorry man!!--, call Jukka or Rov and we'll get it sorted.");
		}
	}
	
	var arr = new Array();
	arr[0] = type;
	arr[1] = id;
	
	if(type == 'events') {
		aj_postLoadResponse('opts_events.php', this.postSaveArticle, 'saveArticle=1&id='+id+'&date='+date+'&title='+title.replace(/&/g,'%26')+'&text='+text.replace(/&/g,'%26'), arr);
	}
	
	if(type == 'news') {
		aj_postLoadResponse('opts_news.php', this.postSaveArticle, 'saveArticle=1&id='+id+'&date='+date+'&title='+title.replace(/&/g,'%26')+'&text='+text.replace(/&/g,'%26'), arr);
	}
}

function addArticle(type) {
	this.postAddArticle = function(resp, arr) {
		if(resp != 'failed') {
			var theTag = $('mainPanelText');
			theTag.innerHTML='';
			theTag.insert(resp);
		}
	}

	arr = new Array();
	$('mainPanelText').innerHTML = '';
	$('mainPanelText').insert('<br /><br /><br /><br /><div align="center"><img src="images/loader.white.gif" /><br /> Loading...</div>');
	aj_postLoadResponse('opts_getHTML.php', this.postAddArticle, 'addArticle=1&type='+type, arr);
}
