function odejmij(id,ilosc){
    if(ilosc > 1){
        document.odejmowanie.odejmij.value=id;
        document.odejmowanie.submit();
    }
    else{
        usun(id);
    }
}

function dodaj(id_koszyka){
    document.dodawanie.dodaj.value=id_koszyka;
    document.dodawanie.submit();
}

function usun(id){
    var tempKoszyk = "u"+ id;
    var komunikat = "Czy naprawdę usun±ć pozycję:\n";
    var tempNazwa = "nazwa" + id;
    var nazwa = document.getElementById(tempNazwa).value;
    var tempIlosc = "ile" + id;
    var ilosc = document.getElementById(tempIlosc).value;
    komunikat += nazwa + ' - ' + ilosc + " szt.";
    
    if(confirm(komunikat)){
        odznacz();
        document.getElementById(tempKoszyk).click();
        document.f.submit();
    }
}

function skasuj_zaznaczone(){
    var ile = 0;
    var komunikat = "Czy naprawdę usun±ć pozycję:\n";
    for (var i = 0; i < document.f.elements.length; i++) {
        var e = document.f.elements[i];
        if (e.type == 'checkbox') {
            if(e.checked){
                var tempKoszyk = e.value;
                var tempNazwa = "nazwa" + tempKoszyk;
                var nazwa = document.getElementById(tempNazwa).value;
                var tempIlosc = "ile" + tempKoszyk;
                var ilosc = document.getElementById(tempIlosc).value;
                komunikat += nazwa + ' - ' + ilosc + " szt.\n";
                ile++;
            }
        }
    }
    if(ile > 0){
        if(confirm(komunikat)){
            document.f.submit();
        }
    }
    else{
        alert("Nie zaznaczono pozycji do skasowania");
    }
}

function odznacz(){
  for (var i = 0; i < document.f.elements.length; i++) {
    var e = document.f.elements[i];
    if (e.type == 'checkbox') {
      if(e.checked){
        e.click();
      }
    }
  }
}
function zaznacz(){
  for (var i = 0; i < document.f.elements.length; i++) {
    var e = document.f.elements[i];
    if (e.type == 'checkbox'){
      if(!e.checked){
        e.click();
      }
    }
  }
}

