/**
 * NumberFormat-Wrapper / OG-2007.
 * 
 * INFO: Here is defined the wrapper for NumberFormat-Library (Library self is in the end of this file).
 * 
 * @author: igor.rulyov@onlinegroup.at
 * 
 */
// Common globals:
var NF_maxDecimal = 0;
var NF_isInteger = false;
var NF_negativePossible = false;
var NF_keyCode = null;

/**
 * @param elem - Object Input field
 * @param f - String Wished format-pattern
 */
function registerNF ( elem, f ) {
	tryNumberFormat(elem, true, true, f, null);
	Event.observe(elem, 'blur', function(event){tryNumberFormat(Event.element(event), true, false, f, null);});
	Event.observe(elem, 'keyup', function(event){tryNumberFormat(Event.element(event), false, false, f, null);});
	Event.observe(elem, 'keydown', function(event){tryKey(Event.element(event), event, f);});
}

/**
 * Formats input field value, or given value
 * @param Object Input field to format
 * @param Boolean Whether finish & full-format should be made
 * @param Boolean Whether value of input is predifened by system
 * @param String Format-pattern
 * @param String If Input-Object wasn't set, then format given string (string will be returned)
 */
function tryNumberFormat ( inputObj, doFullFormat, isPreDefinedVal, formatPattern, value2format ) {
	if(!value2format) value2format = 0.0;
	// Local variables to control output:
	// If work with input object:
	if ( inputObj!=null ) {
		var inVal = modifVal = $F(inputObj);
	// Else work with given value:
	} else {
		var inVal = modifVal = value2format.toString();
	}
	var commaAdded = false;
	var zerosAfterComma = 0;
	var i;
	var minusOnly = false;
	var cursorPos = 0;
	var decMax = decMin = decDiff = 0;
	var isInteger = true;
	var commaIndex = -1;
	var symbolsAfterComma;
	var zeroAssigned = false;
	var negativePossible = false;
	var formatNeeded = false;
	var tmp_formatPattern = formatPattern;

	// Parse formatPattern:
	// Is decimal present?
	if ( formatPattern.indexOf(',') > -1 ) {
		// Extract decimal pattern:
	  formatPattern = formatPattern.substr(formatPattern.indexOf(',')+1);
	  // Analyse pattern:
	  formatPattern = formatPattern.toArray();
	  formatPattern.each(function(s){
	    if ( s === '0' ) decMin++;
	    decMax++;
	  });
	}
	isInteger = decMax == 0;
	// Are negative values possible?
	if ( tmp_formatPattern.indexOf('+') < 0 ) negativePossible = true;
	// Is formating needed?
	var prefix = tmp_formatPattern.substr(0,2);
	if ( prefix=='+#' || prefix=='#,' ) formatNeeded = true;

	// Try to save current cursor position if last key wasn't TAB(!) and we work with input-object:
	if ( NF_keyCode!=9 && inputObj!=null ) {
		try {
			// IE:
			if ( document.selection ) {
				cursorPos = Math.abs(document.selection.createRange().moveEnd('character', -1000000));
			// Mozilla/Gecko:
			} else if ( $(inputObj).selectionStart ) {
				cursorPos = $(inputObj).selectionStart;
			}
		} catch (e) {}
	}

	// Erase possible whitespaces (deprecated: tryKey does keys check):
	// modifVal = modifVal.replace(/\s/g, '');

	// Remeber minus, if it was typed as first:
	if ( modifVal === '-' ) {
		modifVal += '0';
		minusOnly = true;
	}

	// Value was predefined -> preformat it (replace period with comma):
	if ( isPreDefinedVal && (modifVal.indexOf(',') < 0) ) modifVal = modifVal.replace(/\./g, ',');

	// Erase not allowed symbols:
	modifVal = negativePossible ? modifVal.replace(/[^0-9|\,|\-|\.]/g, '') : modifVal.replace(/[^0-9|\,|\.]/g, '');

	// If empty, set to zero:
	if ( modifVal.length == 0 ) {
		modifVal = '0';
		zeroAssigned = true;
	}

	// Cut off minus(es), if it wasn't placed as first or more than one minus was found:
	if ( modifVal.lastIndexOf('-') > 0 || modifVal.substr(0,2) == '--' ) modifVal = modifVal.replace(/[\-]/g, '');

	// If input's type of float and decimal postfix isn't presented (convert's demand) -> add it:
	if ( !isInteger && modifVal.indexOf(',') < 0 ) {
		modifVal += ',';
		commaAdded = true;
	}

	// Get symbol-index of the comma in the string:
	commaIndex = modifVal.indexOf(',');
	// Get all possible symbols after comma:
	symbolsAfterComma = modifVal.substr(commaIndex+1);
	// Count symbol-difference in decimal zone:
	decDiff = decMax - symbolsAfterComma.length;
	// Add (if needed) zeros after:
	if ( decDiff > 0 ) {
		// Add so much zeros to postfix, as needed by symbol-difference in decimal-zone:
		for ( decDiff; decDiff > 0; decDiff-- ) {
			modifVal += '0';
			zerosAfterComma++;
		}
	}

	// More than 2 symbols after comma -> cut off rest (deprecated: tryKey does keys check):
	// var rgxp1 = /[0-9]*\.*\,{1,}([0-9]){3,}/;
	// if ( rgxp1.test(modifVal) ) modifVal = modifVal.substr(0, modifVal.indexOf(',')+3);

	// Erase all periods before convert:
	modifVal = modifVal.replace(/\./g, '');

	// Convert comma to period:
	modifVal = modifVal.replace(/\,/g, '.');

	// Convert:
	var converter = new NumberFormat();
	converter.setNumber(modifVal);
	converter.setSeparators(formatNeeded, '.', ',');
	// Trunc at fields:
	if ( inputObj!=null ) {
		converter.setPlaces(decMax, true);
	// Round at displays:
	} else {
		converter.setPlaces(decMax, false);
	}
	modifVal = converter.toFormatted();

	// Do reverse actions:

	// Remove zeros, if some were added special for conversion and focus stays on input or input's focus is lost:
	if ( (zerosAfterComma > 0 && !doFullFormat) || doFullFormat ) modifVal = modifVal.substr(0, modifVal.length-zerosAfterComma);

	// If decimal was added special for conversion and focus stays on input -> cut it off:
	if ( commaAdded && !doFullFormat ) {
		modifVal = modifVal.substring(0, modifVal.indexOf(','));
		commaAdded = false;
	}

	// Zero is the result of the conversion -> truncate converted value (if initial value was empty and focus stays on input):
	if ( inVal.length==0 && modifVal==='0' && !doFullFormat ) modifVal = '';

	// Return "-", if it was set only and if focus stays on input:
	if ( minusOnly && !doFullFormat ) {
		modifVal = '-';
		minusOnly = false;
	}

	// If focus is lost and input's type of float:
	if ( doFullFormat && !isInteger && inVal.length>0 ) {
		// Check minimum symbols and add zeros if needed
		commaIndex = modifVal.indexOf(',');
		// Get all possible symbols after comma:
		symbolsAfterComma = modifVal.substr(commaIndex+1);
		decDiff = decMin - symbolsAfterComma.length;
		if ( decDiff > 0 ) {
			// Add needed zeros:
			for ( decDiff; decDiff>0; decDiff-- ) {
			  modifVal += '0';
			}
		}
		// If no symbols after comma and minimum decimal is 0 -> cut comma off:
		if ( symbolsAfterComma.length==0 && decMin==0 ) modifVal = modifVal.substring(0, modifVal.indexOf(','));
	}

	// If focus is lost and no symbol in field -> truncate:
	if ( doFullFormat && (inVal.length==0 || inVal==='-' ) ) modifVal = '';

	// If zero was assigned -> cut it off:
	if ( zeroAssigned ) {
		modifVal = '';
	  zeroAssigned = false;
	}

	// Assign modificated value back to input field (if edited):
	// If work with input object, then assig value to it:
	if ( inputObj!=null ) {
		if ( inVal !== modifVal ) {
			$(inputObj).value = modifVal;
			// Calculate new cursor position:
			if ( modifVal.length-inVal.length==1 ) cursorPos++;
			if ( modifVal.length-inVal.length==-1 ) cursorPos--;
			// Try to return cursor to it's position if last key wasn't TAB(!):
			if ( NF_keyCode!=9 ) {
				try {
					// IE:
					if ( document.selection ) {
						var range = $(inputObj).createTextRange(); 
						range.move('character', cursorPos); 
						range.select();
					// Mozilla/Gecko:
					} else if ( $(inputObj).selectionStart ) {
						$(inputObj).selectionStart = cursorPos;
						$(inputObj).selectionEnd = cursorPos;
					}
				} catch (e) {}
			}
		}
	// If work with given value, then return formatted value:
	} else {
		return modifVal;
	}
}

/**
 * Key-tester, to deny wrong symbols
 * @param Object Input field to control
 * @param Object Event fired by user-actions
 * @param String Wished format-pattern
 */
function tryKey ( inputObj, e, formatPattern ) {
	/*
	 * Key-Codes: http://unixpapa.com/js/key.html
	 * http://unixpapa.com/js/testkey.html
	 * This function will be called on onKeyDown event.
	 * Att.: for key-codes for keyDown are OTHERS, than at keyPress!
	 * 8: Backspace
	 * 9: Tab
	 * 35: End
	 * 36: Home
	 * 37: Left arrow
	 * 38: Top arrow
	 * 39: Right arrow
	 * 40: Bottom arrow
	 * 48-57: 0-9
	 * 188: ,
	 * 44: , (Opera & Konqueror)!
	 * 189: -
	 * 45: - (Opera & Konqueror)!
	 * 109: - (Netscape)!
	 * 190: .
	 * 46: . (Opera & Konqueror)!
	 */
	var keysList = [8,9,35,36,37,38,39,40,48,49,50,51,52,53,54,55,56,57];
	// Defaults:
	if ( NF_negativePossible ) keysList.push(109);
	var commaCode = 188;
	var periodCode = 190;
	// Adaprt key-list for browser:
	var rgxpOperaOrKonqueror = /opera|konqueror/gi;
	if ( rgxpOperaOrKonqueror.test(navigator.appName) ) {
		if ( NF_negativePossible ) keysList.push(45);
		commaCode = 44;
		periodCode = 46;
	} else {
		if ( NF_negativePossible ) keysList.push(189);
	}
	// Detect code and assign it to global (needed for formatting too):
	if ( e.keyCode ) {
		NF_keyCode = e.keyCode;
	}	else if ( e.which ) {
		NF_keyCode = e.which;
	}
	// Read format and set globals:
	readFormat(formatPattern);
	// Deny modif. keys:
	if ( e.altKey || e.ctrlKey || e.shiftKey ) {
		doInputErr(inputObj);
		return false;
	} else {
		// User tries to enter a comma:
		if ( !NF_isInteger && NF_keyCode==commaCode ) {	
			// Allow to enter one more comma, if input's type of float and no comma exists now:
			if ( !NF_isInteger && inputObj.value.indexOf(',')<0 ) {
				return true;
			} else {
				doInputErr(inputObj);
				return false;
			}
		// User cannot enter period self:
		} else if ( NF_keyCode==periodCode ) {
			doInputErr(inputObj);
			return false;
		} else if ( keysList.indexOf(NF_keyCode) >= 0 ) {
			return true;
		} else {
			doInputErr(inputObj);
			return false;
		}
	}
}

function readFormat ( formatPattern ) {
	if ( formatPattern.indexOf(',') > -1 ) {
		// Extract decimal pattern:
	  formatPattern = formatPattern.substr(formatPattern.indexOf(',')+1);
	  // Analyse pattern and count max:
	  formatPattern = formatPattern.toArray();
		// Set global:
	  NF_maxDecimal = formatPattern.length;
	} else {
		// Set global:
		NF_maxDecimal = 0;
	}
	// Set global:
	NF_isInteger = NF_maxDecimal == 0;
	NF_negativePossible = formatPattern.indexOf('+') < 0;
}

function doInputOk ( id ) {
	// Normal:
	$(''+id).removeClassName('nf_InputFieldNumberError');
}

function doInputErr ( inputObj ) {
	// Warn:
	$(inputObj).addClassName('nf_InputFieldNumberError');
	// Timeout (0,1 sec):
	setTimeout('doInputOk(\''+inputObj.id+'\');', 100);
}

/*
 * Original from: mredkj.com
 */
function NumberFormat ( num, inputDecimal ) {
	this.VERSION = 'Number Format v1.5.4';
	this.COMMA = ',';
	this.PERIOD = '.';
	this.DASH = '-'; 
	this.LEFT_PAREN = '('; 
	this.RIGHT_PAREN = ')'; 
	this.LEFT_OUTSIDE = 0; 
	this.LEFT_INSIDE = 1;  
	this.RIGHT_INSIDE = 2;  
	this.RIGHT_OUTSIDE = 3;  
	this.LEFT_DASH = 0; 
	this.RIGHT_DASH = 1; 
	this.PARENTHESIS = 2; 
	this.NO_ROUNDING = -1 
	this.num;
	this.numOriginal;
	this.hasSeparators = false;  
	this.separatorValue;  
	this.inputDecimalValue; 
	this.decimalValue;  
	this.negativeFormat; 
	this.negativeRed; 
	this.hasCurrency;  
	this.currencyPosition;  
	this.currencyValue;  
	this.places;
	this.roundToPlaces; 
	this.truncate; 
	this.setNumber = setNumberNF;
	this.toUnformatted = toUnformattedNF;
	this.setInputDecimal = setInputDecimalNF; 
	this.setSeparators = setSeparatorsNF; 
	this.setCommas = setCommasNF;
	this.setNegativeFormat = setNegativeFormatNF; 
	this.setNegativeRed = setNegativeRedNF; 
	this.setCurrency = setCurrencyNF;
	this.setCurrencyPrefix = setCurrencyPrefixNF;
	this.setCurrencyValue = setCurrencyValueNF; 
	this.setCurrencyPosition = setCurrencyPositionNF; 
	this.setPlaces = setPlacesNF;
	this.toFormatted = toFormattedNF;
	this.toPercentage = toPercentageNF;
	this.getOriginal = getOriginalNF;
	this.moveDecimalRight = moveDecimalRightNF;
	this.moveDecimalLeft = moveDecimalLeftNF;
	this.getRounded = getRoundedNF;
	this.preserveZeros = preserveZerosNF;
	this.justNumber = justNumberNF;
	this.expandExponential = expandExponentialNF;
	this.getZeros = getZerosNF;
	this.moveDecimalAsString = moveDecimalAsStringNF;
	this.moveDecimal = moveDecimalNF;
	this.addSeparators = addSeparatorsNF;
	if ( inputDecimal == null ) {
		this.setNumber(num, this.PERIOD);
	} else {
		this.setNumber(num, inputDecimal); 
	}
	this.setCommas(true);
	this.setNegativeFormat(this.LEFT_DASH); 
	this.setNegativeRed(false); 
	this.setCurrency(false); 
	this.setCurrencyPrefix('$');
	this.setPlaces(2);
}

function setInputDecimalNF ( val ) {
	this.inputDecimalValue = val;
}

function setNumberNF ( num, inputDecimal ) {
	if ( inputDecimal != null ) {
		this.setInputDecimal(inputDecimal); 
	}
	this.numOriginal = num;
	this.num = this.justNumber(num);
}

function toUnformattedNF () {
	return (this.num);
}

function getOriginalNF () {
	return (this.numOriginal);
}

function setNegativeFormatNF ( format ) {
	this.negativeFormat = format;
}

function setNegativeRedNF ( isRed ) {
	this.negativeRed = isRed;
}

function setSeparatorsNF ( isC, separator, decimal ) {
	this.hasSeparators = isC;
	if ( separator == null ) separator = this.COMMA;
	if ( decimal == null ) decimal = this.PERIOD;
	if ( separator == decimal ) {
		this.decimalValue = (decimal == this.PERIOD) ? this.COMMA : this.PERIOD;
	} else {
		this.decimalValue = decimal;
	}
	this.separatorValue = separator;
}

function setCommasNF ( isC ) {
	this.setSeparators(isC, this.COMMA, this.PERIOD);
}

function setCurrencyNF (isC) {
	this.hasCurrency = isC;
}

function setCurrencyValueNF ( val ) {
	this.currencyValue = val;
}

function setCurrencyPrefixNF ( cp ) {
	this.setCurrencyValue(cp);
	this.setCurrencyPosition(this.LEFT_OUTSIDE);
}

function setCurrencyPositionNF ( cp ) {
	this.currencyPosition = cp;
}

function setPlacesNF ( p, tr ) {
	this.roundToPlaces = !(p == this.NO_ROUNDING); 
	this.truncate = (tr != null && tr); 
	this.places = (p < 0) ? 0 : p; 
}

function addSeparatorsNF ( nStr, inD, outD, sep ) {
	nStr += '';
	var dpos = nStr.indexOf(inD);
	var nStrEnd = '';
	if ( dpos != -1 ) {
		nStrEnd = outD + nStr.substring(dpos + 1, nStr.length);
		nStr = nStr.substring(0, dpos);
	}
	var rgx = /(\d+)(\d{3})/;
	while ( rgx.test(nStr) ) {
		nStr = nStr.replace(rgx, '$1' + sep + '$2');
	}
	return nStr + nStrEnd;
}

function toFormattedNF () {
	var pos;
	var nNum = this.num; 
	var nStr;            
	var splitString = new Array(2);   
	if ( this.roundToPlaces ) {
		nNum = this.getRounded(nNum);
		nStr = this.preserveZeros(Math.abs(nNum)); 
	} else {
		nStr = this.expandExponential(Math.abs(nNum)); 
	}
	if ( this.hasSeparators ) {
		nStr = this.addSeparators(nStr, this.PERIOD, this.decimalValue, this.separatorValue);
	} else {
		nStr = nStr.replace(new RegExp('\\' + this.PERIOD), this.decimalValue); 
	}
	var c0 = '';
	var n0 = '';
	var c1 = '';
	var n1 = '';
	var n2 = '';
	var c2 = '';
	var n3 = '';
	var c3 = '';
	var negSignL = (this.negativeFormat == this.PARENTHESIS) ? this.LEFT_PAREN : this.DASH;
	var negSignR = (this.negativeFormat == this.PARENTHESIS) ? this.RIGHT_PAREN : this.DASH;
	if ( this.currencyPosition == this.LEFT_OUTSIDE ) {
		if ( nNum < 0 ) {
			if ( this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS ) n1 = negSignL;
			if ( this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS ) n2 = negSignR;
		}
		if ( this.hasCurrency ) c0 = this.currencyValue;
	} else if ( this.currencyPosition == this.LEFT_INSIDE ) {
		if ( nNum < 0 ) {
			if ( this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS ) n0 = negSignL;
			if ( this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS ) n3 = negSignR;
		}
		if ( this.hasCurrency ) c1 = this.currencyValue;
	} else if ( this.currencyPosition == this.RIGHT_INSIDE ) {
		if ( nNum < 0 ) {
			if ( this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS ) n0 = negSignL;
			if ( this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS ) n3 = negSignR;
		}
		if ( this.hasCurrency ) c2 = this.currencyValue;
	} else if ( this.currencyPosition == this.RIGHT_OUTSIDE ) {
		if ( nNum < 0 ) {
			if ( this.negativeFormat == this.LEFT_DASH || this.negativeFormat == this.PARENTHESIS ) n1 = negSignL;
			if ( this.negativeFormat == this.RIGHT_DASH || this.negativeFormat == this.PARENTHESIS ) n2 = negSignR;
		}
		if ( this.hasCurrency ) c3 = this.currencyValue;
	}
	nStr = c0 + n0 + c1 + n1 + nStr + n2 + c2 + n3 + c3;
	if ( this.negativeRed && nNum < 0 ) {
		nStr = '<font color="red">' + nStr + '</font>';
	}
	return (nStr);
}

function toPercentageNF () {
	nNum = this.num * 100;
	nNum = this.getRounded(nNum);
	return nNum + '%';
}

function getZerosNF ( places ) {
	var extraZ = '';
	var i;
	for ( i=0; i<places; i++ ) {
		extraZ += '0';
	}
	return extraZ;
}

function expandExponentialNF ( origVal ) {
	if (isNaN(origVal)) return origVal;
	var newVal = parseFloat(origVal) + ''; 
	var eLoc = newVal.toLowerCase().indexOf('e');
	if ( eLoc != -1 ) {
		var plusLoc = newVal.toLowerCase().indexOf('+');
		var negLoc = newVal.toLowerCase().indexOf('-', eLoc);
		var justNumber = newVal.substring(0, eLoc);
		if ( negLoc != -1 ) {
			var places = newVal.substring(negLoc + 1, newVal.length);
			justNumber = this.moveDecimalAsString(justNumber, true, parseInt(places));
		} else {
			if ( plusLoc == -1 ) plusLoc = eLoc;
			var places = newVal.substring(plusLoc + 1, newVal.length);
			justNumber = this.moveDecimalAsString(justNumber, false, parseInt(places));
		}
		newVal = justNumber;
	}
	return newVal;
}

function moveDecimalRightNF ( val, places ) {
	var newVal = '';
	if ( places == null ) {
		newVal = this.moveDecimal(val, false);
	} else {
		newVal = this.moveDecimal(val, false, places);
	}
	return newVal;
}

function moveDecimalLeftNF ( val, places ) {
	var newVal = '';
	if ( places == null ) {
		newVal = this.moveDecimal(val, true);
	} else {
		newVal = this.moveDecimal(val, true, places);
	}
	return newVal;
}

function moveDecimalAsStringNF ( val, left, places ) {
	var spaces = ( arguments.length < 3 ) ? this.places : places;
	if ( spaces <= 0 ) return val;
	var newVal = val + '';
	var extraZ = this.getZeros(spaces);
	var re1 = new RegExp('([0-9.]+)');
	if ( left ) {
		newVal = newVal.replace(re1, extraZ + '$1');
		var re2 = new RegExp('(-?)([0-9]*)([0-9]{' + spaces + '})(\\.?)');
		newVal = newVal.replace(re2, '$1$2.$3');
	} else {
		var reArray = re1.exec(newVal);
		if ( reArray != null ) {
			newVal = newVal.substring(0,reArray.index) + reArray[1] + extraZ + newVal.substring(reArray.index + reArray[0].length);
		}
		var re2 = new RegExp('(-?)([0-9]*)(\\.?)([0-9]{' + spaces + '})');
		newVal = newVal.replace(re2, '$1$2$4.');
	}
	newVal = newVal.replace(/\.$/, '');
	return newVal;
}

function moveDecimalNF ( val, left, places ) {
	var newVal = '';
	if ( places == null ) {
		newVal = this.moveDecimalAsString(val, left);
	} else {
		newVal = this.moveDecimalAsString(val, left, places);
	}
	return parseFloat(newVal);
}

function getRoundedNF ( val ) {
	val = this.moveDecimalRight(val);
	if ( this.truncate ) {
		val = ( val >= 0 ) ? Math.floor(val) : Math.ceil(val);
	} else {
		val = Math.round(val);
	}
	val = this.moveDecimalLeft(val);
	return val;
}

function preserveZerosNF ( val ) {
	var i;
	val = this.expandExponential(val);
	if ( this.places <= 0 ) return val;
	var decimalPos = val.indexOf('.');
	if ( decimalPos == -1 ) {
		val += '.';
		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;
}

function justNumberNF ( val ) {
	newVal = val + '';
	var isPercentage = false;
	if ( newVal.indexOf('%') != -1 ) {
		newVal = newVal.replace(/\%/g, '');
		isPercentage = true;
	}
	var re = new RegExp('[^\\' + this.inputDecimalValue + '\\d\\-\\+\\(\\)eE]', 'g');
	newVal = newVal.replace(re, '');
	var tempRe = new RegExp('[' + this.inputDecimalValue + ']', 'g');
	var treArray = tempRe.exec(newVal);
	if ( treArray != null ) {
		var tempRight = newVal.substring(treArray.index + treArray[0].length);
		newVal = newVal.substring(0,treArray.index) + this.PERIOD + tempRight.replace(tempRe, '');
	}
	if ( newVal.charAt(newVal.length - 1) == this.DASH ) {
		newVal = newVal.substring(0, newVal.length - 1);
		newVal = '-' + newVal;
	} else if ( newVal.charAt(0) == this.LEFT_PAREN && newVal.charAt(newVal.length - 1) == this.RIGHT_PAREN ) {
		newVal = newVal.substring(1, newVal.length - 1);
		newVal = '-' + newVal;
	}
	newVal = parseFloat(newVal);
	if ( !isFinite(newVal) ) {
		newVal = 0;
	}
	if ( isPercentage ) {
		newVal = this.moveDecimalLeft(newVal, 2);
	}
	return newVal;
}
