// JavaScript Document
<!-- Begin
function editor_generate(objname,w,h) {
  var imgURL = _editor_url + 'library/img/editor/';
  var obj    = document.all[objname];
  if (!w) {
    if (obj.style.width) {
	  width = obj.style.width;
    }
    else if (obj.cols) {
	  width = (obj.cols * 8) + 22;
    }
    else {
	  width = '100%';
	}
  }
  if (!h) {
    if (obj.style.height) {
	  height = obj.style.height;
	}
    else if (obj.rows){
	  height = obj.rows * 17
	}
    else {
	  height = '200';
	}
  }
  var Agent, VInfo, MSIE, Ver, Win32, Opera;
  Agent = navigator.userAgent;
  VInfo = Array();
  VInfo = Agent.split(";")
  MSIE  = Agent.indexOf('MSIE') > 0;
  Ver   = VInfo[1].substr(6,3);
  Win32 = Agent.indexOf('Windows') > 0 && Agent.indexOf('Mac') < 0 && Agent.indexOf('Windows CE') < 0;
  Opera = Agent.indexOf('Opera') > -1;
  if (!MSIE || Opera || Ver < 5.5 || !Win32) {
    return;
  }
  var editor = ''
  // Haupttabelle
  + '<table border=0 cellspacing=0 cellpadding=0  style="padding:0" width=' + width + ' unselectable="on">\n'
  + '  <tr>\n'
  + '    <td>\n'
  + '            <table border=0 cellspacing=2 cellpadding=0  style="float: left;"  unselectable="on">\n'
  + '              <tr>\n'
  + '                <td style="border: inset 1px;">\n'
  + '                  <button unselectable="on" style="width=28; height=26" class="btn" onClick="editor_action(this.id)" title="Fett" id="_' +objname+ '_Bold"><img src="' +imgURL+ 'ed_format_bold.gif" unselectable="on"></button>'
  + '                  <button unselectable="on" style="width=28; height=26" class="btn" onClick="editor_action(this.id)" title="Kursiv" id="_' +objname+ '_Italic"><img src="' +imgURL+ 'ed_format_italic.gif" unselectable="on"></button>'
  + '                  <button unselectable="on" style="width=28; height=26" class="btn" onClick="editor_action(this.id)" title="Unterstrichen" id="_' +objname+ '_Underline"><img src="' +imgURL+ 'ed_format_underline.gif" unselectable="on"></button>\n'
  + '                  <button unselectable="on" style="width=28; height=26" class="btn" onClick="editor_action(this.id)" title="Durschgestrichen" id="_' +objname+ '_StrikeThrough"><img src="' +imgURL+ 'ed_format_strike.gif" unselectable="on"></button>\n'
  + '               </td>\n'
  + '             </tr>\n'
  + '           </table>\n'
  + '            <table border=0 cellspacing=2 cellpadding=0  style="float: left;"  unselectable="on">\n'
  + '              <tr>\n'
  + '                <td style="border: inset 1px;">\n'
  + '                  <button unselectable="on" style="width=28; height=26" class="btn" onClick="editor_action(this.id)" title="Nummerierung" id="_' +objname+ '_InsertOrderedList"><img src="' +imgURL+ 'ed_list_num.gif" unselectable="on"></button>\n'
  + '                  <button unselectable="on" style="width=28; height=26" class="btn" onClick="editor_action(this.id)" title="Aufzählungszeichen" id="_' +objname+ '_InsertUnorderedList"><img src="' +imgURL+ 'ed_list_bullet.gif" unselectable="on"></button>\n'
  + '               </td>\n'
  + '             </tr>\n'
  + '          </table>\n'
  // + '            <table border=0 cellspacing=2 cellpadding=0  style="float: left;"  unselectable="on">\n'
  // + '              <tr>\n'
  // + '                <td style="border: inset 1px;">\n'
  // + '                  <button unselectable="on" style="width=28; height=26" class="btn" onClick="editor_action(this.id)" title="Kopieren" id="_' +objname+ '_Copy"><img src="' +imgURL+ 'ed_copy.gif" unselectable="on"></button>\n'
  // + '                  <button unselectable="on" style="width=28; height=26" class="btn" onClick="editor_action(this.id)" title="Ausschneiden" id="_' +objname+ '_Cut"><img src="' +imgURL+ 'ed_cut.gif" unselectable="on"></button>\n'
  // + '                  <button unselectable="on" style="width=28; height=26" class="btn" onClick="editor_action(this.id)" title="Einfügen" id="_' +objname+ '_Paste"><img src="' +imgURL+ 'ed_paste.gif" unselectable="on"></button>\n'
  // + '               </td>\n'
  // + '             </tr>\n'
  // + '           </table>\n'
  // + '            <table border=0 cellspacing=2 cellpadding=0  style="float: left;"  unselectable="on">\n'
  // + '              <tr>\n'
  // + '                <td style="border: inset 1px;">\n'
  // + '                  <button unselectable="on" style="width=28; height=26; cursor:help" class="btn" onClick="editor_action(this.id)" title="Hilfe" id="_' +objname+ '_about"><img src="' +imgURL+ 'ed_about.gif" unselectable="on"></button>\n'
  // + '               </td>\n'
  // + '             </tr>\n'
  // + '           </table>\n'
  + '    </td>\n'
  + '  </tr>\n' 
  + '  <tr height=200>\n' 
  + '    <td>\n'
  + '      <table width=100% height=1 border=0 cellspacing=0 cellpadding=0>\n'
  + '        <tr>\n'
  + '          <td>\n'
  + '            <textarea ID="_' +objname + '_editor" style="width:' +width+ '; height:' +height+ '; margin-top:-1px; margin-bottom:-1px"></textarea>\n'
  + '            <input type="hidden" name="' +objname+ '" value="">\n'
  + '          </td>\n'
  + '        </tr>\n'
  + '      </table>\n'
  + '    </td>\n'
  + '  </tr>\n'
  + '  <tr>\n' 
  + '    <td>\n'  
  + '    </td>\n'  
  + '  </tr>\n'
  + '</table>\n';
  
  var contents = document.all[objname].value;
  document.all[objname].outerHTML = editor;
  document.all['_'+objname+'_editor'].value = contents;
  editor_setmode('_' +objname+ '_HtmlMode', 'init');
}

function editor_action(button_id) {
  var BtnParts = Array();
  BtnParts = button_id.split("_");
  var objname    = button_id.replace(/^_(.*)_[^_]*$/, '$1');
  var cmdID      = BtnParts[ BtnParts.length-1 ];
  var button_obj = document.all[button_id];
  var editor_obj = document.all["_" +objname + "_editor"];
  if (editor_obj.tagName.toLowerCase() == 'textarea') {
    return;
  }
  var editdoc = editor_obj.contentWindow.document;
  _editor_focus(editor_obj);
  var idx = button_obj.selectedIndex;
  if (idx != null) {
    var val = button_obj[ idx ].value;
    editdoc.execCommand(cmdID,0,val);
  }
  else if (cmdID == 'ForeColor' || cmdID == 'BackColor') {
    var posX    = event.screenX;
    var posY    = event.screenY + 20;
    var screenW = screen.width;
    var screenH = screen.height - 20;
    if (posX + 232 > screenW) {
	  posX = posX - 232 - 40;
	}
    if (posY + 164 > screenH) {
	  posY = posY - 164 - 80;
    }
    var wPosition   = "dialogLeft:" +posX+ "; dialogTop:" +posY;
    var oldcolor = _dec_to_rgb(editdoc.queryCommandValue(cmdID));
    var newcolor = showModalDialog(_editor_url + "insert_colors.php", oldcolor, "dialogWidth:238px; dialogHeight: 190px; " + "resizable: no; help: no; status: no; scroll: no; " + wPosition);
    if (newcolor != null) {
	  editdoc.execCommand(cmdID, false, "#"+newcolor);
	}
  }
  else {
    if (cmdID.toLowerCase() == 'subscript' && editdoc.queryCommandState('superscript')) {
	  editdoc.execCommand('superscript');
	}
    if (cmdID.toLowerCase() == 'superscript' && editdoc.queryCommandState('subscript')) {
	  editdoc.execCommand('subscript');
	}
    if (cmdID.toLowerCase() == 'createlink'){
      editdoc.execCommand(cmdID,1);
    }
    if (cmdID.toLowerCase() == 'about'){
      var popup = window.showModalDialog("about.php", window, "status:no;dialogWidth:451px;dialogHeight:505px;help:no;scroll:no");
    }
    else {
      editdoc.execCommand(cmdID);
    }
  }
  editor_updateUI(objname);
}

function editor_updateUI(objname,runDelay) {
  var editor_obj  = document.all["_" +objname+  "_editor"];
  if (runDelay == null) {
    runDelay = 0;
  }
  var editdoc, editEvent;
  if (runDelay > 0) { return setTimeout(function(){
    editor_updateUI(objname);
    }, runDelay);
  }
  if (this.tooSoon == 1 && runDelay >= 0) {
    this.queue = 1; return;
  }
  this.tooSoon = 1;
  setTimeout(function(){
    this.tooSoon = 0;
    if (this.queue) {
	  editor_updateUI(objname,-1);
	};
    this.queue = 0;
  }, 333);
  if (editor_obj.tagName.toLowerCase() == 'textarea') {
    document.all[objname].value = editor_obj.value;
    return;
  }
  else {
    editdoc = editor_obj.contentWindow.document;
    editEvent = editor_obj.contentWindow.event;
    _fix_placeholder_urls(editdoc);
    document.all[objname].value = editdoc.body.innerHTML;
  }
  var IDList = Array('Bold','Underline','Italic','SubScript','SuperScript','JustifyLeft','JustifyCenter','JustifyRight','InsertOrderedList','InsertUnorderedList','StrikeThrough');
  for (i=0; i<IDList.length; i++) {
    var button_obj = document.all["_" +objname+ "_" +IDList[i]];
    if (button_obj == null) {
	  continue;
	}
    var cmdActive = editdoc.queryCommandState( IDList[i] );
    if (!cmdActive)  {
      if (button_obj.className != 'btn') {
	    button_obj.className = 'btn';
	  }
      if (button_obj.disabled  != false) {
	    button_obj.disabled = false;
	  }
    }
	else if (cmdActive)  {
      if (button_obj.className != 'btnDN') {
	    button_obj.className = 'btnDN';
	  }
      if (button_obj.disabled  != false)   {
	    button_obj.disabled = false;
	  }
    }
  }
//  var IDList = Array('FontName','FontSize');
//  for (i=0; i<IDList.length; i++) {
//    var cmdActive = editdoc.queryCommandState( IDList[i] );
//    var button_obj = document.all["_" +objname+ "_" +IDList[i]];
//    button_obj.disabled = false;
//  }
//  var fontname = editdoc.queryCommandValue('FontName');
//  var fontsize = editdoc.queryCommandValue('FontSize');
//  if (fontname != null) {
//    fontname = fontname.toLowerCase();
//  }
//  var fontname_obj = document.all["_" +objname+ "_FontName"];
//  if (fontname == null) {
//    fontname_obj.value = fontname;
//  }
//  else {
//    var foundfont;
//    var fonts = fontname_obj.length;
//    for (i=0; i<fonts; i++) {
//      var thisfont = fontname_obj[i].text.toLowerCase();
//      if (thisfont == fontname) {
//        fontname_obj.selectedIndex = i;
//        foundfont = 1;
//      }
//    }
//    if (foundfont != 1) {
//	fontname_obj.value = fontname;
//	}
//  }
//  var fontsize_obj = document.all["_" +objname+ "_FontSize"];
//  if (fontsize == null) {
//    fontsize_obj.value = fontsize;
//  }
//  else {
//    for (i=0; i<7; i++) {
//      var thissize = fontsize_obj[i].text;
//      if (thissize == fontsize) {
//	    fontsize_obj.selectedIndex = i;
//      }
//    }
//  }
}

function editor_setmode(button_id, mode) {
  var BtnParts = Array();
  BtnParts = button_id.split("_");
  var objname     = button_id.replace(/^_(.*)_[^_]*$/, '$1');
  var cmdID       = BtnParts[ BtnParts.length-1 ];
  var editor_obj = document.all["_" +objname + "_editor"];
  var editdoc;
  var TextEdit   = '<textarea ID="_' +objname + '_editor" style="width:' +editor_obj.style.width+ '; height:' +editor_obj.style.height+ '; margin-top: -1px; margin-bottom: -1px;"></textarea>';
  var RichEdit   = '<iframe ID="_' +objname+ '_editor"    style="width:' +editor_obj.style.width+ '; height:' +editor_obj.style.height+ ';"></iframe>';
  if (mode == "textedit" || editor_obj.tagName.toLowerCase() == 'iframe') {
    editdoc = editor_obj.contentWindow.document;
    var contents = editdoc.body.createTextRange().htmlText;
    editor_obj.outerHTML = TextEdit;
    editor_obj = document.all["_" +objname + "_editor"];
    editor_obj.value = contents;
    editor_updateUI(objname);
    var IDList = Array('Bold','Print','Italic','Undo','Redo','Copy','Paste','Cut','Underline','StrikeThrough','SubScript','SuperScript','JustifyLeft','JustifyCenter','JustifyRight','InsertOrderedList','InsertUnorderedList','Outdent','Indent','ForeColor','BackColor','InsertHorizontalRule','CreateLink','InsertImage','about','Special00','Special01','Special02','Special03','Special04','Special05','Special06','Special07','Special08','Special09','Special10','Special11','Special12','Special13','Special14','Special15','Special16','Special17','Special18','Special19','Special20','Special21','Special22','Special23','Special24','Special25','Special26','Special27','Special28','Special29','Special30');
    for (i=0; i<IDList.length; i++) { 
      var button_obj = document.all["_" +objname+ "_" +IDList[i]];
      if (button_obj == null) {
	    continue;
	  }
      button_obj.className = 'btnNA';
      button_obj.disabled = true;
    }
    var IDList = Array('FontName','FontSize');
    for (i=0; i<IDList.length; i++) {
      var button_obj = document.all["_" +objname+ "_" +IDList[i]];
      if (button_obj == null) {
	    continue;
	  }
      button_obj.disabled = true;
    }
    editor_obj.onkeypress = function() {
	  editor_updateUI(objname);
	}
    editor_obj.onkeyup = function() {
	  editor_updateUI(objname);
	}
    editor_obj.onmouseup = function() {
	  editor_updateUI(objname);
	}
    editor_obj.ondrop = function() {
	  editor_updateUI(objname, 100);
	}
    editor_obj.oncut = function() {
	  editor_updateUI(objname, 100);
	}
    editor_obj.onpaste = function() {
	  editor_updateUI(objname, 100);
	}
    editor_obj.onblur = function() {
	  editor_updateUI(objname, -1);
	}
	editor_obj.onundo = function() {
	  editor_updateUI(objname, 100);
	}
	editor_obj.onredo = function() {
	  editor_updateUI(objname, 100);
	}
    document.all[objname].value = editor_obj.value;
    _editor_focus(editor_obj);
  }
  else {
    var contents = editor_obj.value;
    editor_obj.outerHTML = RichEdit;
    editor_obj = document.all["_" +objname + "_editor"];
    editdoc    = editor_obj.contentWindow.document;
    editdoc.open();
    editdoc.write(''
      + '  <html><head>\n'
      + '  <style>\n'
      + '    body { background-color: #FFFFFF; font-family: "Verdana"; font-size: x-small; } \n'
      + '  </style>\n'
      + '</head>\n'
      + '<body contenteditable="true" topmargin=1 leftmargin=1>'
      + contents
      + '</body>\n'
      + '</html>\n'
      );
    editdoc.close();
    var IDList = Array('Bold','Print','Undo','Redo','Italic','Copy','Paste','Cut','Underline','StrikeThrough','SubScript','SuperScript','JustifyLeft','JustifyCenter','JustifyRight','InsertOrderedList','InsertUnorderedList','Outdent','Indent','ForeColor','BackColor','InsertHorizontalRule','CreateLink','InsertImage','about','Special00','Special01','Special02','Special03','Special04','Special05','Special06','Special07','Special08','Special09','Special10','Special11','Special12','Special13','Special14','Special15','Special16','Special17','Special18','Special19','Special20','Special21','Special22','Special23','Special24','Special25','Special26','Special27','Special28','Special29','Special30');
    for (i=0; i<IDList.length; i++) {
      var button_obj = document.all["_" +objname+ "_" +IDList[i]];
      if (button_obj == null) {
	    continue;
	  }
      button_obj.className = 'btn';
      button_obj.disabled = false;
    }
    editdoc.onkeypress = function() {
	  editor_updateUI(objname);
	}
    editdoc.onkeyup = function() {
	  editor_updateUI(objname);
	}
    editdoc.onmouseup = function() {
	  editor_updateUI(objname);
	}
    editdoc.body.ondrop = function() {
	  editor_updateUI(objname, 100);
	}
    editdoc.body.oncut = function() {
	  editor_updateUI(objname, 100);
	}
    editdoc.body.onpaste = function() {
	  editor_updateUI(objname, 100);
	}
    editdoc.body.onblur = function() {
	  editor_updateUI(objname, -1);
	}
    editor_obj.onload = function() {
	  editdoc.body.innerHTML = document.all[objname].value;
	}
	editor_obj.onundo = function() {
	  editor_updateUI(objname, 100);
	}
	editor_obj.onredo = function() {
	  editor_updateUI(objname, 100);
	}
    _fix_placeholder_urls(editdoc);
    document.all[objname].value = editdoc.body.innerHTML;
    if (mode != 'init') {
      _editor_focus(editor_obj);
    }
  }
  if (mode != 'init') {
    editor_updateUI(objname);
  }
}

function _editor_focus(editor_obj) {
  if (editor_obj.tagName.toLowerCase() == 'textarea') {
    var myfunc = function() {
	  editor_obj.focus();
	};
    setTimeout(myfunc,100);
  }
  else {
    var editdoc = editor_obj.contentWindow.document;
    var editorRange = editdoc.body.createTextRange();
    var curRange = editdoc.selection.createRange();
    if (curRange.length == null &&!editorRange.inRange(curRange)) {
      editorRange.collapse();
      editorRange.select();
      curRange = editorRange;
    }
  }
}

function _dec_to_rgb(value) {
  var hex_string = "";
  for (var hexpair = 0; hexpair < 3; hexpair++) {
    var byte = value & 0xFF;
    value >>= 8;
    var nybble2 = byte & 0x0F;
    var nybble1 = (byte >> 4) & 0x0F;
    hex_string += nybble1.toString(16);
    hex_string += nybble2.toString(16);
  }
  return hex_string.toUpperCase();
}

function _fix_placeholder_urls(editdoc) {
  var i;
  for (i=0; i < editdoc.links.length; i++) {
    editdoc.links[i].href = editdoc.links[i].href.replace(/^[^*]*(\*\*\*)/, "$1");
  }
  for (i=0; i < editdoc.images.length; i++) {
    editdoc.images[i].src = editdoc.images[i].src.replace(/^[^*]*(\*\*\*)/, "$1");
  }
}

function editor_insertHTML(objname, str1,str2, reqSel) {
  var editor_obj = document.all["_" +objname + "_editor"];    // editor object
  if (str1 == null) {
    str1 = '';
  }
  if (str2 == null) {
    str2 = '';
  }
  if (document.all[objname] && editor_obj == null) {
    document.all[objname].focus();
    document.all[objname].value = document.all[objname].value + str1 + str2;
    return;
  }
  if (editor_obj == null) {
    return alert("Unable to insert HTML.  Invalid object name '" +objname+ "'.");
  }
  _editor_focus(editor_obj);
  var tagname = editor_obj.tagName.toLowerCase();
  var sRange;
  if (tagname == 'iframe') {
    var editdoc = editor_obj.contentWindow.document;
    sRange  = editdoc.selection.createRange();
    var sHtml   = sRange.htmlText;
    if (sRange.length) {
	  return alert("Unable to insert HTML.  Try highlighting content instead of selecting it.");
	}
    var oldHandler = window.onerror;
    window.onerror = function() {
	  alert("Unable to insert HTML for current selection."); return true;
	}
    if (sHtml.length) {
      if (str2) {
	    sRange.pasteHTML(str1 +sHtml+ str2)
	  }
      else {
	    sRange.pasteHTML(str1);
	  }
    }
	else {
      if (reqSel) {
	    return alert("Unable to insert HTML.  You must select something first.");
	  }
      sRange.pasteHTML(str1 + str2);
    }
    window.onerror = oldHandler;
  }
  else if (tagname == 'textarea') {
    editor_obj.focus();
    sRange  = document.selection.createRange();
    var sText   = sRange.text;

    if (sText.length) {
      if (str2) {
	    sRange.text = str1 +sText+ str2;
	  }
      else {
	    sRange.text = str1;
	  }
    }
	else {
      if (reqSel) {
	    return alert("Unable to insert HTML.  You must select something first.");
	  }
      sRange.text = str1 + str2;
    }
  }
  else {
    alert("Unable to insert HTML.  Unknown object tag type '" +tagname+ "'.");
  }
  sRange.collapse(false);
  sRange.select();
}
// End -->