// return wait cursor wall object
function getWaitCursor()
{
	var wall = top.document.getElementById("wait-cursor-wall");
	if( !wall )
	{
		wall = top.document.createElement( "div" );
		wall.id = "wait-cursor-wall";
		wall.style.position = "absolute";
		wall.style.left = 0;
		wall.style.top = 0;
		wall.style.width = "100%";
		wall.style.height = "100%";
		wall.style.display = "none";
		wall.style.zIndex = 10000;
		wall.counter = 0;
		wall.onmousedown = waitCursorStub;
		wall.onmouseup = waitCursorStub;
		wall.oncontextmenu = waitCursorStub;
		top.document.body.appendChild( wall );
	}
	return wall;
}

// begin wait cursor
function beginWaitCursor()
{
	var wall = getWaitCursor();
	if( wall.counter == 0 )
	{
		wall.style.display = "inline";
		wall.style.cursor = "wait";
		wall._onkeydown = document.onkeydown;
		document.onkeydown = waitCursorStub;
		wall.setCapture();
	}
	wall.counter++;
}

// end wait cursor
function endWaitCursor( force )
{
	var wall = getWaitCursor();
	--wall.counter;
	if( wall.counter > 0 && force )
		wall.counter = 0;
	if( wall.counter == 0 )
	{
		wall.releaseCapture();
		document.onkeydown = wall._onkeydown;
		wall.style.cursor = "";
		wall.style.display = "none";
	}
	if( wall.counter < 0 )
		wall.counter = 0;
}

// wait cursor stub function
function waitCursorStub()
{
	var e = event;
	if( !e )
		e = top.event;
	e.returnValue = false;
}
