﻿// funkce na onclick formularovych prvku
// google prelozil jako "druha kontrola"
function zweipruefen (d){
  preisdarstellen ();
}

// funkce vracici castku z textu typu "cena:nazev"
function vratCenu(astr)
{
  var lnIdx = -1;
  var str = new String(astr);
  
  lnIdx = str.indexOf(':');
  if (lnIdx<1)
    return 0
  else  
    return parseFloat(str.substring(0, lnIdx))+0;   
}

// funkce na onChange formularovych prvku
// volana tez z funkce zweipruefen
// scita vsechny ceny a vypisuje je do souhrnu 
// puvodni nemecky kod byl neskutecny, preprogramoval jsem to, snad to bude OK
function preisdarstellen () {

  var cenaDopravy = 0;
  var cenaZbozi = 0;
  var cenaCelkem = 0;
  var idx = 0;
  
  // zakladni cena
  for (idx=0;idx<20;idx++) {
    if (document.Formular.bestellung1[idx]) { 
      if (document.Formular.bestellung1[idx].checked) {
         cenaZbozi += vratCenu(document.Formular.bestellung1[idx].value);
      }
    }
  }  
  // dodatecne kurzy 
  if (document.Formular.bestellung2) cenaZbozi += vratCenu(document.Formular.bestellung2.options[document.Formular.bestellung2.selectedIndex].value);
  if (document.Formular.bestellung3) cenaZbozi += vratCenu(document.Formular.bestellung3.options[document.Formular.bestellung3.selectedIndex].value);
  if (document.Formular.bestellung4) cenaZbozi += vratCenu(document.Formular.bestellung4.options[document.Formular.bestellung4.selectedIndex].value);
  if (document.Formular.bestellung5) cenaZbozi += vratCenu(document.Formular.bestellung5.options[document.Formular.bestellung5.selectedIndex].value);
  if (document.Formular.bestellung6) cenaZbozi += vratCenu(document.Formular.bestellung6.options[document.Formular.bestellung6.selectedIndex].value);
  if (document.Formular.bestellung7) cenaZbozi += vratCenu(document.Formular.bestellung7.options[document.Formular.bestellung7.selectedIndex].value);
  if (document.Formular.bestellung8) cenaZbozi += vratCenu(document.Formular.bestellung8.options[document.Formular.bestellung8.selectedIndex].value);
  // cena dopravy
  for (idx=0;idx<10;idx++) {
    if (document.Formular.bestellung9[idx]) { 
      if (document.Formular.bestellung9[idx].checked) {
         cenaDopravy += vratCenu(document.Formular.bestellung9[idx].value);
      }
    }
  }  
  // cena celkem  
  cenaCelkem = cenaDopravy + cenaZbozi;
  
  document.Formular.kosikCena.value = cenaZbozi + ' €'; 
  document.Formular.kosikDoprava.value = cenaDopravy + ' €'; 
  document.Formular.kosikCelkem.value = cenaCelkem + ' €'; 
}

// funkce, ktera se vola pred placenim pri zmene osloveni - pan, pani, firma atd
// pouze kvuli predchozi kompatibilite, jinak nema vyznam
function ustidform2()
{
  if (ustidformular) 
  {
    ust_id();
  }
  zweipruefen(4);
}


