function insert(elem, startTag, endTag)
{
	if (document.selection) //O+IE
	{
		$('#'+elem).focus();
		var txt = document.selection.createRange().text;
		document.selection.createRange().text = startTag + txt + endTag;
	}
	else if (window.getSelection) //Ff
	{
		elem = $('#'+elem).get(0);
		elem.focus();
		var txt = elem.value;
		var a = elem.selectionStart;
		var b = elem.selectionEnd;
		elem.value = txt.substring(0, a) + startTag + txt.substring(a,b) + endTag + txt.substring(b);
	}
}

function clearBB(elem)
{
    elem = $('#'+elem).get(0);
	elem.value = elem.value.replace(/\[.+?\]/g, ""); 
	//znajdz tag ograniczony [ i ] (oba escape'owane), w ktorym jest minimum 1 (+) dowolny znak (.), szukaj
	//najkrotszeto dopasowania (non-greedy) (?)
}

function quote(postId, text)
{
	$.get('/post/quote/' + postId, 
			function(data){ $('#' + text).get(0).value = '[quote]' + data + '[/quote]';}
		);
	document.location.href = '#odp'; 
	
}

function sendComment(topicId, dir, form)
{
	form.action = '/' + dir + '/post/save/' + topicId;
	form.target = '';
}

function prevComment(form, dir)
{
	form.action = '/' + dir + '/post/preview/'; 
	form.target = 'preview'; 
	$('#preview').toggle(); 
	$('#text2').toggle();
	document.location.href = '#odp'; 
}