/*
##############################################################################
Code by Peter Haserodt - Copyright 2005 - www.haserodt.de
Dieser Code darf ohne Genehmigung nicht weiterverwendet werden.
This Code may not be used without permission
##############################################################################
*/

var tob;
var tle;
var tri;
var wa;
function gabel(wen,was)
{
wa = was;
	
	
	tob = wen;
	tob.focus();
	if (tob.createTextRange)
	ie();
	else
	an();
	
	tob.focus();
	document.formi.inh.focus();
	return;
}

function ie()
{
	s = document.selection.createRange().text;
	if (s.length==0)
	{
		alert ("Bitte etwas markieren");
		tob.focus();
		return;
	}
	
	if (wa<20)
	{
	tswi();
	s = tle + s + tri;
	
	}
	if (wa==30)
	{

		s = ul(s);
			
	}
	document.selection.createRange().text = s;
	tob.focus();
	return;
}



function an()
{
	s = tob.selectionStart;
	e = tob.selectionEnd;
	if (s==e)
	{
		alert ("Bitte etwas markieren");
		tob.focus();
		return;
	}
	
	ee=tob.value.substring(s,e).length;
	if (wa<20)
	{
	tswi();
	t = tob.value.substring(0,s) + tle +  tob.value.substring(s,e) + tri + tob.value.substring(e,tob.textLength) ;
	tob.value=t;
	tob.selectionStart = s + tle.length;
	tob.selectionEnd = s + tle.length +ee;
	}
	
		if (wa==30)
	{
		s = tob.value.substring(s,e)
		s = ul1(s);
		t = tob.value.substring(0,s)  + s +	tob.value.substring(e,tob.textLength);
		tob.value=t;
	}
	
	return;
}

function tswi()
{
	switch (wa)
	{
		case 1:
		tle ="<b>";tri= "</b>";
		break;
		case 2:
		tle ="<i>";tri= "</i>";
		break;
		case 3:
		tle ="<u>";tri= "</u>";
		break;
		case 4:
		tle ="<li>";tri= "</li>";
		break;
		
		case 5:
		tle ="<span style='color:#ff0000;'>";tri= "</span>";
		break;
		case 6:
		tle ="<span style='color:#009900;'>";tri= "</span>";
		break;
		case 7:
		tle ="<span style='color:#000080;'>";tri= "</span>";
		break;
	}

	
	
}

	function ul(tt)
	{
	vt = tt.split('\r\n');
	 return "<ul>\r\n<li>" + vt.join('</li>\r\n<li>') + "</li>\r\n</ul>";
	}
	function ul1(tt)
	{
	vt = tt.split('\n');
	 return "<ul>\n<li>" + vt.join('</li>\n<li>') + "</li>\n</ul>";
	}