
//Add the event handler for the document keyup event
if (document.addEventListener)
{
	//addEventListener is valid, non-IE browser
	document.addEventListener("keyup", findShortcutControl, true)
}
else
{
	//IE-browser
	document.attachEvent('onkeyup', findShortcutControl);
}

/*
-------------------------------------------------------------------------------
Author:		aleonard
Date:		2007.03.27
Description:	This function tests if a keyboard shortcut was attempted
				(checks for the Ctrl+Shift combination) then it loops
				through all of the form elements on the page, looking for
				either a shortcutkey attribute or a shortcutkeycode attribute
				on each element. When one is found it is compared to the
				key that was pressed with the Ctrl+Shift combination. If
				a match is found, then it will set the focus to that element
				and if the element is a button, it will invoke the click event.
-------------------------------------------------------------------------------
*/
function findShortcutControl(oEvent)
{
	var oElements = document.getElementsByTagName("body")[0].getElementsByTagName("*");
	
	if(oEvent != null)
	{
		if (oEvent.shiftKey & oEvent.ctrlKey)
		{
			var intShortcutKeyCode = 0;
			for(var i = 1; i < oElements.length; i++)
			{
				var intKeyPressed = parseInt(oEvent.keyCode);
				var oEL = oElements.item(i);
				var strKey = new String((oEL.getAttribute('shortcutkey') != null)?oEL.getAttribute('shortcutkey'):'');
				var intKeyCode = parseInt((oEL.getAttribute('shortcutkeycode') != null)?oEL.getAttribute('shortcutkeycode'):'0');
				if(strKey.length > 0)
				{
					intShortcutKeyCode = parseInt(strKey.charCodeAt(0));
				}
				else if(intKeyCode > 0)
				{
					intShortcutKeyCode = parseInt(intKeyCode);
				}
				
				if(intKeyPressed == intShortcutKeyCode)
				{
					if (oEL.disabled == false)
					{
						try
						{
							oEL.focus();
						}
						catch(e)
						{
							//let it fail quietly
						}
						
						switch (oEL.tagName.toLowerCase())
						{
							case 'input':
								if( oEL.type != 'submit' & oEL.type != 'button')
								{
									break;
								}
							case 'select':
								break;
							case 'a':
								oEL.style.border = '1px solid black';
							case 'button':
							default:
								oEL.click();
						}
					}
					return;
				}
			}
		}
	}
}
