function FormatNumber(expr,decplaces){
 var str=""+Math.round(eval(expr)*Math.pow(10,decplaces));
 while(str.length<=decplaces){
  str="0"+str;
 }
 var decpoint=str.length-decplaces;
 return str.substring(0,decpoint)+"."+str.substring(decpoint,str.length);
}

function get_selected(object){
 for(var i=0;i<object.length;i++){
  if(object[i].selected)return(object[i].value);
 }
}

function set_selected(object,t_value){
 for(var i=0;i<object.length;i++){
  if(object[i].value==t_value)object[i].selected="TRUE";
 }
}

function changeAdvance(){
 document.CALC.LEASING_ADVANCE.value=FormatNumber(document.CALC.LEASING_ADVANCE_SUM.value/document.CALC.ARTICLE_PRICE.value*100,2);
 change();
}

function changeAdvanceSum(){
 document.CALC.LEASING_ADVANCE_SUM.value=FormatNumber(document.CALC.ARTICLE_PRICE.value*document.CALC.LEASING_ADVANCE.value/100,2);
 change();
}

function change(){
 document.CALC.LEASING_ADVANCE_SUM.value=FormatNumber(document.CALC.ARTICLE_PRICE.value*document.CALC.LEASING_ADVANCE.value/100,2);
 document.CALC.MONTH_PAYMENT.value=
  FormatNumber((Math.round((((document.CALC.LEASING_INTEREST.value/100/12)*
  ((document.CALC.ARTICLE_PRICE.value-document.CALC.LEASING_ADVANCE_SUM.value)-
  ((document.CALC.ARTICLE_PRICE.value*document.CALC.LEASING_RESIDUALVALUE.value/100)/
  (Math.pow((document.CALC.LEASING_INTEREST.value/100/12)+1,get_selected(document.CALC.LEASING_PERIOD)))))/
  (1-(1/Math.pow((document.CALC.LEASING_INTEREST.value/100/12)+1,get_selected(document.CALC.LEASING_PERIOD))))))*100)/100),2)
 ;
}

