function $(id)
{
	return document.getElementById(id);
}

var echo_number = 0;
/**
 * Displays content in upper-right hand corner of screen for diagnostic/testing purposes.
 * @param {String} content Content to display
 */
function echo(content)
{
	if(!$('echo'))
	{
		var body = document.getElementsByTagName('body')[0];
		var echo = document.createElement('div');
		var echo_ul = document.createElement('ul');
		echo.setAttribute('id','echo');
		echo_ul.setAttribute('id','echo_ul');
		echo.appendChild(echo_ul);
		body.appendChild(echo);
	}

	echo_number++;

	var echo = $('echo');
	echo.style.display = 'block';

	var echo_ul = $('echo_ul');
	var first_li = echo_ul.firstChild;
	var new_li = document.createElement('li');
	new_li.innerHTML = echo_number+'. '+content;
	echo_ul.insertBefore(new_li,first_li);
}

/**
 * Fades an element into view by gradually changing opacity.
 * Note: Element must not have "display: none" CSS property or effect will not render.
 * @param {String} element_id Element ID
 */
function fadeIn(element_id,routine)
{
	var element = $(element_id);
	element.style.opacity = 0;
	element.style.filter = 'alpha(opacity=0)';
	fadeInSub(element_id,1,routine);
}

/**
 * Called exclusively by fadeIn function; performs fade-in effect for element
 * @param {String) element_id Element ID
 * @param {Integer} step Numeric step in fade-in process
 * @see #fadeIn
 */
function fadeInSub(element_id,step,routine)
{
	if(step <= 10)
	{
		var element = $(element_id);
		element.style.opacity = step/10;
		element.style.filter = 'alpha(opacity='+step*10+')';
		setTimeout('fadeInSub("'+element_id+'",'+(step+1)+',"'+routine+'")',1);
	}
	else
	{
		eval(routine);
	}
}

/**
 * Fades an element out of view by gradually changing opacity.
 * Note: Element must not have "display: none" CSS property or effect will not render.
 * @param {String} element_id Element ID
 */
function fadeOut(element_id,routine)
{
	var element = $(element_id);
	element.style.opacity = 1;
	element.style.filter = 'alpha(opacity=100)';
	fadeOutSub(element_id,10,routine);
}

/**
 * Called exclusively by fadeOut function; performs fade-out effect for element
 * @param {String) element_id Element ID
 * @param {Integer} step Numeric step in fade-out process
 * @see #fadeOut
 */
function fadeOutSub(element_id,step,routine)
{
	var element = $(element_id);

	if(element && step >= 0)
	{
		element.style.opacity = step/10;
		element.style.filter = 'alpha(opacity='+step*10+')';
		setTimeout('fadeOutSub("'+element_id+'",'+(step-1)+',"'+routine+'")',1);
	}
	else
	{
		eval(routine);
	}
}