function forum_search(go)
{
	if($('#search').val() == '')
	{
		$('#search_result').css('display', 'none');

		return;
	}

	loading(1);

	$.ajax({
		type: 'POST',
		url: home+'forum/section/search',
		data: 'text='+$('#search').val(),
		dataType: 'json',
		success: function(data)
		{
			$.each(data, function(i, val)
			{
				if(i == 's')
				{
					if(val != '')
					{
						$('#search_result').css('display', 'block');
						$('#search_result').html(val);
					}else
						$('#search_result').css('display', 'none');
				}
			});

			loading(0);
		}
	});
}
$('#forum').ajaxForm({
	dataType: 'json',
	success: function(data)
	{
		$.each(data, function(i, val)
		{
			if(i == 'e')
				bootbox.dialog('<h3 class="red">Ошибка</h3>'+val,
					[{
						"label" : "Продолжить",
					}]
				);
			if(i == 'i')
				bootbox.dialog('<h3 class="green">Внимание!</h3>'+val,
					[{
						"label" : "Продолжить",
						callback : function(){location.reload()}
					}]
				);

			if(i == 's')
				location.reload();
		});

		loading(0);
	}
});

function bbcode(bbbegin, bbend)
{
	form = document.getElementById('text');
	begin = form.value.substr(0, form.selectionStart);
	end = form.value.substr(form.selectionEnd);
	sel = form.value.substr(form.selectionStart, form.selectionEnd-form.selectionStart);
	var text = form.firstChild;
	form.value = begin+bbbegin+sel+bbend+end;
	selPos = bbbegin.length+begin.length+sel.length+bbend.length;
	form.setSelectionRange(begin.length, selPos);

	return false;
}