function centerWindow(element)
{
	try
	{
		if($(element) != null)
		{
			if(typeof window.innerHeight != 'undefined')
			{	//sane browsers
				$(element).style.top = 
					Math.round(document.viewport.getScrollOffsets().top + 
					((window.innerHeight - $(element).getHeight()))/2)+'px';
				$(element).style.left = 
					Math.round(document.viewport.getScrollOffsets().left + 
					((window.innerWidth - $(element).getWidth()))/2)+'px';
			}
			else
			{ //ie
				$(element).style.top = 
					Math.round(document.body.scrollTop + 
					((document.documentElement.clientHeight - $(element).getHeight()))/2)+'px';
				$(element).style.left = 
					Math.round(document.body.scrollLeft + 
					((document.documentElement.clientWidth - $(element).getWidth()))/2)+'px';
			}
		}
	}
	catch(err)
	{ return; }
}

function openWindow(url)
{
	var windowprops = "scrollbars,width=400,height=200";
	popup = window.open(url,'remote',windowprops);
}

function nav_class(id,name)
{
	id.className = name;
}

function show_modal()
{
	bd = document.getElementById('backdrop');
	m = document.getElementById('modal');
	frame = document.getElementById('pageframe');
	height = document.body.clientHeight;
	//height = frame.offsetHeight;
	
	if( height >= bd.offsetHeight )
		bd.style.height = height;
	
	bd.style.visibility = "visible";
	bd.style.display = "block";
	
	m.style.visibility = "visible";
	m.style.display="block";
}

function disable_anchor(e)
{
	if(e.title=='Please wait')
		return false;

	e.title='Please wait';
	e.innerHTML=e.title;
	return true;
}

function dim_screen(state)
{
	var dim = document.getElementById('dimmer');
	if(state==true)
	{
		dim.className='dim';
		dim.style.height = $('body').getHeight() + 'px';
		dim.style.width = ($('body').getWidth()-2) + 'px';
		dim.style.display='block';
	}
	else
	{
		dim.className='normal';
		dim.style.display='none';
	}
}


var Notifier = Class.create(
{
	_events:
		[	[window, 'scroll']
		, [window, 'resize']
		, [document, 'mousemove']
		, [document, 'keydown']
		, [document, 'click']
		],
	_timer: null,
	_idleTime: null,
 
	initialize: function(time) {
		this.time = time;
 
		this.initObservers();
		this.setTimer();
	},
 
	initObservers: function() {
		this._events.each(function(e) {
			Event.observe(e[0], e[1], this.onInterrupt.bind(this))
		}.bind(this))
	},
 
	onInterrupt: function() {
		document.fire('state:active', { idleTime: new Date() - this._idleTime });
		this.setTimer();
	},
 
	setTimer: function() {
		clearTimeout(this._timer);
		this._idleTime = new Date();
		this._timer = setTimeout(function() {
			document.fire('state:idle');
		}, this.time)
	}
})



// --- COMMON AJAX FUNCTIONALITY ---
function ajax_page(id,src)
{
	ajax_call(id,src,'get');
	Element.scrollTo($(id));
	return false;
}
function ajax_call(id,src,method)
{
	el = document.getElementById(id);
	new Ajax.Updater(id, src,
		{ method: method
		, asynchronous:true
		, evalScripts:true
		//, onLoading: function() { el.innerHTML = 'Loading...'; }
		}
	);
	return false;
}
function ajax_replace(id,src)
{
	el = document.getElementById(id);
	new Ajax.Request(src, 
		{ asynchronous: false
		, method: 'get'
		, onSuccess: function(transport) { Element.replace(id,transport.responseText); }
		});
	return false;
}

