function show_row(id, show) { 
  if(document.getElementById(id) != null) { 
    if(show) document.getElementById(id).style.display = '';
    else document.getElementById(id).style.display = 'none';
   } 
 } 

function change_cash(form)  { 
  switch(form.TYPE.value)  { 
    case '1':       document.getElementById("ROW_1").innerHTML = "RUR";
      document.getElementById("ROW_3").innerHTML = "WMZ";
      if(document.getElementById("PURSE").value.length < 13 || document.getElementById("PURSE").value.charAt(0) != "Z")
        document.getElementById("PURSE").value = "Z";
      show_row("IS_WMT_COMISSION", false);
    break
    case '2':       document.getElementById("ROW_1").innerHTML = "RUR";
      document.getElementById("ROW_3").innerHTML = "WMR";
      if(document.getElementById("PURSE").value.length < 13 || document.getElementById("PURSE").value.charAt(0) != "R")
        document.getElementById("PURSE").value = "R";
      show_row("IS_WMT_COMISSION", false);
    break
    case '3':       document.getElementById("ROW_1").innerHTML = "RUR";
      document.getElementById("ROW_3").innerHTML = "WMU";
      show_row("IS_WMT_COMISSION", false);
      if (document.getElementById("PURSE").value.length < 13 || document.getElementById("PURSE").value.charAt(0) != "U")
        document.getElementById("PURSE").value = "U";
    break
    case '4':       document.getElementById("ROW_1").innerHTML = "RUR";
      document.getElementById("ROW_3").innerHTML = "WME";
      show_row("IS_WMT_COMISSION", false);
      if (document.getElementById("PURSE").value.length < 13 || document.getElementById("PURSE").value.charAt(0) != "E")
        document.getElementById("PURSE").value = "E";
    break
    case '7':       document.getElementById("ROW_1").innerHTML = "WMZ";
      document.getElementById("ROW_2").innerHTML = "WMZ";
      document.getElementById("ROW_3").innerHTML = "RUR";
      if(document.getElementById("PURSE").value.length < 13 || document.getElementById("PURSE").value.charAt(0) != "Z")
        document.getElementById("PURSE").value = "Z";
      show_row("IS_WMT_COMISSION", true);
    break
    case '8':       document.getElementById("ROW_1").innerHTML = "WMR";
      document.getElementById("ROW_2").innerHTML = "WMR";
      document.getElementById("ROW_3").innerHTML = "RUR";
      if(document.getElementById("PURSE").value.length < 13 || document.getElementById("PURSE").value.charAt(0) != "R")
        document.getElementById("PURSE").value = "R";
      show_row("IS_WMT_COMISSION", true);
    break
    case '9':       document.getElementById("ROW_1").innerHTML = "WMU";
      document.getElementById("ROW_2").innerHTML = "WMU";
      document.getElementById("ROW_3").innerHTML = "RUR";
      if(document.getElementById("PURSE").value.length < 13 || document.getElementById("PURSE").value.charAt(0) != "U")
        document.getElementById("PURSE").value = "U";
      show_row("IS_WMT_COMISSION", true);
    break
    case '10':       document.getElementById("ROW_1").innerHTML = "WME";
      document.getElementById("ROW_2").innerHTML = "WME";
      document.getElementById("ROW_3").innerHTML = "RUR";
      if(document.getElementById("PURSE").value.length < 13 || document.getElementById("PURSE").value.charAt(0) != "E")
        document.getElementById("PURSE").value = "E";
      show_row("IS_WMT_COMISSION", true);
    break

   } // of switch
  form.SUM1.value    = 0.00;
  form.SUM2.value   = 0.00;
  form.WMT_COMISSION.value = 0.00;

  if(form.TYPE.value < 6) show_rekvisits(true);
  else show_rekvisits(false);
 } 

function show_rekvisits(show)  { 
  if(form_id == 1)  {  // используется форма ввода/вывода WM банковским переводом
    if(show)  { 
      document.getElementById("IS_BANK").style.display = 'none';
      document.getElementById("IS_KS").style.display = 'none';
      document.getElementById("IS_RS").style.display = 'none';
      document.getElementById("IS_BIK").style.display = 'none';
      document.getElementById("IS_INN").style.display = 'none';
     } 
    else  { 
      document.getElementById("IS_BANK").style.display = '';
      document.getElementById("IS_KS").style.display = '';
      document.getElementById("IS_RS").style.display = '';
      document.getElementById("IS_BIK").style.display = '';
      document.getElementById("IS_INN").style.display = '';
     } 
   } 
 } 

function calc_cash(form)  { 
  if (form.TYPE.value < 7) amount = form.SUM1.value - CPrice;
  switch (form.TYPE.value)  { 
    case '1':       if(RDec(SellZ*amount) < MinComm) form.SUM2.value = RDec((amount - MinComm)/cbrUSD);
      else form.SUM2.value = RDec((amount * (1 - SellZ))/cbrUSD);
    break
    case '2':       if(RDec(SellR*amount) < MinComm) form.SUM2.value = RDec((amount - MinComm)/cbrRUB);
      else form.SUM2.value = RDec((amount *(1 - SellR))/cbrRUB);
    break
    case '3':       if(RDec(SellU*amount) < MinComm) form.SUM2.value = RDec((amount - MinComm)/(cbrUAH/10));
      else form.SUM2.value = RDec((amount * (1 - SellU))/(cbrUAH/10));
    break
    case '4':       if(RDec(SellE*amount) < MinComm) form.SUM2.value = RDec((amount - MinComm)/cbrEUR);
      else form.SUM2.value = RDec((amount * (1 - SellE))/cbrEUR);
    break
    case '7':       if(RDec(BuyZ*cbrUSD*form.SUM1.value) < MinComm) form.SUM2.value = RDec(form.SUM1.value*cbrUSD - CPrice - MinComm);
      else form.SUM2.value = RDec(form.SUM1.value*cbrUSD*(1 - BuyZ) - CPrice);
            if(form.SUM1.value*comWMT > comWMTmaxZ) form.WMT_COMISSION.value =  parseInt(form.SUM1.value) + parseInt(comWMTmaxZ);
      else form.WMT_COMISSION.value = RDec(Math.ceil(form.SUM1.value*(1+comWMT)*100)/100);
    break
    case '8':       if(RDec(BuyR*cbrRUB*form.SUM1.value) < MinComm) form.SUM2.value = RDec(form.SUM1.value*cbrRUB - CPrice - MinComm);
      else form.SUM2.value = RDec(form.SUM1.value * cbrRUB * (1 - BuyR) - CPrice);
            if(form.SUM1.value*comWMT > comWMTmaxR) form.WMT_COMISSION.value = parseInt(form.SUM1.value) + parseInt(comWMTmaxR);
      else form.WMT_COMISSION.value = RDec(Math.ceil(form.SUM1.value*(1+comWMT)*100)/100);
    break
    case '9':       if(RDec(BuyU*(cbrUAH/10)*form.SUM1.value) < MinComm) form.SUM2.value = RDec(form.SUM1.value*(cbrUAH/10) - CPrice - MinComm);
      else form.SUM2.value = RDec(form.SUM1.value*(cbrUAH/10)*(1 - BuyU) - CPrice);
            if(form.SUM1.value*comWMT > comWMTmaxU) form.WMT_COMISSION.value = parseInt(form.SUM1.value) + parseInt(comWMTmaxU);
      else form.WMT_COMISSION.value = RDec(Math.ceil(form.SUM1.value*(1+comWMT)*100)/100);
    break
    case '10':       if(RDec(BuyE*cbrEUR*form.SUM1.value) < MinComm) form.SUM2.value = RDec(form.SUM1.value*cbrEUR - CPrice - MinComm);
      else form.SUM2.value = RDec(form.SUM1.value*cbrEUR*(1 - BuyE) - CPrice);
            if(form.SUM1.value*comWMT > comWMTmaxE) form.WMT_COMISSION.value = parseInt(form.SUM1.value) + parseInt(comWMTmaxE);
      else form.WMT_COMISSION.value = RDec(Math.ceil(form.SUM1.value*(1+comWMT)*100)/100);
    break

   }  // of switch
 } 
//---------------------------------------------------------------
function RDec(Num) { 
  if(Num < 0) Num=0;
  return (Math.round(Num * 100) / 100);
 } 
function IsFloatDigit(KeyEvent, Form) { 
  var Flag = IsDigit(KeyEvent, Form);
  var KeyPresed = GetKeyPres(KeyEvent);
  if(((KeyPresed==190) ||(KeyPresed==188) ||(KeyPresed==110)) && (Form.value.length<1)) { 
      return false;
   } 
  if((Flag) || ((Form.value.indexOf(".") == -1) && ((KeyPresed==110)||(KeyPresed==190)||(KeyPresed==188))) ) { 
    if(((KeyPresed==190) ||(KeyPresed==188) ||(KeyPresed==110)) && (Form.value.length>1)) { 
      Form.value = Form.value+ ".";
      return false;
     } 
    return true;
   } 
  return false;
 } 
function GetKeyPres(KeyEvent) { 
  if(document.getElementById) return KeyEvent.keyCode;
  else if(document.getElementById || document.layers) return KeyEvent.which;
  return KeyEvent.keyCode;
 } 
function IsDigit(KeyEvent, Form) { 
  var KeyPresed = GetKeyPres(KeyEvent);
  if(KeyPresed==32) return false;
  if((KeyPresed==16) || (KeyPresed==17) || (KeyPresed==45)) return true;
  if(((Form.value.length - (Form.value.indexOf(".")==-1 ? 100 : Form.value.indexOf("."))) < 3) &&
      ((((KeyPresed>=48) && (KeyPresed<=57)) || ((KeyPresed>=96) && (KeyPresed<=105)))) || (KeyPresed<40) || (KeyPresed==46)
    ) return true;
  return false;
 } 
