<!--

  function check_len(aSource, aCounter, MaxLen)
  {
		var source  = document.getElementById(aSource);
		var counter = document.getElementById(aCounter);
		
		var text = new String(source.value);
		var len  = text.length;
		
		if (len > MaxLen)
		{
		  text = text.substr(0, MaxLen);
		  source.value = text;
		  len = text.length;
		}
		
		counter.value = MaxLen - len;
  }	
	
	
	function dislay_hint(OutputID, Hint)
	{
		var HintEdit = document.getElementById(OutputID);
		HintEdit.innerHTML = Hint;
	}
	
	
	function insert_tag(Editor, TagOpen, TagClose)
	{
		var txtarea = document.getElementById(Editor);
		
		var selection = document.selection.createRange().text;

		if (selection)
		{
			document.selection.createRange().text = TagOpen + selection + TagClose;
			txtarea.focus();
			selection = '';			
			return;
		}
		else
		{
			txtarea.focus();
			document.selection.createRange().text = TagOpen + TagClose;			
			selection = '';
			return;
		}	
	}
	
	
	function insert_smile(Smile, Editor)
	{
		var txtarea = document.getElementById(Editor);

    if (txtarea.createTextRange && txtarea.caretPos)
		{
			var caretPos = txtarea.caretPos;
			caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' '
			              ? caretPos.text + Smile + ' ' : caretPos.text + Smile;
			txtarea.focus();
		}
		else
		{
			txtarea.value += Smile;
			txtarea.focus();
		}
	}
	
	
	function insert_nofocus(text, Editor)
	{
		var txtarea = document.getElementById(Editor);
		
		if (txtarea.createTextRange && txtarea.caretPos)
		{
			var caretPos = txtarea.caretPos;
			caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
		}
		else
			txtarea.value += text;			
	}	
	
	
	function check_text(aEditor, Subject, MinLen)
	{
		var editor = document.getElementById(aEditor);
		var text = new String(editor.value);
		var len  = text.length;

		if (len < MinLen)
		{
		  alert("Вы должны ввести " + Subject);			
			editor.focus();
			return false;
		}
		
		return true;
	}
	
	
	var selection = '';
	
	function get_selection()
	{ 
		if (document.getSelection) 
		{ 
			selection = document.getSelection(); 
			selection = selection.replace(/\r\n\r\n/gi, "_doublecaret_"); 
			selection = selection.replace(/\r\n/gi, " "); 
			while (selection.indexOf("  ") !=-1) selection = selection.replace(/  /gi, ""); 
			selection = selection.replace(/_doublecaret_/gi, "\r\n\r\n"); 
		} 
		else 
		{ 
			selection = document.selection.createRange().text; 
		} 
	}
	
	
	function quote_selection(Name, Editor)
	{	
		if (selection)
		{ 
		  insert_nofocus('[quote="'+Name+'"]' + selection + '[/quote]\n', Editor); 
		  selection = ''; 
		  return; 
		}
		else
		  alert('Выделите фрагмент текста и повторите операцию!'); 
	}	
	
//-->
