// ===============================================================================================
// Javascript Function Library
//
// Functions:
//   - checkNull: check if field value is not empty
//   - checkChoices: check how many checkbox values are pressed
//   - checkNumeric: check if the field value is numeric
//   - checkEmail: check if the field value is a email pattern
//   - checkExpression: check if the field value matches the regular expression
//   - checkLength: check if field value is not to long or not to short
//   - checkPostalCode: check field for postal code (dutch style: 1234 AA)
//   - checkDate: check if the date is a valid date format
//   - compareDate: compare the date fields with the operator given
//   - compareFields: compare the fields with the operator given
//   - compareValue: compare field and value with the operator given
//   - disableEnableField: switch field between disabled and enabled state
//   - clearField: clear the field value
// ===============================================================================================

// -- $_ ----------------------------------------------------------------------------------
// get field value
// objField: All dom objects
// -----------------------------------------------------------------------------------------------
function $_(objField) {
	return document.getElementById(objField);
}

// -- $_v ----------------------------------------------------------------------------------
// get field value
// objField: SELECT, INPUT-text, INPUT-radio, INPUT-checkbox, INPUT-file or TEXTAREA elements
// -----------------------------------------------------------------------------------------------
function $_v(objField) {
	switch ($_(objField).tagName.toUpperCase()) {
		case "SELECT":
			return $_(objField).options[$_(objField).selectedIndex].value;
			break;
		case "INPUT":
			switch ($_(objField).type.toUpperCase()) {
				case "FILE":
				case "TEXT":
					return $_(objField).value;
					break;
				case "CHECKBOX":
					return $_(objField).checked;
					break
				case "RADIO":
					return $_(objField).value;
					break;
				default:
					break;
			}
			break;
		case "TEXTAREA":
			return $_(objField).value;
			break;
		default:
			break;
	}
}

// -- checkNull ----------------------------------------------------------------------------------
// check if field value is not empty
// objField: SELECT, INPUT-text, INPUT-radio, INPUT-checkbox, INPUT-file or TEXTAREA elements
// strWarning: textual warning when function returns false (optional)
// -----------------------------------------------------------------------------------------------
function checkNull(objField, strWarning) {
	switch ($_(objField).tagName.toUpperCase()) {
		case "SELECT":
			if (($_(objField).selectedIndex == -1) || ($_(objField).options[$_(objField).selectedIndex].value == '')) {
				if (strWarning) {
					alert(strWarning);
					$_(objField).focus();
				}
				return false;
			}
			break;
		case "INPUT":
			switch ($_(objField).type.toUpperCase()) {
				case "FILE":
				case "TEXT":
					if ($_(objField).value == '') {
						if (strWarning) {
							alert(strWarning);
							$_(objField).focus();
						}
						return false;
					}
					break;
				case "CHECKBOX":
				case "RADIO":
					objArray = document.getElementsByName($_(objField).name);
					for(intCounter = 0; intCounter < objArray.length; intCounter++) {
						if (objArray[intCounter].checked) {
							return true;
						}
					}

					if (strWarning) {
						alert(strWarning);
						$_(objField).focus();
					}
					return false;

					break;
				default:
					break;
			}
			break;
		case "TEXTAREA":
			if ($_(objField).value == '') {
				if (strWarning) {
					alert(strWarning);
					$_(objField).focus();
				}
				return false;
			}
			break;
		default:
			break;
	}

	return true;
}

// -- checkChoices -------------------------------------------------------------------------------
// check how many checkbox values are pressed
// objField: INPUT-checkbox element. The elements must form an array with the same name (use [])
// intMaxChoices: Maximum number of selected choices (Use 0 to ignore)
// intMinChoices: Minimum number of selected choices (Use 0 to ignore)
// strWarning: textual warning when function returns false (optional)
// -----------------------------------------------------------------------------------------------
function checkChoices(objField, intMaxChoices, intMinChoices, strWarning) {
	intMaxChoices = intMaxChoices || 0;
	intMinChoices = intMinChoices || 0;

	if (($_(objField).tagName.toUpperCase() == "INPUT") && ($_(objField).type.toUpperCase() == "CHECKBOX")) {
		objArray = document.getElementsByName($_(objField).name);

		var intChecked = 0;

		for (intCounter = 0; intCounter < objArray.length; intCounter++) {
			if (objArray[intCounter].checked) {
				intChecked = intChecked + 1;
			}
		}

		if (intMaxChoices > 0) {
			if (intChecked > intMaxChoices) {
				if (strWarning) {
					alert(strWarning);
					$_(objField).focus();
				}
				return false;
			}
		}

		if (intMinChoices > 0) {
			if (intChecked < intMinChoices) {
				if (strWarning) {
					alert(strWarning);
					$_(objField).focus();
				}
				return false;
			}
		}
	}

	return true;
}

// -- checkNumeric -------------------------------------------------------------------------------
// check if the field value is numeric
// objField: INPUT-text or TEXTAREA elements
// strWarning: textual warning when function returns false (optional)
// -----------------------------------------------------------------------------------------------
function checkNumeric(objField, strWarning) {
	if ((($_(objField).tagName.toUpperCase() == "INPUT") && ($_(objField).type.toUpperCase() == "TEXT")) || ($_(objField).tagName.toUpperCase() == "TEXTAREA")) {
		regNumeric = /^(\d+)$/;

		if (!regNumeric.test($_(objField).value)) {
			if (strWarning) {
				alert(strWarning);
				$_(objField).focus();
			}
			return false;
		}
	}

	return true;
}

// -- checkExpression ----------------------------------------------------------------------------
// check if the field value matches the regular expression
// objField: INPUT-text or TEXTAREA elements
// regExpression: The regular expression to check
// strWarning: textual warning when function returns false (optional)
// -----------------------------------------------------------------------------------------------
function checkEmail(objField, strWarning) {
	if ((($_(objField).tagName.toUpperCase() == "INPUT") && ($_(objField).type.toUpperCase() == "TEXT")) || ($_(objField).tagName.toUpperCase() == "TEXTAREA")) {
		var strEmailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]{2,4}$/;

		if (!strEmailPattern.test($_(objField).value)) {
			if (strWarning) {
				alert(strWarning);
				$_(objField).focus();
			}
			return false;
		}
	}

	return true;
}

// -- checkExpression ----------------------------------------------------------------------------
// check if the field value matches the regular expression
// objField: INPUT-text or TEXTAREA elements
// regExpression: The regular expression to check
// strWarning: textual warning when function returns false (optional)
// -----------------------------------------------------------------------------------------------
function checkExpression(objField, regExpression, strWarning) {
	if ((($_(objField).tagName.toUpperCase() == "INPUT") && ($_(objField).type.toUpperCase() == "TEXT")) || ($_(objField).tagName.toUpperCase() == "TEXTAREA")) {
		if (!regExpression.test($_(objField).value)) {
			if (strWarning) {
				alert(strWarning);
				$_(objField).focus();
			}
			return false;
		}
	}

	return true;
}

// -- checkLength --------------------------------------------------------------------------------
// check if field value is not to long or not to short
// objField: INPUT-text or TEXTAREA elements
// intMaxLength: Maximum length for the field (Use 0 to ignore)
// intMinLength: Minimum length for the field (Use 0 to ignore)
// strWarning: textual warning when function returns false (optional)
// -----------------------------------------------------------------------------------------------
function checkLength(objField, intMaxLength, intMinLength, strWarning) {
	intMaxLength = intMaxLength || 0;
	intMinLength = intMinLength || 0;

	if ((($_(objField).tagName.toUpperCase() == "INPUT") && ($_(objField).type.toUpperCase() == "TEXT")) || ($_(objField).tagName.toUpperCase() == "TEXTAREA")) {
		if (intMaxLength > 0) {
			if ($_(objField).value.length > intMaxLength) {
				if (strWarning) {
					alert(strWarning);
					$_(objField).focus();
				}
				return false;
			}
		}

		if (intMinLength > 0) {
			if ($_(objField).value.length < intMinLength) {
				if (strWarning) {
					alert(strWarning);
					$_(objField).focus();
				}
				return false;
			}
		}
	}

	return true;
}

// -- checkPostalCode ----------------------------------------------------------------------------
// check field for postal code (dutch style: 1234 AA)
// objField: INPUT-text or TEXTAREA elements
// strWarning: textual warning when function returns false (optional)
// -----------------------------------------------------------------------------------------------
function checkPostalCode(objField, strWarning) {
	if ((($_(objField).tagName.toUpperCase() == "INPUT") && ($_(objField).type.toUpperCase() == "TEXT")) || ($_(objField).tagName.toUpperCase() == "TEXTAREA")) {
		regPostalCode1 = /^\d{4}[a-zA-Z]{2}$/; // 1234az or 1234AZ
		regPostalCode2 = /^\d{4} [a-zA-Z]{2}$/; // 1234 az or 1234 AZ

		if ((!regPostalCode1.test($_(objField).value)) && (!regPostalCode2.test($_(objField).value))) {
			if (strWarning) {
				alert(strWarning);
				$_(objField).focus();
			}
			return false;
		}

		// convert aa to AA
		$_(objField).value = $_(objField).value.toUpperCase();

		// convert from 1234AA to 1234 AA
		if (regPostalCode1.test($_(objField).value)) {
			var arrMatches = $_(objField).value.match(/^(\d{4})([a-zA-Z]{2})?$/);
			$_(objField).value = arrMatches[1] + ' ' + arrMatches[2];
		}
	}

	return true;
}

// -- checkDate ----------------------------------------------------------------------------------
// check if the date is a valid date format
// objField: INPUT-text or TEXTAREA elements
// strWarning: textual warning when function returns false (optional)
// -----------------------------------------------------------------------------------------------
function checkDate(objField, strWarning) {
	if ((($_(objField).tagName.toUpperCase() == "INPUT") && ($_(objField).type.toUpperCase() == "TEXT")) || ($_(objField).tagName.toUpperCase() == "TEXTAREA")) {
		regDate1 = /^\d{2}\-\d{2}\-\d{4}$/;
		regDate2 = /^\d{8}$/;
		regDate3 = /^\d{2}.\d{2}.\d{4}$/;

		// check for a valid date format
		if ((!regDate1.test($_(objField).value)) && (!regDate2.test($_(objField).value)) && (!regDate3.test($_(objField).value))) {
			if (strWarning) {
				alert(strWarning);
				$_(objField).focus();
			}
			return false;
		}

		// convert from 12345678 to 12-34-5678
		if (regDate2.test($_(objField).value)) {
			var arrMatches = $_(objField).value.match(/^(\d{2})(\d{2})(\d{4})?$/);
			$_(objField).value = arrMatches[1] + '-' + arrMatches[2] + '-' + arrMatches[3];
		}

		// convert from 12.34.5678 to 12-34-5678
		if (regDate3.test($_(objField).value)) {
			var arrMatches = $_(objField).value.match(/^(\d{2}).(\d{2}).(\d{4})?$/);
			$_(objField).value = arrMatches[1] + '-' + arrMatches[2] + '-' + arrMatches[3];
		}

		// check if the date can exist
		var arrMatches = $_(objField).value.match(/^(\d{2})-(\d{2})-(\d{4})?$/);

		var blnValidDate = true;

		var intDay = arrMatches[1];
		var intMonth = arrMatches[2];
		var intYear = arrMatches[3];

		if (intMonth < 1 || intMonth > 12) blnValidDate = false;
		if (intDay < 1 || intDay > 31) blnValidDate = false;

		if (intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) {
			if (intDay == 31) blnValidDate = false;
		}
		if (intMonth == 2) {
			if (intDay > 29) blnValidDate = false;
	 		if (intDay == 29){
	  			if ((intYear / 4)!= parseInt(intYear / 4)) blnValidDate = false;
	  		} else {
	  			if ((intYear / 100) == parseInt(intYear / 100)) {
	  				if ((intYear / 400)!= parseInt(intYear / 400)) blnValidDate = false;
	  			}
	  		}
	  	}

  		if (!blnValidDate) {
			if (strWarning) {
				alert(strWarning);
				$_(objField).focus();
			}
			return false;
		}
	}

	return true;
}

// -- compareDate --------------------------------------------------------------------------------
// compare the date fields with the operator given
// The date must be checked before use and must be in the dd-mm-yyyy format
// objField1: INPUT-text or TEXTAREA elements or "now" to use current date
// objField2: INPUT-text or TEXTAREA elements or "now" to use current date
// strWarning: textual warning when function returns false (optional)
// strOperator: Operate to use for the compare (<, >, <=, >=, ==, !=)
// -----------------------------------------------------------------------------------------------
function compareDate(objField1, objField2, strOperator, strWarning) {
	regDate1 = /^\d{2}\-\d{2}\-\d{4}$/;

	if ((objField1.getYear) || (objField1 == "now") || (regDate1.test(objField1)) || (($_(objField1).tagName.toUpperCase() == "INPUT") && ($_(objField1).type.toUpperCase() == "TEXT")) || ($_(objField1).tagName.toUpperCase() == "TEXTAREA")) {
		if ((objField2.getYear) || (objField2 == "now") || (regDate1.test(objField2)) || (($_(objField2).tagName.toUpperCase() == "INPUT") && ($_(objField2).type.toUpperCase() == "TEXT")) || ($_(objField2).tagName.toUpperCase() == "TEXTAREA")) {
			// create date object for field 1
			if (objField1 == "now") {
				var datDate1 = new Date();
				datDate1.setHours(0);
				datDate1.setMinutes(0);
				datDate1.setSeconds(0);
			} else if (objField1.getYear) {
				var datDate1 = objField1;
			} else if (regDate1.test(objField1)) {
				var arrMatches = objField1.match(/^(\d{2})-(\d{2})-(\d{4})?$/);
				var datDate1 = new Date();
				datDate1.setDate(arrMatches[1]);
				datDate1.setMonth(arrMatches[2] - 1);
				datDate1.setYear(arrMatches[3]);
				datDate1.setHours(0);
				datDate1.setMinutes(0);
				datDate1.setSeconds(0);
			} else {
				var arrMatches = $_(objField1).value.match(/^(\d{2})-(\d{2})-(\d{4})?$/);
				var datDate1 = new Date();
				datDate1.setDate(arrMatches[1]);
				datDate1.setMonth(arrMatches[2] - 1);
				datDate1.setYear(arrMatches[3]);
				datDate1.setHours(0);
				datDate1.setMinutes(0);
				datDate1.setSeconds(0);
			}

			// create date object for field 2
			if (objField2 == "now") {
				var datDate2 = new Date();
				datDate2.setHours(0);
				datDate2.setMinutes(0);
				datDate2.setSeconds(0);
			} else if (objField2.getYear) {
				var datDate2 = objField2;
			} else if (regDate1.test(objField2)) {
				var arrMatches = objField2.match(/^(\d{2})-(\d{2})-(\d{4})?$/);
				var datDate2 = new Date();
				datDate2.setDate(arrMatches[1]);
				datDate2.setMonth(arrMatches[2] - 1);
				datDate2.setYear(arrMatches[3]);
				datDate2.setHours(0);
				datDate2.setMinutes(0);
				datDate2.setSeconds(0);
			} else {
				var arrMatches = $_(objField2).value.match(/^(\d{2})-(\d{2})-(\d{4})?$/);
				var datDate2 = new Date();
				datDate2.setDate(arrMatches[1]);
				datDate2.setMonth(arrMatches[2] - 1);
				datDate2.setYear(arrMatches[3]);
				datDate2.setHours(0);
				datDate2.setMinutes(0);
				datDate2.setSeconds(0);
			}

			switch (strOperator) {
				case "<":
					var blnValid = (datDate1.getTime() < datDate2.getTime());
					break;
				case ">":
					var blnValid = (datDate1.getTime() > datDate2.getTime());
					break;
				case "<=":
					var blnValid = (datDate1.getTime() <= datDate2.getTime());
					break;
				case ">=":
					var blnValid = (datDate1.getTime() >= datDate2.getTime());
					break;
				case "==":
					var blnValid = (datDate1.getTime() == datDate2.getTime());
					break;
				case "!=":
					var blnValid = (datDate1.getTime() != datDate2.getTime());
					break;
				default:
					return false;
					break;
			}

			if (!blnValid) {
				if (strWarning) {
					alert(strWarning);
					if (objField1 != "now") {
						$_(objField1).focus();
					} else if (objField2 != "now") {
						$_(objField2).focus();
					}
				}
				return false;
			}
		}
	}

	return true;
}

// -- compareFields ------------------------------------------------------------------------------
// compare the fields with the operator given
// objField1: SELECT (single), INPUT-text or TEXTAREA elements
// objField2: SELECT (single), INPUT-text or TEXTAREA elements
// strOperator: Operate to use for the compare (<, >, <=, >=, ==)
// strWarning: textual warning when function returns false (optional)
// -----------------------------------------------------------------------------------------------
function compareFields(objField1, objField2, strOperator, strWarning) {
	switch ($_(objField1).tagName.toUpperCase()) {
		case "SELECT":
			if (($_(objField).size) && ($_(objField).size > 1)) {
				return true;
			} else {
				var varValue1 = $_(objField1).options[$_(objField1).selectedIndex].value;
			}
			break;
		case "INPUT":
			if ($_(objField1).type.toUpperCase() == "TEXT") {
				var varValue1 = $_(objField1).value;
			} else {
				return true;
			}
			break;
		case "TEXTAREA":
			var varValue1 = $_(objField1).value;
			break;

		default:
			return true;
	}

	switch ($_(objField2).tagName.toUpperCase()) {
		case "SELECT":
			var varValue2 = $_(objField2).options[$_(objField2).selectedIndex].value;
			break;
		case "INPUT":
			if (($_(objField2).type.toUpperCase() == "TEXT") || ($_(objField).type.toUpperCase() == "HIDDEN")) {
				var varValue2 = $_(objField2).value;
			} else {
				return true;
			}
			break;
		case "TEXTAREA":
			var varValue2 = $_(objField2).value;
			break;
		default:
			return true;
	}

	regNumeric = /^(\d+)$/;
	if (regNumeric.test(varValue1)) {
		varValue1 = parseInt(varValue1);
	}

	if (regNumeric.test(varValue2)) {
		varValue2 = parseInt(varValue2);
	}

	switch (strOperator) {
		case "<":
			var blnValid = (varValue1 < varValue2);
			break;
		case ">":
			var blnValid = (varValue1 > varValue2);
			break;
		case "<=":
			var blnValid = (varValue1 <= varValue2);
			break;
		case ">=":
			var blnValid = (varValue1 >= varValue2);
			break;
		case "==":
			var blnValid = (varValue1 == varValue2);
			break;
		case "!=":
			var blnValid = (varValue1 != varValue2);
			break;
		default:
			return false;
			break;
	}

	if (!blnValid) {
		if (strWarning) {
			alert(strWarning);
			$_(objField1).focus();
		}
		return false;
	}

	return true;
}

// -- compareValue -------------------------------------------------------------------------------
// compare field and value with the operator given
// objField: SELECT (single), INPUT-text or  TEXTAREA elements
// varValue2: value to compare field with
// strOperator: Operate to use for the compare (<, >, <=, >=, ==)
// strWarning: textual warning when function returns false (optional)
// -----------------------------------------------------------------------------------------------
function compareValue(objField, varValue2, strOperator, strWarning) {
	switch ($_(objField).tagName.toUpperCase()) {
		case "SELECT":
			if (($_(objField).size) && ($_(objField).size > 1)) {
				return true;
			} else {
				var varValue1 = $_(objField).options[$_(objField).selectedIndex].value;
			}
			break;
		case "INPUT":
			if (($_(objField).type.toUpperCase() == "TEXT") || ($_(objField).type.toUpperCase() == "HIDDEN")) {
				var varValue1 = $_(objField).value;
			} else {
				return true;
			}
			break;
		case "TEXTAREA":
			var varValue1 = $_(objField).value;
			break;
		default:
			return true;
	}

	regNumeric = /^(\d+)$/;
	if (regNumeric.test(varValue1)) {
		varValue1 = parseInt(varValue1);
	}

	if (regNumeric.test(varValue2)) {
		varValue2 = parseInt(varValue2);
	}

	switch (strOperator) {
		case "<":
			var blnValid = (varValue1 < varValue2);
			break;
		case ">":
			var blnValid = (varValue1 > varValue2);
			break;
		case "<=":
			var blnValid = (varValue1 <= varValue2);
			break;
		case ">=":
			var blnValid = (varValue1 >= varValue2);
			break;
		case "==":
			var blnValid = (varValue1 == varValue2);
			break;
		case "!=":
			var blnValid = (varValue1 != varValue2);
			break;
		default:
			return false;
			break;
	}

	if (!blnValid) {
		if (strWarning) {
			alert(strWarning);
			$_(objField).focus();
		}
		return false;
	}

	return true;
}

// -- clearField ---------------------------------------------------------------------------------
// clear the field value
// objField: SELECT, INPUT-text, INPUT-radio, INPUT-checkbox, INPUT-file or TEXTAREA elements
// -----------------------------------------------------------------------------------------------
function clearField(objField) {
	switch ($_(objField).tagName.toUpperCase()) {
		case "SELECT":
			if (($_(objField).size) && ($_(objField).size > 1)) {
				$_(objField).selectedIndex = -1;
			} else {
				$_(objField).selectedIndex = 0;
			}
			break;
		case "INPUT":
			switch ($_(objField).type.toUpperCase()) {
				case "FILE":
				case "TEXT":
					$_(objField).value = '';
					break;
				case "CHECKBOX":
				case "RADIO":
					objArray = document.getElementsByName($_(objField).name);
					for(intCounter = 0; intCounter < objArray.length; intCounter++) {
						objArray[intCounter].checked = false;
					}
					break;
				default:
					break;
			}
			break;
		case "TEXTAREA":
			$_(objField).value == '';
			break;
		default:
			break;
	}
}

// -- disableEnableField -------------------------------------------------------------------------
// switch field between disabled and enabled state
// objField1: SELECT, INPUT-text or  TEXTAREA elements
// -----------------------------------------------------------------------------------------------
function disableEnableField(objField, strClassDisabled, strClassEnabled, blnReset, blnState) {
	switch ($_(objField).tagName.toUpperCase()) {
		case "SELECT":
		case "TEXTAREA":
			if ((blnState === false) || (blnState === true)) {
				if (blnState) {
					if (blnReset) clearField(objField);
					$_(objField).disabled = false;
					if (strClassEnabled) $_(objField).className = strClassEnabled;
				} else {
					if (blnReset) clearField(objField);
					$_(objField).disabled = true;
					if (strClassDisabled) $_(objField).className = strClassDisabled;
				}
			} else {
				if ($_(objField).disabled) {
					if (blnReset) clearField(objField);
					$_(objField).disabled = false;
					if (strClassEnabled) $_(objField).className = strClassEnabled;
				} else {
					if (blnReset) clearField(objField);
					$_(objField).disabled = true;
					if (strClassDisabled) $_(objField).className = strClassDisabled;
				}
			}
		case "INPUT":
			switch ($_(objField).type.toUpperCase()) {
				case "FILE":
				case "TEXT":
					if ((blnState === false) || (blnState === true)) {
						if (blnState) {
							if (blnReset) clearField(objField);
							$_(objField).disabled = false;
							if (strClassEnabled) $_(objField).className = strClassEnabled;
						} else {
							if (blnReset) clearField(objField);
							$_(objField).disabled = true;
							if (strClassDisabled) $_(objField).className = strClassDisabled;
						}
					} else {
						if ($_(objField).disabled) {
							if (blnReset) clearField(objField);
							$_(objField).disabled = false;
							if (strClassEnabled) $_(objField).className = strClassEnabled;
						} else {
							if (blnReset) clearField(objField);
							$_(objField).disabled = true;
							if (strClassDisabled) $_(objField).className = strClassDisabled;
						}
					}
				case "CHECKBOX":
				case "RADIO":
					objArray = document.getElementsByName($_(objField).name);
					for(intCounter = 0; intCounter < objArray.length; intCounter++) {
						if ((blnState === false) || (blnState === true)) {
							if (blnState) {
								if (blnReset) clearField(objField);
								$_(objField).disabled = false;
								if (strClassEnabled) $_(objField).className = strClassEnabled;
							} else {
								if (blnReset) clearField(objField);
								$_(objField).disabled = true;
								if (strClassDisabled) $_(objField).className = strClassDisabled;
							}
						} else {
							if ($_(objField).disabled) {
								if (blnReset) clearField(objField);
								$_(objField).disabled = false;
								if (strClassEnabled) $_(objField).className = strClassEnabled;
							} else {
								if (blnReset) clearField(objField);
								$_(objField).disabled = true;
								if (strClassDisabled) $_(objField).className = strClassDisabled;
							}
						}
					}
					break;
				default:
					break;
			}
			break;
		default:
			break;
	}
}



function checkKeypress(e) {
	var key;
	var keychar;
	var reg;

	if(window.event) {
		// for IE, e.keyCode or window.event.keyCode can be used
		key = e.keyCode;
	} else if(e.which) {
		// netscape
		key = e.which;
	} else {
		// no event, so pass through
		return true;
	}

	keychar = String.fromCharCode(key);
	reg = /\d/;
	return reg.test(keychar);
}



