function OnNumStr(e)
{
var key = (typeof e.charCode == 'undefined' ? e.keyCode : e.charCode);
if (e.ctrlKey || e.altKey || key < 32 )
return true;
var reg;
var src;
if ( e.target ) {
src = e.target;
} else {
src = e.srcElement;
}
if ( src.value.length == 0 ) {
reg = /[1-9]/
} else {
reg = /[0-9]/
}
key = String.fromCharCode(key);
return reg.test(key);
}
function OnEditEnd()
{
window.document.calc_credit.scredit.value=window.document.calc_credit.costkv.value-window.document.calc_credit.fpayment.value;
OnGetPercentRate();
}
function OnGetPercentRate()
{
var percent;
var srok;
var kof_kz;
var kred, kvsum;
var tmp;
var platej;
kvsum=window.document.calc_credit.costkv.value;
kred=window.document.calc_credit.scredit.value;
srok=window.document.calc_credit.srok.value;
if(kred==0){return;}
if(kvsum==''){return;}
if(srok==''){return;}
kof_kz=kred/kvsum;
window.document.calc_credit.kof_kz.value=kof_kz;
if(kof_kz<0.3)
{
alert('Сумма кредита не может быть меньше 30% от стоимости квартиры.');
return;
}
if(kof_kz>0.9)
{
alert('Сумма кредита не может быть больше 90% от стоимости квартиры.');
return;
}
if(kof_kz>=0.3 && kof_kz<=0.5)
{
if(srok>=12&&srok<=180) { percent=11;}
if(srok>=181&&srok<=360) { percent=12;}
}
if(kof_kz>0.5 && kof_kz<=0.7)
{
if(srok>=12&&srok<=180) { percent=12.5;}
if(srok>=181&&srok<=360) { percent=13;}
}
if(kof_kz>0.7 && kof_kz<=0.9)
{
if(srok>=12&&srok<=180) { percent=13.5;}
if(srok>=181&&srok<=360) { percent=14;}
}
window.document.calc_credit.prate.value=percent;
//Считаем платеж
percent=percent/100;
tmp=1+(percent/12);
tmp=1-Math.pow(tmp,-(srok-2));
platej=kred*((percent/12)/tmp)*100;
platej=Math.round(platej)/100;
window.document.calc_credit.eplatej.value=platej;
}
function FormatNum(src)
{
var result;
var ir;
result=Math.round(src*100)/100;
var t = result.toString();
var str=t;
ir = t.indexOf('.');
if(ir>0)
{
str=t.substring(ir+1,t.length);
if(str.length==1)
{
result=result+"0";
}
}
if(ir==-1)
{
result=result+".00";
}
/* str=result.toString();
ir = str.indexOf('.');
str=str.substring(0,ir);
*/
return result;
}
function print_report()
{
var percent;
var srok;
var kof_kz;
var kred, kvsum;
var tmp;
var platej;
var osndolg,percentsum,ostatok;
kvsum=window.document.calc_credit.costkv.value;
kred=window.document.calc_credit.scredit.value;
srok=window.document.calc_credit.srok.value;
percent=window.document.calc_credit.prate.value;
if(kred<=0)
{
alert('Введенная информация некорректна.');
return;
}
percent=percent/100;
tmp=1+(percent/12);
tmp=1-Math.pow(tmp,-(srok-2));
platej=kred*((percent/12)/tmp);
var str;
var pix;
var AllSumPlat, AllSumPercent;
pix = '
' + ' | ' + ' |
';
str = '
';
str += pix + '';
str += '| Номер месяца | ';
str += 'Сумма процентов | ';
str += 'Сумма основного долга | ';
str += 'Сумма платежа общая | ';
str += 'Остаток долга | ';
str += '
';
str += pix;
var cl = "f10_black";
AllSumPlat=0;
AllSumPercent=0;
for(i=1;i1)
{
percentsum=ostatok*(percent/12);
osndolg=platej-percentsum;
ostatok=ostatok-osndolg;
if(ostatok<0.005)ostatok=0;
}
AllSumPlat=AllSumPlat+platej;
AllSumPercent=AllSumPercent+percentsum;
str += '';
str += '| ' + i + ' | ';
str += ' ' + FormatNum(percentsum) + ' | ';
str += ' ' + FormatNum(osndolg) + ' | ';
str += ' ' + FormatNum(platej) + ' | ';
str += ' ' + FormatNum(ostatok) + ' | ';
str += '
';
str += pix;
}
document.getElementById('place').innerHTML = str;
str = '
';
str += pix + '';
str += '| Расчетная сумма: | ';
str += 'Всего внесено: | ';
str += 'Всего в счет процентов: | ';
str += '
';
str += pix;
str += pix + '';
str += '| '+FormatNum(kred)+' | ';
str += ''+FormatNum(AllSumPlat)+' | ';
str += ''+FormatNum(AllSumPercent)+' | ';
str += '
';
document.getElementById('result_credit').innerHTML = str;
}