  // INTEREST RATE
  
  var index = 0;
  var count = 7;
  var toshow = 4;

  aHead = new Array('1Yr','2Yr','3Yr','4Yr','5Yr','7Yr','10Yr');
  aCont = new Array('4.90%','5.60%','6.00%','6.45%','6.70%','7.55%','7.90%');
  
  function go_prev()
    {
      if (index != 0)
        {
          index--;
          for (var i=0; i<4; i++)
            {
              elm = eval('document.all.head_'+i);
              elm.innerText = aHead[index+i];
              elm = eval('document.all.cont_'+i);
              elm.innerText = aCont[index+i];
            } 
        }
      if(index==0)
        document.all.prev.innerText = "";
      document.all.next.innerText = "next>>";
    }

  function go_next()
    {
      if (index+toshow < count)
        {
          index++;
          for (var i=0; i<4; i++)
            {
              elm = eval('document.all.head_'+i);
              elm.innerText = aHead[index+i];
              elm = eval('document.all.cont_'+i);
              elm.innerText = aCont[index+i];
            }
        }
      if(index+toshow >= count)
        document.all.next.innerText = "";
      document.all.prev.innerText = "<<prev";
    }


  // MORTGAHE PAYMENT

  function pvalid()
    {
      result = not_empty('mortgageform', 'fs0LoanAmount', 'Loan Amount') &&
              is_number('mortgageform', 'fs0LoanAmount', 'Loan Amount') &&
              not_empty('mortgageform', 'fs0IntRate', 'Interest Rate') &&
              number_between('mortgageform', 'fs0IntRate', 'Interest Rate', 0, 100) &&
              not_empty('mortgageform', 'fs0LoanTerm', 'Term of Loan') &&
              is_integer('mortgageform', 'fs0LoanTerm', 'Term of Loan');
      return result;
    }

  function pcalculate()
    {
      if (pvalid())
        {
          var LoanAmount = document.forms.mortgageform.elements['fs0LoanAmount'].value;
          var IntRate = parseFloat(document.forms.mortgageform.elements['fs0IntRate'].value/100.00/12.00);
          var LoanTerm = parseInt(document.forms.mortgageform.elements['fs0LoanTerm'].value*12);
          var Payment = parseInt((LoanAmount*IntRate)/(1-Math.pow((1+IntRate),(-1*LoanTerm))));
          document.forms.mortgageform.elements['fs0Payment'].value = Payment;
        }
      return false;
    }
    


  // HOME AFFORDABILITY
    
  function hvalid()
    {
      result = not_empty('mortgageform2', 'fs0MonthLyIncome', 'Gross Monthly Income') &&
                is_number('mortgageform2', 'fs0MonthLyIncome', 'Gross Monthly Income') &&
                not_empty('mortgageform2', 'fs0Funds', 'Saving Funds') &&
                is_number('mortgageform2', 'fs0Funds', 'Saving Funds') &&
                not_empty('mortgageform2', 'fs0IntRate', 'Mortgage Rate') &&
                number_between('mortgageform2', 'fs0IntRate', 'Mortgage Rate', 0, 100) &&
                not_empty('mortgageform2', 'fs0MortTerm', 'Mortgage Term') &&
                is_integer('mortgageform2', 'fs0MortTerm', 'Mortgage Term');
      return result;
    }

  function hcalculate()
    {
      if (hvalid())
        {
          var Payment = parseFloat(document.forms.mortgageform2.elements['fs0MonthLyIncome'].value*0.4);
          var Funds = parseFloat(document.forms.mortgageform2.elements['fs0Funds'].value);
          var IntRate = parseFloat(document.forms.mortgageform2.elements['fs0IntRate'].value/100.00/12.00);
          var MortTerm = parseInt(document.forms.mortgageform2.elements['fs0MortTerm'].value*12);
          var LoanAmount = (Payment * (1-Math.pow((1+IntRate),(-1*MortTerm))))/IntRate;
          Price = parseInt(LoanAmount + Funds);
          document.forms.mortgageform2.elements['fs0Price'].value = Price;
        }
      return false;
    }
    

