function okno(pole) {
  o = window.open("kalendarz.php?p="+pole, "k", "width=200, height=200,"
   + " left=100,top=25,innerwidth=200,innerheight=200,location=0,status=0,"
   + " directories=0, scrollbars=0, menubar=0, toolbar=0, resizable=1");
  o.focus();
  return false;
}

function changeTab(nr){

  for(var i=0; i<4; i++){
    document.getElementById('et'+i).style.display='none';
  }
  document.getElementById('et'+nr).style.display='';
  document.getElementById('tt0').src='gfx/etapy/formularz_2_01.gif';
  document.getElementById('tt1').src='gfx/etapy/formularz_2_02.gif';
  document.getElementById('tt2').src='gfx/etapy/formularz_2_03.gif';
  document.getElementById('tt3').src='gfx/etapy/formularz_2_04.gif';

  document.getElementById('etap').value=nr;

  if(nr==0){ document.getElementById('tt0').src='gfx/etapy/formularz_2_01_over.gif'; }
  else if(nr==1){ document.getElementById('tt1').src='gfx/etapy/formularz_2_02_over.gif'; }
  else if(nr==2){ document.getElementById('tt2').src='gfx/etapy/formularz_2_03_over.gif'; }
  else if(nr==3){ document.getElementById('tt3').src='gfx/etapy/formularz_2_04_over.gif'; }
}

  function pak(nr)
   {
    if(nr==0){
     document.getElementById('a').style.display='';
     document.getElementById('b').style.display='';
     document.getElementById('c').style.display='';
     document.getElementById('d').style.display='';
     document.getElementById('aa').style.display='none';
     document.getElementById('bb').style.display='none';
     document.getElementById('cc').style.display='none';
     document.getElementById('dd').style.display='none';

    }
    else if(nr==1){
     document.getElementById('a').style.display='none';
     document.getElementById('b').style.display='none';
     document.getElementById('c').style.display='none';
     document.getElementById('d').style.display='none';
     document.getElementById('aa').style.display='';
     document.getElementById('bb').style.display='';
     document.getElementById('cc').style.display='';
     document.getElementById('dd').style.display='';
    }
   }


   function sprawdz(theForm)
   {

      if (theForm.pakiet[0].checked == false && theForm.pakiet[1].checked == false && theForm.pakiet[2].checked == false && theForm.pakiet[3].checked == false)
      {
       alert("Prosze wybrać pakiet");
       return (false);
      }
      
      return(true);
   
   }
   
   function sprawdz1(theForm,pakiet)
   {
    if(pakiet==1){
     for (i=0;i<theForm.business.length;i++)
       if (theForm.business[i].checked) var radok=1;
         if (radok!=1) { alert("Proszę wybrać wersję kolorystyczną dystrybutora"); return false; }
     }
     else if(pakiet==2){
       for (i=0;i<theForm.economy.length;i++)
       if (theForm.economy[i].checked) var radok=1;
         if (radok!=1) { alert("Proszę wybrać wersję kolorystyczną dystrybutora"); return false; }
     }
    }

    function sprawdz2(theForm)
   {
     if((theForm.mini.value!=0)||(theForm.compact.value!=0)||(theForm.classic.value!=0)||(theForm.office.value!=0)){
        if((isNaN(theForm.mini.value)==true)||(isNaN(theForm.compact.value)==true)||(isNaN(theForm.classic.value)==true)||(isNaN(theForm.office.value)==true)){
          alert("Podana wartość musi być liczbą");
          theForm.mini.value="0";
          theForm.compact.value="0";
          theForm.classic.value="0";
          theForm.office.value="0";
          return (false);
        }else{
          if(theForm.mini.value==''){mini=0;}else{mini=parseInt(theForm.mini.value);}
          if(theForm.compact.value==''){compact=0;}else{compact=parseInt(theForm.compact.value);}
          if(theForm.classic.value==''){classic=0;}else{classic=parseInt(theForm.classic.value);}
          if(theForm.office.value==''){office=0;}else{office=parseInt(theForm.office.value);}

          var butle= parseInt(theForm.butle.value);
          var ilosc=Math.round((butle+2)/5);
          var suma=mini+compact+classic+office;
          if(suma>parseInt(ilosc))
          {
           alert("Dodatkowych dystrybutorów nie więcej niż "+ilosc);
           return (false);
          }
        }
      }
      return(true);
    }
    function sprawdz3(countMi,countCo,countCl,countOf,mini,compact,classic,office,ilosc,countSt)
   {
     var sumaM=0;
     var sumaCo=0;
     var sumaCl=0;
     var sumaOf=0;
     var sumaSt=0;

     if(compact!=0){
      for(i=1;i<=countCo;i++){
          if((isNaN(document.getElementById('compact'+i).value)==true)||(document.getElementById('compact'+i).value=="")){ co=0; }
          else{ co=parseInt(document.getElementById('compact'+i).value); }
          sumaCo+=co;
       }
          if(sumaCo!=compact){
           alert("Nie zgadza sie liczba dystrybutorow Compact: powinno byc "+compact+", a jest "+sumaCo);
           return(false);
          }

       
     }

     if(classic!=0){
       for(i=1;i<=countCl;i++){
          if((isNaN(document.getElementById('classic'+i).value)==true)||(document.getElementById('classic'+i).value=="")){ cl=0; }
          else{ cl=parseInt(document.getElementById('classic'+i).value); }
          sumaCl+=cl;
       }
          if(sumaCl!=classic){
           alert("Nie zgadza sie liczba dystrybutorow Classic: powinno byc "+classic+", a jest "+sumaCl);
           return(false);
          }
     }

     if(mini!=0){
       for(i=1;i<=countMi;i++){
          if((isNaN(document.getElementById('mini'+i).value)==true)||(document.getElementById('mini'+i).value=="")){ min=0; }
          else{ min=parseInt(document.getElementById('mini'+i).value); }
          sumaM+=min;
       }
        if(sumaM!=mini){
          alert("Nie zgadza sie liczba dystrybutorow Mini: powinno byc "+mini+", a jest "+sumaM);
          return(false);
         }
     }


     if(office!=0){
       for(i=1;i<=countOf;i++){
          if((isNaN(document.getElementById('office'+i).value)==true)||(document.getElementById('office'+i).value=="")){ off=0; }
          else{ off=parseInt(document.getElementById('office'+i).value); }
          sumaOf+=off
       }
          if(sumaOf!=office){
           alert("Nie zgadza sie liczba dystrybutorow Office: powinno byc "+office+", a jest "+sumaOf);
           return(false);
           }

     }
      sumaAll=mini+compact+classic+office;

      if(countSt!=0){
       for(j=1;j<=countSt;j++){
          if((isNaN(document.getElementById('stojaki'+j).value)==true)||(document.getElementById('stojaki'+j).value=="")){ st=0; }
          else{ st=parseInt(document.getElementById('stojaki'+j).value); }
         sumaSt+=st;
       }
          if(sumaSt>sumaAll){
           alert("Stojakow nie więcej niż dystrybutorow ("+sumaAll+")");
           return(false);
          }
       }

     return(true);
    }

function sprawdz4(theForm,umowa){



  if (theForm.imie.value == "")
  {
    alert("Proszę wypełnić pole: 'Imię i nazwisko'");
    theForm.imie.focus();
    return (false);
  }

  if (theForm.nazwa.value == "")
  {
    alert("Proszę wypełnić pole: 'Nazwa firmy'");
    theForm.nazwa.focus();
    return (false);
  }

  if (theForm.adres.value == "")
  {
    alert("Proszę wypełnić pole: 'Adres'");
    theForm.adres.focus();
    return (false);
  }

   if (theForm.miasto.value == "")
  {
    alert("Proszę wypełnić pole: 'Miasto'");
    theForm.miasto.focus();
    return (false);
  }

  if (theForm.tel1.value == "")
  {
    alert("Proszę wypełnić pole: 'Numer telefonu'");
    theForm.tel1.focus();
    return (false);
  }

  if (theForm.tel2.value == "")
  {
    alert("Proszę wypełnić pole: 'Numer telefonu'");
    theForm.tel2.focus();
    return (false);
  }


  if (theForm.email.value == "")
  {
    alert("Proszę wypełnić pole Adres e-mail");
    theForm.email.focus();
    return (false);
  }

   if (theForm.email.value != "")
   {
	   if (theForm.email.value.indexOf('@', 0) == -1)
	  {
	    alert("Proszę podać poprawny adres e-mail");
   		 theForm.email.focus();
		 return (false);
	  }
   }


    if(theForm.adresDostawa.checked == false){

         if (theForm.imie_dos.value == "")
  {
    alert("Proszę wypełnić pole: 'Imię i nazwisko'");
    theForm.imie_dos.focus();
    return (false);
  }

  if (theForm.nazwa_dos.value == "")
  {
    alert("Proszę wypełnić pole: 'Nazwa firmy'");
    theForm.nazwa_dos.focus();
    return (false);
  }

  if (theForm.adres_dos.value == "")
  {
    alert("Proszę wypełnić pole: 'Adres'");
    theForm.adres_dos.focus();
    return (false);
  }

   if (theForm.miasto_dos.value == "")
  {
    alert("Proszę wypełnić pole: 'Miasto'");
    theForm.miasto_dos.focus();
    return (false);
  }

  if (theForm.tel1_dos.value == "")
  {
    alert("Proszę wypełnić pole: 'Numer telefonu'");
    theForm.tel1_dos.focus();
    return (false);
  }

  if (theForm.tel2_dos.value == "")
  {
    alert("Proszę wypełnić pole: 'Numer telefonu'");
    theForm.tel2_dos.focus();
    return (false);
  }

  if (theForm.email_dos.value == "")
  {
    alert("Proszę wypełnić pole Adres e-mail");
    theForm.email_dos.focus();
    return (false);
  }

   if (theForm.email_dos.value != "")
   {
	   if (theForm.email_dos.value.indexOf('@', 0) == -1)
	  {
	    alert("Proszę podać poprawny adres e-mail");
   		 theForm.email_dos.focus();
		 return (false);
	  }
   }

}

  if (theForm.godz_dos[0].checked == false && theForm.godz_dos[1].checked == false)
    {
     alert("Prosze wybrać godziny dostawy");
     return (false);
    }

  if(umowa=="1"){
    if (theForm.akceptacja.checked == false)
    {
     alert("Prosze zaznaczyć pole: 'Akceptuję warunki umowy' ");
     return (false);
    }
   }
	
    if (theForm.przetwarzanie.checked == false)
    {
     alert("Prosze zaznaczyć pole: 'Wyrażam zgodę na przetwarzanie moich danych osobowych ...' ");
     return (false);
    }


  return (true);

}




function sprawdz5(theForm,count){


  if (theForm.imie.value == "")
  {
    alert("Proszę wypełnić pole: 'Imię i nazwisko'");
    theForm.imie.focus();
    return (false);
  }

  if (theForm.firma.value == "")
  {
    alert("Proszę wypełnić pole: 'Nazwa firmy'");
    theForm.firma.focus();
    return (false);
  }

  if (theForm.adres.value == "")
  {
    alert("Proszę wypełnić pole: 'Adres'");
    theForm.adres.focus();
    return (false);
  }

   if (theForm.miasto.value == "")
  {
    alert("Proszę wypełnić pole: 'Miasto'");
    theForm.miasto.focus();
    return (false);
  }

  if (theForm.tel1.value == "")
  {
    alert("Proszę wypełnić pole: 'Numer telefonu'");
    theForm.tel1.focus();
    return (false);
  }

  if (theForm.tel2.value == "")
  {
    alert("Proszę wypełnić pole: 'Numer telefonu'");
    theForm.tel2.focus();
    return (false);
  }

   if (theForm.osoba.value == "")
  {
    alert("Proszę wypełnić pole: 'Osoba zgłaszająca zmianę'");
    theForm.osoba.focus();
    return (false);
  }

   if (theForm.email_klient.value.indexOf('@', 0) == -1)
  {
	    alert("Proszę podać poprawny adres e-mail");
   		 theForm.email_klient.focus();
		 return (false);
  }

   var sumC=0;
   var suma=0;
   for(i=1;i<=count;i++){
   if((isNaN(document.getElementById('pro'+i).value)==true)||(document.getElementById('pro'+i).value=="")){ pro=0; }
   else{ pro=parseInt(document.getElementById('pro'+i).value); }
     sumC=pro*document.getElementById('cen'+i).value;
    suma+=sumC;
   }

  if(suma==0 && ((theForm.dodatkowe_butle.value==""||theForm.dodatkowe_butle.value==0) && theForm.data.value=="") && theForm.wstrzymanie.checked==false && theForm.imie1.value==""){
    alert("Wypełnij przynajmniej jedną zakładkę");
    return (false);
  }
  else{
   var etap=theForm.etapp.value;
   if(etap==0){

   
    if(theForm.dostawa[1].checked==true){
      var dzisiaj = new Date();
      var miesiac = dzisiaj.getMonth()+1;
      var dzien = dzisiaj.getDate();
      var rok = dzisiaj.getYear();

      if (miesiac < 10){ miesiac = "0" + miesiac; }
      if (dzien < 10){ dzien = "0" + dzien; }
      if(rok <= 99){ rok += 1900; }
      var data=rok + "-" + miesiac + "-" + dzien;

     if ((theForm.data.value<data)||theForm.data.value=='') {
        alert("Podana data musi być większa od dzisiejszej daty!");
        theForm.data.value='';
        return false;
      }
    
    }
    if((theForm.dodatkowe_butle.value=="0" || theForm.dodatkowe_butle.value=="") && theForm.data.value==""){
      if(theForm.dodatkowe_butle.value<2){
      alert("Można zamówić minimalnie 2 sztuki butli z wodą");
      theForm.dodatkowe_butle.focus();
      return (false);
     }
    }
    
  }
  else if(etap==2){
     if(theForm.wstrzymanie.checked==true){
       if(theForm.miesiac.value=="none"){
         alert("Wybierz miesiąc");
         return (false);
       }
     }
  }
  else if(etap==3){

  if (theForm.imie1.value == "")
  {
    alert("Proszę wypełnić pole: 'Imię i nazwisko'");
    theForm.imie1.focus();
    return (false);
  }

  if (theForm.nazwa1.value == "")
  {
    alert("Proszę wypełnić pole: 'Nazwa firmy'");
    theForm.nazwa1.focus();
    return (false);
  }

  if (theForm.adres1.value == "")
  {
    alert("Proszę wypełnić pole: 'Adres'");
    theForm.adres1.focus();
    return (false);
  }

   if (theForm.miasto1.value == "")
  {
    alert("Proszę wypełnić pole: 'Miasto'");
    theForm.miasto1.focus();
    return (false);
  }

  if (theForm.tel11.value == "")
  {
    alert("Proszę wypełnić pole: 'Numer telefonu'");
    theForm.tel11.focus();
    return (false);
  }

  if (theForm.tel12.value == "")
  {
    alert("Proszę wypełnić pole: 'Numer telefonu'");
    theForm.tel12.focus();
    return (false);
  }


  if (theForm.email1.value == "")
  {
    alert("Proszę wypełnić pole Adres e-mail");
    theForm.email1.focus();
    return (false);
  }

   if (theForm.email1.value != "")
   {
	   if (theForm.email1.value.indexOf('@', 0) == -1)
	  {
	    alert("Proszę podać poprawny adres e-mail");
   		 theForm.email1.focus();
		 return (false);
	  }
   }


    if(theForm.adresDostawa.checked == false){

         if (theForm.imie_dos.value == "")
  {
    alert("Proszę wypełnić pole: 'Imię i nazwisko'");
    theForm.imie_dos.focus();
    return (false);
  }

  if (theForm.nazwa_dos.value == "")
  {
    alert("Proszę wypełnić pole: 'Nazwa firmy'");
    theForm.nazwa_dos.focus();
    return (false);
  }

  if (theForm.adres_dos.value == "")
  {
    alert("Proszę wypełnić pole: 'Adres'");
    theForm.adres_dos.focus();
    return (false);
  }

   if (theForm.miasto_dos.value == "")
  {
    alert("Proszę wypełnić pole: 'Miasto'");
    theForm.miasto_dos.focus();
    return (false);
  }

  if (theForm.tel1_dos.value == "")
  {
    alert("Proszę wypełnić pole: 'Numer telefonu'");
    theForm.tel1_dos.focus();
    return (false);
  }

  if (theForm.tel2_dos.value == "")
  {
    alert("Proszę wypełnić pole: 'Numer telefonu'");
    theForm.tel2_dos.focus();
    return (false);
  }

  if (theForm.email_dos.value == "")
  {
    alert("Proszę wypełnić pole Adres e-mail");
    theForm.email_dos.focus();
    return (false);
  }

   if (theForm.email_dos.value != "")
   {
	   if (theForm.email_dos.value.indexOf('@', 0) == -1)
	  {
	    alert("Proszę podać poprawny adres e-mail");
   		 theForm.email_dos.focus();
		 return (false);
	  }
   }

}


  }
 }

  return (true);

}




    
function updateKoszt(theForm,trzy,piec,reszta)
{
  var val=theForm.value;
  var cena = 0;
  v = parseInt(val);

   if (isNaN(v) || v <= 0){
      alert("Podana wartość musi być liczbą");
      document.getElementById('kt').value='';
   }
   else{

     if (v <= 3) {
      cena = v * trzy;
      cenatxt = v + 'x '+trzy+' zł';
     }
     else if (v <= 8) {
      cena = 3 * trzy + (v-3) * piec;
      cenatxt = '3x '+trzy+' zł\n' + (v-3) + 'x '+piec+' zł';
     }
     else {
      cena = 3 * trzy + 5 * piec + (v-8) * reszta;
      cenatxt = '3x '+trzy+' zł \n'+ (6-1) +'x '+piec+' zł\n' + (v-8) + 'x '+reszta+' zł';
     }

     document.getElementById('kt').value=cenatxt + '\nRAZEM ' +cena.toFixed(2)+ ' zł';
     document.getElementById('sumButle').value=cena.toFixed(2);
   }
}

function oblicz(produkty)
{
  var sumC=0;
  var suma=0;
  for(i=1;i<=produkty;i++){
   if((isNaN(document.getElementById('produkty'+i).value)==true)||(document.getElementById('produkty'+i).value=="")){ pro=0; }
   else{ pro=parseInt(document.getElementById('produkty'+i).value); }
   sumC=pro*document.getElementById('cena'+i).value;
    suma+=sumC;
   }
   document.getElementById("sumDod").value=suma.toFixed(2);
}

function oblicz_dod(produkty)
{
  var sumC=0;
  var suma=0;
  for(i=1;i<=produkty;i++){
   if((isNaN(document.getElementById('pro'+i).value)==true)||(document.getElementById('pro'+i).value=="")){ pro=0; }
   else{ pro=parseInt(document.getElementById('pro'+i).value); }
   sumC=pro*document.getElementById('cen'+i).value;
    suma+=sumC;
   }
   document.getElementById("sumDoda").value=suma.toFixed(2);

}

