function reviewNav(option_name) {
// Set OPT form value and submit the form on the review page.
	document.review_form.OPT.value = option_name;
	document.review_form.submit();
}

function viewPrinterVersion() {
// Submit the printer-friendly form on the page.
	document.print_form.submit();
}


var punctuation_notice_given = 0;
var empty_notice_given = 1;		// don't display notice

//var decimal_notice_given = 0;
//var dollar_notice_given = 0;


function validateNumeric(fieldObject) {
// Validate any numeric value in the estimator forms.
	stripChars(fieldObject);
	dropDecimals(fieldObject);
	emptiesToZeros(fieldObject);	

} // validateNumeric


function validateMonetary(fieldObject) {
// Validate a monetary value in the estimator.
	stripChars(fieldObject);
	dropDecimals(fieldObject);
	emptiesToZeros(fieldObject);
	
} // validateMonetary


function validateField(fieldObject) {
// Validate any numeric value in the estimator forms.
	stripChars(fieldObject);
	dropDecimals(fieldObject);
	emptiesToOnes(fieldObject);	
} // validateNumeric




function displayPuntuationNotice() {
// display warning of ignored punctuation
	if (!punctuation_notice_given) {
		alert ("COMMAS, DECIMALS, and DOLLAR SIGNS will be ignored.  \nPlease do not include punctuation in the values that you enter here.");
		punctuation_notice_given = 1;
	}	
} // displayPunctuationNotice



function stripChars (field) {
// strip illegal characters from numeric and monetary fields

	var illegals = new Array(',', '$');
	var inputString = field.value;
	var charPosition = -1;
	var testChar;
	var substrings;
	
	// run tests for each illegal character
	for (var i = 0; i < illegals.length; i++) {
		testChar = illegals[i];	
		charPosition = inputString.indexOf(testChar);
		if (charPosition == -1) {
		 	continue;
		} else {
			// send warning to user of illegals
			displayPuntuationNotice();
	
			// remove all instances of testChar in the input string
			substrings = inputString.split(testChar);
			inputString = '';
			for (var j = 0; j < substrings.length; j++) {
				inputString += substrings[j];
			} 
		}
	}
	
	// return the string to the form	
	field.value = inputString;
	return;
	
} // stripChars		



function emptiesToZeros(field) {
// Set any empty fields to zero
	if (field.value == '') {
		if (!empty_notice_given) {
			alert ("Empty values will be automatically set to zero.");
			empty_notice_given = 1;
		}
		field.value = 0;
	}
} // emptiesToZeros


function emptiesToOnes(field) {
// Set any empty fields to zero
	if (field.value == '' || field.value < 1) {
	  if (field.name == 'household[family_size]') {
	    alert ("Family sizes less than one will be automatically set to one.");
			//			empty_notice_given = 1;
	  } else if (field.name == 'household[num_college]') {
	    alert ("Number of full time students less than one will be automatically set to one.");
			//			empty_notice_given = 1;
	  }
	  field.value = 1;
	}
} // emptiesToOnes


function dropDecimals (field) {
// Drop decimals points and numbers from the field value
	var inputString = field.value;
	var decimalPoint = inputString.indexOf('.');
	
	if (decimalPoint == -1) {
		return;
	} else {
		// note to user, but only once
		displayPuntuationNotice();
		
		// drop decimal and trailing characters
		inputString = inputString.substring(0, decimalPoint);
		field.value = inputString;	
	}
} // dropDecimals



