// JavaScript Document

function calculate() {
    // Get the user's input from the form. Assume it is all valid.
    // Convert interest from a percentage to a decimal, and convert from
    // an annual rate to a monthly rate. Convert payment period in years
    // to the number of monthly payments.
    
	//var monthlypayment = document.loandata.monthlypayment.value;
    
	var maintenancefees = document.loandata.maintenancefees.value;
    var peryear = document.loandata.peryear.value;
 
 
 
//MFM
    var MemebershipDues = document.loandata.membershipdues.value;
    var ExchangeFees = document.loandata.exchangefees.value;
 
    // Now compute the monthly payment figure, using esoteric math.
   // var x = Math.pow(1 + interest, payments);
  //  var monthly = (principal*x*interest)/(x-1);
 
//var monthlypaymentx12months = (monthlypayment * 12);
 
var maintenancex12months = (maintenancefees * peryear);
var paymentandmaintenance = ( maintenancex12months); //monthlypaymentx12months +
 
//var yearlypaymentx15years = (monthlypaymentx12months *15);
 
var yearlymaintenancex15years = (((maintenancefees*peryear) *15)*1.999); //1.55133
 
var total15yearpaymentandmaintenance = ( yearlymaintenancex15years); //round(yearlypaymentx15years) + 
 
 
//MFM
var MembershipDuesExchangeFeesx15 = (round(MemebershipDues) + round(ExchangeFees)) * 15;
var AnnualTimeShareCost = round(((round(yearlymaintenancex15years) + round(MembershipDuesExchangeFeesx15))/15)); //round(yearlypaymentx15years) + 
 
 
    // Check that the result is a finite number. If so, display the results
   // if (!isNaN(monthly) &&
      //  (monthly != Number.POSITIVE_INFINITY) &&
    //    (monthly != Number.NEGATIVE_INFINITY)) {
        
		//document.loandata.monthlypaymentx12months.value = round(monthlypaymentx12months);
        
		document.loandata.maintenancex12months.value = round(maintenancex12months);
		//document.loandata.paymentandmaintenance.value = round(paymentandmaintenance);
		
		//document.loandata.yearlypaymentx15years.value = round(yearlypaymentx15years);
		
		document.loandata.yearlymaintenancex15years.value = round(yearlymaintenancex15years);
		document.loandata.total15yearpaymentandmaintenance.value = round(total15yearpaymentandmaintenance);
 
		// MFM
		document.loandata.total15yearpaymentandmaintenance.value = round( round(yearlymaintenancex15years) + round(MembershipDuesExchangeFeesx15)); //round(yearlypaymentx15years) +
	    document.loandata.membershipplusexchangex15years.value = round(MembershipDuesExchangeFeesx15);
	    document.loandata.anualtimesharevacationcost.value = AnnualTimeShareCost;
 
 
 
  //  }
    // Otherwise, the user's input was probably invalid, so don't
    // display anything.
 //   else {
   //     document.loandata.payment.value = "nope";
    //   document.loandata.total.value = "nope";
//        document.loandata.totalinterest.value = "nope";
 //   }
}
 
// This simple method rounds a number to two decimal places.
function round(x) {
  return Math.round(x*100)/100;
}
