/*******************************************************/
/*            Disable <Enter Key> Function             */
/*            ============================             */
/* Disable the use of the <ENTER> key that issues a    */
/* submit form in IE.                                  */
/*******************************************************/
function noenter() {
  return !(window.event && window.event.keyCode == 13);
}


/*******************************************************/
/* Checks the contents of any object and verifies that */
/* it is a floating point number.                      */
/*******************************************************/
function valnumber(field,notempty) {
	if (notempty == null){
		notempty = false;
	}
	 
	if (notempty == true && field.value.length == 0) {
		field.value = field.defaultValue;
		field.select();
		field.focus();
		return false;
	}

	if (field.value.length > 0) {
		if (parseFloat(field.value) != field.value) {
			field.value = field.defaultValue;
			field.select();
			field.focus();
			return false;
		}
	}
	return true;
}


/*******************************************************/
/* Checks the contents of any object and verifies that */
/* it contains numeric characters only.                */
/*******************************************************/
function valnumeric(field,notempty) {
	var Chars = "0123456789";

	if (notempty == null){
		notempty = false;
	}
	 
	if (notempty == true && field.value.length == 0) {
		field.value = field.defaultValue;
		field.select();
		field.focus();
		return false;
	}

	for (var i = 0; i < field.value.length; i++) {
		if (Chars.indexOf(field.value.charAt(i)) == -1) {
			field.value = field.defaultValue;
			field.select();
			field.focus();
			return false;
		}
	}
	return true;
} 


/*********************************************************/
/* extracts the file name from a forms file upload field */
/*********************************************************/
function extract(what,ufile) {
    if (what.indexOf('/') > -1)
        answer = what.substring(what.lastIndexOf('/')+1,what.length);
    else
        answer = what.substring(what.lastIndexOf('\\')+1,what.length);
    ufile.value = answer;
}


/**********************************/
/* Reset a form upon confirmation */
/*********************************/
function resetForm(formName, confirmMessage) {
  if (confirm(confirmMessage) == true) {
     getvalue = eval('document.' + formName + '.reset()');
  }
  return true;
}


/*************************/
/* Format numeric output */
/*************************/
function formatNumber(num, decimalNum, bolLeadingZero, bolParens, bolCommas)
/*
num: 		       the number to be formatted
decimalNum:     the number of decimals after the digit
bolLeadingZero: true / false to use leading zero for numbers between -1 and 1
bolParens:      true / false to use parenthesis for - num
bolCommas:      put commas as number separators

RETVAL - formatted number
*/
{
	if (decimalNum == null){
		decimalNum = 2;
	}
	if (bolLeadingZero == null){
		bolLeadingZero = true;
	}
	if (bolParens == null){
		bolParens = false;
	}
	if (bolCommas == null){
		bolCommas = false;
	}
	
	if (isNaN(parseInt(num))) return "0.00";

	var tmpNum = num;
	var iSign = num < 0 ? -1 : 1;		// Get sign of number

	// Adjust number so only the specified number of numbers after
	// the decimal point are shown.
	tmpNum *= Math.pow(10,decimalNum);
	tmpNum = Math.round(Math.abs(tmpNum))
	tmpNum /= Math.pow(10,decimalNum);
	tmpNum *= iSign;					// Readjust for sign

	// Create a string object to do our formatting on
	var tmpNumStr = new String(tmpNum);

	// See if we need to put in the commas
	if (bolCommas && (num >= 1000 || num <= -1000)) {
		var iStart = tmpNumStr.indexOf(".");
		if (iStart < 0)
			iStart = tmpNumStr.length;

		iStart -= 3;
		while (iStart >= 1) {
			tmpNumStr = tmpNumStr.substring(0,iStart) + "," + tmpNumStr.substring(iStart,tmpNumStr.length)
			iStart -= 3;
		}		
	}

	// See if we need to use parenthesis
	if (bolParens && num < 0)
		tmpNumStr = "(" + tmpNumStr.substring(1,tmpNumStr.length) + ")";

	return tmpNumStr;		// Return our formatted string!
}
