
/*************************************************************************
*
* ADOBE CONFIDENTIAL
* ___________________
*
*  Copyright 2008 Adobe Systems Incorporated
*  All Rights Reserved.
*
* NOTICE:  All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any.  The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and may be covered by U.S. and Foreign Patents,
* patents in process, and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
*
* $DateTime: 2008/04/10 13:35:00 $
*
* Adobe Output Module 2.0
*
* MediaGallery Originally Written by Quality Process Incorporated, Enhanced by
* Adobe System China. Contact Sheet written by Adobe System China.
* 
*
**************************************************************************/

AOM.Keyboard = function() {};

AOM.Keyboard.keyIsAlt = function(event) {
	return (event.keyName == 'Alt') ;
}


AOM.Keyboard.keyIsTab = function(event) {
	return event.keyName == 'Tab';
}

AOM.Keyboard.keyIsDecimal = function(event) {
	var cdecimal = AOM.CS.Locale.getDecimal();
	if (cdecimal == AOM.CS.Locale.DECIMAL_AS_COMMA) {
		return (event.keyName == 'Comma' && !AOM.Keyboard.keyHasModifier(event));
	} else if (cdecimal == AOM.CS.Locale.DECIMAL_AS_DOT) {
		return (event.keyName == 'Decimal' || (event.keyName == 'Period' && !AOM.Keyboard.keyHasModifier(event)));
	} else {
		throw new Error("AOM.CS.Locale.toLocaleString(), decimal must be dot or comma.");
	}
}

AOM.Keyboard.keyIsDelete = function(event) {
	return (event.keyName == 'Backspace') && !(event.ctrlKey);
}

AOM.Keyboard.keyHasModifier = function(event) {
	return (event.shiftKey || event.ctrlKey || event.altKey || event.metaKey);
}

AOM.Keyboard.keyIsNumeric = function(event) {
	return (event.keyName >= '0') 
				&& (event.keyName <= '9')  
				&& !AOM.Keyboard.keyHasModifier(event);
}


AOM.Keyboard.KeyIsLRArrow = function(event) {
	return ((event.keyName == 'Left') || (event.keyName == 'Right')) 
				&& !(event.altKey || event.metaKey);
}

AOM.Keyboard.keyIsMinus = function(event) {
	return (event.keyName == 'Minus') ;
}

AOM.Keyboard.keyIsPlus = function(event) {
	return ((event.keyName == 'Plus')|| (event.keyName == 'Equal' && AOM.Keyboard.keyHasModifier(event)) );
}

AOM.Keyboard.keyIsCopy = function(event) {
	return ( (event.keyName == 'C') && (event.ctrlKey || event.metaKey) );
}

AOM.Keyboard.keyIsPaste = function(event) {
	return ( (event.keyName == 'V') && (event.ctrlKey || event.metaKey) );
}

AOM.Keyboard.keyIsEnter = function(event) {
	return (event.keyName == 'Enter') ;
}

//only number
AOM.Keyboard.nonNegativeIntegerEditText = function(event) {
	/*
	try {	
		var keyIsOk = AOM.Keyboard.keyIsNumeric(event) 
			|| AOM.Keyboard.keyIsDelete(event)
			|| AOM.Keyboard.KeyIsLRArrow(event) 
			|| AOM.Keyboard.keyIsTab(event)
			 || AOM.Keyboard.keyIsEnter(event)
			|| AOM.Keyboard.keyIsCopy(event)
			|| AOM.Keyboard.keyIsPaste(event);
								
		if (keyIsOk) {
			//
		} else {
			event.preventDefault();
		}
	} catch(e) {
		AOM.CS.Log.writeError("AOM.Keyboard.rowAndColumnEditKeyboardHandler() throw an exception:" + e);
	}
	*/
}

AOM.Keyboard.nonNegativeRealEditText = function(event) {
	/*
	try {
		var keyIsOk = AOM.Keyboard.keyIsNumeric(event) 
			|| AOM.Keyboard.keyIsDelete(event) 
			|| AOM.Keyboard.keyIsDecimal(event)
			|| AOM.Keyboard.KeyIsLRArrow(event) 
			|| AOM.Keyboard.keyIsTab(event) 
			|| AOM.Keyboard.keyIsEnter(event)
			|| AOM.Keyboard.keyIsCopy(event)
			|| AOM.Keyboard.keyIsPaste(event);
		if (keyIsOk) {
			var text = this.text;
			if (AOM.CS.Locale.existDecimal(text) && AOM.Keyboard.keyIsDecimal(event)) {
				event.preventDefault();
			}
		} else {
			event.preventDefault();
		}
	} catch(e) {
		AOM.CS.Log.writeError("AOM.Keyboard.numericaEditKeyboardHandler() throw an exception:" + e);
	}
	*/
}

AOM.Keyboard.integerEditText = function(event) {
	/*
	try {
		var keyIsOk = AOM.Keyboard.keyIsNumeric(event) 
			|| AOM.Keyboard.keyIsDelete(event) 
			|| AOM.Keyboard.KeyIsLRArrow(event) 
			|| AOM.Keyboard.keyIsTab(event)
			|| AOM.Keyboard.keyIsMinus(event)
			|| AOM.Keyboard.keyIsPlus(event)
			|| AOM.Keyboard.keyIsEnter(event)
			|| AOM.Keyboard.keyIsCopy(event)
			|| AOM.Keyboard.keyIsPaste(event);
								
		if (keyIsOk) {
			var text = this.text;
			if (text.length >= 1 
				&& (AOM.Keyboard.keyIsPlus(event) || AOM.Keyboard.keyIsMinus(event))) {
				event.preventDefault();
			}
		} else {
			event.preventDefault();
		}
	} catch(e) {
		AOM.CS.Log.writeError("AOM.Keyboard.numericaEditKeyboardHandler() throw an exception:" + e);
	}
	*/
}
