<!--
function replace(s, F, R) {
	var find = 0;
	var start = 0
	while (find != -1) {
		find = s.indexOf(F, start);
		if (find != -1) {
			s = s.substring(0,find) + R + s.substring(find + F.length);
			start = find + R.length;
		}
	}
	return s;
}

function clean(s) {
	if (!s) return s;
	s = replace(s, '$', '');
	s = replace(s, ',', '');
	s = replace(s, '%', '');	
	return s;
}

function checkamt(elem, dec, disp) {
	if ((elem.value == null) || (elem.value.length==0)) elem.value = 0
	value = parseFloat(clean(elem.value));
	if (isNaN(value)) {
		if (disp) alert('You have entered an incorrect character in this field. \nPlease check your information and try again.');
		elem.focus();
		return false;
	}
	elem.value = FmtMoney(value,dec)
	return true
}

function checknum(elem, dec, disp) {
	if ((elem.value == null) || (elem.value.length==0)) elem.value = 0
	value = parseInt(clean(elem.value));
	if (isNaN(value)) {
		if (disp) alert('You have entered an incorrect character in this field. \nPlease check your information and try again.');
		elem.focus();
		return false;
	}
	elem.value = value
	return true
}

function checkrate(elem, disp) {
	if ((elem.value == null) || (elem.value.length==0)) elem.value = "0%";
	value = parseFloat(clean(elem.value));
	if (isNaN(value)) {
		if (disp) alert('You have entered an incorrect character in this field. \nPlease check your information and try again.');
		elem.focus();
		return false;
	}
	if ((value<1) || (value>99)) {
		if (disp) alert('You have exceeded the range for some information on this tab. \nPlease check your information and try again.');
		elem.focus();
		return false;
	}
	elem.value = FmtRate(value)
	return true
}

function FmtRate(A) {
	N=Math.abs(Math.round(A*1000));
	S=((N<10)?"00":((N<100)?"0":""))+N;
	S=S.substring(0,(S.length-3))+"."+S.substring((S.length-3),S.length)+"%";
	return S;
}

function FmtMoney(A,D) {
	N=Math.abs(Math.round(A*100));
	S=((N<10)?"00":((N<100)?"0":""))+N;
	S=((A<0)?"-":"")+"$"+WGgroup(S.substring(0,(S.length-2))) + 
	      ((D>0)?"."+S.substring((S.length-2),S.length):"");
	return S;
}

function WGgroup(S) {
	return (S.length<4)?S:(WGgroup(S.substring(0,S.length-3))+","+S.substring(S.length-3,S.length));
}

function pmtCalc(rate, nper, pv, fv) {	
	if (isNaN(rate) || isNaN(nper)) return ""
	if (rate==0) 
		rVal=-(fv + pv)/nper;
	else {
		ir = Math.pow(1+rate,nper);
		rVal=-((rate * (fv + ir * pv))/(ir-1));
	}
	return rVal;
}

function loanCalc(rate, nper, pmt, fv) {	
	if (isNaN(rate) || isNaN(nper)) return ""
	if (rate==0) 
		rVal=-(pmt* nper) - fv;
	else {
		ir = Math.pow(1+rate,nper);
		rVal=-(((pmt*(ir-1)/rate) - fv)/ir);
	}
	return rVal;
}
//-->
