
// enable/disable enter key
var enableEnterKey = false;

function toggleAllowEnterKey(argEnable) {
	enableEnterKey = argEnable;
}

// key press validation
function validateKeyPressNumeric(e, allowNegative, allowDecimal) {
	
	// get keycode
	var code;
	
	if (window.event) {
		code = window.event.keyCode;
		
	} else  {
		if (e.keyCode == 0 && typeof(e.which)!='undefined') {
			code = e.which;
		} else {
			return true;
		}
	}

	// define valid codes
	var arrValidCodes = new Array();
	arrValidCodes.push(48);
	arrValidCodes.push(49);
	arrValidCodes.push(50);
	arrValidCodes.push(51);
	arrValidCodes.push(52);
	arrValidCodes.push(53);
	arrValidCodes.push(54);
	arrValidCodes.push(55);
	arrValidCodes.push(56);
	arrValidCodes.push(57);
	arrValidCodes.push(13);

	if (allowNegative) { arrValidCodes.push(45); }
	if (allowDecimal) {arrValidCodes.push(46); }
	
	// find match
	for (i in arrValidCodes) {
		if (arrValidCodes[i] == code) {
			// found
			return true;
		}
	}
	
	// no match found
	return false;
}

function validateKeyPressEnter(e) {
	if (window.event) {
		
		if (window.event.keyCode == 13) {
			return enableEnterKey;
		}
		
	} else {
		
		if (e.keyCode == 0 && typeof(e.which) != 'undefined') {
			
			if (e.which == 13) {
				return enableEnterKey;
			}
			
		} else {
			return true;
		}
	}
}
