Advertisement
Guest User

credit calc

a guest
Apr 19th, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. <!--
  3. var a = 100000.00;
  4. var p = 11;
  5. var t = 12;
  6. var pr1 = 0.12;
  7. var min1 = 1000;
  8. var option1 = 1;
  9. var pr2 = 0.10;
  10. var option2 = 2;
  11. var min3 = 170;
  12. var option3 = 3;
  13.  
  14. var d = 0;
  15.  
  16. function add_favorite(a) {
  17.   title=document.title;
  18.   url=document.location;
  19.   try {
  20.     // Internet Explorer
  21.     window.external.AddFavorite(url, title);
  22.   }
  23.   catch (e) {
  24.     try {
  25.       // Mozilla
  26.       window.sidebar.addPanel(title, url, "");
  27.     }
  28.     catch (e) {
  29.       // Opera
  30.       if (typeof(opera)=="object") {
  31.         a.rel="sidebar";
  32.         a.title=title;
  33.         a.url=url;
  34.         return true;
  35.       }
  36.       else {
  37.         // Unknown
  38.         alert('Нажмите Ctrl-D чтобы добавить страницу в закладки');
  39.       }
  40.     }
  41.   }
  42.   return false;
  43. }
  44.  
  45.  
  46. function Init()
  47. {
  48.   document.forms.mainform["amount"].value = a.toString();
  49.   document.forms.mainform["term"].value = t.toString();
  50.   document.forms.mainform["percent"].value = p.toString();
  51.   document.forms.mainform["pr1"].value = pr1.toString();
  52.   document.forms.mainform["min1"].value = min1.toString();
  53.   document.forms.mainform["option1"].value = option1.toString();
  54.   document.forms.mainform["pr2"].value = pr2.toString();
  55.   document.forms.mainform["option2"].value = option2.toString();
  56.   document.forms.mainform["min3"].value = min3.toString();
  57.   document.forms.mainform["option3"].value = option3.toString();
  58.  
  59.   onChangeParameter();
  60. }
  61.  
  62.  
  63. /* Made by Mathias Bynens <http://mathiasbynens.be/> */
  64. function number_format(a, b, c, d) {
  65.  a = Math.round(a * Math.pow(10, b)) / Math.pow(10, b);
  66.  e = a + '';
  67.  f = e.split('.');
  68.  if (!f[0]) {
  69.   f[0] = '0';
  70.  }
  71.  if (!f[1]) {
  72.   f[1] = '';
  73.  }
  74.  if (f[1].length < b) {
  75.   g = f[1];
  76.   for (i=f[1].length + 1; i <= b; i++) {
  77.    g += '0';
  78.   }
  79.   f[1] = g;
  80.  }
  81.  if(d != '' && f[0].length > 3) {
  82.   h = f[0];
  83.   f[0] = '';
  84.   for(j = 3; j < h.length; j+=3) {
  85.    i = h.slice(h.length - j, h.length - j + 3);
  86.    f[0] = d + i +  f[0] + '';
  87.   }
  88.   j = h.substr(0, (h.length % 3 == 0) ? 3 : (h.length % 3));
  89.   f[0] = j + f[0];
  90.  }
  91.  c = (b <= 0) ? '' : c;
  92.  return f[0] + c + f[1];
  93. }
  94.  
  95. function onChangeParameter()
  96. {
  97.  var sPay = 0
  98.  var mPay = 0;
  99.  var yPay = 0;
  100.  var Pay = 0;
  101.  var aPay = 0;
  102.  var ePay = 0;
  103.  var ePr = 0;
  104.  var minV, maxV;
  105.  var year;
  106.  var eff = 0.0;
  107.  var emPay, effPay = 0;
  108.  
  109.  a = Number(document.forms.mainform["amount"].value.replace(",","."));
  110.  p = Number(document.forms.mainform["percent"].value.replace(",","."));
  111.  t = Number(document.forms.mainform["term"].value.replace(",","."));
  112.  d = a*p/1200/(1-Math.pow(1+p/1200,-t));
  113.  
  114.  year = ( Math.floor(t / 12) == (t / 12) ) ? t / 12 : Math.floor (t / 12) + 1;
  115.  
  116.  for(i=1;i<=5;i++)
  117.  {
  118.    Pay = Number(document.forms.mainform["pr"+i+""].value.replace(",",".")) * a / 100;
  119.    minV = Number(document.forms.mainform["min"+i+""].value.replace(",","."));
  120.    maxV = Number(document.forms.mainform["max"+i+""].value.replace(",","."));
  121.    if (minV && Pay < minV) Pay = minV;
  122.    if (maxV && Pay > maxV) Pay = maxV;
  123.    
  124.    switch (document.forms.mainform["option"+i+""].value)
  125.    {
  126.      case "1":
  127.       sPay = sPay + Pay;
  128.       break;
  129.      case "2":
  130.       mPay = mPay + Pay;
  131.       break;
  132.      case "3":
  133.       yPay = yPay + Pay;
  134.       break;
  135.    }
  136.   }
  137.  
  138.   aPay = sPay + (mPay + d)*t + yPay * year;
  139.   ePay = aPay - a;
  140.   ePr = ePay / a * 100;
  141.  
  142.   emPay = aPay / t;
  143.  
  144.   while (emPay - effPay > 0) {
  145.    eff = eff + 0.01;
  146.    effPay = a*eff/1200/(1-Math.pow(1+eff/1200,-t));
  147.   }
  148.  
  149.   document.forms.mainform["singlePay"].value = number_format(sPay, 0, ".", " ");
  150.   document.forms.mainform["comission"].value = number_format(mPay, 0, ".", " ");
  151.   document.forms.mainform["yearPay"].value = number_format(yPay, 0, ".", " ");
  152.   document.forms.mainform["basic"].value = number_format(d, 0, ".", " ");
  153.   document.forms.mainform["monthPay"].value = number_format(mPay + d, 0, ".", " ");
  154.   document.forms.mainform["allPay"].value = number_format(aPay, 0, ".", " ");
  155.   document.forms.mainform["extraPay"].value = number_format(ePay, 0, ".", " ");
  156.   document.forms.mainform["extraPercent"].value = number_format(ePr, 1, ".", " ");
  157.   document.forms.mainform["comissionPercent"].value = number_format(eff, 1, ".", " ");
  158.  
  159. }
  160.  
  161.  
  162. -->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement