function ajaxRead(url,bitOfPage){
	var callback = { 
		success: function(o) {
			updateObj(o.argument.bitOfPage, o.responseText);
		}, 
		failure: function(o) {/*failure handler code*/}, 
		argument: { bitOfPage:bitOfPage }
	};
	YAHOO.util.Connect.asyncRequest('GET',url,callback,null);
}

function updateObj(obj, data){
   document.getElementById(obj).innerHTML = data;
}

function revertRightColumn() {
   updateObj('right-column','<div id="threads">Choose a topic from the left</div><div id="message-pane">&nbsp;</div>');
}

function refreshSections() {
	ajaxRead('sections.cgi','sections');
	window.setTimeout("refreshSections()",300000); // check for new messages every 5 minutes
}

function sectionsHandler(e) {
	YAHOO.util.Event.preventDefault(e);
	//get the resolved (non-text node) target:
	var elTarget = YAHOO.util.Event.getTarget(e);	
	//walk up the DOM tree looking for an <A>
	//in the target's ancestry; desist when you
	//reach the sections div
	while (elTarget.id != "sections") {
		//are you an A?
		if(elTarget.nodeName.toUpperCase() == "A") {
			updateObj('threads','Loading ' + elTarget.title + '...');
			ajaxRead("topic.cgi/" + elTarget.title,'threads');
			updateObj('message-pane','');
			updateObj('rich-header','bunkum - '+elTarget.title);
			//and then stop looking:
			break;
		} else {
			//wasn't the sections, but wasn't an li; so
			//let's step up the DOM and keep looking:
			elTarget = elTarget.parentNode;
		}
	}
}
//attach sectionsHandler as a listener for any click on
//the sections div:
// YAHOO.util.Event.on("sections", "click", sectionsHandler);

function getTopic(t) {
	t.replace('Mark all messages in ','');
	t.replace(' as read','');
	t.replace('show all threads in ','');
	return t;
}

function markAllAsRead(e) {
	YAHOO.util.Event.preventDefault(e);
	var elTarget = YAHOO.util.Event.getTarget(e);	
	topicName=getTopic(elTarget.title);
	alert(topicName);
}
YAHOO.util.Event.on("mark-all", "click", markAllAsRead);

function showAll(e) {
	YAHOO.util.Event.preventDefault(e);
	var elTarget = YAHOO.util.Event.getTarget(e);	
	topicName=getTopic(elTarget.title);
	alert(topicName);
}

function showPostForm(e) {
	YAHOO.util.Event.preventDefault(e);
	var elTarget = YAHOO.util.Event.getTarget(e);
	alert(elTarget);
}

YAHOO.util.Event.on("post-message","click",showPostForm);


