$('#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 == 'error')
				$('#error').html(val);

			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;
}