(function () {
"use strict";

function request(querytext, func, errorfunc) {
	var req = new XMLHttpRequest();
	req.onreadystatechange = function() {
		if (req.readyState !== 4) {
			return;
		}
		if (req.status !== 200) {
			errorfunc();
			return;
		}
		func(req.responseText);
	};
	req.open("GET",querytext);
	req.send();
}

gotonewpost.onclick = function(e) {
	window.location="/newpost.html"+window.location.search
};

document.getElementById("posts").innerHTML='Loading posts...';

request("/lastpost"+window.location.search,function(r) {
	request("/getpost"+window.location.search+"n="+r, function(r1) {
		document.getElementById("posts").innerHTML=r1;
	},function() {
		document.getElementById("posts").innerHTML='Error getting posts';
	}
},function() {
	document.getElementById("posts").innerHTML='There are no posts';
});

}());