/* Strip whitespace from the beginning and end of a string */
function trim(str){	return str.replace(/^\s+|\s+$/g,'');}

function checkDecimals(testValue) {
  decallowed = 2;  
  if (isNaN(testValue) || testValue == "") { return false; }    

   if (testValue.indexOf('.') == -1) testValue += ".";

   dectext = testValue.substring(testValue.indexOf('.')+1, testValue.length);
   if (dectext.length > decallowed) { return false; }
   else
   {
     return true;
   }
}

/* Make sure a textBox only contains a number */
function checkNumber(textBox) {
	/* allow decimal point as first character */
	if(textBox.value.length == 1 && textBox.value ==".") { return; }
	/* check keypress is a number */
	while (textBox.value.length > 0 && isNaN(textBox.value)) {
		textBox.value = textBox.value.substring(0, textBox.value.length - 1);
	}
	textBox.value = trim(textBox.value);
}

/* Check if a form element is empty. If so, display alert and focus */
function isEmpty(formElement, message) {
	formElement.value = trim(formElement.value);
	_isEmpty = false;
	if (formElement.value == '') {
		_isEmpty = true;
		alert(message);
		formElement.focus();
	}
	return _isEmpty;
}

