

function jhcs_ValidatorOnSubmit() {
	if ( typeof(getAspForm) != "function" ) { alert( 'no aspform' ); return false; }
	if (!theForm) { getAspForm(); }
	
	if ( !theForm ) { alert( 'no form' ); return false; }
	
	var tab = 0;
	if (theForm.csf_currentTab) { tab = theForm.csf_currentTab.value }
	switch (tab) {
		case "1":   return validateTab1( theForm ); break;
		case "2":   return true; break;
		default:  return false;
	}
}

function getCheckedValue(radioObj) {
	if(!radioObj) return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked) return radioObj.value;  else return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) return radioObj[i].value;
	}
	return "";
}

function validateTab1( frm ) {

	
	f = frm.csf_currentAge;
	var age= f.value;
	var ageI = parseFloat( age );
	if ( !( isInteger( age ) && ( 0 <= ageI ) && ( ageI < 100 ) ) )  {
		return warnInvalid( f, "Please enter the child's current age." ); 
	}
	f.value = ageI;
	
	
	f = frm.csf_collegeAge;
	var cage = f.value;
	var cageI = parseFloat( cage );
	if ( !( isInteger( cage ) && 0 <= cageI && 100 > cageI ) ) {
		return warnInvalid( f, "Please enter the child's age when entering college." ); 
	}	
	f.value = cageI;
	
	if ( (cageI <= ageI) || (cageI > 50 + ageI) ) {
		return warnInvalid( f, "Please enter a college age which is greater than the child's current age by at most 50 years." ); 
	}

	
	var ct = getCheckedValue( frm.csf_SelectInOutState );
	if ( ct != 1 && ct != 2 ) 
		{
		alert(" Please select the type of college the child will attend.");
		frm.csf_SelectInOutState[0].focus();
		return false;
	}
		
	
	f = frm.csf_yearsOfCollege;
	var yc = f.value;
	var ycI = parseFloat( yc );

	if ( !( isInteger( yc ) && ( 0 < ycI ) && ( ycI < 10 ) ) ) {
		return warnInvalid( f, "Please enter a positive number between 1 and 9 for Number of Years Child Plans to Attend college." ); 
	}
	f.value = ycI;
	

	
	f = frm.csf_alreadyInvested;
	var inv = f.value;
	var invI = parseFloat( inv );
	
	if ( isEmpty( inv ) ) { inv = 0; f.value = 0; } 
	if ( !( isInteger( inv ) && ( 0 <= invI ) && ( invI < 1000000 ) ) ) {
		return warnInvalid( f, "Please enter a positive number without commas for dollar amount already invested." ); 
	}
	f.value = invI;

	
	
	f = frm.csf_expectedPercent;
	
	var rr = f.value;
	var rrF = parseFloat( rr );
	var msg1 = "Please enter a positive number for expected rate of return.  NOTE: This Calculator assumes the same rate of return on both amounts already invested and the savings alternatives to fully fund your future college costs.";
	var msg2 = " You have entered an expected return on investment of over 11%.  Long term stock market returns average about 11%.  Estimating a return much over this amount may be too aggressive.  NOTE: This Calculator assumes the same rate of return on both amounts already invested and the savings alternatives to fully fund your future college costs.";
	if ( !( isFloat( rr ) ) ) {
		return warnInvalid( f, msg1 ); 
	} else {
		if ( rrF < 0.0001 ) {
			return warnInvalid( f, msg1 ); 
		}
	
		if ( rrF > 11.00 ) {
			return warnInvalid( f, msg2 ); 
		}
	}
	f.value = rrF;
	
	return true;
}

function validateTab1Old ( frm ) {
	
	var ct = getCheckedValue( frm.csf_SelectInOutState );
	
	if ((frm.csf_currentAge.value < 0) || isNaN(frm.csf_currentAge.value) || frm.csf_currentAge.value == "")
		{
		alert("Please enter the child's current age.");
		frm.csf_currentAge.value="";
		frm.csf_currentAge.focus();
		return false;
		}
	else if ( isNaN(frm.csf_collegeAge.value)
	            || ( (parseInt(frm.csf_collegeAge.value,10)) <= (parseInt(frm.csf_currentAge.value,10)) )
				|| (frm.csf_collegeAge.value == "")
			)
		{
		alert("Please enter a positive number for Age When Entering College which is greater than the child's current age.");
		frm.csf_collegeAge.value="";
		frm.csf_collegeAge.focus();
		return false;
		}
	else if ( ct != 1 && ct != 2 ) 
		{
		alert(" Please select the type of college the child will attend.");
		frm.csf_SelectInOutState[0].focus();
		return false;
		}
	else if ( isNaN(frm.csf_yearsOfCollege.value) 
				|| (frm.csf_yearsOfCollege.value < 1)
				|| (frm.csf_yearsOfCollege.value > 9)
				|| (frm.csf_yearsOfCollege.value == "")
			)
		{
		alert("Please enter a positive number between 1 and 9 for Number of Years Child Plans to Attend college.");
		frm.csf_yearsOfCollege.value="";
		frm.csf_yearsOfCollege.focus();
		return false;
		}
	else if(isNaN(frm.csf_alreadyInvested.value) || (frm.csf_alreadyInvested.value < 0))
		{
		alert("Please enter a positive number without commas for dollar amount already invested.");
		frm.csf_alreadyInvested.value="";
		return false;
		}
	else if ((frm.csf_expectedPercent.value < 0.0001) || isNaN(frm.csf_expectedPercent.value))
		{
		alert("Please enter a positive number for expected rate of return.  NOTE: This Calculator assumes the same rate of return on both amounts already invested and the savings alternatives to fully fund your future college costs.");
		frm.csf_expectedPercent.value="";
		frm.csf_expectedPercent.focus();
		return false;
		}
	else if (frm.csf_expectedPercent.value > 11)
		{
		frm.csf_expectedPercent.value="";
		alert(" You have entered an expected return on investment of over 11%.  Long term stock market returns average about 11%.  Estimating a return much over this amount may be too aggressive.  NOTE: This Calculator assumes the same rate of return on both amounts already invested and the savings alternatives to fully fund your future college costs.");
		frm.csf_expectedPercent.value="";
		frm.csf_expectedPercent.focus();
		return false;
		}
	else 
		{
		return true;
		}
}

