function Smile(what)
		{
  		document.forms.form_komentar.komentar.focus();
  		document.forms.form_komentar.komentar.value=
		document.forms.form_komentar.komentar.value+what;
		}

function SmileB(what)
		{
  		document.forms.form_blog.blog_text.focus();
  		document.forms.form_blog.blog_text.value=
		document.forms.form_blog.blog_text.value+what;
		}
	
function SmileCH(what)
		{
  		document.forms.form_chat.zprava.focus();
  		document.forms.form_chat.zprava.value=
		document.forms.form_chat.zprava.value+what;
		}

// Surrounds the selected text with text1 and text2.
function surroundText(text1, text2, textarea)
{
 if(typeof(textarea.caretPos) != "undefined") {
 
 var SelectedString = document.selection.createRange().text;  
	// Can a text range be created?
	if (SelectedString.length>0)
	{

  var ReplaceString = text1+SelectedString+text2;
  document.selection.createRange().text = ReplaceString;


	}
	}
	// Mozilla text range wrap.
	else if (typeof(textarea.selectionStart) != "undefined")
	{
		var begin = textarea.value.substr(0, textarea.selectionStart);
		var selection = textarea.value.substr(textarea.selectionStart, textarea.selectionEnd - textarea.selectionStart);
		var end = textarea.value.substr(textarea.selectionEnd);
		var newCursorPos = textarea.selectionStart;
		var scrollPos = textarea.scrollTop;

		textarea.value = begin + text1 + selection + text2 + end;

		if (textarea.setSelectionRange)
		{
			if (selection.length == 0)
				textarea.setSelectionRange(newCursorPos + text1.length, newCursorPos + text1.length);
			else
				textarea.setSelectionRange(newCursorPos, newCursorPos + text1.length + selection.length + text2.length);
			textarea.focus();
		}
		textarea.scrollTop = scrollPos;
	}
	// Just put them on the end, then.
	else
	{
	  var SelectedString = document.selection.createRange().text;  
	// Can a text range be created?
	if (SelectedString.length>0)
	{

  var ReplaceString = text1+SelectedString+text2;
  document.selection.createRange().text = ReplaceString;


	}else{
		textarea.value += text1 + text2;
		textarea.focus(textarea.value.length - 1);
	}


	}
}