function in_out(fid, id, code, bForce){

  if (document.forms[fid].amount_in == null)
  { return; }
  
  in_val = document.forms[fid].amount_in.value.replace(",",".");
  if (isNaN(in_val))
  { in_val = "0"; }

  amount = Math.round( in_val*inP[fid] )/inP[fid];
  if(amount < min_amt[fid]){
 	amount = min_amt[fid];
  }
  if(amount > max_amt[fid]){
 	amount = max_amt[fid];
	document.forms[fid].amount_in.value = amount;
	alert('Максимальная сумма обмена '+max_amt[fid]);
	in_out(fid, id, code, bForce);
	return;
  }

  document.forms[fid].out.value = Math.round(amount * courses[fid] * outP)/outP;

  if (bForce)
  { out_in(fid,code); }
}

function out_in(fid, id, code,bForce){
  
  if (document.forms[fid].out == null)
  { return; }
  if (id == null)
  { return; }

  out_val = document.forms[fid].out.value.replace(",",".");
  if (isNaN(out_val))
  { out_val = "0"; }

  amount = Math.round(out_val*outP)/outP;
  
  if(courses[fid]==0){
  	return;
  }
    
  document.forms[fid].amount_in.value = Math.round((out_val / courses[fid]) * inP[fid])/inP[fid];


  if (bForce)
  { in_out(fid,code); }

}