var mErrorColor = "ff0000";
var mSaveColor;


function _checkCentsField(evt, elem) {
	var evt = (evt) ? evt : (window.event) ? window.event : "";
	var lRC = false;
	var theVal = elem.value;
	if (document.selection) {  // if IE
		var theR = document.selection.createRange();
		window.status="document.selection:  '"+theR.startOffset+"', '"+theR.endOffset+"'";
		var theSel = document.selection.createRange().text;
	} else if (window.getSelection) {
		var theSel = window.getSelection();
		window.status="document.getSelection:  '"+theSel+"'";
	}
	// if whole field selected then it's as if the field were blank...right?
	if (theSel == theVal) theVal = "";
	if (evt) {
		var theKey = (evt.which) ? evt.which : evt.keyCode
		if (theKey < 32) { // if enter is treated as tab
			/*if (theKey == 13) {
				findNextFocus(elem)
				return false;
			}*/
			lRC = true;
		} else if (theKey == 45 || theKey == 46) {
			lRC = true;
		} else if (theKey >= 48 && theKey <= 57) {
			lRC = true;
		}
	}
	return lRC;
}

function _isCentsValue(elem) 
{
	var str = elem.value;
	var lNegative = false;
	var lRC = false;
	if (str.length == 0) {
		elem.value = "0.0000";
	} else if (str.charAt(0) == '-') {
		str = str.substr(1);
		lNegative = true;
	}
	if (str.charAt(0) == '.') {
		str = "0" + str;
	} else {
		lIX = str.indexOf('.');
		if (lIX == -1) {
			str = "0." + str;
		} else {
			str = str.substr(lIX-1);
		}
	}
	if (str.length > 6) {
		str = str.substr(0,6);
	}
	while (str.length < 6) {
		str = str + "0";
	}
	
	var re = /^\d\.\d{4}$/;

	if (!re.test(str)) {
		alert("Field must be in format [-]0.0000");
		 _doCentsErr(elem);
	 } else {
		if (lNegative) {
			str = "-"+str;
		}
		elem.value = str;
		_revertCentsColor(elem);
		lRC = true;
	}
	return lRC;
}

function _doCentsErr(elem) {
	_changeCentsColor(elem);
	setTimeout("focusElement('" + elem.id + "')", 50);
}
function _changeCentsColor(elemName) {
	mSaveColor  = elemName.style.color;
	elemName.style.color = mErrorColor;
	return true;
}
function _revertCentsColor(elemName) {
	elemName.style.color = "#000000";
	return true;
}




