   cost_arenda=0;
   cost_days=0;
   Hull15=0;
   days=1;
   limit=0;
   age=0;
   strahovka=0;
function auto_days() {
   days=$("#size_arenda").val();
   if (1<=days && days<=3) 
       cost_days=FirstCategory*days;
   if (4<=days && days<=7) 
       cost_days=SecondCategory*days;
   if (8<=days && days<=14) 
       cost_days=ThirdCategory*days;
   if (15<=days && days<=30) 
      cost_days=FourthCategory*days;
   if (31<=days) 
      cost_days=FifthCategory*days;
   if (days==0) 
      cost_days=NoLimitMileage;
	  total_cost();
   if (days>5) $("#limit_probeg").attr("disabled","");
      else
      $("#limit_probeg").attr("disabled","disabled");
	  }
  
function ajax_select_avto () {
   var url = '/module/calc_rent/calc_sql.php';
   $.get (
            url, "" ,
            function(result) {
			var options = '';
			$(result.marka_avto).each (function () {
			if ($(this).attr('sName')!=null)
			options +='<option value="' + $(this).attr('nId') + '">' + $(this).attr('sName') + '</option>';
			});
			options +='<option value="Марка и модель" selected>Марка и модель</option>';
			$('#type_avto').html(options);
			}
			,
            "json"
        );
   }
   
function total_cost() {
   totals=cost_days+strahovka+limit+age;
$("#resultat").html(" " + totals + "р" );
   }
   
 $(document).ready(function() {

   ajax_select_avto ();
   
   $("#type_avto").change(function () {
   select_avto=$(this).val();
   var url = '/module/calc_rent/calc_sql.php';
   $.get (
            url, "act=select_avto&zapros=" + select_avto ,
            function(result) {
			var options = '';
			$(result.tarif).each (function () {
			FirstCategory=$(this).attr('FirstCategory');
			SecondCategory=$(this).attr('SecondCategory');
			ThirdCategory=$(this).attr('ThirdCategory');
			FourthCategory=$(this).attr('FourthCategory');
			FifthCategory=$(this).attr('FifthCategory');
			NoLimitMileage=$(this).attr('NoLimitMileage');
			Hull15=$(this).attr('Hull15');
			});
			  if (Hull15 != 0)
			  $("#strahovka").html('<option value="0" selected>45000</option><option value="1">15000</option>');
			  else $("#strahovka").html('<option value="0">45000</option>');
			  auto_days();
			  total_cost();
			}
			,
            "json"
        );
   })
  

   
  $("#strahovka").change(function () {
  strahovka_val=$(this).val(); 
   if (Hull15 != 0) 
       if (strahovka_val==1) strahovka = Number(Hull15)*days;
           else strahovka=0;	   
   total_cost();
    }) 
	
  $("#limit_probeg").change(function () {
   limit_val=$(this).val(); 
   if (limit_val==1) limit=NoLimitMileage*days;
      else limit=0;
	  total_cost();
    })
  $("#vozrast").change(function () {
   age_val=$(this).val(); 
   if (age_val==1) age=300*days;
      else age=0;
	  total_cost();
    })
});

