function dspTrend_GetTrendHtml(oSetting, oTrendBody, oTrendTime, oTrendM1, sBorderColor) {
	var oParam = new Object, c;
	oTrendBody.style.height = (oSetting.WebPartHeight) + "px";
	oTrendBody.parentElement.parentElement.parentElement.style.width = oSetting.WebPartWidth + "px";
	dspUtil_ApplyTopBorderStyle(oTrendTime.id, sBorderColor);
	oParam.TimeRow = oTrendTime;
	oParam.ValueRow = oTrendM1;
	with (oSetting) {
		oParam.Periods = RowHeader;
		oParam.BorderColor = BorderColor;;
		oParam.WebPartWidth = WebPartWidth;
		oParam.WebPartHeight = WebPartHeight;
		oParam.Values = Values;
		oParam.SerieColor = SerieColor;
		oParam.FillOpacity = FillOpacity;
	}	
	return dspTrend_UpdateTrendArrow(oParam);
}

function dspTrend_UpdateTrendArrow(oParam) {
	var iPeriod = new Number(dspTrend_GetStartPeriod(oParam.TimeRow, oParam.Periods.length));
	dspTrend_UpdateValueLegend(oParam.ValueRow, oParam.Values[0], iPeriod);
	dspTrend_UpdatePeriodLegend(oParam.TimeRow, oParam.Periods, iPeriod);
	if (oParam.Periods.length < 3)
		var s = "Need at least 3 periods to be able to display the trend arrow!";
	else {
		dspTrend_SetButtonState(oParam.TimeRow, oParam.Periods.length-3, iPeriod);
		var s = dspTrend_GetPath(oParam.Values, iPeriod, oParam.WebPartWidth, oParam.WebPartHeight, "", oParam.SerieColor, oParam.BorderColor, oParam.FillOpacity);
	}
	return s;
}

function dspTrend_SetButtonState(oTimeRow, iCount, iIndex) {
	var p = (iIndex > 0)?0:1;
	var n = (iIndex < iCount)?0:1;
	oTimeRow.cells[0].disabled = p;
	oTimeRow.cells[4].disabled = n;
	if (oTimeRow.cells[0].childNodes(2).filters.length > 0) {
		oTimeRow.cells[0].childNodes(2).filters.item(0).enabled = p;
		oTimeRow.cells[4].childNodes(2).filters.item(0).enabled = n;
	}
}

function dspTrend_SetImageState(oTag) {
	oTag.childNodes(1).filters.item("DXImageTransform.Microsoft.Alpha").enabled = oTag.disabled;
}

function dspTrend_UpdateValueLegend(oTR, aValues, iIndex) {
	var c = oTR.cells.length-2;
	for (var i=0;i<c;i++)
		if ((iIndex+i) < aValues.length)
			oTR.cells(i+1).innerHTML = aValues[iIndex+i].Formatted != "" ? aValues[iIndex+i].Formatted : "&nbsp;";
		else
			oTR.cells(i+1).innerText = "-";
}

function dspTrend_UpdatePeriodLegend(oTR, aValues, iIndex) {
	var c = oTR.cells.length-2;
	for (var i=0;i<c;i++)
		if (i < aValues.length)
			oTR.cells(i+1).innerHTML = aValues[iIndex+i];
		else
			oTR.cells(i+1).innerText = "-";
}

function dspTrend_GetPath(aValues, iPeriod, iWidth, iHeight, sIEVersion, aArrowColor, sStrokeColor, sOpacity) {
	var s="", strPath="", fFlip=false;
	var sInput = aValues[2][1+iPeriod].toString() + aValues[2][2+iPeriod].toString();
	var c1 = dspTrend_Color(aValues[3][0+iPeriod], aArrowColor);
	var c2 = dspTrend_Color(aValues[3][1+iPeriod], aArrowColor);
	var c3 = dspTrend_Color(aValues[3][2+iPeriod], aArrowColor);
	switch (sInput) {
		case "00":
			strPath = "path=\"m0,20 l 133,20,130,15,160,25,130,35,133,30,0,30,0,20 e\">";
			break;
		case "-10":
			strPath = "path=\"m3,8 l 70,45,133,45,130,50,160,40,130,30,133,35,75,35,11,0,3,8 e\">";
			break;
		case "01":
			strPath = "path=\"m0,50 l 72,50,134,16,133,23,153,0,124,4,129,7,69,40,0,40,0,50 e\">";
			break;
		case "-11":
			strPath = "path=\"m3,8 l 72,50,134,16,133,23,153,0,124,4,129,7,72,38,11,0,3,8 e\">";
			break;
		case "11":
			strPath = "path=\"m11,50 l 134,16,133,23,160,3,126,4,129,7,7,40,11,50 e\">";
			break;
		case "10":
			strPath = "path=\"m3,8 l 70,45,133,45,130,50,160,40,130,30,133,35,75,35,11,0,3,8 e\">";
			fFlip = true;
			break;
		case "0-1":
			strPath = "path=\"m0,50 l 72,50,134,16,133,23,153,0,124,4,129,7,69,40,0,40,0,50 e\">";
			fFlip = true;
			break;
		case "1-1":
			strPath = "path=\"m3,8 l 72,50,134,16,133,23,153,0,124,4,129,7,72,38,11,0,3,8 e\">";
			fFlip = true;
			break;
		case "-1-1":
			strPath = "path=\"m11,50 l 134,16,133,23,160,3,126,4,129,7,7,40,11,50 e\">";
			fFlip = true;
			break;
		default:
			break;
	}

	if (strPath!="") {
		s += "<v:shape style='width:" + (iWidth-50) + "px;height:" + iHeight + "px";
		s += (fFlip)?";flip:y'":"'";
		s += " stroked='true' coordsize='160 100' strokecolor='" + sStrokeColor + "' " + strPath;
		s += "<v:fill Type='Gradient' opacity='" + sOpacity + "%' o:opacity2='" + sOpacity + "%' Method='Sigma' Angle='90' Color2='" + c1 + "' Colors='65% " + c2 + "' Color='" + c3 + "' />";
		s += "</v:shape>";
	}
	return s;
}

function dspTrend_GetStartPeriod(oTag, iDefault) {
	if (oTag.startperiod == "-1") {
		oTag.startperiod = (iDefault-3>-1)?iDefault-3:0;
	}
	return oTag.startperiod;
}

function dspTrend_ChangePeriod(i) {
	var oTag = event.srcElement.parentElement.parentElement;
	if (!event.srcElement.parentElement.disabled) {
		var p = new Number(oTag.startperiod);
		oTag.startperiod = p + i;
		eval(oTag.movetimefunction);
	}
}

function dspTrend_Color(v, aColor) {
	if (v==-1) return aColor[0];
	if (v==1)  return aColor[2];
	if (v==0)  return aColor[1];
}

