function opacityFade(id, opacStart, opacEnd, millisec) {	
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
		setTimeout("document.getElementById('"+id+"').style.display = 'none';", millisec);
	} else if(opacStart < opacEnd) {
		document.getElementById(id).style.display = 'block';
		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)
	if(object != null) {
		object.style.opacity = (opacity / 100);
		object.style.MozOpacity = (opacity / 100);
		object.style.KhtmlOpacity = (opacity / 100);
		object.style.filter = "alpha(opacity=" + opacity + ")"; 
	}
}

//Adds the iFrame by js to avoid Ajax Async postback error inthe ASP.Net handler causing the page to postback
function addIFrame(id) {
	var ni = document.getElementById(id);
	var newFrame = document.createElement('iframe');
	var frameId = id+'_iframe';
	
	//If the iFrame hasnt been added yet
	if(document.getElementById(id+'_iframe') == null) {
		newFrame.setAttribute('id',frameId);
		newFrame.setAttribute('width','100%');
		newFrame.setAttribute('height','100%');
		newFrame.setAttribute('frameborder','0');
	}
}

//Only called by IE 6
function coverAll(id) {
	var winInWd=window.innerHeight? window.innerWidth : Math.max(document.body.clientWidth, (document.documentElement? document.documentElement.clientWidth : 0))
	var free_width= window.opera? winInWd/ 2 - document.getElementById(id).offsetWidth : winInWd/ 2 - (document.all? document.all[id] : document.getElementById(id)).offsetWidth/2;
	var winInHt=window.innerHeight? window.innerHeight : Math.max(document.body.clientHeight, (document.documentElement? document.documentElement.clientHeight : 0))
	var free_height = window.opera? winInHt/ 2 - document.getElementById(id).offsetHeight : winInHt/ 2 - (document.all? document.all[id] : document.getElementById(id)).offsetHeight/2;

	with ((document.all? document.all[id] : document.getElementById(id)).style) {
		zIndex=100;
		position='absolute';
		top=0;
		left=0;
		right=winInWd;
		width=winInWd;
		height=winInHt;
	}
}

//Only called by IE 6
function valignCenter(id) {
	var winInHt = document.documentElement.clientHeight;
	var scrollPos = document.documentElement.scrollTop;
	var ele = document.getElementById(id);
	var disp = ele.style.display;
	ele.style.display = 'block';
	var ele_height = ele.clientHeight;
	ele.style.display = disp;

	var free_height = ele_height / 2 + (winInHt - ele_height) / 2 + scrollPos;

	with ((document.all? document.all[id] : document.getElementById(id)).style) {
		zIndex=100;
		position='absolute';
		top=free_height + 'px';
	}
}

function openOverLayPanel(overlayId, msgBoxId) {
	var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
	if (IE6)
	{
		coverAll(overlayId);
		addIFrame(msgBoxId);
		//valignCenter(msgBoxId);
		opacityFade(overlayId, 0, 85, 1);
		opacityFade(msgBoxId, 0, 100, 5);
	}
	else
	{
		addIFrame(msgBoxId);
		opacityFade(overlayId, 0, 85, 1);
		opacityFade(msgBoxId, 0, 100, 5);
	}
}

function closeOverlayPanel(overlayId, msgBoxId) {
	opacityFade(overlayId, 100, 0, 1); 
	opacityFade(msgBoxId, 100, 0, 1);
}