function calculate(){
	var fail = countValidators('.validation-failed','more',0,'There are some files which did not validate');
	var pass = countValidators('.validation-passed','less',1,'There were some blank fields, please fill in all required elements');
	if(pass && fail){
	//set variables to calculate
		pp = parseFloat($F('PurchasePrice'));
		dp = parseFloat($F('DownPayment'));
		if(isNaN(dp))dp=0;
		ti = parseFloat($F('TradeIn'));
		if(isNaN(ti))ti=0;
		lp = parseFloat($F('LeinPayout'));
		if(isNaN(lp))lp=0;
		rv = parseFloat($F('ResidualValue'));
		if(isNaN(rv))rv=0;
		tm = parseInt($F('Term'));
		ir = parseFloat($F('InterestRate'))/100;
		tx = parseFloat(1.13); //tax

	// calculate loan
		if( ti > 0 ) adt = pp - ti + lp;
		else adt = pp;
		adt = adt - dp;
		if( adt < 0 ){ 
			alert("The sum of Down Payment and Trade In should not be larger than the Purchase Price");
			return false;; }
		if( ir > 1.15 ){
			alert("The Interest Rate should not be larger than 15%");
			return false; }
		
	// here monthly payment
		adt = adt * tx; //add tax
		lmp = (adt * (ir/12) * Math.pow((1+ir/12), tm))/((Math.pow((1+ir/12), tm)) - 1 );
		lmp = Math.round(lmp*100)/100;
		strlmp = "$" + lmp; 
		$('LoanPayment').setValue(strlmp);
	
	// calculate lease
		if (rv > 0) {
			adt = pp - ti - dp - rv;
			if( adt < 0 ){ 
			  alert("The sum of Down Payment, Trade In, and Residual Value should not be larger than the Purchase Price");
			  $('LeasePayment').setValue(" ");
			  //theform.LeasePayment.value = "";
			  return false; 
			}
		  dp = dp + ti - lp;
		  iMonthlyLease = ((((pp - dp + rv) * tx) *  ir) / 24) + (pp - dp - rv) / tm;
		  iMonthlyLease = Math.round(iMonthlyLease * 100)/100;
		  $('LeasePayment').setValue("$" + iMonthlyLease);
		  return false;
		}else{$('LeasePayment').setValue('insert ')}
	}
}
function countValidators(selector,ltgt, max, message){
	var validators = $$(selector);
	if(ltgt=='more'){
		if(validators.size() > max){alert(message);return false;}
	}else{
		if(validators.size() < max){alert(message);return false;}
	}
	return true;
}


