// numeric question
function initialiseNumericQuestion() {
	initialiseQuestion();
	numericElement = findElementByClassName(document.forms[0], "odinnumeric");
	numericElement.focus();
	if (odinbrowser && odinbrowser.isIE) {
		questionConstraints.questionForm.attachEvent("onsubmit", ValidateNumericAnswer);
	} else {
		questionConstraints.questionForm.onsubmit = ValidateNumericAnswer;
	}
}
function initialiseNumericFormElements() {
}
// all events that are called for a numeric question field
function OdinOnNumericKeyDown(event, sender) {
	if (window.event) {
		event = window.event;
	}
	var key = 0;
	if (event.keyCode) {
		key = event.keyCode;
	} else if (event.which) {
		key = event.which;
	}
	if (key == 13) {
		if (window.event) {
			event.returnValue = false;
			event.cancelBubble = true;
		} else {
			event.preventDefault();
			event.stopPropagation();
		}
		clickOK();
	} else {
		if (key < 47) {
			return true;
		}
    	if (key > 47 && !((key > 47 && key < 58) || (key > 95 && key < 106) || key == 109 || key == 110 || key == 189 || key == 190)) {
			if (window.event) {
				event.returnValue = false;
				event.cancelBubble = true;
			} else {
 				event.preventDefault();
				event.stopPropagation();
				event.cancelBubble = true;
			}
			return false;
		}
	}
}
function OdinOnNumericKeyPress(event, sender) {
	if (window.event) {
		event = window.event;
	}
	if (event.keyCode) {
		key = event.keyCode;
	} else if (event.which) {
		key = event.which;
	}
	if ((key > 33 && key < 45 && event.shiftkey == true) || key == 47 || key > 57) {
		if (window.event) {
			event.returnValue = false;
			event.cancelBubble = true;
		} else {
			event.preventDefault();
			event.stopPropagation();
			event.cancelBubble = true;

		}
		return false;
	}
}
function OdinOnNumericKeyUp(event, sender) {
	if (!window.event) {
		var str = sender.value;
		var patt = /\-{1}(\d*)\.{1}(\d*)/;
		var donepatt = /(^-?\d*\.\d*$)|(^-?\d*$)|(^-?\.\d\d*$)/;
		var result;
		if (!str.match(donepatt)) {
			result = str.match(patt);
			if (result != null) {
				sender.value = sender.value.replace(/[^\d]/gi,'');
				var newstr = result[1] + '.' + result[2] ;
				if (str[0] == '-') {
				  newstr = '-' + newstr;
				}
				sender.value = newstr;
			} else {
				if (sender.value.match(/[^\d]/gi)) {
					sender.value = sender.value.replace(/[^\d]/gi,'');
  				if (str[0] == '-') {
  					sender.value = '-' + sender.value;
  				}
				}
			}
		}
	}
}
function ValidateNumericAnswer(event) {
	// only validate if OK button is pressed
	if (clickedButton == "OK") {
		if (numericElement && numericElement.value) {
			if (numericElement.value.length > 0) {
				if (validateNumeric(numericElement.value) != true) {
					var p = new Array(1);
					p[0] = numericElement.value;
					reportValidationError(13, p);
// will have to be enabled, if reporting validation errors is in place
//					numericElement.focus();
//					return false;
				}
			} else {
				if (questionConstraints.allowNon != true) {
					reportValidationError(1, null);
// will have to be enabled, if reporting validation errors is in place
//					numericElement.focus();
//					return false;
				}
			}
		} else {
			reportValidationError(1, null);
// will have to be enabled, if reporting validation errors is in place
//			numericElement.focus();
//			return false;
		}
	}
	return true;
}
//-----------------------------------------------------------------------------
// A linked validation error text has been clicked
//-----------------------------------------------------------------------------
function validationErrorClick(error) {
}

