function calcFigures()
{
	
	GPI = document.mmcc.GPI.value-0
	VUpercent = document.mmcc.VUpercent.value-0
	VU = Math.round((GPI*VUpercent)/100)
	EGI = GPI-VU
	
	document.mmcc.VU.value = VU
	document.mmcc.EGI.value = EGI
	
	Taxes = document.mmcc.Taxes.value-0
	Insurance = document.mmcc.Insurance.value-0
	Utilities = document.mmcc.Utilities.value-0
	Management = document.mmcc.Management.value-0
	Trash = document.mmcc.Trash.value-0
	Maintenance = document.mmcc.Maintenance.value-0
	Janitorial = document.mmcc.Janitorial.value-0
	Administrative = document.mmcc.Administrative.value-0
	Miscellaneous = document.mmcc.Miscellaneous.value-0
	
	pcGPI = Math.round(GPI*0.05)
	
	if (Management<pcGPI)
	{
		Management = Math.round(EGI*0.05)
		document.mmcc.Management.value = Management
	}	
	
	TOE = Taxes+Insurance+Utilities+Management+Trash+Maintenance+Janitorial+Administrative+Miscellaneous	
	NOI = EGI-TOE
	pcGPI = Math.round((TOE/GPI)*100)
	
	document.mmcc.TOE.value = TOE
	document.mmcc.NOI.value = NOI
	
	pcGPITest = pcGPI/pcGPI
	
	if(!isNaN(pcGPITest))
	{	
		document.mmcc.pcGPI.value = pcGPI
	} else	{
		document.mmcc.pcGPI.value = 0
	}
	
	TotalSqFt = document.mmcc.TotalSqFt.value
	CapitalReservesUnit = document.mmcc.CapitalReservesUnit.value	
	TIRunit = document.mmcc.TIRunit.value	
	LCRunit = document.mmcc.LCRunit.value 
	CapitalReserves = Math.round(TotalSqFt*CapitalReservesUnit)
	TIR = Math.round(TotalSqFt*TIRunit)
	LCR = Math.round(TotalSqFt*LCRunit)
	BLE = CapitalReserves+TIR+LCR
	CashFlowDebtServices = NOI-BLE
		
	document.mmcc.CapitalReserves.value = CapitalReserves	
	document.mmcc.TIR.value = TIR	
	document.mmcc.LCR.value = LCR
	document.mmcc.BLE.value = BLE	
	document.mmcc.CashFlowDebtServices.value = CashFlowDebtServices
		
	InterestRate = document.mmcc.InterestRate.value-0
	RepaymentSchedule = document.mmcc.RepaymentSchedule.value-0
	DebtService = document.mmcc.DebtService.value-0

	
	rate = (InterestRate/12)/100
	NPER = RepaymentSchedule * 12
	PV = -100
	FV = 0
	ptype = 0
	
	powRate = Math.pow(1+rate,NPER)	
	PMT  = (rate*(FV+PV*(powRate)))/((1+rate*ptype)*(1-(powRate)))*12
	pmtRev = format_number(PMT,2)
	//alert(test)
	//PMT  = (irate*(FV+PV*powRate)
	///((1+rate*ptype)*(1-powRate)*12
	//PMT = formatNumber(PMT,2)	
	valTest = pmtRev/pmtRev
	
	if(!isNaN(valTest))
	{	
		document.mmcc.LoanAmount.value = Math.round((NOI/DebtService/pmtRev)*100)
	} else	{
		document.mmcc.LoanAmount.value = 0
	}


}

function format_number(pnumber,decimals){ 
if (isNaN(pnumber)) { return 0}; 
if (pnumber=='') { return 0}; 

var snum = new String(pnumber); 
var sec = snum.split('.'); 
var whole = parseFloat(sec[0]); 
var result = ''; 

if(sec.length > 1){ 
var dec = new String(sec[1]); 
dec = String(parseFloat(sec[1])/Math.pow(10,(dec.length - decimals))); 
dec = String(whole + Math.round(parseFloat(dec))/Math.pow(10,decimals)); 
var dot = dec.indexOf('.'); 
if(dot == -1){ 
dec += '.'; 
dot = dec.indexOf('.'); 
} 
while(dec.length <= dot + decimals) { dec += '0'; } 
result = dec; 
} else{ 
var dot; 
var dec = new String(whole); 
dec += '.'; 
dot = dec.indexOf('.'); 
while(dec.length <= dot + decimals) { dec += '0'; } 
result = dec; 
} 
return result; 
} 
