///////////////////FORUMS/////////////////////////
var xmlhttp;


function textCounter(field, countfield, maxlimit) 
{
if (field.value.length > maxlimit)
field.value = field.value.substring(0, maxlimit);
else
countfield.value = maxlimit - field.value.length;
}


function PostNewTopic (){
TopicSubject = document.posttopic.TopicSubject.value;
TopicBody = document.posttopic.TopicBody.value;
GroupID = document.posttopic.GroupID.value;
Page = document.posttopic.Page.value;

var i = 0;
var PollOptions = '';
var x = document.getElementsByName('polloption');
for (i=0; i<x.length; i++)
	{
	var Opt = x[i].value;
	PollOptions = PollOptions + "&Opt"+i+"="+Opt;
	}


	
var TopicBody = TopicBody.replace(new RegExp( "\\n", "g" ), " <br /> " );
var TopicBody = TopicBody.replace(/&/g, "[amp]");
var TopicBody = TopicBody.replace(/\+/g,"[plus]");


if(x.length == 1)
{
$.pnotify({pnotify_text: 'At least three options are required for a poll'});
}
else
if(document.posttopic.TopicSubject.value.length == 0)
{
$.pnotify({pnotify_text: 'Topic subject required'});
}
	else if(document.posttopic.TopicSubject.value.length > 100)
	{
	$.pnotify({pnotify_text: 'Topic subject too long (50 characters max)'});
	}
		else if(document.posttopic.TopicBody.value.length == 0)
		{
		$.pnotify({pnotify_text: 'Topic message required'});
		}
			else if(document.posttopic.TopicBody.value.length > 9999)
			{
			$.pnotify({pnotify_text: 'Topic message too long (999 characters max)'});
			}
				else
				{
				xmlHttp=GetXmlHttpObject();
				if (xmlHttp==null){
				 alert ("Browser does not support HTTP Request");
				 return;}
				ajaxpage('/Forum/GetTopics.php?GroupID='+GroupID+'&Page='+Page+'&NewTopic=1&TopicSubject='+TopicSubject+'&TopicBody='+TopicBody+PollOptions, 'blankwrapper_forum');
				
				$('#formcontainer').hide("slow");
				
				}
}





function PostNewReply (){

ReplyBody = document.postreply.ReplyBody.value;
GroupID = document.postreply.GroupID.value;
TopicID = document.postreply.TopicID.value;
Page = document.postreply.Page.value;
var ReplyBody = ReplyBody.replace(new RegExp( "\\n", "g" ), " <br /> " );
var ReplyBody = ReplyBody.replace(/&/g, "[amp]");
var ReplyBody = ReplyBody.replace(/\+/g,"[plus]");

	
if(document.postreply.ReplyBody.value.length == 0)
{
$.pnotify({pnotify_text: 'Reply message required'});
}
else
	{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
	 alert ("Browser does not support HTTP Request");
	 return;}
	ajaxpage('/Forum/GetMessages.php?TopicID='+TopicID+'&GroupID='+GroupID+'&Page='+Page+'&ReplyBody='+ReplyBody+'&NewMessage=1', 'blankwrapper_forum');
	$('#formcontainer').hide("slow");
	
	
	}
}




function PostEdit (){
ReplyBody = document.postreply.ReplyBody.value;
PostID = document.postreply.PostID.value;
GroupID = document.postreply.GroupID.value;
TopicID = document.postreply.TopicID.value;
Page = document.postreply.Page.value;
var ReplyBody = ReplyBody.replace(new RegExp( "\\n", "g" ), " <br /> " );
var ReplyBody = ReplyBody.replace(/&/g, "[amp]");
var ReplyBody = ReplyBody.replace(/\+/g,"[plus]");

if(document.postreply.ReplyBody.value.length == 0)
{
$.pnotify({pnotify_text: 'Message required'});
}
else
	{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
	 alert ("Browser does not support HTTP Request");
	 return;}

	ajaxpage('/Forum/GetMessages.php?TopicID='+TopicID+'&GroupID='+GroupID+'&PostID='+PostID+'&Page='+Page+'&ReplyBody='+ReplyBody+'&NewEdit=1', 'blankwrapper_forum');
	$('#formcontainer').hide("slow");
	}
}
