function rur_amount(currency){
  $('amount_rur').value = ($('in_pay_amount').value * currency).toFixed(2);
  $('com_rur_amount').innerHTML = (($('in_pay_amount').value * currency) + (0.008 * ($('in_pay_amount').value * currency))).toFixed(2);
  $('com_doll_amount').innerHTML = (($('amount_rur').value / currency) + (0.008 * ($('amount_rur').value / currency))).toFixed(2);
}
function doll_amount(currency){
    $('in_pay_amount').value = ($('amount_rur').value / currency).toFixed(2);
    $('com_rur_amount').innerHTML = (($('in_pay_amount').value * currency) + (0.008 * ($('in_pay_amount').value * currency))).toFixed(2);
    $('com_doll_amount').innerHTML = (($('amount_rur').value / currency) + (0.008 * ($('amount_rur').value / currency))).toFixed(2);
}


function check_tender_price(recommended_price, average_price){
  var tender_price = parseFloat(eval($('tender_price').value).toFixed(2));
  var low_price = parseFloat((average_price * 0.8).toFixed(2));
  var critically_low_price = parseFloat((average_price * 0.5).toFixed(2));


  if($('tender_task_self').checked){
    price_alert('tender_price', 'price_annotation', "none", "");
    return;
  }

  if(tender_price == 0){
    price_alert('tender_price', 'price_annotation', "none", "");
    return;
  }

  if(tender_price == recommended_price)
    price_alert('tender_price', 'price_annotation', "green", "");
  else if(tender_price < critically_low_price)
    price_alert('tender_price', 'price_annotation', "red", "Ошибка! Установленная цена ниже средней более, чем в 2 раза. Заказ не будет принят!");
  else if(tender_price < low_price)
    price_alert('tender_price', 'price_annotation', "red", "Указанная стоимость заказа существенно ниже средней цены на бирже, что может повлечь за собой посредственное качество работы и потерю времени на доработки.");
  else
    price_alert('tender_price', 'price_annotation', "none", "");
}


function check_offer_price(){
  var average_price = parseFloat(eval($('avg').value).toFixed(2));
  var current_price = parseFloat(eval($('offer_price').value).toFixed(2));
  var min_price = average_price / 2;

  if(current_price < min_price)
    price_alert('offer_price', 'price_annotation', "red", "Ошибка! Установленная цена ниже средней более, чем в 2 раза.");
  else
    price_alert('offer_price', 'price_annotation', "none", "");
}


function check_article_price(){
  var current_price = parseFloat(eval($('price').value).toFixed(2));
  var average_price = parseFloat(eval($('avg').value).toFixed(2));
  var min_price = average_price / 2;
  var max_price = average_price * 3;

  if(current_price == 0){
    price_alert('price', 'price_annotation', "none", "");
    return;
  }

  if(current_price == average_price)
    price_alert('price', 'price_annotation', "green", "");
  else if(current_price < min_price)
    price_alert('price', 'price_annotation', "red", "Ошибка! Установленная цена ниже средней более, чем в 2 раза. Заказ не будет принят!");
  else if(current_price > max_price)
    price_alert('price', 'price_annotation', "red", "Ошибка! Установленная цена выше средней более, чем в 3 раза. Заказ не будет принят!");
  else
    price_alert('price', 'price_annotation', "none", "");
}


function price_alert(field, annotation, col, mes){
  $(field).removeClassName('warning_r');
  $(field).removeClassName('warning_g');
  $(annotation).removeClassName('warning_r');
  $(annotation).removeClassName('warning_g');

  switch (col) {
    case "red":
      $(field).addClassName('warning_r');
      $(annotation).addClassName('warning_r');
      break
    case "green":
      $(field).addClassName('warning_g');
      $(annotation).addClassName('warning_g');
      break
    default:
  }
  if(mes=="")
    $(annotation).hide();
  else
  {
    $(annotation).innerHTML = mes;
    $(annotation).show();
  }
}



function discount_price(discount){
  if($('discount_user')){
    var discount=discount/100;
    if(isNaN($('tender_price').value)){
        $('discount_user').innerHTML = "Это не число!";
    }
    else
    {
        tvalue = $('tender_price').value;
        discount =  tvalue - (tvalue * discount);

         $('discount_user').innerHTML = discount.toFixed(2);

    }
  }
}


function noncahe_percent_amount(currency, noncahe_percent){
    if(isNaN($('noncash_amount').value)){
        $('amount_wmz').innerHTML = "Это не чиcло!";
    }else
    {
       sum = $('noncash_amount').value / currency
      $('amount_wmz').innerHTML  = (sum - (sum * noncahe_percent)).toFixed(2);
    }
}

