
	function set_caret(text_obj)
	{ 
		if(text_obj.createTextRange)
		{ 
			text_obj.caret_pos=document.selection.createRange().duplicate();
		}
	}

	function paste_tag(start_text,end_text)
	{
		text_obj=document.getElementById('message');
		text_obj.focus();
		if(document.all)
		{
			if(text_obj.createTextRange && text_obj.caret_pos)
			{
				var caret_pos=text_obj.caret_pos;
				caret_pos.text=(caret_pos.text.charAt(caret_pos.text.length-1)==' ') ? start_text+caret_pos.text+end_text+' ' : start_text+caret_pos.text+end_text;
			}
			else
			{
				text_obj.value+=start_text+end_text;
			}
		}
		else
		{
			if(typeof(text_obj.selectionStart)!='undefined')
			{
				var range_start=text_obj.selectionStart;
				var range_end=text_obj.selectionEnd;
				var temp_str1=text_obj.value.substring(0,range_start);
				var temp_str2=text_obj.value.substring(range_end,text_obj.value.length);
				var selection_str=text_obj.value.substring(range_start,range_end);
				text_obj.value=temp_str1+start_text+selection_str+end_text+temp_str2;
				text_obj.selectionStart=text_obj.selectionEnd=range_start+(temp_str1+start_text+selection_str+end_text+temp_str2).length;
			}
			else
			{ 
				text_obj.value+=start_text+end_text;
			}
		}
	}
	
	function to_bold()
	{
		paste_tag('[b]','[/b]');
	}
	
	function to_italic()
	{
		paste_tag('[i]','[/i]');
	}
	
	function to_under()
	{
		paste_tag('[u]','[/u]');
	}
	
	function to_strike()
	{
		paste_tag('[s]','[/s]');
	}
	
	function to_offtopic()
	{
		paste_tag('[offtopic]','[/offtopic]');
	}
	
	function to_quote()
	{
		paste_tag('[quote]','[/quote]');
	}
	
	function to_code()
	{
		paste_tag('[code]','[/code]');
	}
	
	function img()
	{
		var FoundErrors = '';
		var enterURL   = prompt("Enter your image URL","http://");
		if (!enterURL) 
			{
			FoundErrors += " You have not entered the URL yet!";
			}
	if (FoundErrors) 
		{
		alert("Error!"+FoundErrors);
		return;
		}
		paste_tag('[img src='+enterURL+']','[/img]');
	}
	
	
	