function basketCarModelIdChanged(iModelId)
{
  //if (!iModelId) return true;

  ajaxObj = new ajax(HTTP_PATH+'ajax/ajax_basket_car_model_form.php?car_model_id='+iModelId, 'carModelForm');
  

}

function ajax(url, idForChange)
{
  self.idForChange = idForChange;

  if (window.XMLHttpRequest)
    self.xmlhttp=new XMLHttpRequest();
  else if (window.ActiveXObject)
    self.xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

  self.xmlhttp.onreadystatechange=function ()
  {
    if (self.xmlhttp.readyState == 4)
      self.changeContent();

  }
  self.xmlhttp.open("GET", url, true);
  self.xmlhttp.send(null);


  changeContent = function ()
  {
    elm = document.getElementById(self.idForChange);
    if (!elm) return false;
    elm.innerHTML = self.xmlhttp.responseText;
  }
}


// kompletace a montaz //
$(document).ready(function () {
  $('input[name="delivery_terms_id"]').bind('click', function () {    
    if ($(this).val() == 8)
    {
      if ($('#basket_kompletace').length != 0) $('#basket_kompletace').hide('fast', function () {$('#basket_montaz').show('fast')});
      else $('#basket_montaz').show('fast');
      changeTotalBasketPrice();
    }
    else
    {
      if ($('#basket_montaz').length != 0) $('#basket_montaz').hide('fast', function (){$('#basket_kompletace').show('fast')});
      else $('#basket_kompletace').show('fast');
      changeTotalBasketPrice();
    }
    this.blur();

  });

  $('input[name="montaz_count"]').bind('keyup', function () {
    iMontazCount = $('input[name="montaz_count"]').val();
    if (isNaN(iMontazCount)) iMontazCount = 0;
    iMontazPriceVatTotal = iMontazPriceVat * iMontazCount;
    iMontazPriceTotal = iMontazPrice * iMontazCount;
    if (is_seller) $('#montaz_price_total').html(iMontazPriceTotal);
    else $('#montaz_price_total').html(iMontazPriceVatTotal);
    changeTotalBasketPrice();
    this.blur();
  });

  $('input[name="kompletace"]').bind('click', function () {
    if ($(this).val() == "1") $('input[name="montaz"][value="0"]').attr('checked', true);
    changeTotalBasketPrice();
    this.blur();
  });

  $('input[name="montaz"]').bind('click', function () {
    if ($(this).val() == "1") $('input[name="kompletace"][value="0"]').attr('checked', true);
    changeTotalBasketPrice();
    this.blur();
  });

});


function changeTotalBasketPrice()
{
  iTotalBasketPrice = iTotalGoodsPrice;
  iTotalBasketPriceVat = iTotalGoodsPriceVat;

  if ($('input[name="kompletace"][value="1"]').attr('checked') == true)
  {    
    iTotalBasketPrice += iKompletaceTotalPrice;
    iTotalBasketPriceVat += iKompletaceTotalPriceVat;
  }

  if ($('input[name="montaz"][value="1"]').attr('checked') == true)
  {
    iMontazCount = $('input[name="montaz_count"]').val();
    iMontazTotalPriceVat = iMontazPriceVat * iMontazCount;
    iMontazTotalPrice = iMontazPrice * iMontazCount;
    
    iTotalBasketPrice += iMontazTotalPrice;
    iTotalBasketPriceVat += iMontazTotalPriceVat;
  }

  deliveryId = $('input[name="delivery_terms_id"]:checked').val();
  eval('iDeliveryPrice = aDeliveryPrice.id_'+deliveryId+';');
  eval('iDeliveryPriceVat = aDeliveryPriceVat.id_'+deliveryId+';');
  
  if (iDeliveryPrice) {iTotalBasketPrice += Math.round(iDeliveryPrice);}
  if (iDeliveryPriceVat) {iTotalBasketPriceVat += Math.round(iDeliveryPriceVat);}
  

  iTotalBasketPriceVat = Math.round(iTotalBasketPriceVat);
  iTotalBasketPrice = Math.round(iTotalBasketPrice);

  iTotalBasketVat = iTotalBasketPriceVat - iTotalBasketPrice;
  
  sBasketVat = iTotalBasketVat+"";
  sBasketPriceVat = iTotalBasketPriceVat+"";
  sBasketPrice = iTotalBasketPrice+"";
  
  if (sBasketVat.length > 3) sBasketVat = sBasketVat.substr(0,sBasketVat.length - 3)+' '+sBasketVat.substr(sBasketVat.length - 3);
  if (sBasketPriceVat.length > 3) sBasketPriceVat = sBasketPriceVat.substr(0,sBasketPriceVat.length - 3)+' '+sBasketPriceVat.substr(sBasketPriceVat.length - 3);
  if (sBasketPrice.length > 3) sBasketPrice = sBasketPrice.substr(0,sBasketPrice.length - 3)+' '+sBasketPrice.substr(sBasketPrice.length - 3);

  if (is_seller)
  {
    $('#total_basket_price_vat').html(sBasketPrice);
    $('#total_basket_price').html(sBasketPriceVat);
  }
  else
  {
    $('#total_basket_price_vat').html(sBasketPriceVat);
    $('#total_basket_price').html(sBasketPrice);
  }
  $('#total_basket_vat').html(sBasketVat);
}




