﻿function posSave(feld){
if(feld.createTextRange){
feld.caretPos=document.selection.createRange().duplicate();
}
}
if(typeof document.selection!='undefined'){}

function addElement(feld,type,code,txt)
{
var anfang=(type==false?"["+code+"]":"["+type+'='+code+"]");
var ende=(type==false?"[/"+code+"]":"[/"+type+"]");
var startText=feld.value.substr(0,feld.selectionStart)+anfang;
var endText=ende+feld.value.substr(feld.selectionEnd);
if(feld.selectionStart!=undefined){
if(feld.selectionStart==feld.selectionEnd){
feld.value=startText+(txt!=false?txt:'')+endText;
}
else{
feld.value=startText+feld.value.substring(feld.selectionStart,feld.selectionEnd)+endText;
}
var pos=startText.length;
feld.selectionStart=pos;feld.selectionEnd=pos;
}
else if(feld.createTextRange&&feld.caretPos){
var caretPos=feld.caretPos;
caretPos.text=anfang+(txt==false?caretPos.text:txt)+ende;}
else{
feld.value+=anfang+(txt==false?' ':txt)+ende;
var pos=startText.length;
feld.selectionStart=pos;feld.selectionEnd=pos;}
feld.focus();}

function code(feld,code,art,beispiel){
if((feld.selectionStart!=undefined&&feld.selectionStart>=0&&feld.selectionEnd>0&&feld.selectionStart!=feld.selectionEnd)||(feld.createTextRange&&feld.caretPos&&feld.caretPos.text.length>0)){
addElement(feld,false,code,false);
}
else{
txt=prompt("Text für "+art+" eingeben:","");
if((txt!=null)&&(txt!="")){
addElement(feld,false,code,txt);
}
}
}
function addTextUrl(feld,code,type){
if(code=="-"){
return;
}
else{
txt=prompt("Geben Sie die gewünschte Internetadresse an:","http://");
if((txt!=null)&&(txt!="")){
if((feld.selectionStart!=undefined&&feld.selectionStart>=0&&feld.selectionEnd>0&&feld.selectionStart!=feld.selectionEnd)||(feld.createTextRange&&feld.caretPos&&feld.caretPos.text.length>0)){
addElement(feld,type,txt,false);
}
else{
addElement(feld,type,txt,txt);
}
}
feld.selectedIndex=0;
}
}
