KeyEvent = {};

KeyEvent.OnKeyEvent = function(evt, Call, sKeyCombination, arArguments){
	this._Ctrl = false;
	this._Alt = false;
	this._Shift = false;
	this._KeyMatch = true;
	this._Key = null;
	this._KeyCombination = sKeyCombination;
	
	if(window.event){                               //IE
		this._Key = window.event.keyCode;
		
		if(window.event.ctrlKey){
			this._Ctrl = true;
			this._Key = this._Key + 96;
		}
		if(window.event.shiftKey){
			this._Shift = true;
			if(this._Key > 90)
				this._Key = this._Key - 32;
		}
		if(window.event.altKey){
			this._Alt = true;
		}
	}else{                                               //Firefox
		this._Key = evt.which;
		
		if(evt.ctrlKey){
			this._Ctrl = true;
		}
		if(evt.shiftKey){
			this._Shift = true;
		}
		if(evt.altKey){
			this._Alt = true;
		}
	}
	
	/////////////////////////////////////////////////////////////////////////////////////////////////
	this.MatchKey = function(Key, sKeyCombination){
		var arKeyCombination = sKeyCombination.split("+");
		for(var z = 0; z < arKeyCombination.length; z++){
			switch(arKeyCombination[z]){
				
				case 'Ctrl':
					if(!this._Ctrl)
						this._KeyMatch = false
				break;
				
				case 'Shift':
					if(!this._Shift)
						this._KeyMatch = false
				break;
				
				case 'Alt':
					if(!this._Alt)
						this._KeyMatch = false
				break;
				
				default:
					if(String.fromCharCode(Key) != arKeyCombination[z])
						 this._KeyMatch = false;
			}
		}
		return this._KeyMatch;
	}
	/////////////////////////////////////////////////////////////////////////////////////////////////
	
	this.MatchKey(this._Key, this._KeyCombination);
	
	if(this._KeyMatch){
		//eval(Call + "(" + arArguments + ")");
		Call(arArguments); 
	}
}
