//function to change the forum
function changeForum(obj){
	var url = document.getElementById('website_url').value + 'members/';
	if (obj.value > 0) url += 'forum/' +obj.value+ '.html';
	document.location.href = url;
}

//function to redirect to reply to the forum topic
function replyForum(forumid, postid){
	var url = document.getElementById('website_url').value + 'members/forum/' +forumid+ '/' +postid+ '/reply.html';
	document.location.href = url;
}

//function to submit a forum post
function submitPost(forumid, postid){
	if (postid){
		var text = document.getElementById('forum_edit_text').value;
		var topic = "";
	}  else {
		var text = document.getElementById('forum_new_text').value;
		var topic = document.getElementById('forum_topic').value;
	}
	var textarea = /(<(\S+).*>)|(<\/(\S+).*>)/ ;
	if (text == "") {
		alert("Please enter some text.");
	} else if(text.match(textarea)){
		alert("No tags allowed")
	} else {
	    xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null) {
	      alert ("Your browser does not support AJAX!");
	      return;
		}
		var url = document.getElementById('website_url').value + "forum.val";
		var params = "option=addpost" + "&forumid=" + forumid + "&postid=" + postid + "&postedtext=" + text + "&topic=" + topic;
		xmlHttp.onreadystatechange = responseSubmitPost;
		sendPostAjax(xmlHttp, url, params);
		return false;
	}
}

function responseSubmitPost() {
	if(xmlHttp.readyState == 4) {
		if(xmlHttp.status == 200) {
			var result = xmlHttp.responseText;
			var xx = result.split("||");
			document.location.href = document.getElementById('website_url').value + 'members/forum/' +xx[0]+ '/' +xx[1]+ '.html' ;
		} else {
			alert("Error: "+ xmlHttp.statusText +" "+ xmlHttp.status);
		}
	}
}

// function to cancel the post
function cancelpost(forumid, postid){
	if (postid){
		var url = document.getElementById('website_url').value + 'members/forum/' +forumid+ '/' +postid+ '.html';
	}  else {
		var url = document.getElementById('website_url').value + 'members/forum/' +forumid+ '.html';
	}
	document.location.href = url;
}

//function to open the new forum post url
function newForumPost(forumid) {
	var url = document.getElementById('website_url').value + 'members/forum/' +forumid+ '/new.html';
	document.location.href = url;
}

//function to go to forum back
function getForumBack(forumid){
	var url = document.getElementById('website_url').value + 'members/forum/' +forumid+ '.html';
	document.location.href = url;
}