var bbtags   = new Array();

// browser detection
var myAgent   = navigator.userAgent.toLowerCase();
var myVersion = parseInt(navigator.appVersion);
var is_ie   = ((myAgent.indexOf("msie") != -1)  && (myAgent.indexOf("opera") == -1));
var is_win   =  ((myAgent.indexOf("win")!=-1) || (myAgent.indexOf("16bit")!=-1));

function smilie(theSmilie) {
	addText(" " + theSmilie + " ", "", false, document.formular);
}


function addText(theTag, theClsTag, isSingle, theForm)
{
 var isClose = false;
 var nachricht = theForm.nachricht;
 var set=false;
 var old=false;
 var selected="";
  	
if( nachricht.textLength>=0 ) { // mozilla, firebird, netscape
if(theClsTag!="" && nachricht.selectionStart!=nachricht.selectionEnd) {
selected=nachricht.value.substring(nachricht.selectionStart,nachricht.selectionEnd);
str=theTag + selected+ theClsTag;
old=true;
isClose = true;
}
else {
str=theTag;
}
nachricht.focus();
start=nachricht.selectionStart;
end=nachricht.textLength;
endtext=nachricht.value.substring(nachricht.selectionEnd,end);
starttext=nachricht.value.substring(0,start);
nachricht.value=starttext + str + endtext;
nachricht.selectionStart=start;
nachricht.selectionEnd=start;
nachricht.selectionStart = nachricht.selectionStart + str.length;
if(old) { return false; }
set=true;
if(isSingle) {
isClose = false;
}
}
if ( (myVersion >= 4) && is_ie && is_win) {  // Internet Explorer
if(nachricht.isTextEdit) {
nachricht.focus();
var sel = document.selection;
var rng = sel.createRange();
rng.colapse;
if((sel.type == "Text" || sel.type == "None") && rng != null){
if(theClsTag != "" && rng.text.length > 0)
theTag += rng.text + theClsTag;
else if(isSingle)
isClose = true;
rng.text = theTag;
}
}
else{
if(isSingle) isClose = true;
if(!set) {
nachricht.value += theTag;
}
}
}
else
{
if(isSingle) isClose = true;
if(!set) {
nachricht.value += theTag;
}
}
nachricht.focus();
return isClose;
}

function setFocus(theForm) {
theForm.nachricht.focus();
}
