
	function formatNumber(number, decimals, bIgnoreCommas) {

		if ( number.length - number.indexOf(".") > decimals && number.indexOf(".") > -1 ) {
			num = parseFloat(number);
			num2 = num * Math.pow(10, decimals);
			num3 = Math.round(num2);
			num4 = num3 / Math.pow(10, decimals);

			number = "" + num4
		}

		output = new String ("");
		len = number.length;
		period = number.indexOf(".");

		if (period == 0) {
			output = "0";
		} else {

//form the pre period

			pos = period > - 1 ? period - 1: len - 1;
			comma = 0;

			while (pos > - 1) {
				c = number.charAt(pos);

				if (c >= '0' && c <='9') {

					if (comma == 3 && ! bIgnoreCommas){
						output = ',' + output;
						comma = 0;
					}

					output = c + output;
					comma ++;
				}
 
				pos --;
			}
		}

		if ( decimals > 0 ) output += ".";

		if (period == - 1) {
			for ( x=0; x<decimals; x++ ) output += "0";
		} else {
			precision = 0;
			
			for (ui = period + 1; ui < len && precision < decimals; ui ++) {
				output += number.charAt(ui);
				precision ++;
			}

			while (precision ++ < decimals)
				output += "0";
		}
  
		if (number.indexOf("-") > - 1) output = "-" + output;
 
		return output;
	}

	function isEmpty(strVal) {

		str = new String(strVal);
		len = str.length;

		for (ui = 0; ui < len; ui ++) {
			if (str.charAt(ui) != ' ') return false;
		}

		return true;
	}

	function validateDouble(field, fieldName, error) {

		if ( field == null || field.value == null || isEmpty(field.value) ) {
			alert(error);
			field.select();
			field.focus();
			return false;
		}

		n = new Number(field.value);
	
	//check for zero

		if ( n == 0 ) {
			alert(error);
			field.select();
			field.focus();
			return false;
		}

		strVal = field.value;

		if ( isNaN(strVal) ) {
			alert(error);
			field.select();
			field.focus();
			return false;
		}

		return true;
	}
