/***************************************************************************
 *                                  app.js
 *                            -------------------
 *   begin                : Thursday, Feb 19, 2009
 *   copyright            : (C) 2009 Michael Fritscher
 *   email                : fritscher@tunipages.de
 *
 *   $Id: app.js,v 1.2 2009/03/05 17:09:05 mfritscher Exp $
 *
 ***************************************************************************/

var app_div_lock = null;

function app_start()
{
	app_div_lock = document.createElement('div')
	app_div_lock.id = 'app_lock';
	with( app_div_lock.style )
	{
		display = 'none';
		position = 'absolute';
		left = 0;
		top = 0;
		width = '100%';
		height = '100%';
		zIndex = 250;
	}
	document.body.appendChild(app_div_lock);
}

function app_close()
{
}

function app_lockUI(f)
{
	var els;
	
	if ( f )
	{
		els = document.getElementsByTagName('select');
		for(i=0; i<els.length; i++) els[i].style.visibility = 'hidden';
		app_div_lock.style.display = 'block';
	}
	else
	{
		els = document.getElementsByTagName('select');
		for(i=0; i<els.length; i++) els[i].style.visibility = 'visible';
		app_div_lock.style.display = 'none';
	}
}

function app_modal(ele)
{
	if ( typeof(ele) == 'string' ) ele = $(ele);
	with(ele.style)
	{
		position = 'relative';
		zIndex = 255;
		background = 'white';
		border='1px solid black';
	}
	rt = ele.getClientRects()[0];
	shadow = document.createElement('div')
	with( shadow.style )
	{
		display = 'block';
		position = 'absolute';
		left = (rt.left - 6) + 'px';
		top = (rt.top - 6) + 'px';
		width = (rt.right - rt.left + 12) + 'px';
		height = (rt.bottom - rt.top + 12) + 'px';
		zIndex = 254;
		opacity = 0.66;
		background = '#cccccc';
	}
	document.body.appendChild(shadow);
	app_lockUI(true);
}

function $(id)
{
	return document.getElementById(id);
}

function $on(ele, event, handler)
{
	if ( typeof(ele) == 'string' ) ele = $(ele);
	if ( window.attachEvent )
	{
		ele.attachEvent('on' + event, handler);
	}
	else
	{
		ele.addEventListener(event, handler, false);
	}
}

function $classAdd(ele, cls)
{
	if ( typeof(ele) == 'string' ) ele = $(ele);
	if ( null == ele.classArray ) ele.classArray = ele.className.split(' ');
	ele.classArray[ele.classArray.length] = cls;
	ele.className = ele.classArray.join(' ');
}

function $classRemove(ele, cls)
{
	if ( typeof(ele) == 'string' ) ele = $(ele);
	if ( null == ele.classArray ) ele.classArray = ele.className.split(' ');
	for(var i=0; i<ele.classArray.length; i++)
	{
		if ( ele.classArray[i] == cls ) delete ele.classArray[i];
	}
	ele.className = ele.classArray.join(' ');
}

$on(window, 'load', app_start);
$on(window, 'unload', app_close);
