{
	var oHtmlData;
	function HtmlData(banner_id,type,vendor,html,weight,do_not_nullify,do_not_nullify_click)
	{
		this.banner_id = banner_id
		this.type = type;
		this.vendor = vendor;
		this.html = html;
		this.weight = weight;
		this.originalWeight = weight;
		this.do_not_nullify = do_not_nullify;
		this.do_not_nullify_click = do_not_nullify_click;
	}
	
	function CalculateCommonDenominator(type)
	{
		var iIndex;
		var iCommonDenominator;
		iIndex = 0;
		iCommonDenominator=0;
		for (iIndex=0;iIndex<oHtmlData.length;iIndex++)
		{
			if (oHtmlData[iIndex].type==type)
			{		
				iCommonDenominator = iCommonDenominator + oHtmlData[iIndex].weight;
			}
		}
		return iCommonDenominator;
	}
	
	function ApplyOriginalWeights()
	{
		var iIndex;
		for (iIndex=0;iIndex<oHtmlData.length;iIndex++)
		{
			oHtmlData[iIndex].weight = oHtmlData[iIndex].originalWeight;
		}
	}
	
	function Nullify (vendor,type)
	{
		var iIndex;
		if (vendor != 0)
		{ 
			for (iIndex=0;iIndex<oHtmlData.length;iIndex++)
			{
				if (oHtmlData[iIndex].vendor==vendor && oHtmlData[iIndex].type==type)
				{
					oHtmlData[iIndex].weight = 0;
				}
			}
		}
	}
	
	function GetHTML(type)
	{
		var iRandomPercent;
		var iWeight;
		var iWeightPercent;
		var iWeightPercentSum;
		var iCommonDenominator;
		var iIndex;
		var bPrinted=false;
		var sHTML;
	
		iIndex=0;
		iRandomPercent = Math.round(Math.random() * 100);
		iWeightPercentSum = 0;
		bPrinted = false;
		iCommonDenominator = CalculateCommonDenominator(type);
		if (iCommonDenominator == 0) return;
		while(!bPrinted)
		{
			if (oHtmlData[iIndex].type==type)
			{
				iWeight = oHtmlData[iIndex].weight;
				iWeightPercent = Math.round (iWeight / iCommonDenominator * 100);
				iWeightPercentSum = iWeightPercentSum + iWeightPercent;
				if (iWeightPercentSum >= iRandomPercent && iWeight>0)
				{
					if (oHtmlData[iIndex].vendor!=0)
					{
						Nullify (oHtmlData[iIndex].vendor,type);
					}
					else
					{
						oHtmlData[iIndex].weight = 0;
					}
					sHTML = oHtmlData[iIndex].html;
					bPrinted=true;
					iCommonDenominator = CalculateCommonDenominator(type);
					if (iCommonDenominator==0)
						ApplyOriginalWeights();
				}
			}	
			iIndex = iIndex+1;
			if (iIndex>= oHtmlData.length) break;
		}
		return sHTML;
	}
	
	function handleBannersHTML()
	{
		var oSpans = document.getElementsByName("dthtml");
		var sType = "";
		var iIndex;
		var sHTML;
		
		for (iIndex=0;iIndex<oSpans.length;iIndex++)
		{
			sType = (oSpans[iIndex].type)? oSpans[iIndex].type : oSpans[iIndex].getAttribute("type");
			sHTML = GetHTML(sType);
			
			if (sHTML!=null) 
				oSpans[iIndex].innerHTML = sHTML;
		}
	}
}
