function addPost(postId, parentPostId, postTitle, postSubject, postNM, postMember, postDate) {
	
	// Check to see if post already exists
	post = document.getElementById("li" + postId);
	
	// If post doesn't exist then add it
	if (!post) {
		parentPost = document.getElementById("li" + parentPostId);
		if (parentPost || parentPostId == 0) {
			
			// Get a reference to the parent post list
			parentList = document.getElementById("ul" + parentPostId);
			
			if (!parentList) {
				// Create the parent post list if it doesn't exist
				parentList = document.createElement("ul");
				parentList.setAttribute("id","ul" + parentPostId);
				parentPost.appendChild(parentList);
			}
			
			// Create post title and link
			newPostAnchor = document.createElement("a");
			newPostAnchor.setAttribute("class","boardMessage");
			newPostAnchor.setAttribute("id","titleHref"+postId);
			newPostAnchor.setAttribute("target","mW");
			newPostAnchor.setAttribute("href","message.php?pid=" + postId);
			newPostAnchor.appendChild(document.createTextNode(postTitle));
			
			// Creat post category n/m span
			newPostSpan = document.createElement("span");
			newPostSpan.setAttribute("id","catSpan"+postId);
			newPostSpan.setAttribute("class","boardPostCategory");
			if (postNM == 1) {
				newPostNM = document.createElement("strong");
				newPostNM.appendChild(document.createTextNode(" (n\/m)"));
				newPostSpan.appendChild(newPostNM);
			}
			newPostSpan.appendChild(document.createTextNode(" (" + postSubject + ") - "));
			
			// Create post member and link
			newPostMember = document.createElement("a");
			newPostMember.setAttribute("id","userHref"+postId);
			newPostMember.setAttribute("class","boardUsername");
			newPostMember.setAttribute("target","_top");
			newPostMember.setAttribute("href","../directory/profile.php?member=" + postMember);
			newPostMember.appendChild(document.createTextNode(postMember));		
			
			// Create the post list element and append contents
			newPostElement = document.createElement("li");
			newPostElement.setAttribute("id","li" + postId);
			newPostElement.appendChild(newPostAnchor);
			newPostElement.appendChild(newPostSpan);
			newPostElement.appendChild(newPostMember);
			newPostElement.appendChild(document.createTextNode(", " + postDate));
			
			// Add the new post to the parent post
			parentList.insertBefore(newPostElement, parentList.firstChild);
			document.getElementById("userHref"+postId).className = "boardUsername";
			document.getElementById("titleHref"+postId).className = "boardMessage";
			document.getElementById("catSpan"+postId).className = "boardPostCategory";
		}
	}
}


// holds an instance of XMLHttpRequest
var xmlHttp = createXmlHttpRequestObject();

// creates an XMLHttpRequest instance
function createXmlHttpRequestObject() {
	// will store the reference to the XMLHttpRequest object
	var xmlHttp;
	// this should work for all browsers except IE6 and older
	try {
		// try to create XMLHttpRequest object
		xmlHttp = new XMLHttpRequest();
	} catch(e) {
		// assume IE6 or older
		var XmlHttpVersions = new Array('MSXML2.XMLHTTP.6.0', 'MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP');
		// try every prog id until one works
		for (var i =0 ; i < XmlHttpVersions.length && !xmlHttp; i++) {
			try { 
				// try to create XMLHttpRequest object
				xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
			} catch (e) {
			}
		}
	}
	// return the created object or display an error message
	if (!xmlHttp) {
		alert("Error creating the XMLHttpRequest object.");
	} else {
		return xmlHttp;
	}
}

// read a file from the server
function process() {
	// only continue if xmlHttp isn't void
	if (xmlHttp) {
		// try to connect to the server
		try {
			// initiate reading a file from the server
			xmlHttp.open("GET", "ajax2.php?latest_post=" + latestPost, true);
			xmlHttp.onreadystatechange = handleRequestStateChange;
			xmlHttp.send(null);
		} catch (e) {
			// display the error in case of failure
			alert("Can't connect to server:\n" + e.toString());
		}
	}
}

// function called when the state of the HTTP request changes
function handleRequestStateChange() {
	// when readyState is 4, we are ready to read the server response
	if (xmlHttp.readyState == 4) {
		// continue only if HTTP status is "OK"
		if (xmlHttp.status == 200) {
			try {
				// do something with the response from the server
				handleServerResponse();
			} catch(e) {
				// display error message
				//alert("Error reading the response: " + e.toString());
			}
		} else {
			// display status message
			//alert("There was a problem retrieving the data:\n" + xmlHttp.statusText);
		}
	}
}

 
// handles the response received from the server
function handleServerResponse() {
	// read the message from the server
	var xmlResponse = xmlHttp.responseXML;
	// obtain the XML's document element
	xmlRoot = xmlResponse.documentElement;  
	// obtain arrays with book titles and ISBNs 
	postIdArray = xmlRoot.getElementsByTagName("post_id");
	parentIdArray = xmlRoot.getElementsByTagName("post_parent_id");
	postTitleArray = xmlRoot.getElementsByTagName("post_title");
	postCategoryArray = xmlRoot.getElementsByTagName("post_category");
	postNmArray = xmlRoot.getElementsByTagName("post_nm");
	postMemberArray = xmlRoot.getElementsByTagName("post_member");
	postDateArray = xmlRoot.getElementsByTagName("post_date");
	// generate HTML output
	var html = "";  
	// iterate through the arrays and create an HTML structure
	for (var i = 0; i < postTitleArray.length; i++) {
		addPost(postIdArray.item(i).firstChild.data, parentIdArray.item(i).firstChild.data, postTitleArray.item(i).firstChild.data, postCategoryArray.item(i).firstChild.data, postNmArray.item(i).firstChild.data, postMemberArray.item(i).firstChild.data, postDateArray.item(i).firstChild.data);
		latestPost = postIdArray.item(i).firstChild.data;
	}
	setTimeout("process();", 120000);
}