﻿function Display(client)
{
  Effect.Appear($(client), {delay: 0, duration: 1});
}

function Hide(client)
{
  Effect.Fade($(client), {delay: 0, duration: .6});
}

//-------------------------------------------------------------------------------------
// Used in RiskProfile.aspx
//-------------------------------------------------------------------------------------
function CalculateRiskTotal(elementID)
{
  // get the form
  var frmRP = document.frmRiskProfile;
  
  var intCurrentTotal = parseInt(frmRP.riskTotal.value);
  
  // split the current elements identifier
  var arrCurrent = elementID.split('|');
  
  var intCurrentRow = parseInt(arrCurrent[1]);

  var intCurrentValue = parseInt(document.getElementById(elementID).value);

  for (var i = 0; i < frmRP.length; i++)
  {
    if (frmRP.elements[i].type == 'checkbox')
    {
      var arrBits = frmRP.elements[i].id.split('|');
      
      var intCurrentElementRow = arrBits[1];
      
      if (intCurrentElementRow == intCurrentRow)
      {
        // elements differ
        if (elementID != frmRP.elements[i].id)
        {
          if (frmRP.elements[i].checked == true)
          {
            frmRP.elements[i].checked = false;
          
            intCurrentTotal -= parseInt(frmRP.elements[i].value);
          }
        }
      }
    }
  }

  document.getElementById(elementID).checked = true;

  intCurrentTotal += intCurrentValue;
  
  frmRP.riskTotal.value = "";
  
  frmRP.riskTotal.value = intCurrentTotal;
}

function docalc() 
{
  var x=document.getElementById("calc");
  var months = Number(x.time.value);
  var amt = Number(x.ammount.value);
  var years = (months / 12);
  var an = (amt * 0.129);
  var repay =  (parseInt(amt) +  parseInt((years * an)));
  var repaymo = Math.floor(repay / months);
  x.repay.value = repaymo;
  x.repaytotal.value = repaymo*months;
}

function computerepvsinv() 
{ 
  alert("These figures are only illustrative. An assessment of your needs will be confirmed before a recommendation can be made. Key features, including a projection which is personal to your circumstances, will be provided if a recommendation for an investment product is made.")

  //set up data
  var payment=0;
  var x=0;

  // AMC=1.02;;
  var ir=1+(document.repvsinv.ir.value/100);
  var term=document.repvsinv.term.value*12;
  var mortgage=document.repvsinv.mortgage.value;
  var investgrowth=(1+(document.repvsinv.investgrowth.value/100))*0.9896;

  //deal with growth over 9%
  if (document.repvsinv.investgrowth.value>9){
  alert("Your chosen growth rate is considered too high and cannot be processed. At present the maximium growth rates considered reasonable by the Financial Services Industry Regulators are 9% for tax efficient investments, 8% for the rest. Middle of the road rates are 7% for tax efficient investments, 6% for the rest.");
  payment=0;
  mortgage=0;
}

  //deal with growth over 7.5%
  if (document.repvsinv.investgrowth.value>7.5 && document.repvsinv.investgrowth.value<9.00001){
alert("You are being too optimistic about future growth. We can show you the results you request, but frankly, you shouldn't do any serious planning on this basis. Much better to be more cautious and use a lower growth rate.");
}

//compute repayment mortgage maths

ir=Math.pow(ir,(1/12));


// create mortage output

mortgageout=mortgage;
document.repvsinv.mortgageout.value=mortgageout;

//r^n, and repayment math

x=Math.pow(ir,term);
if(x==1){payment=mortgage/term
}else
{ 
payment=((mortgage*x)*(1-ir))/(1-x)
}

document.repvsinv.payment.value=Math.round(payment*100)/100;

//total paid over the term
totalrepayment=Math.round(term*payment*100)/100;
document.repvsinv.totalrepayment.value=Math.round(totalrepayment);

//investment math
//determine the a value for a geometric progression whose final fund is the mortgage

investgrowthstd=investgrowth;
//avoid getting zeros by fudging
if(investgrowthstd==1){investgrowthstd=investgrowthstd+0.001};

investgrowthstd=Math.pow(investgrowthstd,(1/12));
monthlyinvestment=mortgage*((investgrowthstd-1)/(Math.pow(investgrowthstd,term)-1));

// create a for geometric progression. 
a=monthlyinvestment;

document.repvsinv.monthlyinvestment.value=Math.round(monthlyinvestment*100)/100;

// determine the monthly interest payment for investment mortgage

monthlyinterest=mortgage*(document.repvsinv.ir.value/100)/12;
document.repvsinv.monthlyinterest.value=Math.round(monthlyinterest*100)/100;

//determine total investment and interest for investment mortgage

monthlycostinvestmentmortgage=monthlyinterest+monthlyinvestment;
document.repvsinv.monthlycostinvestmentmortgage.value=Math.round(monthlycostinvestmentmortgage*100)/100;

// determine total global cost of investment mortgage

totalcostinvestment=monthlycostinvestmentmortgage*term;
document.repvsinv.totalcostinvestment.value=Math.round(totalcostinvestment*100)/100;

// determine future fund value if growth 2% better pa than expected
// avoid zeros leading to NaN errors by fudging when they will appear

investgrowth2more=investgrowth+0.02;
if(investgrowth2more==1){investgrowth2more=0.999}else{ 
investgrowth2more=Math.pow(investgrowth2more,(1/12))}


futurefund2more=(a*(1-Math.pow(investgrowth2more,term)))/(1-investgrowth2more);
document.repvsinv.futurefund2more.value=Math.round(futurefund2more);

// determine future fund value if growth 4% better pa than expected
// avoid zeros leading to NaN errors by fudging when they will appear

investgrowth4more=investgrowth+0.04;
if(investgrowth4more==1){investgrowth4more=0.999}else{ 
investgrowth4more=Math.pow(investgrowth4more,(1/12))}


futurefund4more=(a*(1-Math.pow(investgrowth4more,term)))/(1-investgrowth4more);
document.repvsinv.futurefund4more.value=Math.round(futurefund4more);

// determine future fund value if growth 6% better pa than expected
// avoid zeros leading to NaN errors by fudging when they will appear

investgrowth6more=investgrowth+0.06;
if(investgrowth6more==1){investgrowth6more=0.999}else{ 
investgrowth6more=Math.pow(investgrowth6more,(1/12))}


futurefund6more=(a*(1-Math.pow(investgrowth6more,term)))/(1-investgrowth6more);
document.repvsinv.futurefund6more.value=Math.round(futurefund6more);


// determine future fund value if growth 2% less pa than expected
// avoid zeros leading to NaN errors by fudging when they will appear

investgrowth2less=investgrowth-0.02;
if(investgrowth2less==1){investgrowth2less=0.999}else{ 
investgrowth2less=Math.pow(investgrowth2less,(1/12))}


futurefund2less=(a*(1-Math.pow(investgrowth2less,term)))/(1-investgrowth2less);
document.repvsinv.futurefund2less.value=Math.round(futurefund2less);

// determine future fund value if growth 4% less pa than expected
// avoid zeros leading to NaN errors by fudging when they will appear

investgrowth4less=investgrowth-0.04;
if(investgrowth4less==1){investgrowth4less=0.999}else{ 
investgrowth4less=Math.pow(investgrowth4less,(1/12))}

futurefund4less=(a*(1-Math.pow(investgrowth4less,term)))/(1-investgrowth4less);
document.repvsinv.futurefund4less.value=Math.round(futurefund4less);


// determine future fund value if growth 6% less pa than expected
// avoid zeros leading to NaN errors by fudging when they will appear

investgrowth6less=investgrowth-0.06;
if(investgrowth6less==1){investgrowth6less=0.999}else{ 
investgrowth6less=Math.pow(investgrowth6less,(1/12))}


futurefund6less=(a*(1-Math.pow(investgrowth6less,term)))/(1-investgrowth6less);
document.repvsinv.futurefund6less.value=Math.round(futurefund6less);

// compute net gain/loss scenarios

costcomparedstd=totalrepayment-totalcostinvestment;
document.repvsinv.costcomparedstd.value=Math.round(costcomparedstd);

costcompared2more=(totalrepayment-totalcostinvestment)+futurefund2more-mortgage;
document.repvsinv.costcompared2more.value=Math.round(costcompared2more);

costcompared4more=(totalrepayment-totalcostinvestment)+futurefund4more-mortgage;
document.repvsinv.costcompared4more.value=Math.round(costcompared4more);

costcompared6more=(totalrepayment-totalcostinvestment)+futurefund6more-mortgage;
document.repvsinv.costcompared6more.value=Math.round(costcompared6more);

costcompared2less=(totalrepayment-totalcostinvestment)+futurefund2less-mortgage;
document.repvsinv.costcompared2less.value=Math.round(costcompared2less);

costcompared4less=(totalrepayment-totalcostinvestment)+futurefund4less-mortgage;
document.repvsinv.costcompared4less.value=Math.round(costcompared4less);

costcompared6less=(totalrepayment-totalcostinvestment)+futurefund6less-mortgage;
document.repvsinv.costcompared6less.value=Math.round(costcompared6less);

}

//clears form
    function clearrepvsinv() { 
        
    }

function computeflexmort() { 

      // maths et al to be computed    
// interest is ^(1/12) of the annual interest

var mortgage=parseInt(document.flexmort.mortgage.value);
var payment1=parseInt(document.flexmort.payment1.value*100)/100;
var payment2=parseInt(document.flexmort.payment2.value*100)/100;
var interest=parseInt(document.flexmort.interest.value*100);
var interest=(interest/10000)+1;
var interest=Math.pow(interest,(1/12));


//initial conditions
//parseInt(0.001) is a way of setting at zero

var debt1=mortgage;
var debt2=mortgage;
var totalp1=parseInt(0.001);
var totalp2=parseInt(0.001);


for (var month=1; month<=12; month++){   

// math for paying off over full term

debt1=(debt1*interest)-payment1;
totalp1=payment1+totalp1;
if(debt1<0){debt1=0; totalp1=0}else{debt1=debt1+0}

// math for paying off asap

debt2=(debt2*interest)-payment2;
totalp2=payment2+totalp2;
if(debt2<0){debt2=0; totalp2=0}else{debt2=debt2+0}


} 

//set output values

document.flexmort.term1debt1.value=Math.round(debt1);
document.flexmort.term1totalp1.value=Math.round(totalp1);
document.flexmort.term1debt2.value=Math.round(debt2);
document.flexmort.term1totalp2.value=Math.round(totalp2);


for (var month=13; month<=24; month++){   

// math for paying off over full term

debt1=(debt1*interest)-payment1;
totalp1=payment1+totalp1;
if(debt1<0){debt1=0; totalp1=0}else{debt1=debt1+0}

// math for paying off asap

debt2=(debt2*interest)-payment2;
totalp2=payment2+totalp2;
if(debt2<0){debt2=0; totalp2=0}else{debt2=debt2+0}



} 

//set output values

document.flexmort.term2debt1.value=Math.round(debt1);
document.flexmort.term2totalp1.value=Math.round(totalp1);
document.flexmort.term2debt2.value=Math.round(debt2);
document.flexmort.term2totalp2.value=Math.round(totalp2);


for (var month=25; month<=36; month++){   

// math for paying off over full term

debt1=(debt1*interest)-payment1;
totalp1=payment1+totalp1;
if(debt1<0){debt1=0; totalp1=0}else{debt1=debt1+0}

// math for paying off asap

debt2=(debt2*interest)-payment2;
totalp2=payment2+totalp2;
if(debt2<0){debt2=0; totalp2=0}else{debt2=debt2+0}



} 

//set output values

document.flexmort.term3debt1.value=Math.round(debt1);
document.flexmort.term3totalp1.value=Math.round(totalp1);
document.flexmort.term3debt2.value=Math.round(debt2);
document.flexmort.term3totalp2.value=Math.round(totalp2);


for (var month=37; month<=48; month++){   

// math for paying off over full term

debt1=(debt1*interest)-payment1;
totalp1=payment1+totalp1;
if(debt1<0){debt1=0; totalp1=0}else{debt1=debt1+0}

// math for paying off asap

debt2=(debt2*interest)-payment2;
totalp2=payment2+totalp2;
if(debt2<0){debt2=0; totalp2=0}else{debt2=debt2+0}



} 

//set output values

document.flexmort.term4debt1.value=Math.round(debt1);
document.flexmort.term4totalp1.value=Math.round(totalp1);
document.flexmort.term4debt2.value=Math.round(debt2);
document.flexmort.term4totalp2.value=Math.round(totalp2);


for (var month=49; month<=60; month++){   

// math for paying off over full term

debt1=(debt1*interest)-payment1;
totalp1=payment1+totalp1;
if(debt1<0){debt1=0; totalp1=0}else{debt1=debt1+0}

// math for paying off asap

debt2=(debt2*interest)-payment2;
totalp2=payment2+totalp2;
if(debt2<0){debt2=0; totalp2=0}else{debt2=debt2+0}



} 

//set output values

document.flexmort.term5debt1.value=Math.round(debt1);
document.flexmort.term5totalp1.value=Math.round(totalp1);
document.flexmort.term5debt2.value=Math.round(debt2);
document.flexmort.term5totalp2.value=Math.round(totalp2);


for (var month=61; month<=72; month++){   

// math for paying off over full term

debt1=(debt1*interest)-payment1;
totalp1=payment1+totalp1;
if(debt1<0){debt1=0; totalp1=0}else{debt1=debt1+0}

// math for paying off asap

debt2=(debt2*interest)-payment2;
totalp2=payment2+totalp2;
if(debt2<0){debt2=0; totalp2=0}else{debt2=debt2+0}


} 

//set output values

document.flexmort.term6debt1.value=Math.round(debt1);
document.flexmort.term6totalp1.value=Math.round(totalp1);
document.flexmort.term6debt2.value=Math.round(debt2);
document.flexmort.term6totalp2.value=Math.round(totalp2);


for (var month=73; month<=84; month++){   

// math for paying off over full term

debt1=(debt1*interest)-payment1;
totalp1=payment1+totalp1;
if(debt1<0){debt1=0; totalp1=0}else{debt1=debt1+0}


// math for paying off asap

debt2=(debt2*interest)-payment2;
totalp2=payment2+totalp2;
if(debt2<0){debt2=0; totalp2=0}else{debt2=debt2+0}



} 

//set output values

document.flexmort.term7debt1.value=Math.round(debt1);
document.flexmort.term7totalp1.value=Math.round(totalp1);
document.flexmort.term7debt2.value=Math.round(debt2);
document.flexmort.term7totalp2.value=Math.round(totalp2);


for (var month=85; month<=96; month++){   

// math for paying off over full term

debt1=(debt1*interest)-payment1;
totalp1=payment1+totalp1;
if(debt1<0){debt1=0; totalp1=0}else{debt1=debt1+0}

// math for paying off asap

debt2=(debt2*interest)-payment2;
totalp2=payment2+totalp2;
if(debt2<0){debt2=0; totalp2=0}else{debt2=debt2+0}



} 

//set output values

document.flexmort.term8debt1.value=Math.round(debt1);
document.flexmort.term8totalp1.value=Math.round(totalp1);
document.flexmort.term8debt2.value=Math.round(debt2);
document.flexmort.term8totalp2.value=Math.round(totalp2);


for (var month=97; month<=108; month++){   

// math for paying off over full term

debt1=(debt1*interest)-payment1;
totalp1=payment1+totalp1;
if(debt1<0){debt1=0; totalp1=0}else{debt1=debt1+0}

// math for paying off asap

debt2=(debt2*interest)-payment2;
totalp2=payment2+totalp2;
if(debt2<0){debt2=0; totalp2=0}else{debt2=debt2+0}



} 

//set output values

document.flexmort.term9debt1.value=Math.round(debt1);
document.flexmort.term9totalp1.value=Math.round(totalp1);
document.flexmort.term9debt2.value=Math.round(debt2);
document.flexmort.term9totalp2.value=Math.round(totalp2);


for (var month=109; month<=120; month++){   

// math for paying off over full term

debt1=(debt1*interest)-payment1;
totalp1=payment1+totalp1;
if(debt1<0){debt1=0; totalp1=0}else{debt1=debt1+0}

// math for paying off asap

debt2=(debt2*interest)-payment2;
totalp2=payment2+totalp2;
if(debt2<0){debt2=0; totalp2=0}else{debt2=debt2+0}


} 

//set output values

document.flexmort.term10debt1.value=Math.round(debt1);
document.flexmort.term10totalp1.value=Math.round(totalp1);
document.flexmort.term10debt2.value=Math.round(debt2);
document.flexmort.term10totalp2.value=Math.round(totalp2);


for (var month=121; month<=132; month++){   

// math for paying off over full term

debt1=(debt1*interest)-payment1;
totalp1=payment1+totalp1;
if(debt1<0){debt1=0; totalp1=0}else{debt1=debt1+0}

// math for paying off asap

debt2=(debt2*interest)-payment2;
totalp2=payment2+totalp2;
if(debt2<0){debt2=0; totalp2=0}else{debt2=debt2+0}



} 

//set output values

document.flexmort.term11debt1.value=Math.round(debt1);
document.flexmort.term11totalp1.value=Math.round(totalp1);
document.flexmort.term11debt2.value=Math.round(debt2);
document.flexmort.term11totalp2.value=Math.round(totalp2);


for (var month=133; month<=144; month++){   

// math for paying off over full term

debt1=(debt1*interest)-payment1;
totalp1=payment1+totalp1;
if(debt1<0){debt1=0; totalp1=0}else{debt1=debt1+0}

// math for paying off asap

debt2=(debt2*interest)-payment2;
totalp2=payment2+totalp2;
if(debt2<0){debt2=0; totalp2=0}else{debt2=debt2+0}



} 

//set output values

document.flexmort.term12debt1.value=Math.round(debt1);
document.flexmort.term12totalp1.value=Math.round(totalp1);
document.flexmort.term12debt2.value=Math.round(debt2);
document.flexmort.term12totalp2.value=Math.round(totalp2);


for (var month=145; month<=156; month++){   

// math for paying off over full term

debt1=(debt1*interest)-payment1;
totalp1=payment1+totalp1;
if(debt1<0){debt1=0; totalp1=0}else{debt1=debt1+0}

// math for paying off asap

debt2=(debt2*interest)-payment2;
totalp2=payment2+totalp2;
if(debt2<0){debt2=0; totalp2=0}else{debt2=debt2+0}



} 

//set output values

document.flexmort.term13debt1.value=Math.round(debt1);
document.flexmort.term13totalp1.value=Math.round(totalp1);
document.flexmort.term13debt2.value=Math.round(debt2);
document.flexmort.term13totalp2.value=Math.round(totalp2);


for (var month=157; month<=168; month++){   

// math for paying off over full term

debt1=(debt1*interest)-payment1;
totalp1=payment1+totalp1;
if(debt1<0){debt1=0; totalp1=0}else{debt1=debt1+0}

// math for paying off asap

debt2=(debt2*interest)-payment2;
totalp2=payment2+totalp2;
if(debt2<0){debt2=0; totalp2=0}else{debt2=debt2+0}



} 

//set output values

document.flexmort.term14debt1.value=Math.round(debt1);
document.flexmort.term14totalp1.value=Math.round(totalp1);
document.flexmort.term14debt2.value=Math.round(debt2);
document.flexmort.term14totalp2.value=Math.round(totalp2);


for (var month=169; month<=180; month++){   

// math for paying off over full term

debt1=(debt1*interest)-payment1;
totalp1=payment1+totalp1;
if(debt1<0){debt1=0; totalp1=0}else{debt1=debt1+0}

// math for paying off asap

debt2=(debt2*interest)-payment2;
totalp2=payment2+totalp2;
if(debt2<0){debt2=0; totalp2=0}else{debt2=debt2+0}



} 

//set output values

document.flexmort.term15debt1.value=Math.round(debt1);
document.flexmort.term15totalp1.value=Math.round(totalp1);
document.flexmort.term15debt2.value=Math.round(debt2);
document.flexmort.term15totalp2.value=Math.round(totalp2);


for (var month=181; month<=192; month++){   

// math for paying off over full term

debt1=(debt1*interest)-payment1;
totalp1=payment1+totalp1;
if(debt1<0){debt1=0; totalp1=0}else{debt1=debt1+0}

// math for paying off asap

debt2=(debt2*interest)-payment2;
totalp2=payment2+totalp2;
if(debt2<0){debt2=0; totalp2=0}else{debt2=debt2+0}



} 

//set output values

document.flexmort.term16debt1.value=Math.round(debt1);
document.flexmort.term16totalp1.value=Math.round(totalp1);
document.flexmort.term16debt2.value=Math.round(debt2);
document.flexmort.term16totalp2.value=Math.round(totalp2);


for (var month=193; month<=204; month++){   

// math for paying off over full term

debt1=(debt1*interest)-payment1;
totalp1=payment1+totalp1;
if(debt1<0){debt1=0; totalp1=0}else{debt1=debt1+0}

// math for paying off asap

debt2=(debt2*interest)-payment2;
totalp2=payment2+totalp2;
if(debt2<0){debt2=0; totalp2=0}else{debt2=debt2+0}



} 

//set output values

document.flexmort.term17debt1.value=Math.round(debt1);
document.flexmort.term17totalp1.value=Math.round(totalp1);
document.flexmort.term17debt2.value=Math.round(debt2);
document.flexmort.term17totalp2.value=Math.round(totalp2);


for (var month=205; month<=216; month++){   

// math for paying off over full term

debt1=(debt1*interest)-payment1;
totalp1=payment1+totalp1;
if(debt1<0){debt1=0; totalp1=0}else{debt1=debt1+0}

// math for paying off asap

debt2=(debt2*interest)-payment2;
totalp2=payment2+totalp2;
if(debt2<0){debt2=0; totalp2=0}else{debt2=debt2+0}



} 

//set output values

document.flexmort.term18debt1.value=Math.round(debt1);
document.flexmort.term18totalp1.value=Math.round(totalp1);
document.flexmort.term18debt2.value=Math.round(debt2);
document.flexmort.term18totalp2.value=Math.round(totalp2);


for (var month=217; month<=228; month++){   

// math for paying off over full term

debt1=(debt1*interest)-payment1;
totalp1=payment1+totalp1;
if(debt1<0){debt1=0; totalp1=0}else{debt1=debt1+0}

// math for paying off asap

debt2=(debt2*interest)-payment2;
totalp2=payment2+totalp2;
if(debt2<0){debt2=0; totalp2=0}else{debt2=debt2+0}



} 

//set output values

document.flexmort.term19debt1.value=Math.round(debt1);
document.flexmort.term19totalp1.value=Math.round(totalp1);
document.flexmort.term19debt2.value=Math.round(debt2);
document.flexmort.term19totalp2.value=Math.round(totalp2);


for (var month=229; month<=240; month++){   

// math for paying off over full term

debt1=(debt1*interest)-payment1;
totalp1=payment1+totalp1;
if(debt1<0){debt1=0; totalp1=0}else{debt1=debt1+0}

// math for paying off asap

debt2=(debt2*interest)-payment2;
totalp2=payment2+totalp2;
if(debt2<0){debt2=0; totalp2=0}else{debt2=debt2+0}



} 

//set output values

document.flexmort.term20debt1.value=Math.round(debt1);
document.flexmort.term20totalp1.value=Math.round(totalp1);
document.flexmort.term20debt2.value=Math.round(debt2);
document.flexmort.term20totalp2.value=Math.round(totalp2);


for (var month=241; month<=252; month++){   

// math for paying off over full term

debt1=(debt1*interest)-payment1;
totalp1=payment1+totalp1;
if(debt1<0){debt1=0; totalp1=0}else{debt1=debt1+0}

// math for paying off asap

debt2=(debt2*interest)-payment2;
totalp2=payment2+totalp2;
if(debt2<0){debt2=0; totalp2=0}else{debt2=debt2+0}



} 

//set output values

document.flexmort.term21debt1.value=Math.round(debt1);
document.flexmort.term21totalp1.value=Math.round(totalp1);
document.flexmort.term21debt2.value=Math.round(debt2);
document.flexmort.term21totalp2.value=Math.round(totalp2);


for (var month=253; month<=264; month++){   

// math for paying off over full term

debt1=(debt1*interest)-payment1;
totalp1=payment1+totalp1;
if(debt1<0){debt1=0; totalp1=0}else{debt1=debt1+0}

// math for paying off asap

debt2=(debt2*interest)-payment2;
totalp2=payment2+totalp2;
if(debt2<0){debt2=0; totalp2=0}else{debt2=debt2+0}



} 

//set output values

document.flexmort.term22debt1.value=Math.round(debt1);
document.flexmort.term22totalp1.value=Math.round(totalp1);
document.flexmort.term22debt2.value=Math.round(debt2);
document.flexmort.term22totalp2.value=Math.round(totalp2);


for (var month=265; month<=276; month++){   

// math for paying off over full term

debt1=(debt1*interest)-payment1;
totalp1=payment1+totalp1;
if(debt1<0){debt1=0; totalp1=0}else{debt1=debt1+0}

// math for paying off asap

debt2=(debt2*interest)-payment2;
totalp2=payment2+totalp2;
if(debt2<0){debt2=0; totalp2=0}else{debt2=debt2+0}



} 

//set output values

document.flexmort.term23debt1.value=Math.round(debt1);
document.flexmort.term23totalp1.value=Math.round(totalp1);
document.flexmort.term23debt2.value=Math.round(debt2);
document.flexmort.term23totalp2.value=Math.round(totalp2);


for (var month=277; month<=288; month++){   

// math for paying off over full term

debt1=(debt1*interest)-payment1;
totalp1=payment1+totalp1;
if(debt1<0){debt1=0; totalp1=0}else{debt1=debt1+0}

// math for paying off asap

debt2=(debt2*interest)-payment2;
totalp2=payment2+totalp2;
if(debt2<0){debt2=0; totalp2=0}else{debt2=debt2+0}



} 

//set output values

document.flexmort.term24debt1.value=Math.round(debt1);
document.flexmort.term24totalp1.value=Math.round(totalp1);
document.flexmort.term24debt2.value=Math.round(debt2);
document.flexmort.term24totalp2.value=Math.round(totalp2);


for (var month=289; month<=300; month++){   

// math for paying off over full term

debt1=(debt1*interest)-payment1;
totalp1=payment1+totalp1;
if(debt1<0){debt1=0; totalp1=0}else{debt1=debt1+0}

// math for paying off asap

debt2=(debt2*interest)-payment2;
totalp2=payment2+totalp2;
if(debt2<0){debt2=0; totalp2=0}else{debt2=debt2+0}



} 

//set output values

document.flexmort.term25debt1.value=Math.round(debt1);
document.flexmort.term25totalp1.value=Math.round(totalp1);
document.flexmort.term25debt2.value=Math.round(debt2);
document.flexmort.term25totalp2.value=Math.round(totalp2);


} 

function computemortint() 
{
  document.mortint.Cm.value=Math.round((document.mortint.Hp.value*document.mortint.ir.value/100)/12);

  document.mortint.CCm.value=Math.round((document.mortint.Hp.value*.12)/12);  
}

function clearmortint() 
{

}

function computerepaycalc() 
{ 
  var payment=0;
  
  var payment12=0;
  
  ir=1+(document.repaycalc.ir.value/100);
  
  ir=Math.pow(ir,(1/12));
  
  term=document.repaycalc.term.value*12;
  
  mortgage=document.repaycalc.mortgage.value;
  
  var x=0;

  x=Math.pow(ir,term);
  
  ir12=Math.pow(1.12,(1/12));
  
  x12=Math.pow(ir12,term);


  if (x == 1)
  {
    payment=mortgage/term
  }
  else
  { 
    payment=((mortgage*x)*(1-ir))/(1-x)
  }
  
  payment12=((mortgage*x12)*(1-ir12))/(1-x12);

  document.repaycalc.payment.value=Math.round(payment*100)/100;
  
  document.repaycalc.payment12.value=Math.round(payment12*100)/100;  
}

//clears form
function clearrepaycalc() 
{ 

}

// this array consists of the id attributes of the divs we wish to alternate between
var divs_to_fade = new Array('box-1', 'box-2');

// the starting index in the above array.  It should be set to the value of the div which doesn't have the CSS Display property set to "none"
var i = 0;

// the number of milliseconds between swaps.  Default is five seconds.
var wait = 5000;

// the function that performs the fade
function swapFade() 
{
	Effect.Fade(divs_to_fade[i], { duration:1, from:1.0, to:0.0 });
	i++;
	if (i == 2) i = 0;
	Effect.Appear(divs_to_fade[i], { duration:1, from:0.0, to:1.0 });
}

// the onload event handler that starts the fading.
function startPage() 
{
	setInterval('swapFade()',wait);
}