/**
Script to fade a div element in (by id), changing the inner HTML at the same time. Useful for AJAX status messages. 
*/
function showMessageBox(id, text)
{
	$(id).style.zIndex=100;
	$(id).innerHTML=text;
	opacity(id,0,100,1000);
}

function closeMessageBox(id, text)
{
	
	$(id).innerHTML=text;
	opacity(id,100,0,1000);
	//$(id).style.zIndex=0;
}

function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	if( !isIE() && getOpacity(id) != opacStart)
	{
		setTimeout("opacity('"+id+"'," + opacStart + ", " + opacEnd + ", " + millisec + ")", 1000);
	}
	else
	{
		if(opacStart > opacEnd) {
			for(i = opacStart; i >= opacEnd; i--) {
				setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
				timer++;
			}
		} else if(opacStart < opacEnd) {
			for(i = opacStart; i <= opacEnd; i++)
				{
				setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
				timer++;
			}
		}

	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style;
	if(opacity<=0)
	{
		object.zIndex=-1;
	}
	else
	{
		object.zIndex=100;
	}
	
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";

} 

function getOpacity(id)
{
	var object = document.getElementById(id).style;
	if(!object.opacity)
	{
		//alert('filter:'+object.filter);
	}
	return object.opacity * 100;
}

function isIE(){return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);}
