function initKeyEvents()
{
	// Mozilla Firefox e Google Chrome
    if (document.addEventListener)
    {
       document.addEventListener("keydown",keydown,false);
       //document.addEventListener("keypress",keypress,false);
       //document.addEventListener("keyup",keyup,false);
       //document.addEventListener("textInput",textinput,false);
    }
	// IE
    else if (document.attachEvent)
    {
       document.attachEvent("onkeydown", keydown);
       //document.attachEvent("onkeypress", keypress);
       //document.attachEvent("onkeyup", keyup);
       //document.attachEvent("ontextInput", textinput);
    }
    else
    {
       document.onkeydown = keydown;
       //document.onkeypress= keypress;
       //document.onkeyup= keyup;
       //document.ontextinput= textinput;   // probably doesn't work
    }
}

function keyval(n)
{
    if (n == null) return 'undefined';
    var s= '' + n;
    if (n >= 32 && n < 127) s+= ' (' + String.fromCharCode(n) + ')';
    while (s.length < 9) s+= ' ';
    return s;
}

function suppressdefault(e,flag)
{
   if (flag)
   {
       if (e.preventDefault) e.preventDefault();
       if (e.stopPropagation) e.stopPropagation();
   }
   return !flag;
}

function keypress(e)
{
   if (!e) e= event;
   //return suppressdefault(e,document.testform.keypress.checked);
   if (GB_CURRENT) {
	if (e.keyCode == 39) GB_CURRENT.switchNext();
	if (e.keyCode == 37) GB_CURRENT.switchPrev();
   }
}
function keydown(e)
{
   if (!e) e= event;   
   if (GB_CURRENT) {
	if (e.keyCode == 39) {
		GB_CURRENT.switchNext();
		return false;
	}
	if (e.keyCode == 37) {
		GB_CURRENT.switchPrev();
		return false;
	}
   }
}
