function dir_openclose(id)
{
 var x;
 x=document.getElementById(id);
 if(x.className=='indir') x.className='indirs';
 else x.className='indir';
}

////////////////////////////////////////////////////////////////////////////////

te_input='te_input';
te_field='te_field';

function insert_sub(typ,insText)
{
 t=(insText=="" || insText==undefined);
 if(t)
 {
  if(typ=="img" || typ=="imgl" || typ=="imgr") return window.prompt("Geben sie die Url des Bildes an.", t?"http://":insText);
  else if(typ=="b") return window.prompt("Geben sie den Text an der Fett formatiert werden soll.", t?"Text":insText);
  else if(typ=="i") return window.prompt("Geben sie den Text an der kursiv formatiert werden soll.", t?"Text":insText);
  else if(typ=="an") return "#"+window.prompt("Geben sie die Bezeichnunk des Ankers an.", t?"Ankername":insText);
 }

 if((typ=="a") || (typ=="al"))
 {
  if(t) insText=window.prompt("Welcher Text soll am Link stehen ?", "Irgend eine Seite");
  if(typ=="a") return window.prompt("Geben sie die URL an", "http://")+"]a]"+insText;
  return "#"+window.prompt("Geben sie die Bezeichnunk des Zielankers an.", "Ankername")+"]an]"+insText;
 }
 else if(typ=="style")
 {
  if(t) insText=window.prompt("Welcher Text soll formatiert werden?", "Text");
  return window.prompt("Bitte geben sie die Style Informationen an.", "border-style:solid;border-width:2px;border-color:red;")+"]style]"+insText;
 }

 if(t) return "";
 else return insText;
}

function te_insert(typ)
{
 var input = document.getElementById(te_input);
 if     (typ=="img")  {aTag="[img]";  eTag="[/img]";  }
 else if(typ=="imgr") {aTag="[imgr]"; eTag="[/imgr]";  }
 else if(typ=="imgl") {aTag="[imgl]"; eTag="[/imgl]";  }
 else if(typ=="a")    {aTag="[a[";    eTag="[/a]";   }
 else if(typ=="an")   {aTag="[an[";   eTag="[/an]";   }
 else if(typ=="style"){aTag="[style[";eTag="[/style]";   }
 else if(typ=="b")    {aTag="[b]";    eTag="[/b]";   }
 else if(typ=="i")    {aTag="[i]";    eTag="[/i]";   }

 input.focus();
 if(typeof document.selection != 'undefined') // für Internet Explorer
 {// Einfügen des Formatierungscodes
  var range = document.selection.createRange();
  var insText = range.text;
  insText=insert_sub(typ,insText);
  range.text = aTag + insText + eTag;
  // Anpassen der Cursorposition
  range = document.selection.createRange();
  if (insText.length == 0) range.move('character', -eTag.length);
  else range.moveStart('character', aTag.length + insText.length + eTag.length);
  range.select();
 }
 else if(typeof input.selectionStart != 'undefined')  //für neuere auf Gecko basierende Browser
 {//   Einfügen des Formatierungscodes
  var start = input.selectionStart;
  var end = input.selectionEnd;
  var insText = input.value.substring(start, end);
  insText=insert_sub(typ,insText);
  input.value = input.value.substr(0, start) + aTag + insText + eTag + input.value.substr(end);
  // Anpassen der Cursorposition
  var pos;
  if (insText.length == 0) pos = start + aTag.length;
  else pos = start + aTag.length + insText.length + eTag.length;
  input.selectionStart = pos;
  input.selectionEnd = pos;
 }
 else alert("Diese Funktion steht in den von ihnen verwendeten Browser nicht zur verfügung");
 te_check(te_input);
}

function te_check()
{
 s=document.getElementById(te_input).value;
 s=s.replace(/&/g, "&amp;");
 s=s.replace(/</g, "&lt;");
 s=s.replace(/>/g, "&gt;");
 s=s.replace(/\n/g, "<br>");
 s=s.replace(/"/g, "&quot;");
 s=s.replace(/\[b\](.*?)\[\/b\]/g, "<b>$1</b>");
 s=s.replace(/\[i\](.*?)\[\/i\]/g, "<i>$1</i>");
 s=s.replace(/\[an\](.*?)\[\/an\]/g, "<a name='$1'>");
 s=s.replace(/\]pics\//g, "]site/pics/"); // ]pics/ -> ]site/pics/
 s=s.replace(/\[img\](.*?)\[over\](.*?)\[\/img\]/g, "<img alt='' src='$1' onmouseout='this.src=\"$1\"' onmouseover='this.src=\"$2\"'>");
 s=s.replace(/\[img\](.*?)\[\/img\]/g, "<img alt='' src='$1'>");
 s=s.replace(/\[a\[(.*?)\]a\](.*?)\[\/a\]/g, "<a href='$1'>$2</a>");
 s=s.replace(/\[al\[(.*?)\]al\](.*?)\[\/al\]/g, "<a href='#$1'>$2</a>");
 s=s.replace(/\[imgr\](.*?)\[\/imgr\]/g, "<img alt='' class='dfr' src='$1'>");
 s=s.replace(/\[imgl\](.*?)\[\/imgl\]/g, "<img alt='' class='dfl' src='$1'>");
 s=s.replace(/\[style\[(.*?)\]style\](.*?)\[\/style\]/g, "<span style='$1'>$2</span>");

 document.getElementById(te_field).innerHTML=s;
}

////////////////////////////////////////////////////////////////////////////////
function layershow(url)
{
 document.getElementById('layerdiv').className='layerclass';
 document.getElementById('layerdiv').innerHTML="<iframe frameborder='0' src='"+url+"' id='layerframe'>";
}

function layerhide()
{
 parent.document.getElementById('layerdiv').className='';
 parent.document.getElementById('layerdiv').innerHTML='';
}
////////////////////////////////////////////////////////////////////////////////

function wind (url,x,y)
// <a href='asd.htm' target='_blank' onclick='oeffnefenster(this.href); return false'>
{
 fenster = window.open(url, "Window", "width="+x+",height="+y+",status=no,scrollbars=no,resizable=no");
 fenster.focus();
}

function go(x)
{
 if (x != "-") location.href = x;
}

function wwh ()
{
 if (isFinite(window.innerWidth))
 {
  ww = window.innerWidth;
  wh = window.innerHeight;
 }
 else if (isFinite(document.body.clientWidth))
 {
  ww = document.body.clientWidth;
  wh = document.body.clientHeight;
 }
 else if (isFinite(document.documentElement.clientWidth))
 {
  ww = document.documentElement.clientWidth;
  wh = document.documentElement.clientHeight;
 }
 window.location.href="index.php?ww="+ww+"&wh="+wh;
}

////////////////////////////////////////////////////////////////////////////////

function sm(v)
{
 var x;
 if (document.getElementById)
 {
  x = document.getElementById(v);
 }
 else if (document.all)
 {
  x = document.all[v];
 }
 x.submit();
}

function login()
{
 md5idvl('tun');
 md5idvl('tpw');
 sm('form');
}

function clrvl(id)
{
 var x;
 if (document.getElementById)
 {
  x = document.getElementById(id);
 }
 else if (document.all)
 {
  x = document.all[id];
 }
 x.value = "";
}

////////////////////////////////////////////////////////////////////////////////

function flink()
{
 var enterURL   = window.prompt("Geben sie die URL an", "http://");
 if ((enterURL)&&(enterURL != "http://"))
 {
  var enterTITLE = window.prompt("Welcher Text soll am Lin stehen ?", "Irgend eine Seite");
  if ((enterTITLE) && (enterTITLE != "Irgend eine Seite"))
  {
   var ToAdd = " [a["+enterURL+"]a] "+enterTITLE+" [/a] ";
   document.form.txtfld.value+=ToAdd;
  }
 }
}
function fimg()
{
 var enterURL   = window.prompt("Geben sie die Url des Bildes an", "http://");
 if ((enterURL)&&(enterURL != "http://"))
 {
  var ToAdd = " [img]"+enterURL+"[/img] ";
  document.form.txtfld.value+=ToAdd;
 }
}


