function ForumInsertAtCursor(myValue) 
{
	myField	= document.getElementById('_val_tresc');
	//IE support
	if (document.selection) 
	{
		myField.focus();
		sel = document.selection.createRange();
		sel.text = myValue;
	}
	//MOZILLA/NETSCAPE support
	else if (myField.selectionStart || myField.selectionStart == '0') 
	{
		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		myField.value = myField.value.substring(0, startPos)
		+ myValue
		+ myField.value.substring(endPos, myField.value.length);

		myField.selectionStart = startPos + myValue.length;
		myField.selectionEnd = startPos + myValue.length;
	} 
	else 
	{
		myField.value += myValue;
	}
	myField.focus();
	return false;
}

function ForumWrapAtCursor(myValue) 
{
  var $tb = document.getElementById("_val_tresc");

  if (document.selection)
	{
		// IE
    var str=document.selection.createRange().text;
		if (str.length != 0)
		{
			var sel=document.selection.createRange();
			sel.text="["+myValue+"]"+str+"[/"+myValue+"]";
			sel.moveStart('character', -str.length - myValue.length - 3);
			sel.moveEnd('character', -myValue.length - 3); 
			sel.select();
			$tb.focus();
		}
		else
		{
			ForumInsertAtCursor("["+myValue+"][/"+myValue+"]");
			var sel=document.selection.createRange();
			sel.moveStart('character', -myValue.length - 3);
			sel.moveEnd('character', -myValue.length - 3); 
			sel.select();
		}
  }
	else if (typeof $tb.selectionStart != 'undefined')
	{		
		// Others
    var $before, $after, $selection, $start, $end;
		
		$start = $tb.selectionStart + 2 + myValue.length;
		$end = $tb.selectionEnd + 2 + myValue.length;

    $before= $tb.value.substring(0, $tb.selectionStart);
    $selection = $tb.value.substring($tb.selectionStart, $tb.selectionEnd);
    $after = $tb.value.substring($tb.selectionEnd, $tb.value.length);
    $tb.value= String.concat($before, "[" , myValue, "]", $selection, "[/", myValue, "]", $after);

		$tb.selectionStart = $start;
		$tb.selectionEnd = $end;
	}
  $tb.focus();
}

function ForumForm_Init()
{
	$('#TB_window a.buttonInsert').each(function(){
		$(this).bind('click',function(){
			ForumInsertAtCursor(this.title);
			return false;
		});
	});
	$('#TB_window a.buttonWrap').each(function(){
		$(this).bind('click',function(){
			ForumWrapAtCursor(this.title);
			return false;
		});
	});
}
function ajaxForm_ForumEditPost_Init()
{
	ForumForm_Init();
}
function ajaxForm_BlogEditPost_Init()
{
	ForumForm_Init();
}
function ajaxForm_BlogEditKoment_Init()
{
	ForumForm_Init();
}
function ajaxForm_BlogAddPost_Init()
{
	ForumForm_Init()
}
function ajaxForm_ForumAddPost_Init()
{
	ForumForm_Init()
}
function ajaxForm_BlogAddKoment_Init()
{
	ForumForm_Init()
}
function ajaxForm_ForumAddTopicPost_Init()
{
	ForumForm_Init();
}