/*
	2/8/06	SGH	 Created - cross browser implementation IE and FireFox
*/
// ============= DisableKeys.js =============// 

// Keys to be disabled can be added to the lists below. 
// The number is the key code for the particular key 
// and the text is the description displayed in the 
// status window if the key [combination] is pressed. 

var ie=document.all; 
var w3c=document.getElementById&&!document.all; 
var handlerEnabled = false
var badKeys = new Object(); 
badKeys.single = new Object(); 
badKeys.single['8'] = 'Backspace outside text or textarea fields'; 
badKeys.single['13'] = 'Enter outside of textarea fields'; 
//badKeys.single['116'] = 'F5 (Refresh)'; 
//badKeys.single['122'] = 'F11 (Full Screen)'; 

badKeys.alt = new Object(); 
//badKeys.alt['37'] = 'Alt+Left Cursor'; 
//badKeys.alt['39'] = 'Alt+Right Cursor'; 

badKeys.ctrl = new Object(); 
//badKeys.ctrl['78'] = 'Ctrl+N'; 
//badKeys.ctrl['79'] = 'Ctrl+O'; 

function checkKeyCode(type, code) 
{ 
	if (badKeys[type][code]) 
	{ 
		return true; 
	} 
	else 
	{ 
		return false; 
	} 
} 
function getKeyText(type, code) 
{ 
	return badKeys[type][code]; 
} 

function keyEventHandler(evt) 
{ 
	this.target = evt.target || evt.srcElement; 
	this.keyCode = evt.keyCode || evt.which; 
	var targtype = this.target.type; 
	if (w3c) 
	{ 
		if (document.layers) 
		{ 
			this.altKey = ((evt.modifiers & Event.ALT_MASK) > 0); 
			this.ctrlKey = ((evt.modifiers & Event.CONTROL_MASK) > 0); 
			this.shiftKey = ((evt.modifiers & Event.SHIFT_MASK) > 0); 
		} 
		else 
		{ 
			this.altKey = evt.altKey; 
			this.ctrlKey = evt.ctrlKey; 
		} 
	} 
	else 
	{ 
		// Internet Explorer 
		this.altKey = evt.altKey; 
		this.ctrlKey = evt.ctrlKey; 
	} 
	// Find out if we need to disable this key combination 
	var badKeyType = "single"; 
	if (this.ctrlKey) 
	{ 
		badKeyType = "ctrl"; 
	} 
	else 
		if (this.altKey) 
		{ 
			badKeyType = "alt"; 
		} 
	if (checkKeyCode(badKeyType, this.keyCode)) 
	{ 
		return cancelKey(evt, this.keyCode, this.target, getKeyText(badKeyType, this.keyCode)); 
	} 
} 

function cancelKey(evt, keyCode, target, keyText) 
{ 
	var clickFired = false
	if (backSpaceInText(target, keyCode) || enterInButtonOrLink(target, keyCode) ) 
	{ 
		// Don't want to disable Backspace or Enter in text fields 
		window.status = ""; 
		return true; 
	} 
	//If custom attribute exist on contatiner node, then use that to fire event
	clickFired =  fireContainerButton( target )
	if (evt.preventDefault) 
	{ 
		evt.preventDefault(); 
		evt.stopPropagation(); 
	} 
	else 
	{ 
		evt.keyCode = 0; 
		evt.returnValue = false; 
	} 
	if ( ! clickFired )
	{
		window.status = keyText+" is disabled"; 
	}
	return false; 
} 
function fireContainerButton( target )
{
	var tempObj = target
	var hasParent = ( tempObj.parentNode != null )
	var foundMyButtonAttribute = false
	var att 
	var button
	var sID
	var clickFired  = false
	while( hasParent && ! foundMyButtonAttribute )
	{
		att = tempObj.attributes['SubmitDiv']
		if(att!=null) 
		{
			foundMyButtonAttribute = true
			if (att.value)
				sID = att.value
			else
				sID = att
			//ie does not handle getElementByID with div well
			if (document.all)
			{
				button = document.all[sID]
			}
			else
			{
				if ( document.getElementById )
				{
					//Firefox does handle this
					button = document.getElementById(sID)
				}
			}
			if ( button != null )
			{
				if ( button.childNodes != null  )
				{
					if ( button.childNodes[0] != null )
					{
						try
						{
							var submitButton
							if ( button.childNodes[0].length >  1 )
							{
								//Firefox treats whitespace as a node, so iterate until we find a node that supports click
								for( i = 0; i < button.childNodes[0].length; i ++ ) 
								{
									try
									{
										if(  button.childNodes[i].type ==  "image" ||  button.childNodes[i].type == "submit" || button.childNodes[i].tagName == "A" )
										{
											submitButton = button.childNodes[i]
											submitButton.click()
											clickFired = true
											break;
										}
									}
									catch( ex )
									{
										//alert('Error: ' + ex.message )
									}
								}
							}
							else
							{
								submitButton = button.childNodes[0]
								submitButton.click()
								clickFired = true
							}
						}
						catch(ex)
						{
							//alert('Error ' + ex.message)
						}
					}
				}
			}
		}
		else
		{
			tempObj = tempObj.parentNode
			hasParent =  ( tempObj.parentNode != null )
		}
	}
	return clickFired
}
function backSpaceInText( target, keyCode )
{
	return ( keyCode==8 && ( target.type == "text" || target.type == "textarea" )  )
}
function enterInButtonOrLink( target, keyCode )
{
	//return false;
	return ( keyCode==13 && ( target.type == "image" ||  target.type == "submit" || target.tagName == "A" )  )
}
// ============= DisableKeys.js =============// 
// ============= PageSetup.inc =============// 

function addEvent(obj, evType, fn, useCapture)
 { 
	// General function for adding an event listener 
	if (obj.addEventListener) 
	{ 
		obj.addEventListener(evType, fn, useCapture); 
		return true; 
	} 
	else 
		if (obj.attachEvent) 
		{ 
			var r = obj.attachEvent("on" + evType, fn); 
			return r; 
		} 
		else 
		{ 
			//alert(evType+" handler could not be attached"); 
		} 
} 
function addKeyEvent() { 
	// Specific function for this particular browser 
	var e = (document.addEventListener) ? 'keypress' : 'keydown'; 
	//ensure that this happens a maximum of one times
	if ( ! handlerEnabled )
	{
		addEvent(document,e,keyEventHandler,false); 
		handlerEnabled = true
	}
	//alert("Added Key event")
} 
//To disable the right mouse button 
//document.oncontextmenu=new Function("return false"); 
// ============= PageSetup.inc =============// 

