function calc() {
var price, result, w;
var extra = document.getElementById('extra');
// ====== проверка поля вес =========
var weight = new String(document.getElementById('weight').value);
weight = weight.replace(",",".");
 if(weight=="") { 
   alert("Не заполнено обязательное поле"); 
   document.getElementById('weight').style.border = "2px solid red";
   document.getElementById('weight').focus();
   return false; 
 }
 if(isNaN(parseFloat(weight))) {
   alert("Неверный формат числа");
   document.getElementById('weight').style.border = "2px solid red";
   document.getElementById('weight').focus();
   return false; 
 }
weight = Math.round(parseFloat(weight));
document.getElementById('weight').style.border = "1px solid #C0C0C0";

// ====== проверка поля объем =========
var volume = new String(document.getElementById('volume').value);
volume = volume.replace(",",".");
 if(isNaN(parseFloat(volume))) {
   volume = 0.01;
 }
volume = parseFloat(volume);

// ====== если умный пользователь ввел ноли  =========
   if(weight == 0 || weight < 0) weight = 1;
   if(volume == 0 || volume < 0) volume = 0.01;

// ====== все проверки прошли, показываем назад рабочие значения =========
   document.getElementById('weight').value = weight;
   document.getElementById('volume').value = volume;

// ====== проверяем, по каким параметрам считать тариф =========
  if(weight > eval(volume*220)){
  w = weight;
   } else {
  w = volume*220;
  }
// ====== вычисляем тариф =========
     if(w < 101) {
     price = 4.8;
     } else if (w > 100 && w < 201) {
     price = 4.8;
     } else if (w > 200 && w < 501) {
     price = 4.8;
     } else if (w > 500 && w < 1001) {
     price = 4.4;
     } else if (w > 1000 && w < 1501) {
     price = 4.3;
     } else if (w > 1500 && w < 2001) {
     price = 4.2;
     } else if (w > 2000 && w < 3001) {
     price = 4.1;
     } else {
     price = 3.8;
    }
// ====== вычисляем результат =========
   if(extra.checked == true) {
     if(weight < (volume*220)) {
     result = Math.round(volume*220*price*1.25);
    } else {
     result = Math.round(weight*price*1.25);
    }
  } else {
     if(weight < (volume*220)) {
     result = Math.round(volume*220*price);
    } else {
     result = Math.round(weight*price);
    }
  }
  document.getElementById('result').value = result;
  return true;
}


