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
    }
  }
}

function ShowHide(id) {
  obj = document.getElementById(id);
  if (obj.style.display == 'none' || !obj.style.display) {
    obj.style.display = 'block';
    obj.style.visibility = 'visible';
  } else {
    obj.style.display = 'none';
    obj.style.visibility = 'hidden';
  }
}



/************
 * BBCODES Functions
 ************/
 
 
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(vor, nach) {
  var textfeld = document.getElementById(idTextfeld);
  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 != idTextfeld) { 
    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;
  }
}

//coolerchooser - let it sleep :=)


 // remember IE Text Position (onMouseDown in the colorchooser)
function getSelectionIE() {
  if (document.selection) {       // nur im IE
    document.getElementById(idTextfeld).focus();
    rangeIE = document.selection.createRange();    // remember selection
  }
}

//round for GD-less capture
function RND() {
 fluke = Math.round(Math.random()*29+1);
 $("input[name='codec2']").val(fluke);
 return fluke;
}




$(document).ready(function() {
    //avatar and rank wrapper
    $("#sbb_modalbg").appendTo("body");
    $("#sbbavatars").appendTo("body");
    $("#sbb_modalbg").click(function() {
      closeavatars();
    });
    
    //tooltips
    $('#sbb .tt[title]').tooltip({
      delay: 0, 
      showURL: false
    });
});

/*******
 * for the internal Avatars and Ranks [+]
 *******/ 
function openavatars(path) {
  $("#sbb_modalbg").fadeTo("slow",0.7);
  $("#sbbavatars").fadeIn();
  $("#sbbavatars").load(path+"/images/avatars/index.php", { 'd' : "" } );
}
function openrankimgs(path) {
  $("#sbb_modalbg").fadeTo("slow",0.7);
  $("#sbbrankimgs").fadeIn();
  $("#sbbrankimgs").load(path+"/images/ranks/index.php");
}
function changeDir(d,path) {
  $("#sbbavatars").load(path+"/index.php", { 'd' : d } );  
}
function closeavatars() {
  $("#sbb_modalbg").fadeOut("slow");
  $("#sbbavatars").fadeOut("slow");
  $("#sbbrankimgs").fadeOut("slow");
}
function delsbbavatar(path) {
  $("#sbb .sbbav").attr("src",path+"/images/spacer.png");
  $("input[name='sbb_avatar']").val("");
}
/*******
 * for the internal Avatars and Ranks [-]
 *******/   

$(document).ready(function() {
  
  /** to toggle checkboxes **/
  $("#CBSwitchT").change( function() {
    $('input[name^=tids]').each(function() {
      $(this).attr("checked",$(this).attr("checked")?false:"checked");
    });
  });

  /**show/hide recaptcha options**/
  if ($(".boardadminform select[name='board_use_cap']").val() == 3) {
    $(".recaptcha_data").show();
  }
  $(".boardadminform select[name='board_use_cap']").change(function() { 
    if ($(this).val() == 3) $(".recaptcha_data").fadeIn();
    else $(".recaptcha_data").fadeOut();
  });

});