function correctPNG() // correctly handle PNG transparency in Win IE 5.5 or higher.
{
  for(var i=0; i<document.images.length; i++) {
    var img = document.images[i]
    var imgName = img.src.toUpperCase()
    var img2check = img.name.toUpperCase()
    if ((imgName.substring(imgName.length-3, imgName.length) == "PNG")) {
       var imgOver = img.onmouseover;
       var imgID = (img.id) ? "id='" + img.id + "' " : ""
       var imgClass = (img.className) ? "class='" + img.className + "' " : ""
       var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
       var imgStyle = "display:inline-block;" + img.style.cssText 
       if (img.align == "left") imgStyle = "float:left;" + imgStyle
       if (img.align == "right") imgStyle = "float:right;" + imgStyle
       if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
       
       var strNewHTML = "<span " + imgID + imgClass + imgTitle
       + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
         + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
       + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
       img.outerHTML = strNewHTML
       i = i-1
    }
  }
}


/************
 * Functions für das Forum (BBCODES)
 ************/
 
 
var idTextfeld    = 'message';       // ID der <textarea>
var idColorpicker = 'colorpicker';     // ID der Tabelle

var rangeIE = null;

function insertProperty(prop,val) {
  insertText('[' + prop + '=' + val + ']', '[\/' + prop + ']');
}
 
// IE/Gecko-Weiche zum Einfügen von Text ins Textfeld
function insertText(textField, vor, nach) {
  var textfeld = document.getElementById(textField);
  textfeld.focus();                                         // falls Cursor außerhalb war

  if(typeof document.selection != 'undefined') {              // für IE, auch Opera
    insertIE(textfeld, vor, nach);
  } else if (typeof textfeld.selectionStart != 'undefined') {  // Geckos (FF)
    insertGecko(textfeld, vor, nach);
  }
}

// Im "textfeld" Portionen "vor" und "nach" einfügen (IE)
function insertIE(textfeld, vor, nach) {
  if(!rangeIE) rangeIE = document.selection.createRange();

  // nichts weiter tun, falls wir nicht im Textfeld sind
  if(rangeIE.parentElement().id != textField) { 
    rangeIE = null; return; 
  }
  var alterText = rangeIE.text;

  // Auswahl um BBC ergänzen
  rangeIE.text = vor + alterText + nach;

  // Cursor neu setzen (wie SelfHTML)
  if (alterText.length == 0)
    rangeIE.move('character', -nach.length);
  else
    rangeIE.moveStart('character', rangeIE.text.length);

  rangeIE.select();
  rangeIE = null;
}

// Im "textfeld" Portionen "vor" und "nach" einfügen (Geckos)
function insertGecko(textfeld, vor, nach) {
  von = textfeld.selectionStart;            // liefert Zeichenposition
  bis = textfeld.selectionEnd;              //

  // Text zerlegen
  anfang = textfeld.value.slice(0,   von);
  mitte  = textfeld.value.slice(von, bis);
  ende   = textfeld.value.slice(bis);        // der Rest des Strings

  // BBC einfügen und ins Textfeld schreiben
  textfeld.value = anfang + vor + mitte + nach + ende;

  // Cursor neu setzen
  if(bis - von == 0) {
    textfeld.selectionStart = von + vor.length;
    textfeld.selectionEnd   = textfeld.selectionStart;
  } else {
    textfeld.selectionEnd   = bis + vor.length + nach.length;
    textfeld.selectionStart = textfeld.selectionEnd;
  }
}

//farbauswähler - lassen wir noch


 // Im IE die Textauswahl merken (onMouseDown im Farbwähler)
function getSelectionIE() {
  if (document.selection) {       // nur im IE
    document.getElementById(idTextfeld).focus();
    rangeIE = document.selection.createRange();    // Auswahl merken
  }
}
