function storeCaret(ref)
{ 
	if (ref.createTextRange)
	{
		ref.caretPos = document.selection.createRange().duplicate();
	}
}

function AddText(text, ref)
{
	if (document.forms[ref].textcont.createTextRange && document.forms[ref].textcont.caretPos)
	{      
		var caretPos = document.forms[ref].textcont.caretPos;      
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?
		text + ' ' : text;
	}
	else document.forms[ref].textcont.value += text;
	document.forms[ref].textcont.focus(caretPos)
}

function bold_text(ref)
{
	AddText("[B][/B]", ref);
}

function italic_text(ref)
{
	AddText("[I][/I]", ref);
}

function underline_text(ref)
{
	AddText("[U][/U]", ref);
}

function align_left(ref)
{
	AddText("[LEFT][/LEFT]", ref);
}

function align_center(ref)
{
	AddText("[CENTER][/CENTER]", ref);
}

function align_right(ref)
{
	AddText("[RIGHT][/RIGHT]", ref);
}

function hyperlink(ref)
{
	AddText("[URL=adress]beskrivning[/URL]", ref);
}

function image(ref)
{
	AddText("[IMG][/IMG]", ref);
}

function insert_TAB(ref)
{
	AddText("\t", ref);
}

