/*
 
Correctly handle PNG transparency in Win IE 5.5 & 6.
http://homepage.ntlworld.com/bobosola. Updated 18-Jan-2006.

Use in <HEAD> with DEFER keyword wrapped in conditional comments:
<!--[if lt IE 7]>
<script defer type="text/javascript" src="pngfix.js"></script>
<![endif]-->

*/

var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])
function debugString (sStr) {
    var
       sResult = '';
       
    sResult = 'ASCII Values For "' + sStr + '":\n\r\n\r';   
    for (var i = 0; i < sStr.length; i ++)
      sResult += sStr.charAt (i) + '\t' + sStr.charCodeAt (i) + '\n\r';
      
    alert (sResult); 
  }

  /*
  **  Performs a case-insensitive search-and-replace operation on the
  **  specified string.  Identical to PHP's "str_ireplace" function.
  */
  function replaceStr (sFind, sReplace, sString) {

    // Initialize
    var iIndex = sString.indexOf (sFind);

    // Replace all matches
    while (iIndex > -1) {
      sString = sString.replace (sFind, sReplace); 
      iIndex = sString.indexOf (sFind);
    }

    // Return results
    return (sString);
  }
  
  function doFixPNG () {
    if ((version >= 5.5) && (version < 7) && (document.body.filters)) 
    {
       for(var i=0; i<document.images.length; i++)
       {
          var img = document.images[i]
          var imgName = img.src.toUpperCase()
          if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
          {
             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 
             try {
               var imgOnClick = img.onclick;
               var imgOnClick = replaceStr (String.fromCharCode (10), '', img.onclick.toString ().replace ('function anonymous()', '').replace ('{', '').replace ('}', '').replace ('\n', '').replace ('\r', ''));
               var imgOnMouseOver = replaceStr (String.fromCharCode (10), '', img.onmouseover.toString ().replace ('function anonymous()', '').replace ('{', '').replace ('}', '').replace ('\n', '').replace ('\r', '').replace ('this.', 'this.filters[0].'));
               var imgOnMouseOut = replaceStr (String.fromCharCode (10), '', img.onmouseout.toString ().replace ('function anonymous()', '').replace ('{', '').replace ('}', '').replace ('\n', '').replace ('\r', '').replace ('this.', 'this.filters[0].'));
               var imgOnMouseDown = replaceStr (String.fromCharCode (10), '', img.onmousedown.toString ().replace ('function anonymous()', '').replace ('{', '').replace ('}', '').replace ('\n', '').replace ('\r', '').replace ('this.', 'this.filters[0].'));
               var imgOnMouseUp = replaceStr (String.fromCharCode (10), '', img.onmouseup.toString ().replace ('function anonymous()', '').replace ('{', '').replace ('}', '').replace ('\n', '').replace ('\r', '').replace ('this.', 'this.filters[0].'));
             }
             catch (e) {
               var imgOnClick = '';
               var imgOnMouseOver = '';
               var imgOnMouseOut = '';
               var imgOnMouseDown = '';
               var imgOnMouseUp = '';
             }
             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 onClick=\"" + imgOnClick + "\" onMouseOver=\"" + imgOnMouseOver + "\" onMouseOut=\"" + imgOnMouseOut + "\" onMouseDown=\"" + imgOnMouseDown + "\" onMouseUp=\"" + imgOnMouseUp + "\"" + imgID + imgClass + imgTitle
             + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
             + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
             + "(enabled=\'true\', src=\'" + img.src + "\', sizingMethod='scale');\"></span>";
             img.outerHTML = strNewHTML;
             i = i-1
          }
       }
    }
  }
