/* Last Modified: 10/27/99 9:30am - mft */

/* ============================================================= */

//Purpose: Check if a string is all alpha-numeric
//Input: vstrTest: Any string
//Output: false if not alpha-numeric, true if it is alpha-numeric

function isAlphaNum(vstrTest) {
	var i;
	var blnValid = true;

	for (i = 0; i < vstrTest.length; i++) {
		if (!(((vstrTest.charAt(i) >= "a") && (vstrTest.charAt(i) <= "z")) || ((vstrTest.charAt(i) >= "A") && (vstrTest.charAt(i) <= "Z")) || ((vstrTest.charAt(i) >= 0) && (vstrTest.charAt(i) <= 9))))
			{ blnValid = false; }
	}

	return blnValid;
}

/* ============================================================= */

//Purpose: Check if a string is all alphabet characters
//Input: vstrTest: Any string
//Output: false if not alpha-characters, true if it is alpha-characters

function isAlpha(vstrTest) {
	var i;
	var blnValid = true;

	for (i = 0; i < vstrTest.length; i++) {
		if (!(((vstrTest.charAt(i) >= "a") && (vstrTest.charAt(i) <= "z")) || ((vstrTest.charAt(i) >= "A") && (vstrTest.charAt(i) <= "Z"))))
			{ blnValid = false; }
	}

	return blnValid;
}

/* ============================================================= */

//Purpose: Check if a string is all digits
//Input: vstrTest: Any string
//Output: false if not digits, true if it is digits

function isInteger(vstrTest) {
	var i;
	var blnValid = true;

	for (i = 0; i < vstrTest.length; i++) {
		if (!((vstrTest.charAt(i) >= '0') && (vstrTest.charAt(i) <= '9')))
			{ blnValid = false; }
	}

	return blnValid;
}

/* ============================================================= */

//Purpose: Check if a string is all digits (and possibly a decimal point)
//Input: vstrTest: Any string
//Output: false if not a number, true if it is a number

function isNumber(vstrTest) {
	var i;
	var blnValid = true;
	var intNumDecimals = 0;

	for (i = 0; i < vstrTest.length; i++) {
		if (!(((vstrTest.charAt(i) >= '0') && (vstrTest.charAt(i) <= '9')) || (vstrTest.charAt(i) == '.')))
			{ blnValid = false; }
		if (vstrTest.charAt(i) == '.')
			{ intNumDecimals++; }
	}

	if (intNumDecimals > 1)
		{ blnValid = false; }

	return blnValid;
}

/* ============================================================= */

//Purpose: Force a string to only digits
//Input: robjField: Object where value is located
//Output: none

//function ForceNumeric(robjField) {
//	if (isNumber(robjField.value)) {
//		//alert(robjField.value);
//	} else {
//		robjField.value = robjField.value.substring(0,robjField.value.length-1);
//	}
//}

function ForceNumeric() {
	if (window.event.keyCode - 48 < 0 || window.event.keyCode - 48 > 9) {
		return false;
	} else {
		return true;
	}
}

/* ============================================================= */

//Purpose: Force a string to only digits
//Input: robjField: Object where value is located
//Output: none

function ForceInteger(robjField) {
	if (isInteger(robjField.value)) {
//		alert(robjField.value);
	} else {
		robjField.value = robjField.value.substring(0,robjField.value.length-1);
	}
}

/* ============================================================= */

//Purpose: strip all commas from numeric fields
//Input: robjForm: Object where fields are located
//Output: none

function doStripCommas(robjForm) {
	for (var intLoopValidate = 0; intLoopValidate < robjForm.length; intLoopValidate++) {
		var strType = robjForm[intLoopValidate].name.substring(robjForm[intLoopValidate].name.length-4,robjForm[intLoopValidate].name.length);
		if ((strType == "_num") && (robjForm[intLoopValidate].value.length > 0)) {
			robjForm[intLoopValidate].value = doRemoveCommas(robjForm[intLoopValidate].value);
		}
	}
}

/* ============================================================= */

//Purpose: strip all commas from the given string
//Input: rstrThisNumber: the current number that needs commas removed
//Output: the string with commas removed

function doRemoveCommas(rstrThisNumber) {
	var strTempValue = '';
	for (var i = 0; i < rstrThisNumber.length; i++) {
		if (((rstrThisNumber.charAt(i) >= '0') && (rstrThisNumber.charAt(i) <= '9')) || (rstrThisNumber.charAt(i) == '.')) {
			strTempValue += rstrThisNumber.charAt(i);
		}
	}
	return strTempValue;
}

/* ============================================================= */

//Purpose: insert proper commas into numeric fields
//Input: rstrThisNumber: the current number that needs commas
//Output: the string with commas added properly

function doInsertCommas(rstrThisNumber) {
	var strNumber = '';
	if (rstrThisNumber != '') {
		var intDigitCount = rstrThisNumber.indexOf('.');
		if (intDigitCount == -1) {
			intDigitCount = rstrThisNumber.length;
		}
		var blnBeforeDecimal = true;
		for (var i = 0; i < rstrThisNumber.length; i++) {
			if (rstrThisNumber.charAt(i) == '.') {
				blnBeforeDecimal = false;
			}
			if (((rstrThisNumber.charAt(i) >= '0') && (rstrThisNumber.charAt(i) <= '9')) || (rstrThisNumber.charAt(i) == '.')) {
				if (blnBeforeDecimal == true) {
					strNumber += rstrThisNumber.charAt(i);
					if ((((intDigitCount - i) - 1)%3 == 0) && (intDigitCount != i + 1)) {
						strNumber += ',';
					}
				} else {
					strNumber += rstrThisNumber.charAt(i);
				}
			}
		}
	}
	return strNumber;
}

/* ============================================================= */
