
var blankImg = "/CfgAPImagesCentral/Images/Medias/Layout/blank.gif";

// This must be a path to a blank image. That's all the configuration you need.
if (typeof blankImg == 'undefined')
	var blankImg = 'blank.gif';

var f = 'DXImageTransform.Microsoft.AlphaImageLoader';

function filter(obj, src, method)
{
	if ((typeof (filters) != "undefined") && (typeof (filters) != "unknown") && (filters != null) && (filters[f] != null))
	{
		obj.filters[f].enabled = src ? true : false;
		if (src)
		{
			var filter = obj.filters[f];
			obj.filter.src = src;
			obj.filter.sizingMethod = method;
		}
	}
	else if (src)
	{
		var s = 'progid:' + f + '(src="' + encodeURI(src) + '",sizingMethod="' + method + '")';
		obj.style.filter = s;
	}
}

var filtering = false;

function doFix(obj, force)
{
	if (filtering)
		return;

	// Assume IE7 is OK.
	if (!/MSIE (5\.5|6\.)/.test(navigator.userAgent))
		return ;
		
	filtering = true;
  
	try
	{
  		var bgImg = obj.currentStyle.backgroundImage || obj.style.backgroundImage;
			
		if (obj.tagName.toLowerCase() == 'img')
		{
			if (!force && obj.src.toLowerCase().indexOf('png') < 0)
			{
				filtering = false;
				return ;
				// if (obj.src.indexOf(blankImg) < 0)
				//	filter(obj, obj.src);
			}
			else
			{
				if (obj.currentStyle.width == 'auto' && obj.offsetWidth > 0)
					obj.style.width = obj.offsetWidth + 'px';
				if (obj.currentStyle.height == 'auto' && obj.offsetHeight > 0)
					obj.style.height = obj.offsetHeight + 'px';
				filter(obj, obj.src, /* 'scale' */ 'image');
				obj.src = blankImg;
			}
		}
		else if (bgImg && bgImg != 'none')
		{
			if (bgImg.match(/^url[("']+(.*\.png)[)"']+$/i))
			{
				var s = RegExp.$1;
				if (obj.currentStyle.width == 'auto' && obj.currentStyle.height == 'auto')
					obj.style.width = obj.offsetWidth + 'px';
				obj.style.backgroundImage = 'none';
				filter(obj, s, 'crop');

				// IE link fix.
				for (var n = 0; n < obj.childNodes.length; n++)
					if (obj.childNodes[n].style)
						obj.childNodes[n].style.position = 'relative';
			}
			else filter(obj);
		}
	}
	catch (ex) { /* nada */ }

	filtering = false;
}

