// local variablesvar __decimalPoint;var __radixPoint;var __decimalPlaces;setImplicitDecimalPoint(",");setImplicitDecimalPlaces(-1);setImplicitRadixPoint("  ");function setImplicitDecimalPoint(decp) {	__decimalPoint = decp;}function setImplicitRadixPoint(radp) {	__radixPoint = radp;}function setImplicitDecimalPlaces(decp) {	__decimalPlaces = decp;}// shortcutfunction formatNumber(value) {	var copy = ""+value;	//alert("value is: "+value+"copy is: "+copy);	if(value == "" || copy.search(/^\s+$/)!=-1) return "";	// else	return new NumberFormat(value).toFormatted();}function formatNumberDecP(value,decimalPlaces) {	var olddp=__decimalPlaces;	var result;	__decimalPlaces=decimalPlaces;	result = new NumberFormat(value).toFormatted();	__decimalPlaces = olddp;	return result;}// shortcutfunction unformatNumber(value) {	return ''+new NumberFormat(value).num;	//var myregexp = new RegExp("[^\\d"+(__decimalPoint=="."?"\\.":__decimalPoint)+"\\-]","g");	//value+= '';	//return value.replace(myregexp,"");}// shortcutfunction unformatToParsableNumber(value) {	return ''+new NumberFormat(value).num;}// shortcutfunction numberToFloat(value) {	//alert("vstup: "+value+"\nvystup: "+new NumberFormat(value).num);	return parseFloat(new NumberFormat(value).num);}// shortcutfunction formatInputElemNumber(elem) {	if(elem!=null && elem.value != "" && elem.value.search(/^\s+$/)==-1){	 //alert("elem: "+elem);		elem.value = new NumberFormat(elem.value).toFormatted();	}}function formatInputElemNumberDecP(elem,decimalPlaces) {	var olddp=__decimalPlaces;	__decimalPlaces=decimalPlaces;	elem.value = new NumberFormat(elem.value).toFormatted();	__decimalPlaces = olddp;}// shortcutfunction unformatInputElemNumber(elem,doSelect) {	//alert("value: "+elem.value+", match result:"+elem.value.search(/^\s+$/));	if(elem.value != "" && elem.value.search(/^\s+$/)==-1) {		//alert("unformatting "+elem.value);		var myregexp = new RegExp("[^\\d"+(__decimalPoint=="."?"\\.":__decimalPoint)+"\\-]","g");		elem.value = elem.value.replace(myregexp,"");		if(doSelect) elem.select();	}}/* Complete class: NumberFormat 1.0.3 * v1.0.3 - 23-March-2002 * v1.0.2 - 13-March-2002 * v1.0.1 - 20-July-2001 * v1.0.0 - 13-April-2000 * http://www.mredkj.com *//* * NumberFormat - constructor * num - The number to be formatted */function NumberFormat(num) {	// member variables	this.num;	this.numOriginal;	this.places;	this.separator;	this.decimalPoint;	// external methods	this.setNumber = setNumberNF;	this.toUnformatted = toUnformattedNF;	this.setRadixPoint = setRadixPointNF;	this.setDecimalPlaces = setDecimalPlacesNF;	this.setDecimalPoint = setDecimalPointNF;	this.toFormatted = toFormattedNF;	this.getOriginal = getOriginalNF;	// internal methods	this.getRounded = getRoundedNF;	this.preserveZeros = preserveZerosNF;	this.justNumber = justNumberNF;	// setup defaults	this.setDecimalPlaces(__decimalPlaces);	this.setRadixPoint(__radixPoint);	this.setDecimalPoint(__decimalPoint);	this.setNumber(num);}/* * setNumber - Sets the number * num - The number to be formatted */function setNumberNF(num) {	//alert("nastavuji cislo: "+num);	this.numOriginal = num;	this.num = this.justNumber(num);	//alert("cislo: "+this.num);}/* * toUnformatted - Returns the number as just a number. * If the original value was '100,000', then this method will return the number 100000 * v1.0.2 - Modified comments, because this method no longer returns the original value. */function toUnformattedNF() {	return (this.num);}/* * getOriginal - Returns the number as it was passed in, which may include non-number characters. * This function is new in v1.0.2 */function getOriginalNF() {	return (this.numOriginal);}/* * setRadixPoint - Sets a switch that indicates if there should be commas * isC - true, if should be commas; false, if no commas */function setRadixPointNF(isC) {	this.separator = isC;}/* * setCurrency - Sets a switch that indicates if should be displayed as currency * isC - true, if should be currency; false, if not currencyfunction setCurrencyNF(isC) {	this.isCurrency = isC;} */function setDecimalPointNF(del) {	this.decimalPoint = del;}/* * setDecimalPlaces - Sets the precision of decimal places * p - The number of places. Any number of places less than or equal to zero is considered zero. */function setDecimalPlacesNF(p) {	this.places = p;}/* * toFormatted - Returns the number formatted according to the settings (a string) */function toFormattedNF() {	var pos;	var nNum = this.num; // v1.0.1 - number as a number	var nStr;            // v1.0.1 - number as a string	// round decimal places	nNum = this.getRounded(nNum);	nStr = this.preserveZeros(Math.abs(nNum)); // this step makes nNum into a string. v1.0.1 Math.abs	if (this.separator!="") {		pos = nStr.indexOf(this.decimalPoint);		if (pos == -1)	{			pos = nStr.length;		}		while (pos > 0)	{			pos -= 3;			if (pos <= 0) break;			nStr = nStr.substring(0,pos) + this.separator + nStr.substring(pos, nStr.length);		}	}	nStr = (nNum < 0) ? '-' + nStr : nStr; // v1.0.1	/*	if (this.isCurrency) {		// add dollar sign in front		nStr = nStr+this.currencyPostfix;	}	*/	return (nStr);}/* * getRounded - Used internally to round a value * val - The number to be rounded */function getRoundedNF(val) {	if(this.places==-1) return val;	var factor;	var i;	// round to a certain precision	factor = 1;	for (i=0; i<this.places; i++)	{	factor *= 10; }	val *= factor;	val = Math.round(val);	val /= factor;	return (val);}/* * preserveZeros - Used internally to make the number a string * 	that preserves zeros at the end of the number * val - The number */function preserveZerosNF(val){	var i;	// make a string - to preserve the zeros at the end	val = val + '';	if(this.decimalPoint!=".")		val = val.replace(/\./,this.decimalPoint);	if (this.places <= 0) return val; // leave now. no zeros are necessary - v1.0.1 less than or equal	var decimalPos = val.indexOf(this.decimalPoint);	if (decimalPos == -1) {		val += this.decimalPoint;		for (i=0; i<this.places; i++) val += '0';	} else {		var actualDecimals = (val.length - 1) - decimalPos;		var difference = this.places - actualDecimals;		for (i=0; i<difference; i++) val += '0';	}	return val;}/* * justNumber - Used internally to parse the value into a floating point number. * If the value is not set, then return 0. * If the value is not a number, then replace all characters that are not 0-9, a decimal point, or a negative sign. * *  Note: The regular expression cleans up the number, but doesn't get rid of - and . *  Because all negative signs and all decimal points are allowed, *  extra negative signs or decimal points may corrupt the result. *  parseFloat will ignore all values after any character that is NaN. * *  A number can be entered using special notation. *  For example, the following is a valid number: 0.0314E+2 * * This function is new in v1.0.2 */function justNumberNF(val) {	val = (val==null || (val+'').match(/^\s*$/)) ? 0 : val;	// check if a number, otherwise try taking out non-number characters.	//alert("neupravene cislo je: "+val);	if(this.decimalPoint!='.') {		val += '';		val = val.replace(new RegExp(this.decimalPoint,"g"),".");	}	// removing whitespaces	//val = val.replace(/\s/g,'');	if (isNaN(val)) {		var newVal;		val += '';		newVal = parseFloat(val.replace(/[^\d\.\-]/g, ''));		// check if still not a number. Might be undefined, '', etc., so just replace with 0.		// v1.0.3		//alert("parsovany float je: "+newVal+"\nvracim: "+(isNaN(newVal) ? 0 : newVal));		return (isNaN(newVal) ? 0 : newVal); 	} else if (!isFinite(val)) {		return 0;	}	return val;}