var site_root = "http://novusrp.org/";

function setPostText(postid) {
	var ajax = new XMLHttpRequest();
	ajax.onreadystatechange = function() {
		if(ajax.readyState == 4) {
			var el = document.getElementById(postid+"-body");
			el.innerHTML = ajax.responseText;
			
			el.style.display="";
			var newpost = document.getElementById(postid+"-newmarker");
			try {
				newpost.innerHTML="";
			}
			catch(e) {}
		}
	}
	ajax.open("GET",site_root+"getpost.php?pid="+postid,true);
	ajax.send(null);
}
function parsePostClick(postid) {
	var places = ["body","menu"];
	for(var i=0;i<places.length;i++) {
		var el = document.getElementById(postid+"-"+places[i]);
		
		if(places[i]=="body"&&(el.innerHTML==""||el.innerHTML==undefined)) {
			setPostText(postid);
		}
		toggleViewElement(el);
	}
}
function toggleViewElement(element) {
	if(element.style.display=="none") {
		element.style.display="";
	}
	else {
		element.style.display="none";
	}
}
function parseReplyClick(postid,boardid) {
	var ajax = new XMLHttpRequest();
	ajax.onreadystatechange = function() {
		if(ajax.readyState ==4) {
			var el = document.getElementById(postid+"-menu");
			el.innerHTML = ajax.responseText;
			var newpost = document.getElementById(postid+"-newmarker");
		}
	}
	ajax.open("GET",site_root+"editform.php?parent_pid="+postid+"&bid="+boardid,true);
	ajax.send(null);
} 


function newSubmit(type) {
	var selectList = document.getElementById("mainmenu-select");
	var myindex  = selectList.selectedIndex;
	var SelValue = selectList.options[myindex].value;
	var url=site_root+"boards/"+SelValue;
	if(type=="motd") {
		url = url + "/motd"
	}
	location.href=url;
	return 0;
}