﻿// calculations

function EquityTotal() {

var txPropVal
txPropVal = document.getElementById('txPropVal').value


var txMortLeft
txMortLeft = document.getElementById('txMortLeft').value


var txSecuredDebt
txSecuredDebt = document.getElementById('txSecuredDebt').value



var tEquity
tEquity = document.getElementById('txtTotalEquity')
tEquity.value = parseInt(txPropVal) -  (parseInt(txMortLeft) + parseInt(txSecuredDebt))


}

function setEnquity() {

tEquity = document.getElementById('txtTotalEquity').value;

Equity = document.getElementById('TotalEquity');

Equity.value=tEquity;
}







function DebtTotal(){

var txDebtOver
txDebtOver = document.getElementById('txDebtOver').value

var txDebtCC
txDebtCC = document.getElementById('txDebtCC').value

var txDebtUnsecured
txDebtUnsecured = document.getElementById('txDebtUnsecured').value

var txDebtStoreCards
txDebtStoreCards = document.getElementById('txDebtStoreCards').value

var txDebtCatalogues
txDebtCatalogues = document.getElementById('txDebtCatalogues').value

var txDebtOther
txDebtOther = document.getElementById('txDebtOther').value



var txTotalDebt
txTotalDebt = document.getElementById('txTotalDebt')

txTotalDebt.value =  parseInt(txDebtOver) +  parseInt(txDebtCC) +  parseInt(txDebtUnsecured) +  parseInt(txDebtStoreCards) +  parseInt(txDebtCatalogues) +  parseInt(txDebtOther)
}

function DebtorsTotal() {
var txCreditorsOver
txCreditorsOver = document.getElementById('txCreditorsOver').value

var txCreditorsCC
txCreditorsCC = document.getElementById('txCreditorsCC').value

var txCreditorsUnsecured
txCreditorsUnsecured = document.getElementById('txCreditorsUnsecured').value

var txCreditorsStoreCards
txCreditorsStoreCards = document.getElementById('txCreditorsStoreCards').value

var txCreditorsCatalogues
txCreditorsCatalogues = document.getElementById('txCreditorsCatalogues').value

var txCreditorsOther
txCreditorsOther = document.getElementById('txCreditorsOther').value



var txTotalCreditors
txTotalCreditors = document.getElementById('txTotalCreditors')

txTotalCreditors.value =  parseInt(txCreditorsOver) +  parseInt(txCreditorsCC) +  parseInt(txCreditorsUnsecured) +  parseInt(txCreditorsStoreCards) +  parseInt(txCreditorsCatalogues) +  parseInt(txCreditorsOther)
}


function setDebtAndCreditors() {

var txTotalDebt


txTotalDebt = document.getElementById('txTotalDebt').value;

TotalDebt = document.getElementById('TX_ApproxDebt');

TotalDebt.value=txTotalDebt;

var txTotalCreditors
txTotalCreditors = document.getElementById('txTotalCreditors').value;

TotalCreditors = document.getElementById('TX_Creditors');

TotalCreditors.value=txTotalCreditors;



}


///// Income functions



Event.observe(window, 'load', page_loaded, false);


function page_loaded() {
        $('TakeHomePay').observe('blur', calculateIncome); 
        $('TakeHomePayFreq').observe('blur', calculateIncome);
        $('PartnerTakeHomePay').observe('blur', calculateIncome);
        $('PartnerTakeHomePayFreq').observe('blur', calculateIncome);
        $('Childbenefit').observe('blur', calculateIncome);
        $('ChildbenefitFreq').observe('blur', calculateIncome);
        $('WorkingTaxCredit').observe('blur', calculateIncome);
        $('WorkingTaxCreditFreq').observe('blur', calculateIncome);
        $('Pension').observe('blur', calculateIncome);
        $('PensionFreq').observe('blur', calculateIncome);
        $('PartnerPension').observe('blur', calculateIncome);
        $('PartnerPensionFreq').observe('blur', calculateIncome);
        $('IncomeSupport').observe('blur', calculateIncome);
        $('IncomeSupportFreq').observe('blur', calculateIncome);
        $('JobseekersAllowance').observe('blur', calculateIncome);
        $('JobseekersAllowanceFreq').observe('blur', calculateIncome);
        $('IncapacityBenefit').observe('blur', calculateIncome);
        $('IncapacityBenefitFreq').observe('blur', calculateIncome);
        $('DLA_AA').observe('blur', calculateIncome);
        $('DLA_AAFreq').observe('blur', calculateIncome);
        $('ChildMaintenance').observe('blur', calculateIncome);
        $('ChildMaintenanceFreq').observe('blur', calculateIncome);
        $('OtherIncome').observe('blur', calculateIncome);
        $('OtherIncomeFreq').observe('blur', calculateIncome);
    }

    function calculateIncome(evt) {
        var totalMonthlyIncome = 0;
        totalMonthlyIncome += ((isNaN($F('TakeHomePay')) ? 0 : parseInt($F('TakeHomePay'))) * parseInt($F('TakeHomePayFreq')) / 12 );
        totalMonthlyIncome += ((isNaN($F('PartnerTakeHomePay')) ? 0 : parseInt($F('PartnerTakeHomePay'))) * parseInt($F('PartnerTakeHomePayFreq')) / 12 );
        totalMonthlyIncome += ((isNaN($F('Childbenefit')) ? 0 : parseInt($F('Childbenefit'))) * parseInt($F('ChildbenefitFreq')) / 12 );
        totalMonthlyIncome += ((isNaN($F('WorkingTaxCredit')) ? 0 : parseInt($F('WorkingTaxCredit'))) * parseInt($F('WorkingTaxCreditFreq')) / 12 );
        totalMonthlyIncome += ((isNaN($F('Pension')) ? 0 : parseInt($F('Pension'))) * parseInt($F('PensionFreq')) / 12 );
        totalMonthlyIncome += ((isNaN($F('PartnerPension')) ? 0 : parseInt($F('PartnerPension'))) * parseInt($F('PartnerPensionFreq')) / 12 );
        totalMonthlyIncome += ((isNaN($F('IncomeSupport')) ? 0 : parseInt($F('IncomeSupport'))) * parseInt($F('IncomeSupportFreq')) / 12 );
        totalMonthlyIncome += ((isNaN($F('JobseekersAllowance')) ? 0 : parseInt($F('JobseekersAllowance'))) * parseInt($F('JobseekersAllowanceFreq')) / 12 );
        totalMonthlyIncome += ((isNaN($F('IncapacityBenefit')) ? 0 : parseInt($F('IncapacityBenefit'))) * parseInt($F('IncapacityBenefitFreq')) / 12 );
        totalMonthlyIncome += ((isNaN($F('DLA_AA')) ? 0 : parseInt($F('DLA_AA'))) * parseInt($F('DLA_AAFreq')) / 12 );
        totalMonthlyIncome += ((isNaN($F('ChildMaintenance')) ? 0 : parseInt($F('ChildMaintenance'))) * parseInt($F('ChildMaintenanceFreq')) / 12 );
        totalMonthlyIncome += ((isNaN($F('OtherIncome')) ? 0 : parseInt($F('OtherIncome'))) * parseInt($F('OtherIncomeFreq')) / 12 );
        
    $('TotalMonthlyIncome').value = Math.round(totalMonthlyIncome);
    
}

function setIncome() {


var txTotalIncome


txTotalIncome = document.getElementById('TotalMonthlyIncome').value;

TotalIncome = document.getElementById('TXApproxIncome');

TotalIncome.value=txTotalIncome;

}


/// Outgoings

Event.observe(window, 'load', page_loaded2, false);

function page_loaded2(evt) {

    $('MortgageRent').observe('blur', calculateExpenditure2); 
    $('MortgageRentFreq').observe('blur', calculateExpenditure2);
    $('MortgageRentArrears').observe('blur', calculateExpenditure2); 
    $('MortgageRentArrearsFreq').observe('blur', calculateExpenditure2);
  
    $('Endowment').observe('blur', calculateExpenditure2); 
    $('EndowmentFreq').observe('blur', calculateExpenditure2);
    $('CouncilTax').observe('blur', calculateExpenditure2); 
    $('CouncilTaxFreq').observe('blur', calculateExpenditure2);
    $('WaterRates').observe('blur', calculateExpenditure2); 
    $('WaterRatesFreq').observe('blur', calculateExpenditure2);
    $('HouseBuildingInsurance').observe('blur', calculateExpenditure2); 
    $('HouseBuildingInsuranceFreq').observe('blur', calculateExpenditure2);
    $('Electricity').observe('blur', calculateExpenditure2); 
    $('ElectricityFreq').observe('blur', calculateExpenditure2);
    $('Gas').observe('blur', calculateExpenditure2); 
    $('GasFreq').observe('blur', calculateExpenditure2);
    $('Oil').observe('blur', calculateExpenditure2); 
    $('OilFreq').observe('blur', calculateExpenditure2);
    $('Telephone').observe('blur', calculateExpenditure2); 
    $('TelephoneFreq').observe('blur', calculateExpenditure2);
    $('MobilePhone').observe('blur', calculateExpenditure2); 
    $('MobilePhoneFreq').observe('blur', calculateExpenditure2);
    $('CarHirePurchase').observe('blur', calculateExpenditure2); 
    $('CarHirePurchaseFreq').observe('blur', calculateExpenditure2);
    $('CarInsurance').observe('blur', calculateExpenditure2); 
    $('CarInsuranceFreq').observe('blur', calculateExpenditure2);
    $('CarTax').observe('blur', calculateExpenditure2); 
    $('CarTaxFreq').observe('blur', calculateExpenditure2);
    $('CarMaintenance').observe('blur', calculateExpenditure2); 
    $('CarMaintenanceFreq').observe('blur', calculateExpenditure2);
    $('PetrolDiesel').observe('blur', calculateExpenditure2); 
    $('PetrolDieselFreq').observe('blur', calculateExpenditure2);
    $('Food').observe('blur', calculateExpenditure2); 
    $('FoodFreq').observe('blur', calculateExpenditure2);
    $('Clothing').observe('blur', calculateExpenditure2); 
    $('ClothingFreq').observe('blur', calculateExpenditure2);
    $('ChildSupport').observe('blur', calculateExpenditure2); 
    $('ChildSupportFreq').observe('blur', calculateExpenditure2);
    $('LifeInsurance').observe('blur', calculateExpenditure2); 
    $('LifeInsuranceFreq').observe('blur', calculateExpenditure2);
    $('ChildCare').observe('blur', calculateExpenditure2); 
    $('ChildCareFreq').observe('blur', calculateExpenditure2);
    $('Entertainment').observe('blur', calculateExpenditure2); 
    $('EntertainmentFreq').observe('blur', calculateExpenditure2);
    $('TransportTravel').observe('blur', calculateExpenditure2); 
    $('TransportTravelFreq').observe('blur', calculateExpenditure2);
    $('TvLicenseSkyCable').observe('blur', calculateExpenditure2); 
    $('TvLicenseSkyCableFreq').observe('blur', calculateExpenditure2);
    $('DentalPlan').observe('blur', calculateExpenditure2); 
    $('DentalPlanFreq').observe('blur', calculateExpenditure2);
    $('Opticians').observe('blur', calculateExpenditure2); 
    $('OpticiansFreq').observe('blur', calculateExpenditure2);
    $('MedicalCosts').observe('blur', calculateExpenditure2); 
    $('MedicalCostsFreq').observe('blur', calculateExpenditure2);
    $('Contingency').observe('blur', calculateExpenditure2); 
    $('ContingencyFreq').observe('blur', calculateExpenditure2);
    $('OutstandingFines').observe('blur', calculateExpenditure2); 
    $('OutstandingFinesFreq').observe('blur', calculateExpenditure2);
   $('StudentLoans').observe('blur', calculateExpenditure2); 
  
    $('Other').observe('blur', calculateExpenditure2); 
    $('OtherFreq').observe('blur', calculateExpenditure2);
}

function calculateExpenditure2(evt) {

    var totalExpenditure = 0;
    totalExpenditure += ((isNaN($F('MortgageRent')) ? 0 : parseInt($F('MortgageRent'))) * parseInt($F('MortgageRentFreq')) / 12 );
   totalExpenditure += ((isNaN($F('MortgageRentArrears')) ? 0 : parseInt($F('MortgageRentArrears'))) * parseInt($F('MortgageRentArrearsFreq')) / 12 );
   
    totalExpenditure += ((isNaN($F('Endowment')) ? 0 : parseInt($F('Endowment'))) * parseInt($F('EndowmentFreq')) / 12 );
    totalExpenditure += ((isNaN($F('CouncilTax')) ? 0 : parseInt($F('CouncilTax'))) * parseInt($F('CouncilTaxFreq')) / 12 );
  totalExpenditure += ((isNaN($F('WaterRates')) ? 0 : parseInt($F('WaterRates'))) * parseInt($F('WaterRatesFreq')) / 12 );
   totalExpenditure += ((isNaN($F('HouseBuildingInsurance')) ? 0 : parseInt($F('HouseBuildingInsurance'))) * parseInt($F('HouseBuildingInsuranceFreq')) / 12 );
  totalExpenditure += ((isNaN($F('Electricity')) ? 0 : parseInt($F('Electricity'))) * parseInt($F('ElectricityFreq')) / 12 );
 totalExpenditure += ((isNaN($F('Gas')) ? 0 : parseInt($F('Gas'))) * parseInt($F('GasFreq')) / 12 );
    totalExpenditure += ((isNaN($F('Oil')) ? 0 : parseInt($F('Oil'))) * parseInt($F('OilFreq')) / 12 );
   totalExpenditure += ((isNaN($F('Telephone')) ? 0 : parseInt($F('Telephone'))) * parseInt($F('TelephoneFreq')) / 12 );
    totalExpenditure += ((isNaN($F('MobilePhone')) ? 0 : parseInt($F('MobilePhone'))) * parseInt($F('MobilePhoneFreq')) / 12 );
    totalExpenditure += ((isNaN($F('CarHirePurchase')) ? 0 : parseInt($F('CarHirePurchase'))) * parseInt($F('CarHirePurchaseFreq')) / 12 );
    totalExpenditure += ((isNaN($F('CarInsurance')) ? 0 : parseInt($F('CarInsurance'))) * parseInt($F('CarInsuranceFreq')) / 12 );
   totalExpenditure += ((isNaN($F('CarTax')) ? 0 : parseInt($F('CarTax'))) * parseInt($F('CarTaxFreq')) / 12 );
    totalExpenditure += ((isNaN($F('CarMaintenance')) ? 0 : parseInt($F('CarMaintenance'))) * parseInt($F('CarMaintenanceFreq')) / 12 );
   totalExpenditure += ((isNaN($F('PetrolDiesel')) ? 0 : parseInt($F('PetrolDiesel'))) * parseInt($F('PetrolDieselFreq')) / 12 );
    totalExpenditure += ((isNaN($F('Food')) ? 0 : parseInt($F('Food'))) * parseInt($F('FoodFreq')) / 12 );
 totalExpenditure += ((isNaN($F('Clothing')) ? 0 : parseInt($F('Clothing'))) * parseInt($F('ClothingFreq')) / 12 );
   totalExpenditure += ((isNaN($F('ChildSupport')) ? 0 : parseInt($F('ChildSupport'))) * parseInt($F('ChildSupportFreq')) / 12 );
   totalExpenditure += ((isNaN($F('LifeInsurance')) ? 0 : parseInt($F('LifeInsurance'))) * parseInt($F('LifeInsuranceFreq')) / 12 );
   totalExpenditure += ((isNaN($F('ChildCare')) ? 0 : parseInt($F('ChildCare'))) * parseInt($F('ChildCareFreq')) / 12 );
   totalExpenditure += ((isNaN($F('Entertainment')) ? 0 : parseInt($F('Entertainment'))) * parseInt($F('EntertainmentFreq')) / 12 );
  totalExpenditure += ((isNaN($F('TransportTravel')) ? 0 : parseInt($F('TransportTravel'))) * parseInt($F('TransportTravelFreq')) / 12 );
    totalExpenditure += ((isNaN($F('TvLicenseSkyCable')) ? 0 : parseInt($F('TvLicenseSkyCable'))) * parseInt($F('TvLicenseSkyCableFreq')) / 12 );
   totalExpenditure += ((isNaN($F('DentalPlan')) ? 0 : parseInt($F('DentalPlan'))) * parseInt($F('DentalPlanFreq')) / 12 );
    totalExpenditure += ((isNaN($F('Opticians')) ? 0 : parseInt($F('Opticians'))) * parseInt($F('OpticiansFreq')) / 12 );
    totalExpenditure += ((isNaN($F('MedicalCosts')) ? 0 : parseInt($F('MedicalCosts'))) * parseInt($F('MedicalCostsFreq')) / 12 );
    totalExpenditure += ((isNaN($F('Contingency')) ? 0 : parseInt($F('Contingency'))) * parseInt($F('ContingencyFreq')) / 12 );
  totalExpenditure += ((isNaN($F('OutstandingFines')) ? 0 : parseInt($F('OutstandingFines'))) * parseInt($F('OutstandingFinesFreq')) / 12 );
 
   totalExpenditure += ((isNaN($F('Other')) ? 0 : parseInt($F('Other'))) * parseInt($F('OtherFreq')) / 12 );
    
    $('TotalExpenditure').value = Math.round(totalExpenditure);
    
}




//// Outgoings - Repayments

Event.observe(window, 'load', page_loaded3, false);

function page_loaded3(evt) {
   $('LoansNoMort').observe('blur', calculateExpenditure3); 
    $('LoansNoMortFreq').observe('blur', calculateExpenditure3);
    
       $('CreditStoreCards').observe('blur', calculateExpenditure3); 
    $('CreditStoreCardsFreq').observe('blur', calculateExpenditure3);
   
    
   $('StudentLoans').observe('blur', calculateExpenditure3); 
    $('StudentLoansFreq').observe('blur', calculateExpenditure3);
}

function calculateExpenditure3(evt) {

    var totalExpenditure = 0;
  
   totalExpenditure += ((isNaN($F('LoansNoMort')) ? 0 : parseInt($F('LoansNoMort'))) * parseInt($F('LoansNoMortFreq')) / 12 );
   
     totalExpenditure += ((isNaN($F('CreditStoreCards')) ? 0 : parseInt($F('CreditStoreCards'))) * parseInt($F('CreditStoreCardsFreq')) / 12 );
  
  totalExpenditure += ((isNaN($F('StudentLoans')) ? 0 : parseInt($F('StudentLoans'))) * parseInt($F('StudentLoansFreq')) / 12 );
  

    
    $('TotalRepayments').value = Math.round(totalExpenditure);
    
}

function setOutgoing() {


var txTotalExpenditure


txTotalExpenditure = document.getElementById('TotalExpenditure').value;

TotalExpenditure = document.getElementById('txOutgoings');

TotalExpenditure.value=txTotalExpenditure;

}

function setOutgoingLoans() {
var txTotalLoans


txTotalLoans = document.getElementById('TotalRepayments').value;

TotalRepayments = document.getElementById('txOutgoingsLoans');

TotalRepayments.value=txTotalLoans;

}
