﻿initializeEditLabelImageUrl = function(control)
{
	control.style.color = "";
	control.style.backgroundColor = "";
	control.style.fontSize = "";
	var innerHTMLText = dnn.dom.getAttr(control, 'innerHTMLText', '');
	
	if (control.style.filter != null && control.style.filter != "")
	{
		control.style.filter = getFilter(control, getCSSPropertyValue(control, "color"), innerHTMLText, getCSSPropertyValue(control, "fontSize"), getCSSPropertyValue(control, "fontFamily"), getCSSPropertyValue(control, "fontWeight"));
	}
	else
	{
		control.src = getImageUrl(control, getCSSPropertyValue(control, "color"), innerHTMLText, getCSSPropertyValue(control, "fontSize"), getCSSPropertyValue(control, "fontFamily"), getCSSPropertyValue(control, "fontWeight"))
		control.style.width = "";
		control.style.height = "";
	}
}

getCSSPropertyValue = function(control, propName)
{
	if (control.currentStyle)
	{
		return control.currentStyle[propName];
	}
	else if (window.getComputedStyle)
	{
		var style = window.getComputedStyle(control, "");
		if (propName == "fontSize")
		{
			return style.fontSize;
		} 
		else if (propName == "fontFamily")
		{
			return style.fontFamily;
		}
		else if (propName == "fontWeight")
		{
			return style.fontWeight;
		}
		
		return style.getPropertyValue(propName);
	}
	return null;
}

getFilter = function(control, color, text, fontSize, fontFamily, fontWeight)
{
	if (color != null && text != null)
	{	
		var url = getImageUrl(control, color, text, fontSize, fontFamily, fontWeight);
		if (url != "")
		{
			return "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + url + "')";	
		}
	}
	
	return "";
}

getImageUrl = function(control, color, text, fontSize, fontNames, weight)
{
	var filterImageServerUrl = dnn.dom.getAttr(control, 'filterImageServerUrl', null);
	var filterImageParams = dnn.dom.getAttr(control, 'filterImageParams', null);
	
	if (color != null && text != null && filterImageServerUrl != null && filterImageParams != null)
	{
		var url = filterImageServerUrl+"/TextService.aspx?Text="+dnn.encode(text.replace('&','::amp::'))+filterImageParams;
		url += "&ForeColor="+(color+"").replace('#','_');
		
		if (fontSize != null)
		{
			url += "&FontSize=" + fontSize;
		}
		
		if (fontNames != null)
		{
		    url += "&FontName=" + fontNames;
		}

        if (weight == "bold" || weight == "700")
        {
            url += "&Bold=1";
        }

		return url;	
	}
	return "";
}