/**
 * $input should be a number rounded to decimalPlaces
 */
validateNumericInput = function( $input, decimalPlaces ) {
	
	//Set empty inputs to zero
	if ( $input.val() == '' ) {
		$input.val( parseFloat('0').toFixed(decimalPlaces) );
		return true;
	}

	var numericInput = parseFloat( $input.val() );
	if ( isNaN(numericInput) ) {
		console.log($input);
		$input.css('border-color', 'red').select().focus();
		$('#dialog-text').text('Input should be a number with zero or one decimal places.')
		$('#dialog').dialog( {
			title: "Invalid Input"
		}).dialog('open');
		return false;
	} else {
		$input.css('border-color', '').val(numericInput.toFixed(decimalPlaces));
	}
	
	return true;
	
}

/**
 * $input should be between minVal and maxVal, rounded to decimalPlaces
 */
validateRange = function( $input, decimalPlaces, minVal, maxVal, defaultVal ) {

	//Set empty inputs to default value
	if ( $input.val() == '' ) {
		$input.val( parseFloat(defaultVal).toFixed(decimalPlaces) );
		return true;
	}

	var numericInput = parseFloat( $input.val() );
	if ( isNaN(numericInput) ) {
		$input.css('border-color', 'red').select().focus();
		$('#dialog-text').text('Input should be a number with zero or one decimal places.')
		$('#dialog').dialog( {
			title: "Invalid Input"
		}).dialog('open');
		$input.val( parseFloat(defaultVal).toFixed(decimalPlaces) );
		return false;
	} else if ( numericInput < minVal || numericInput > maxVal ) {
		$input.css('border-color', 'red').select().focus();
		$('#dialog-text').text('Input should be between ' + minVal + ' and ' + maxVal + '.')
		$('#dialog').dialog( {
			title: "Invalid Input"
		}).dialog('open');
		var inputVal = (numericInput < minVal) ? minVal : maxVal;
		$input.val( inputVal.toFixed(decimalPlaces) );
		return false;
	} else {
		$input.css('border-color', '').val(numericInput.toFixed(decimalPlaces));
	}
	
	return true;
}