function showMbReplyForm(id,contriId)
{

	var idName = 'msgBoardParentID';
	var search = id.toString().indexOf('=');
	if (search && search > 0) {
		idName = id.toString().substring(0,search);
		id = id.toString().substring(search+1);
	}

	if (document.getElementById('formMbReply'+id) || document.getElementById('pLoginMsgMbReply'+id))
		return hideMbReplyForm(id);

	if (!isLogged) {
		var html = '<p id="pLoginMsgMbReply'+id+'" style="text-align: left;">To reply to this message you need to be logged in!<br />';
		html += 'Please <a href="/user/members/login.php">login here</a>';
		html += ' or <a href="/user/signup/signup.php">sign up</a> for a free acount!</p>';
		document.getElementById('mbReply'+id).innerHTML = html;
		return false;
	}

	if (document.getElementById('formMbReply'+id))
		return hideMbReplyForm(id);

	var form = document.createElement('form');
	form.id = 'formMbReply'+id;
	form.name = 'formMbReply'+id;
	var textArea = document.createElement('textarea');
	var submitButton =  document.createElement('input');
	var cancelButton =  document.createElement('input');

	form.action="?";
	form.method="post";

	// add page if exists
	var m = window.location.href.match(/page=(\d+)/);
	if (m != null) {
		form.action += m[0];
	}

	if (typeof contriId != 'undefined') {
		var inputContriId = document.createElement('input');
		inputContriId.name = 'contriID';
		inputContriId.value = contriId;
		inputContriId.type = 'hidden';
	}

	var inputMsgBoardParentId= document.createElement('input');
	inputMsgBoardParentId.name = idName;
	inputMsgBoardParentId.value = id;
	inputMsgBoardParentId.type = 'hidden';

	var inputAction = document.createElement('input');
	inputAction.name = 'action';
	inputAction.value = 'exec_post_message';
	inputAction.type = 'hidden';

	textArea.name = 'message';
	textArea.id = 'mbReplyMessage' + id;
	textArea.cols = 55;
	textArea.rows = 3;

	submitButton.type = 'button';
	submitButton.value = 'Post Comment';
	submitButton.onclick = function() { return submitMbReplyForm(id); }

	cancelButton.type = 'button';
	cancelButton.value = 'Cancel';
	cancelButton.onclick = function() { return hideMbReplyForm(id); }

	var d = document.getElementById('mbReply'+id);
	form.appendChild(inputAction);

	if (typeof inputContriId != 'undefined') {
		form.appendChild(inputContriId);
	}

	form.appendChild(inputMsgBoardParentId);

	form.appendChild(textArea);
	form.appendChild(document.createElement('br'));
	form.appendChild(submitButton);

	form.appendChild(document.createTextNode(' '));
	form.appendChild(cancelButton);

	d.appendChild(form);
}

function hideMbReplyForm(id) 
{
	if (document.getElementById('mbReply'+id))
		document.getElementById('mbReply'+id).innerHTML = '';
}

function submitMbReplyForm(id)
{
	var form = document.forms['formMbReply'+id];
	var message = document.getElementById('mbReplyMessage'+id).value;
	if (message == '') {
		alert('Please enter your message!');
		return false;
	}
	form.submit();
}

