/******
 * Copyright: Bernardini & Schnyder GmbH
 * Author: Sebastian Haller
 * Date: 2006
 */

// allow only numbers to be entered in sone fields
function goodchars(e, chars)
{
	var key, keychar;

	if (window.event)
		key = window.event.keyCode;
	else if (e)
		key = e.which;
	else
		return true;

	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	chars = chars.toLowerCase();

	if (chars.indexOf(keychar) != -1)
		return true;

	// control keys
	if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
		return true;

	return false;
}

// new window
function newwindow(url, name, w, h, features) {
	if(screen.width)
	{
		var winl = (screen.width-w)/2;
		var wint = (screen.height-h)/2;
	}
	else
	{
		winl = 0;
		wint = 0;
	}
	if (winl < 0)
		winl = 0;
	if (wint < 0)
		wint = 0;
	//var settings = 'scrollbars=yes, resizable=yes, ';
	var settings = '';
	settings += 'height=' + h + ', ';
	settings += 'width=' + w + ', ';
	//settings += 'top=' + wint + ', ';
	//settings += 'left=' + winl + ', ';
	settings += features;
	win = window.open(url, name, settings);
	win.resizeTo(w, h);
	win.focus();
	// do not uncomment this. it is used in links containing
	// a href for users without javascript and an onclick="return newwindow(...);" for users with javascript
	// we do not want the href action to be excuted on success!
	return false;
}

// used to confirm a link before sending request (i.e. for delete links)
function confirmlink(text, obj)
{
	var is_confirmed = confirm(text);
	if (is_confirmed)
		obj.href += '&js_confirmed=1';

	return is_confirmed;
}

// changes content of a div
function setcontent(obj, content)
{
	document.getElementById(obj).innerHTML = content;
	return false;
}

// hide div
function hidediv(obj)
{
	o = document.getElementById(obj);
	o.style.display='none';
}

// show div
function showdiv(obj)
{
	o = document.getElementById(obj);
	o.style.display='block';
}
