test
-- "on test
  
  put 1 into i
  
  repeat while i < 220
    put the scripttext of cast i into temp
    
    if (temp <> "") then
      
      put temp
      put "**********************************************************************"
    end if
    
    put i+1 into i
  end repeat
  
end test

"
-- "**********************************************************************"
-- "on mouseUp
  newPage 1
end"
-- "**********************************************************************"
-- "on mouseUp
  newPage 2
end"
-- "**********************************************************************"
-- "on mouseUp
  newPage 3
end"
-- "**********************************************************************"
-- "on mouseUp
  newPage 4
end"
-- "**********************************************************************"
-- "on mouseUp
  newPage 5
end"
-- "**********************************************************************"
-- "on mouseUp
  newPage 6
end"
-- "**********************************************************************"
-- "on exitFrame
  global calcType
  getValues  
  puppetSprite 24, true
  puppetSprite 25, true
  case calcType of
    "term": set the memberNum of sprite 24 = 14
    "payment": set the memberNum of sprite 25 = 14
  end case
end"
-- "**********************************************************************"
-- "on exitFrame
  global bookmarks, firstTimeThrough
  getValues
  go to frame (the frame + getAt(bookmarks,2))
end"
-- "**********************************************************************"
-- "on exitFrame
  getValues
  go to frame (the frame + getAt(bookmarks,3))
end
"
-- "**********************************************************************"
-- "on exitFrame
  global bookmarks, loanType
  puppetSprite 13, true
  getValues
  puppetSprite 24, true
  puppetSprite 25, true
  case loanType of
    "homeequity": set the memberNum of sprite 24 = 14
    "personal": set the memberNum of sprite 25 = 14
  end case
  set the locV of sprite 13 = (the locV of sprite (16 + getAt(bookmarks,4))) + 7
  set the text of member "explanation" = line (getAt(bookmarks,4)) of the text of member "exp4"
  go to frame (the frame + getAt(bookmarks,4))
end
"
-- "**********************************************************************"
-- "on exitFrame
  global bookmarks, loanType, numBoxes, calcType
  puppetSprite 13, true
  
  
  getValues
  set the locV of sprite 13 = (the locV of sprite (23 + getAt(bookmarks,5))) + 7
  set the text of member "explanation" = line (getAt(bookmarks,5)) of the text of member "exp5"
  if loanType = "personal" then
    puppetSprite 19, true
    puppetSprite 27, true
    set the locH of sprite 19 = 800
    set the locH of sprite 27 = 800
    setAt numBoxes, 5, 3
    if getAt(bookmarks, 5) > getAt(numBoxes, 5) then
      setAt bookmarks, 5, getAt(numBoxes, 5)
    end if
  else
    setAt numBoxes, 5, 4
  end if
  if calcType = "term" then
    set the text of member "termorpaymenttext" = "Monthly" & RETURN & "payment:"
    set the text of member "termorpayment" = the text of member "payment"
  else
    set the text of member "termorpaymenttext" = "Length" & RETURN & "of loan:"
    set the text of member "termorpayment" = the text of member "term"
  end if
  go to frame (the frame + getAt(bookmarks,5))
end"
-- "**********************************************************************"
-- "on exitFrame
    getValues
end"
-- "**********************************************************************"
-- "on enterframe
  checkRollOver 43
end


on exitFrame
  go the frame
end

on keyUp
  keyboardNav 1
end

on mouseUp
  global numBoxes, calcType, bookmarks
  if rollover(24) or rollover(16) then
    set the memberNum of sprite 24 = 14
    set the memberNum of sprite 25 = 13
    set calcType = "term"
  end if
  if rollover(25) or rollover(17) then
    set the memberNum of sprite 24 = 13
    set the memberNum of sprite 25 = 14
    set calcType = "payment"
  end if
end


"
-- "**********************************************************************"
-- "on enterframe
  checkRollOver 44
end

on keyUp
  keyboardNav 2
end


on exitFrame
  go the frame
end


on mouseUp
  global bookmarks
  if (rollover(16) or rollover(24)) then
    setAt bookmarks, 2, 1
    page 2
  end if
  if (rollover(17) or rollover(25)) then
    setAt bookmarks, 2, 2
    page 2
  end if
  if (rollover(18) or rollover(26)) then
    setAt bookmarks, 2, 3
    page 2
  end if
  if (rollover(19) or rollover(27)) then
    setAt bookmarks, 2, 4
    page 2
  end if
end
"
-- "**********************************************************************"
-- "on enterframe
  checkRollOver 45
end

on keyUp
  keyboardNav 3
end


on exitFrame
  go the frame
end


on mouseUp
  global bookmarks
  if (rollover(16) or rollover(24)) then
    setAt bookmarks, 3, 1
    page 3
  end if
  if (rollover(17) or rollover(25)) then
    setAt bookmarks, 3, 2
    page 3
  end if
  if (rollover(18) or rollover(26)) then
    setAt bookmarks, 3, 3
    page 3
  end if
  if (rollover(19) or rollover(27)) then
    setAt bookmarks, 3, 4
    page 3
  end if
end
"
-- "**********************************************************************"
-- "on enterframe
  checkRollOver 46
end

on keyUp
  keyboardNav 4
end


on exitFrame
  go the frame
end


on mouseUp
  global numBoxes, loanType, bookmarks
  if rollover(24) or rollover(17) then
    set the memberNum of sprite 24 = 14
    set the memberNum of sprite 25 = 13
    set loanType = "homeequity"
  end if
  if rollover(25) or rollover(18) then
    set the memberNum of sprite 24 = 13
    set the memberNum of sprite 25 = 14
    set loanType = "personal"
  end if
  if (rollover(17) or rollover(24)) then
    setAt bookmarks, 4, 1
    page 4
  end if
  if (rollover(18) or rollover(25)) then
    setAt bookmarks, 4, 2
    page 4
  end if
end
"
-- "**********************************************************************"
-- "on enterframe
  checkRollOver 47
end

on keyUp
  keyboardNav 5
end


on exitFrame
  go the frame
end


on mouseUp
  global bookmarks
  if (rollover(16) or rollover(24)) then
    setAt bookmarks, 5, 1
    page 5
  end if
  if (rollover(17) or rollover(25)) then
    setAt bookmarks, 5, 2
    page 5
  end if
  if (rollover(18) or rollover(26)) then
    setAt bookmarks, 5, 3
    page 5
  end if
  if (rollover(19) or rollover(27)) then
    setAt bookmarks, 5, 4
    page 5
  end if
end
"
-- "**********************************************************************"
-- "on enterframe
  checkRollOver 48
end

on exitFrame
  go the frame
end

on keyUp
  keyboardNav 6
end
"
-- "**********************************************************************"
-- "on exitFrame
  global bookmarks, numBoxes, maxPages, loanType, ccActive, ccBalance, ccInterest, ccFees, LActive, LBalance, LInterest, LPayment, term, irate, fees, marginal, payment, calcType, frameNum
  set the floatPrecision to 12
  set loanType = "homeequity"
  set calcType = "term"
  set maxPages = 6
  set thisRoll = 0
  puppetSprite 40, true
  
  set n = 0
  repeat while n < 5
    set n = n + 1
    set the text of member "cc" & n & "b" = "$0"
    set the text of member "cc" & n & "i" = "0%"
    set the text of member "cc" & n & "f" = "$0"
    set the text of member "L" & n & "b" = "$0"
    set the text of member "L" & n & "i" = "0%"
    set the text of member "L" & n & "p" = "$0"
  end repeat
  
  
  
  set term = float(12)
  set the text of member "term" = "12 months"
  set irate = float(10)
  set the text of member "irate" = "10%"
  set fees = float(0)
  set the text of member "fees" = "$0"
  set payment = float(100)
  set the text of member "payment" = "$100"
  set marginal = float(36)
  set the text of member "marginal" = "36%"
  
  set bookmarks = list(1,1,1,1,1,1)
  set frameNum = list(2,5,22,39,51,58)
  set numBoxes = list(1,15,15,2,4,1)
  set ccActive = list(0,0,0,0,0)
  set ccBalance = list(0.0000000000,0.0000000000,0.0000000000,0.0000000000,0.0000000000)
  set ccInterest = list(0.0000000000,0.0000000000,0.0000000000,0.0000000000,0.0000000000)
  set ccFees = list(0.0000000000,0.0000000000,0.0000000000,0.0000000000,0.0000000000)
  set LActive = list(0,0,0,0,0)
  set LBalance = list(0.0000000000,0.0000000000,0.0000000000,0.0000000000,0.0000000000)
  set LInterest = list(0.0000000000,0.0000000000,0.0000000000,0.0000000000,0.0000000000)
  set LPayment = list(0.0000000000,0.0000000000,0.0000000000,0.0000000000,0.0000000000)
end"
-- "**********************************************************************"
-- "on otherRoll
  global thisRoll
  if (thisRoll <> 0) and not(rollover(43) or rollover(44) or rollover(45) or rollover(46) or rollover(47) or rollover(48) or rollover(16) or rollover(17) or rollover(18) or rollover(19) or rollover(20) or rollover(21) or rollover(22) or rollover(23)) then
    resetColors 0
  end if
end"
-- "**********************************************************************"
-- "on checkRollOver exempt
  global thisRoll
  set n = 43
  repeat while (n < 49)
    if (rollover(n) and (thisRoll <> (the memberNum of sprite n)) and (n <> exempt)) then
      resetColors n
    end if
    set n = n + 1
  end repeat
  if (exempt <> 0) and (exempt <> 48) and (exempt <> 44) and (exempt <> 45) then
    set n = 16
    repeat while (n < 24)
      if (rollover(n) and (thisRoll <> (the memberNum of sprite n))) then
        resetColors n
      end if
      set n = n + 1
    end repeat
  end if
  otherroll
end
"
-- "**********************************************************************"
-- "on newPage thisPage
  puppetSprite 13, false
  puppetSprite 16, false
  puppetSprite 17, false
  puppetSprite 18, false
  puppetSprite 19, false
  puppetSprite 20, false
  puppetSprite 21, false
  puppetSprite 22, false
  puppetSprite 23, false
  puppetSprite 24, false
  puppetSprite 25, false
  puppetSprite 26, false
  puppetSprite 27, false
  puppetSprite 28, false
  puppetSprite 29, false
  getValues
  set the locV of sprite 40 = 800
  case thisPage of
    6:
      compare
      page thisPage
    otherwise
      page thisPage
  end case
end "
-- "**********************************************************************"
-- "on getValues
  global bookmarks, numBoxes, maxPages, loanType, ccActive, ccBalance, ccInterest, ccFees, LActive, LBalance, LInterest, LPayment, term, irate, fees, marginal, payment, calcType, frameNum
  set the floatPrecision = 2
  
  if (the frame >= getAt(frameNum,2)) and (the frame < getAt(frameNum,3)) then
    set n = 0
    repeat while n < 5
      set n = n + 1
      set incomeString = line 1 of the text of member ("cc" & n & "b")
      calcNum incomeString
      set incomeString = the result
      setAt ccBalance, n, value(incomeString)
      if getAt(ccBalance,n) < 0 then
        setAt ccBalance, n, 0
        set incomeString = "0"
      end if
      calcDollar incomeString, 0
      set incomeString = the result
      set the text of member ("cc" & n & "b") = incomeString
      
      set incomeString = line 1 of the text of member ("cc" & n & "i")
      calcNum incomeString
      set incomeString = the result
      setAt ccInterest, n, value(incomeString)
      if getAt(ccInterest,n) > 100 then
        setAt ccInterest, n, 100
      end if
      if getAt(ccInterest,n) < 0 then
        setAt ccInterest, n, 0
      end if
      set the text of member ("cc" & n & "i") = getAt(ccInterest,n) & "%"
      
      set incomeString = line 1 of the text of member ("cc" & n & "f")
      calcNum incomeString
      set incomeString = the result
      setAt ccFees, n, value(incomeString)
      if getAt(ccFees,n) < 0 then
        setAt ccFees, n, 0
        set incomeString = "0"
      end if
      calcDollar incomeString, 0
      set incomeString = the result
      set the text of member ("cc" & n & "f") = incomeString
      
      if (getAt(ccBalance,n) = 0) or (getAt(ccInterest,n) = 0) then
        setAt ccActive, n, 0
        setAt ccBalance, n, 0
        set the text of member ("cc" & n & "b") = "$0"
        setAt ccInterest, n, 0
        set the text of member ("cc" & n & "i") = "0%"
        setAt ccFees, n, 0
        set the text of member ("cc" & n & "f") = "$0"
      else
        setAt ccActive, n, 1
      end if
    end repeat
  end if  
  
  if (the frame >= getAt(frameNum,3)) and (the frame < getAt(frameNum,4)) then
    set n = 0
    repeat while n < 5
      set n = n + 1
      
      set incomeString = line 1 of the text of member ("L" & n & "b")
      calcNum incomeString
      set incomeString = the result
      setAt LBalance, n, value(incomeString)
      if getAt(LBalance,n) < 0 then
        setAt LBalance, n, 0
        set incomeString = "0"
      end if
      calcDollar incomeString, 0
      set incomeString = the result
      set the text of member ("L" & n & "b") = incomeString
      
      set incomeString = line 1 of the text of member ("L" & n & "i")
      calcNum incomeString
      set incomeString = the result
      setAt LInterest, n, value(incomeString)
      if getAt(LInterest,n) > 100 then
        setAt LInterest, n, 100
      end if
      if getAt(LInterest,n) < 0 then
        setAt LInterest, n, 0
      end if
      set the text of member ("L" & n & "i") = getAt(LInterest,n) & "%"
      
      set incomeString = line 1 of the text of member ("L" & n & "p")
      calcNum incomeString
      set incomeString = the result
      setAt LPayment, n, value(incomeString)
      if getAt(LPayment,n) < 0 then
        setAt LPayment, n, 0
        set incomeString = "0"
      end if
      calcDollar incomeString, 0
      set incomeString = the result
      set the text of member ("L" & n & "p") = incomeString
      
      if (getAt(LBalance,n) = 0) or (getAt(LPayment,n) = 0) then
        setAt LActive, n, 0
        setAt LBalance, n, 0
        set the text of member ("L" & n & "b") = "$0"
        setAt LInterest, n, 0
        set the text of member ("L" & n & "i") = "0%"
        setAt LPayment, n, 0
        set the text of member ("L" & n & "p") = "$0"
      else
        setAt LActive, n, 1
      end if
    end repeat
  end if
  
  if (the frame > getAt(frameNum,5)) and (the frame < getAt(frameNum,6)) then
    if calcType = "term" then
      --PAYMENT
      set incomeString = line 1 of the text of member "termorpayment"
      calcNum incomeString
      set incomeString = the result
      set payment = value(incomeString)
      if payment <= 0 then
        set payment = 100
        set incomeString = "100"
      end if
      calcDollar incomeString, 0
      set incomeString = the result
      set the text of member "payment" = incomeString
      set the text of member "termorpayment" = incomeString
    else
      --TERM
      set incomeString = line 1 of the text of member "termorpayment"
      calcNum incomeString
      set incomeString = the result
      set term = value(incomeString)
      set term = integer(term)
      if term <= 1 then
        set term = 1
      end if
      if term = 1 then
        set the text of member "term" = term & " month"
        set the text of member "termorpayment" = term & " month"
      else
        set the text of member "term" = term & " months"
        set the text of member "termorpayment" = term & " months"
      end if
    end if
    --IRATE
    set incomeString = line 1 of the text of member "irate"
    calcNum incomeString
    set incomeString = the result
    set irate = value(incomeString)
    if irate > 50 then
      set irate = 50
    end if
    if irate <= 0 then
      set irate = 0
    end if
    set the text of member "irate" = irate & "%"
    --FEES
    set incomeString = line 1 of the text of member "fees"
    calcNum incomeString
    set incomeString = the result
    set fees = value(incomeString)
    if fees < 0 then
      set fees = 0
      set incomeString = "0"
    end if
    calcDollar incomeString, 0
    set incomeString = the result
    set the text of member "fees" = incomeString
    --MARGINAL
    set incomeString = line 1 of the text of member "MARGINAL"
    calcNum incomeString
    set incomeString = the result
    set marginal = value(incomeString)
    if marginal > 70 then
      set marginal = 50
    end if
    if marginal < 0 then
      set marginal = 0
    end if
    set the text of member "marginal" = marginal & "%"
  end if  
  
  set the floatPrecision = 12
end
"
-- "**********************************************************************"
-- "on clearSprites
  puppetSprite 13, false
  puppetSprite 16, false
  puppetSprite 17, false
  puppetSprite 18, false
  puppetSprite 19, false
  puppetSprite 20, false
  puppetSprite 21, false
  puppetSprite 22, false
  puppetSprite 23, false
  puppetSprite 24, false
  puppetSprite 25, false
  puppetSprite 26, false
  puppetSprite 27, false
  puppetSprite 28, false
  puppetSprite 29, false
end
"
-- "**********************************************************************"
-- "on calcNum thisString
  if (the number of chars in thisString = 0) then
    set thisString = "0"
  end if
  set minus = "false"
  set n = 1
  set decimal = "false"
  repeat while (n <= the number of chars in thisString)
    if not((value(char n of thisString) >= 0) and (value(char n of thisString) <= 9)) then
      if (not(char n of thisString = ".")) or decimal = "true" then
        if ((char n of thisString = "-") and (n = 1)) then
          set minus = "true"
        end if
        delete char n of thisString
      else
        set decimal = "true"
        set n = n + 1
      end if
    else
      set n = n + 1
    end if
  end repeat
  set zeros = TRUE
  repeat while (zeros = TRUE)
    if (char 1 of thisString) = "0" then
      delete char 1 of thisString
    else
      set zeros = FALSE
    end if
  end repeat
  if decimal = "true" then
    set zeros = TRUE
    repeat while (zeros = TRUE)
      if (char (the number of chars in thisString) of thisString) = "0" then
        delete char (the number of chars in thisString) of thisString
      else
        set zeros = FALSE
      end if
    end repeat
  end if
  
  if thisString = "." then
    set thisString = "0"
  end if
  
  if (the number of chars in thisString = 0) then
    set thisString = "0"
  end if
  if (minus = "true") and not(thisString = "0") then
    set thisString = "-" & thisString
  end if
  repeat while (the number of chars in thisString) > 8
    delete char (the number of chars in thisString) of thisString
    
  end repeat
  if char (the number of chars in thisString) of thisString = "." then
    delete char (the number of chars in thisString) of thisString
  end if
  
  return thisString
end
"
-- "**********************************************************************"
-- "on resetColors n
  global thisRoll
  if (thisRoll <> 0) then
    cursor -1
    set the locV of sprite 40 = 800
  end if
  if (n <> 0) then
    if (n < 43) then
      cursor [1,2]
    end if
    set thisRoll = (the memberNum of sprite n)
    if (n > 42) then
      set the locV of sprite 40 = 46 + (37 * (n - 43))
      cursor [1,2]
    end if
  else
    set thisRoll = 0
  end if
end
"
-- "**********************************************************************"
-- "on page thisPage
  global frameNum
  case thisPage of
    1:
      go to frame (getAt(frameNum,1))
    2:
      set the text of member "temp1" = the text of member "cc1b"
      set the text of member "temp2" = the text of member "cc2b"
      set the text of member "temp3" = the text of member "cc3b"
      set the text of member "temp4" = the text of member "cc4b"
      set the text of member "temp5" = the text of member "cc5b"
      set the text of member "temp6" = the text of member "cc1i"
      set the text of member "temp7" = the text of member "cc2i"
      set the text of member "temp8" = the text of member "cc3i"
      set the text of member "temp9" = the text of member "cc4i"
      set the text of member "temp10" = the text of member "cc5i"
      set the text of member "temp11" = the text of member "cc1f"
      set the text of member "temp12" = the text of member "cc2f"
      set the text of member "temp13" = the text of member "cc3f"
      set the text of member "temp14" = the text of member "cc4f"
      set the text of member "temp15" = the text of member "cc5f"
      go to frame (getAt(frameNum,2))
    3:
      set the text of member "temp1" = the text of member "L1b"
      set the text of member "temp2" = the text of member "L2b"
      set the text of member "temp3" = the text of member "L3b"
      set the text of member "temp4" = the text of member "L4b"
      set the text of member "temp5" = the text of member "L5b"
      set the text of member "temp6" = the text of member "L1i"
      set the text of member "temp7" = the text of member "L2i"
      set the text of member "temp8" = the text of member "L3i"
      set the text of member "temp9" = the text of member "L4i"
      set the text of member "temp10" = the text of member "L5i"
      set the text of member "temp11" = the text of member "L1p"
      set the text of member "temp12" = the text of member "L2p"
      set the text of member "temp13" = the text of member "L3p"
      set the text of member "temp14" = the text of member "L4p"
      set the text of member "temp15" = the text of member "L5p"
      go to frame (getAt(frameNum,3))
    4:  
      go to frame (getAt(frameNum,4))
    5:
      getValues
      set the text of member "temp1" = the text of member "termorpayment"
      set the text of member "temp2" = the text of member "irate"
      set the text of member "temp3" = the text of member "fees"
      set the text of member "temp4" = the text of member "marginal"
      go to frame (getAt(frameNum,5))
    6:
      go to frame (getAt(frameNum,6))
  end case
end
"
-- "**********************************************************************"
-- "on calcDollar thisString, decimal
  set minus = "false"
  set n = 0
  if (char 1 of thisString = "-") then
    delete char 1 of thisString
    set minus = "true"
  end if
  
  set x = the number of chars in thisString
  repeat while (n < x)
    set n = n + 1
    if (char n of thisString = ".") then
      set x = n - 1
      if decimal = 0 then
        delete char n to (the number of chars in thisString) of thisString
      else
        delete char (n + 3) to (the number of chars in thisString) of thisString
      end if
    end if
  end repeat
  set n = 0
  repeat while (n < x - 1)
    set n = n + 1
    if (n mod 3 = 0) then
      set thisString = chars(thisString,1,x - n) & "," & chars(thisString,x - n + 1,the number of chars in thisString)
    end if
  end repeat
  if minus = "false" then
    set thisString = "$" & thisString
  else
    set thisString = "-$" & thisString
  end if
  if decimal <> 0 then
    if char (the number of chars in thisString) of thisString = "." then
      set thisString = thisString & "0"
    end if
    if char ((the number of chars in thisString) - 1) of thisString = "." then
      set thisString = thisString & "0"
    end if
    if char ((the number of chars in thisString) - 2) of thisString <> "." then
      set thisString = thisString & ".00"
    end if
  end if
  return thisString
end
"
-- "**********************************************************************"


test
-- "on setDefaults
  global firstTimeThrough, fedtaxes1, statetaxes1, socsec1, fedtaxes2, statetaxes2, socsec2, i196, i296, s96
  if (firstTimeThrough = 0) then
    set firstTimeThrough = 1
    --set fedTaxes = ((i196 + i296) * 0.1029) - 2134
    --set stateTaxes = ((i196 + i296) * 0.02589) - 415
        if (i196 > 62700) then
          set templow1 = 62700
          set temphigh1 = i196 - 62700
        else
          set templow1 = i196
          set temphigh1 = 0
        end if
        if (i296 > 62700) then
          set templow2 = 62700
          set temphigh2 = i296 - 62700
        else
          set templow2 = i296
          set temphigh2 = 0
        end if
        set socsec1 = (templow1 * 0.0765) + (temphigh1 * 0.0145)
        set socsec2 = (templow2 * 0.0765) + (temphigh2 * 0.0145)
    case s96 of
      2,4:
        set socsec1 = socsec1 + socsec2
    end case
    
    
    set the floatPrecision = 2
    --calcDollar string(fedTaxes)
    --set incomeString = the result
    --set the text of member "fedTaxes" = incomeString
    --calcDollar string(stateTaxes)
    --set incomeString = the result
    --set the text of member "stateTaxes" = incomeString
    calcDollar string(socsec1)
    set incomeString = the result
    set the text of member "socsec1" = incomeString
    calcDollar string(socsec2)
    set incomeString = the result
    set the text of member "socsec2" = incomeString
    set the floatPrecision = 12
  end if
end
"
-- "**********************************************************************"
-- "on compare
  global bookmarks, numBoxes, maxPages, loanType, ccActive, ccBalance, ccInterest, ccFees, LActive, LBalance, LInterest, LPayment, term, irate, fees, marginal, payment, calcType, frameNum
  
  --FIRST, CALCULATE THE TOTAL AMOUNT OWED.
  set n = 0
  set currentTotal = 0
  set tempRate = float(irate) / float(1200)
  set tempTaxRate = float(marginal) / float(100)
  repeat while n < 5
    set n = n + 1
    if getAt(ccActive,n) <> 0 then
      set currentTotal = currentTotal + getAt(ccBalance,n)
    end if
    if getAt(LActive,n) <> 0 then
      set currentTotal = currentTotal + getAt(LBalance,n)
    end if
  end repeat
  
  --SECOND, SPLIT UP THE TASK DEPENDING ON WHETHER CALCULATING TERM OR PAYMENT.
  set totalNewInterest = float(0)
  set totalNewTaxes = float(0)
  if calcType = "term" then
    
    --WE KNOW THE PAYMENT; GET THE TERM OF THE LOAN, PLUS TOTAL INTEREST AND TAXES
    set tempTotal = float(currentTotal)
    set term = 0
    repeat while tempTotal > 0
      set term = term + 1
      set thisInterest = float(float(tempTotal) * float(tempRate))
      if loanType = "homeequity" then
        set thisTax = float(float(thisInterest) * float(tempTaxRate))
      else
        set thisTax = 0
      end if
      set totalNewInterest = float(totalNewInterest) + float(thisInterest)
      set totalNewTaxes = float(totalNewTaxes) + float(thisTax)
      set tempTotal = float(tempTotal) + float(thisInterest) - float(thisTax) - float(payment)
    end repeat
    set totalNewPayments = (payment * term) + tempTotal + fees
    set the text of member "term" = term & " month"
    if term <> 1 then
      set the text of member "term" = the text of member "term" & "s"
    end if
  else
    
    --WE KNOW THE TERM; GET THE PAYMENT
    set rate =  float(1) + float(tempRate)
    set n = -1
    set tempTotal = float(0)
    repeat while (n < (term - 1))
      set n = n + 1
      set tempTotal = float(tempTotal) + (power(float(rate),n))
    end repeat
    set payment = currentTotal * (power(float(rate),term)) / float(tempTotal)
    put "payment: " & payment
    
    --THEN CALCULATE INTEREST AND TAXES
    set tempTotal = float(currentTotal)
    set totalNewInterest = float(0)
    set totalNewTaxes = float(0)
    set n = 0
    repeat while n < term
      set n = n + 1
      set thisInterest = float(tempTotal) * float(tempRate)
      if loanType = "homeequity" then
        set thisTax = float(thisInterest) * float(tempTaxRate)
      else
        set thisTax = 0
      end if
      set totalNewInterest = float(totalNewInterest) + float(thisInterest)
      set totalNewTaxes = float(totalNewTaxes) + float(thisTax)
      set tempTotal = float(tempTotal) + float(thisInterest) - float(thisTax) - float(payment)
    end repeat
    set totalNewPayments = (payment * term) + fees
  end if
  
  --THIRD, PRIORITIZE PAYMENT ORDER OF CREDIT CARDS.
  set ccOrder = list(0,0,0,0,0)
  set m = 0
  repeat while m < 5
    set m = m + 1
    set n = 0
    set highest = -1
    repeat while n < 5
      set n = n + 1
      set p = 1
      set taken = FALSE
      repeat while p < m
        if getAt(ccOrder,p) = n then
          set taken = TRUE
        end if
        set p = p + 1
      end repeat
      if (getAt(ccInterest,n) > highest) and (getAt(ccActive,n) <> 0) and (taken = FALSE) then
        set highest = getAt(ccInterest,n)
        setAt ccOrder, m, n
      end if
    end repeat
  end repeat
  
  --FOURTH, RUN THE TIME CALCULATIONS ON OLD LOANS.
  set n = 0
  set tempCCBalance = list(0.000000,0.000000,0.000000,0.000000,0.000000)
  set tempLBalance = list(0.000000,0.000000,0.000000,0.000000,0.000000)
  set tempCCInterest = list(0.000000,0.000000,0.000000,0.000000,0.000000)
  set tempLInterest = list(0.000000,0.000000,0.000000,0.000000,0.000000)
  set tempCCActive = list(0,0,0,0,0)
  set tempLActive = list(0,0,0,0,0)
  repeat while n < 5
    set n = n + 1
    if getAt(ccActive,n) <> 0 then
      setAt tempCCBalance, n, getAt(ccBalance,n)
      setAt tempCCInterest, n, (float(getAt(ccInterest,n)) / float(1200))
      setAt tempCCActive, n, 1
    end if
    if getAt(LActive,n) <> 0 then
      setAt tempLBalance, n, getAt(LBalance,n)
      setAt tempLInterest, n, (float(getAt(LInterest,n)) / float(1200))
      setAt tempLActive, n, 1
    end if
  end repeat
  
  set tempMonths = 0
  set alldone = FALSE
  set totalOldInterest = float(0)
  set totalOldPayments = float(0)
  set tempSavings = float(0)



  repeat while (tempMonths < term) and (alldone = FALSE)
    set tempMonths = tempMonths + 1
    if tempMonths = 1 then
      set tempPayment = payment + fees
    else
      set tempPayment = payment
    end if
    
    
    --ADD INTEREST TO REMAINING BALANCES
    set n = 0
    repeat while n < 5
      set n = n + 1
      if getAt(tempCCActive,n) <> 0 then
        set tempInterest = (getAt(tempCCBalance,n) * (float(getAt(tempCCInterest,n))))
        set totalOldInterest = float(totalOldInterest) + float(tempInterest)
        setAt tempCCBalance, n, (float(getAt(tempCCBalance,n)) + float(tempInterest))
        if ((tempMonths - 6) mod 12) = 0 then
          setAt tempCCBalance, n, (float(getAt(tempCCBalance,n)) + float(getAt(ccFees,n)))
        end if
      end if
      if getAt(tempLActive,n) <> 0 then
        set tempInterest = (getAt(tempLBalance,n) * (float(getAt(tempLInterest,n))))
        set totalOldInterest = float(totalOldInterest) + float(tempInterest)
        setAt tempLBalance, n, (float(getAt(tempLBalance,n)) + float(tempInterest))
      end if
    end repeat
    
    --SUBTRACT PAYMENTS FROM REMAINING BALANCES
    --SUBTRACT REQUIRED PAYMENTS
    set n = 0
    repeat while n < 5
      set n = n + 1
      if getAt(tempLActive,n) <> 0 then
        if getAt(tempLBalance,n) > getAt(LPayment,n) then
          set tempPayment = tempPayment - getAt(LPayment,n)
          set totalOldPayments = totalOldPayments + getAt(LPayment,n)
          setAt tempLBalance, n, (getAt(tempLBalance,n) - getAt(LPayment,n))
        else
          set tempPayment = tempPayment - getAt(tempLBalance,n)
          set totalOldPayments = totalOldPayments + getAt(tempLBalance,n)
          setAt tempLBalance, n, 0
          setAt tempLActive, n, 0
        end if
      end if
    end repeat
    
    --PAY CREDIT CARD MINIMUMS
    set n = 0
    repeat while n < 5
      set n = n + 1
      if getAt(tempCCActive,n) <> 0 then
        if getAt(tempCCBalance,n) > 15 then
          set tempMinimum = (float(0.013) * float(getAt(tempCCBalance,n)))
          if tempMinimum < 15 then
            set tempMinimum = float(15)
          end if
          set tempPayment = tempPayment - tempMinimum
          set totalOldPayments = totalOldPayments + tempMinimum
          setAt tempCCBalance, n, (getAt(tempCCBalance,n) - tempMinimum)
        else
          set tempPayment = tempPayment - getAt(tempCCBalance,n)
          set totalOldPayments = totalOldPayments + getAt(tempCCBalance,n)
          setAt tempCCBalance, n, 0
          setAt tempCCActive, n, 0
        end if
      end if
    end repeat
    
    --(C) ALLOT REMAINING BALANCE
    
    --IF NEED TO BORROW FROM CC TO MAKE PAYMENTS
    if tempPayment <= 0 then
      if tempPayment < 0 then
        set n = 5
        set tempLastOne = 0
        
        --FIND CC WITH LOWEST RATE
        repeat while n <> 0
          if getAt(ccOrder,n) <> 0 then
            set tempLastOne = getAt(ccOrder,n)
            set n = 0
          else
            set n = n - 1
          end if
        end repeat
        
        --CREATE NEW CC IF NONE EXISTS
        if tempLastOne = 0 then
          set tempLastOne = 1
          setAt ccOrder, 1, 1
          setAt tempCCActive, 1, 1
          setAt tempCCInterest, 1, 18.000000
        end if
        
        setAt tempCCBalance, tempLastOne, (getAt(tempCCBalance,tempLastOne) - tempPayment)
        set tempPayment = 0
      end if
      
      
      --IF THERE'S MONEY LEFT OVER
    else
      set n = 0
      repeat while n < 5
        set n = n + 1
        if getAt(ccOrder,n) <> 0 then
          if getAt(tempCCBalance,(getAt(ccOrder,n))) > tempPayment then
            setAt tempCCBalance, (getAt(ccOrder,n)), (getAt(tempCCBalance,(getAt(ccOrder,n))) - tempPayment)
            set totalOldPayments = totalOldPayments + tempPayment
            set tempPayment = 0
            set n = 5
          else
            set totalOldPayments = totalOldPayments + getAt(tempCCBalance,(getAt(ccOrder,n)))
            set tempPayment = tempPayment - getAt(tempCCBalance,(getAt(ccOrder,n)))
            if tempPayment <= 0 then
              set tempPayment = 0
              set n = 5
            end if
            setAt tempCCBalance, (getAt(ccOrder,n)), 0
            setAt tempCCActive, (getAt(ccOrder,n)), 0
            setAt ccOrder, n, 0
          end if
        end if
      end repeat
      
      --IF THERE'S STILL MONEY LEFT OVER, PUT IT IN ZERO-INTEREST SAVINGS
      if tempPayment > 0 then
        set tempSavings = tempSavings + tempPayment
      end if
      
      --IF THERE'S ENOUGH SAVINGS, PAY OFF OTHER LOANS
      set n = 0
      repeat while n < 5
        set n = n + 1
        if (getAt(tempLActive,n) <> 0) and (tempSavings >= (getAt(tempLBalance,n))) then
          set totalOldPayments = totalOldPayments + (getAt(tempLBalance,n))
          set tempSavings = tempSavings - (getAt(tempLBalance,n))
          setAt tempLBalance, n, 0
          setAt tempLActive, n, 0
        end if
      end repeat
    end if
    
    --FIGURE OUT IF WE'RE DONE
    set n = 0
    set alldone = TRUE
    repeat while n < 5
      set n = n + 1
      if (getAt(tempCCActive,n) <> 0) or (getAt(tempLActive,n) <> 0) then
        set alldone = FALSE
      end if
    end repeat
  end repeat


  set n = 0
  set termBalance = 0
  repeat while n < 5
    set n = n + 1
    if getAt(tempCCActive,n) <> 0 then
      set termBalance = termBalance + getAt(tempCCBalance,n)
    end if
    if getAt(tempLActive,n) <> 0 then
      set termBalance = termBalance + getAt(tempLBalance,n)
    end if
  end repeat
  
  
  
  --FINALLY, FILL THE FIELDS ON THE LAST PAGE.
  if alldone then
    set oldTermText = tempMonths & "month"
    if tempMonths <> 1 then
      set oldTermText = oldTermText & "s"
    end if
  else
    set oldTermText = "an infinite amount of time"
  end if
  
  
  if loanType = "homeequity" then
    set tempLoanType = "home equity"
  else
    set tempLoanType = "personal"
  end if
  calcDollar string(payment), 0
  set tempPaymentText = the result
  calcDollar string(termBalance), 0
  set termBalanceText = the result
  
  set the text of member "totaltext" = "If you consolidate your debts into one " & tempLoanType & " loan (with an interest rate of " & the text of member "irate" & " and a monthly contribution of  " & tempPaymentText & "), it will take you " & the text of member "term" & " to pay off all your debts."
  
  calcDollar string(totalOldPayments), 0
  set the text of member "remainingBefore" = termBalanceText
  set the text of member "remainingAfter" = "$0"
  calcDollar string(totalOldPayments), 0
  set the text of member "incomeBefore" = the result
  calcDollar string(totalNewPayments), 0
  set the text of member "incomeAfter" = the result
  calcDollar string(totalOldInterest), 0
  set the text of member "interestBefore" = the result
  calcDollar string(totalNewInterest), 0
  set the text of member "interestAfter" = the result
  set the text of member "taxesBefore" = "$0"
  calcDollar string(totalNewTaxes), 0
  set the text of member "taxesAfter" = the result
  calcDollar string(totalOldPayments + totalOldInterest + termBalance), 0
  set the text of member "totalBefore" = the result
  calcDollar string(totalNewPayments + totalNewInterest - totalNewTaxes), 0
  set the text of member "totalAfter" = the result
  
  
end

"
-- "**********************************************************************"
-- "on keyboardNav pageNum
  global bookmarks, numBoxes, maxPages
  --DOWNARROW, TAB, RETURN
  if (the keyCode = 125) or ((the keyCode = 48) and not(the shiftDown)) then
    setAt bookmarks, pageNum, (getAt(bookmarks, pageNum) + 1)
    if getAt(bookmarks, pageNum) > getAt(numBoxes, pageNum) then
      setAt bookmarks, pageNum, getAt(numBoxes, pageNum)
      if (pageNum <> maxPages) then
        setAt bookmarks, (pageNum + 1), 1
        clearSprites
        page (pageNum + 1)
      end if
    else
      page pageNum
    end if
  end if
  
  
  
  
  --UPARROW, SHIFT-TAB
  if (the keyCode = 126) or ((the keyCode = 48) and the shiftDown) then
    setAt bookmarks, pageNum, (getAt(bookmarks, pageNum) - 1)
    if getAt(bookmarks, pageNum) < 1 then
      setAt bookmarks, pageNum, 1
      if (pageNum <> 1) then
        setAt bookmarks, (pageNum - 1), getAt(numBoxes, (pageNum - 1))
        clearSprites
        page (pageNum - 1)
      end if
    else
      page pageNum
    end if
  end if
  
  
  --HOME KEY
  if (the keyCode = 115) and (pageNum <> 1) then
    clearSprites
    page 1
  end if
  
  --END KEY
  if (the keyCode = 119) and (pageNum <> maxPages) then
    clearSprites
    page maxPages
  end if
  
  --PAGE UP
  if (the keyCode = 116) and (pageNum <> 1) then
    clearSprites
    page (pageNum - 1)
  end if
  
  --PAGE DOWN
  if (the keyCode = 121) and (pageNum <> maxPages) then
    clearSprites
    page (pageNum + 1)
  end if
end
"
-- "**********************************************************************"
