function checkCount()
  // kontroluje, aby se mnozstvi neprehouplo pres mnozstvi maximalni
  {
  
  if (!maxGoodsCount) return false;
  
  buyCount=document.detail_form.buyCount.value;
  
  if (maxGoodsCount<buyCount) document.detail_form.buyCount.value=maxGoodsCount;
  }
  


function changePrice()
  {
  var cat_number;
  //cat_number=pattern_main_catalogue_number;
  
  reg=/^(pattern_id_(.*)).*/
  
  totalExtraPrice=0;
  
  replace_price=0;  
  form=document.getElementById('detail_form');
  
  
  
  for(i=0;i<form.length;i++)
    {
    str=form[i].name;
    regs=false;
    regs=str.match(reg);
    if (regs)
      {
      if (form[i].checked===true)
        {
        patternId=regs[2];
        value=form[i].value;

        // katalogove cislo
        //if (pattern_main_catalogue_number!=pattern_catalogue_number[patternId][value])
          cat_number=pattern_catalogue_number[patternId][value];
        
        // zmena materialu
        changeCatalogMaterial(pattern_material[patternId][value]);
        
        // nejprve zjistime, zda neni replace_price nulova, pokud neni, tak pouzijeme ji a nahradime puvodni cenu
        if (pattern_replace[patternId][value]!=0)
          {
          replace_price+=pattern_replace[patternId][value];
          
          }
        else // pouzijeme extraprice pro vypocet ceny
          {
          totalExtraPrice+=pattern[patternId][value];
          }
        }
      }
    }
  
  if (replace_price>0) goodsPrice=replace_price;

  var totalPrice;

  totalPrice=goodsPrice+totalExtraPrice;
  changeTextPrice(totalPrice,totalExtraPrice);  
  
  
  // zmena katalogoveho cisla
  changeCatalogueNumber(cat_number);
  
  }
  

function changeCatalogMaterial(material)
{
  elm=document.getElementById('goods_material');
  if (elm==null) return true;
  
  if (elm.fistChild) elm.removeChild(elm.firstChild);
  
  elm.innerHTML=material;
  
  
  // zmenit nadpis
  elm=document.getElementById('aMetaTitle');
  if (elm==null) return true;
  if (goodsName==null) return true;
  
  if (elm.fistChild) elm.removeChild(elm.firstChild);
  
  elm.innerHTML=goodsName+' ('+material+')';
  

}



function changeCatalogueNumber(catNumber)
{
  elm=document.getElementById('catalogue_number');
  if (elm==null) return true;
  
  if (elm.fistChild) elm.removeChild(elm.firstChild);
  
  elm.innerHTML=catNumber;
}


function changeTextPriceReplace(replacePriceVat)
  {
  totalPriceVatEl=document.getElementById('totalPriceVat');
  while (totalPriceVatEl.firstChild) totalPriceVatEl.removeChild(totalPriceVatEl.firstChild);
  totalPriceVatEl.innerHTML=replacePriceVat+",- ";

  
  replacePrice=Math.round(replacePriceVat/(1 + vat/100));
  
  
  totalPriceEl=document.getElementById('totalPrice');
  while (totalPriceEl.firstChild) totalPriceEl.removeChild(totalPriceEl.firstChild);
  totalPriceEl.innerHTML=replacePrice+",- ";
  }





function changeTextPrice (totalPriceVat,totalExtraPrice)
  // funkce pro zmenu textu v cenach vyrobku
{

  var totalExtraPriceWithoutVat=0 ;
  var totalPriceWithoutVat=0 ;
  totalExtraPriceWithoutVat = Math.round((totalExtraPrice/(1 + vat/100))*100)/100 ;
  totalPriceWithoutVat=Math.round((totalPriceVat/(1 + vat/100))*100)/100 ;


  
  extraprice=document.getElementById('extraPrice');
  
  if (extraprice!==null)
  {
    while (extraprice.firstChild) extraprice.removeChild(extraprice.firstChild);
    extraprice.innerHTML=totalExtraPriceWithoutVat+",- Kč";
  }
  
  
  totalPriceEl=document.getElementById('totalPrice');
  if (totalPriceEl!==null)
  {
  while (totalPriceEl.firstChild) totalPriceEl.removeChild(totalPriceEl.firstChild);
  totalPriceEl.innerHTML=totalPriceWithoutVat+",- Kč";
  }
  
  totalPriceVatEl=document.getElementById('totalPriceVat');
  if (totalPriceVatEl!==null)
  {
  while (totalPriceVatEl.firstChild) totalPriceVatEl.removeChild(totalPriceVatEl.firstChild);
  totalPriceVatEl.innerHTML=totalPriceVat+",- Kč";
  }  
}
