﻿/********** Fade Background *************************************/
function fadeBackground(elementId, startColor, endColor, timeMs) {
    var startTime = new Date().getTime();
    
	function stepFade(elementId, startColor, endColor, startTime, endTime) {
		var now = new Date().getTime();

		var step = new Array(3);

		var progress = (now - startTime) / (endTime - startTime);

		step[0] = Math.round(startColor[0] + ((endColor[0] - startColor[0]) * progress));
		step[1] = Math.round(startColor[1] + ((endColor[1] - startColor[1]) * progress));
		step[2] = Math.round(startColor[2] + ((endColor[2] - startColor[2]) * progress));

		document.getElementById(elementId).style.backgroundColor
			= "rgb(" + step[0] + "," + step[1] + "," + step[2] + ")";

		if (now <= endTime) {
			setTimeout(function() {
				stepFade(elementId, startColor, endColor, startTime, endTime);
			}, 20);
		}
		else {
			document.getElementById(elementId).style.backgroundColor
				= "rgb(" + endColor[0] + "," + endColor[1] + "," + endColor[2] + ")";
		}
	}
	
	stepFade(elementId, startColor, endColor, startTime, startTime + timeMs);
};

/******************* Textarea Maxlength Function *********************/
function ismaxlength(obj)
{
var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
if (obj.getAttribute && obj.value.length>mlength)
obj.value=obj.value.substring(0,mlength)
};

