function HeyesKeyPressAuth() {
	this.enabled = false;
	this.count = 1;
	this.currentKey = '';
	this.pressed = false;
	this.keyCount = 1;
	this.seconds = 0;
	this.startTime;
}
HeyesKeyPressAuth.prototype.setCurrentKey = function(keyCode) {
	this.currentKey = String.fromCharCode(keyCode);
}
HeyesKeyPressAuth.prototype.OnKeyPress = function(e) {	
	if(this.pressed == false) {
		
		if(this.getCharCode(e) > 64 && this.getCharCode(e) < 91) {
			this.enabled = true;
		} else {
			this.enabled = false;
		}
		
		if(this.enabled == true) {
			this.seconds = 0;
			this.setSeconds();
			this.setCurrentKey(this.getCharCode(e));
			this.pressed = true;
			this.timer = setInterval("kpa.updateSeconds()",1000);
			this.seconds = 0;
			this.setKeysStatus();
		}
	}
}
HeyesKeyPressAuth.prototype.getCharCode = function(e) {
   e = e || window.event; 
   return e.keyCode;
}
HeyesKeyPressAuth.prototype.resetTimer = function() {
	window.clearInterval(this.timer);
}
HeyesKeyPressAuth.prototype.OnKeyUp = function(e) {
	if(this.enabled == true) {
		this.pressed = false;
		this.updateKey();
		this.resetTimer();
		this.setKeysStatus();
		this.updateDescription();
		this.enabled = false;
	}
}
HeyesKeyPressAuth.prototype.setKeysStatus = function() {
	var keysHeld = document.getElementById('keyDisplay');
	if(this.pressed == true) {
		keysHeld.innerHTML = 'Key held down';
		this.keyCount++;
	} else {
		keysHeld.innerHTML = 'No keys held down';
	}
}
HeyesKeyPressAuth.prototype.hideSequence = function() {
	var sequenceLayerElement = document.getElementById('sequenceLayer');
	sequenceLayerElement.style.display = 'none';
}
HeyesKeyPressAuth.prototype.updateKey = function() {
	var sequenceKey = document.getElementById('sequence');
	sequenceKey.value += this.currentKey + this.seconds + '';
}
HeyesKeyPressAuth.prototype.updateDescription = function() {
	this.count++;
	var descElement = document.getElementById('description');
	switch(this.count) {
		case 1:
			word = "first";
		break;
		case 2:
			word = "second";
		break;
		case 3:
			word = "third";
		break;
		case 4:
			word = "forth";
		break;
		case 5:
			word = "fifth";
		break;

	}
	if(this.count == 6) {
		this.hideSequence();
		descElement.innerHTML = 'You cannot hold press anymore keys, please click login to perform authorisation. ( <a href="heyes_keypress_test.php">Cancel</a> )';
	} else {
		descElement.innerHTML = 'Please hold your '+word+' key for the required time.';
	}
}
HeyesKeyPressAuth.prototype.updateSeconds = function() {
	if(this.pressed == false) {
		this.resetTimer();
	} else {
		this.seconds++;
		this.setSeconds();	
	}
}
HeyesKeyPressAuth.prototype.setSeconds = function() {
	secsElement = document.getElementById('secondsDisplay');
	var msg = " seconds";
	secsElement.innerHTML = this.seconds + msg;	
}
var kpa = new HeyesKeyPressAuth;