
function ChangeVisibility2(layer)
{
    diver=document.getElementById(layer);
    
    
    if (diver.style.display=='none') diver.style.display='block';
    else
    if (diver.style.display=='block') diver.style.display='none';
    
}

function ChangeVisibilityTrescPotwierdzenia()
{
    layer1=document.getElementById('tresc1');
    layer2=document.getElementById('tresc2');
    
    if (layer1.style.display=='none') layer1.style.display='block';
    else
    if (layer1.style.display=='block') layer1.style.display='none';
    
    if (layer2.style.display=='none') layer2.style.display='block';
    else
    if (layer2.style.display=='block') layer2.style.display='none';
    
}

function wyslijform(form)
{
    document.getElementById(form).submit();
}

function wyslijformSendData(form)
{
    var index=document.getElementById('INPUT[index4]').value;
    document.getElementById('INPUT[index]').value=index;
    
    var sortowanie=document.getElementById('INPUT[sortowanie2]').value;
    document.getElementById('INPUT[sortowanie]').value=sortowanie;
    
    document.getElementById(form).submit();
}

function wyslijformlistatowaro(form,akcja)
{
    var val=document.getElementById('INPUT[index]').value;
    
    if(akcja=='nastepna')    val++;
    if(akcja=='poprzednia')  val--;
    
    document.getElementById('INPUT[index]').value=val;
    
    document.getElementById(form).submit();
}

function wyslijformlistatowarsenddata(form,akcja)
{
    var index=document.getElementById('INPUT[index3]').value;
    document.getElementById('INPUT[index2]').value=index;
    
    wyslijformlistatowaro(form,akcja);
        
}

function ChangAction(controller,caction,submit_form)
{
    document.getElementById("h3").value=controller;
    document.getElementById("h4").value=caction;
}

function ChangActionSubmit(controller,caction,submit_form,form_name)
{
    var formularz=document.forms[form_name];
    document.getElementById("h3").value=controller;
    document.getElementById("h4").value=caction;
    
    if(submit_form=='yes') formularz.submit();
}

function ChangActionCheckAdres(controller,caction)
{
    var formularz=document.forms['koszyk_adresdostawy'];
    var napis="";
    var brakuje_danych=false;
    
    document.getElementById("h3").value=controller;
    document.getElementById("h4").value=caction;
    adres=document.getElementById("adres_dostawy").value;
    
    if (formularz.elements['INPUT[nazwa1_fak]'].value == ""){
    napis += "Nie podano nazwy.\n"
    brakuje_danych=true;
    }
    
    if (formularz.elements['INPUT[ulica_fak]'].value == ""){
    napis += "Nie podano nazwy ulicy.\n"
    brakuje_danych=true;
    }
    
    if (formularz.elements['INPUT[nr_domu_fak]'].value == ""){
    napis += "Nie podano numeru domu.\n"
    brakuje_danych=true;
    }
    
    if (formularz.elements['INPUT[kod_fak]'].value == ""){
    napis += "Nie podano kodu pocztowego.\n"
    brakuje_danych=true;
    }
    
    if (formularz.elements['INPUT[miasto]'].value == ""){
    napis += "Nie podano nazwy miasta.\n"
    brakuje_danych=true;
    }
    
    if(adres!=0 )
    { 
        if (!brakuje_danych)
        {
            formularz.submit();
        }
        
        if(brakuje_danych)
        {
            alert ("Nie wypełnieś następujących pól w danych do faktury:\n" + napis);
        }  
    }
    else
    {
        alert("Wybierz adres dostawy.");
    }
    
    
    
}

function ChangActionDelete(controller,caction,question,caption) 
{
    if (question==1)
    {
        ans=window.confirm(caption); 
        if (ans==false)
        {
            return;
        }
        else
        {
            document.getElementById("h3").value=controller;
            document.getElementById("h4").value=caction;    
        }
    }
             
}

function ChangActionAndCheck(controller,caction,submit_form)
{
    document.getElementById("h3").value=controller;
    document.getElementById("h4").value=caction;
    
    var brakuje_danych=false;
    var formularz=document.forms['koszyk_adresdostawy'];
    var napis="";
    if (formularz.elements['INPUT[nazwa1]'].value == ""){
    napis += "Nie podano nazwiska\n"
    brakuje_danych=true;
    }
    if (formularz.elements['INPUT[nazwa2]'].value == ""){
    napis += "Nie podano imienia\n"
    brakuje_danych=true;
    }
  if (formularz.elements['INPUT[ulica]'].value == ""){
    napis += "Nie podano nazwy ulicy\n"
    brakuje_danych=true;
  }
  if (formularz.elements['INPUT[miasto]'].value == ""){
    napis += "Nie podano nazwy miasta\n"
    brakuje_danych=true;
  }
  
  if (formularz.elements['INPUT[nr_tel1]'].value == "" && formularz.elements['INPUT[nr_telkom]'].value == ""){
    napis += "Nie podano żadnego numeru kontaktowego\n"
    brakuje_danych=true;
  }
  
    if(submit_form=='yes')
    {
        if (formularz.elements['INPUT[nazwa_listy]'].value == "" && formularz.elements['INPUT[nazwa_listy]'].value == ""){
            napis += "Nie podano nazwy pod jaką chcesz zapisać ten adres dostawy.\n"
            brakuje_danych=true;
        }
    }
   if (!brakuje_danych)
   {
        formularz.submit();
   }
   if(brakuje_danych)
   {
        alert ("Nie wypełnieś następujących pól:\n" + napis);
   }
}
     
function ChangActionAndCheck2(controller,caction,submit_form)
{
    document.getElementById("h3").value=controller;
    document.getElementById("h4").value=caction;
    
    var brakuje_danych=false;
    var formularz=document.forms['koszyk_adresdostawy'];
    var napis="";
    if (formularz.elements['INPUT[nazwa1]'].value == ""){
    napis += "Nie podano nazwiska\n"
    brakuje_danych=true;
    }
    if (formularz.elements['INPUT[nazwa2]'].value == ""){
    napis += "Nie podano imienia\n"
    brakuje_danych=true;
    }
  if (formularz.elements['INPUT[ulica]'].value == ""){
    napis += "Nie podano nazwy ulicy\n"
    brakuje_danych=true;
  }
  if (formularz.elements['INPUT[miasto]'].value == ""){
    napis += "Nie podano nazwy miasta\n"
    brakuje_danych=true;
  }
  
  if (document.koszyk_adresdostawy.zgoda.checked == false){
    napis += "Musisz wyrazić zgode na przetważanie danych osobowych.\n"
    brakuje_danych=true;
  }
  
  if (formularz.elements['INPUT[nr_tel1]'].value == "" && formularz.elements['INPUT[nr_telkom]'].value == ""){
    napis += "Nie podano żadnego numeru kontaktowego\n"
    brakuje_danych=true;
  }
  
    if (formularz.elements['INPUT[email]'].value == "" && formularz.elements['INPUT[email]'].value == ""){
    napis += "Nie podano żadnego adresu e-mail.\n"
    brakuje_danych=true;
  }
    
   if (!brakuje_danych)
   {
        formularz.submit();
   }
   if(brakuje_danych)
   {
        alert ("Nie wypełnieś następujących pól:\n" + napis);
   }
}
     
     
function clearDefault(EL) 
{    
    if (EL.defaultValue == EL.value) EL.value = '';
}

function AddValue(element)
{
    value=document.getElementById(element).value;
    value++;
    document.getElementById(element).value=value;
}

function SubValue(element)
{
    value=document.getElementById(element).value;
    value--;
    if (value<1) value=1;
    document.getElementById(element).value=value;
}

function SendCount()
{
    value_count=document.getElementById('count').value;
    document.getElementById('INPUT[ilosc]').value=value_count;        
}  

function SendDataToPopUp(formularz)
{
    value1=document.getElementById('pgid').value;
    document.getElementById('INPUT[pgid]').value=value1;
    
    value2=document.getElementById('gid').value;
    document.getElementById('INPUT[gid]').value=value2;
    
    value3=document.forms[formularz].elements['INPUT[idel]'].value;
    document.getElementById('INPUT[id_towaru]').value=value3;        
} 

function ShowButton(element,warunek)
{
    val=document.getElementById(element).value; 
    if(val!=warunek) document.getElementById('button_dodaj2').style.display='inline';
} 

function ShowButtonTowar(element,warunek)
{
    val=document.getElementById(element).value; 
    if(val!=warunek) document.getElementById('button_dodaj').style.display='inline';
} 

function ShowButtonKoszykBok(element,warunek)
{
    val=document.getElementById(element).value; 
    if(val!=warunek) document.getElementById('button_dodaj3').style.display='inline';
}

function CheckDataAdres()
{
  var brakuje_danych=false;
  var formularz=document.forms['dodawanie_adresu_dostawy'];
  var napis="";
  if (formularz.elements['INPUT[nazwa1]'].value == ""){
    napis += "Nie podano nazwiska\n"
    brakuje_danych=true;
  }
  if (formularz.elements['INPUT[nazwa2]'].value == ""){
    napis += "Nie podano imienia\n"
    brakuje_danych=true;
  }
  if (formularz.elements['INPUT[ulica]'].value == ""){
    napis += "Nie podano nazwy ulicy\n"
    brakuje_danych=true;
  }
  if (formularz.elements['INPUT[miasto]'].value == ""){
    napis += "Nie podano nazwy miasta\n"
    brakuje_danych=true;
  }
  
  if (formularz.elements['INPUT[nr_tel1]'].value == "" && formularz.elements['INPUT[nr_telkom]'].value == ""){
    napis += "Nie podano żadnego numeru kontaktowego\n"
    brakuje_danych=true;
  }
  
   if (!brakuje_danych)
        formularz.submit();
  else
    alert ("Nie wypełnieś następujących pól:\n" + napis);
  
  
}   

function SetValue(name,var_value)
{
    document.getElementById(name).value=var_value;            
}    

function SetValueAndCheck(form_id,name,var_value,check_value,show_edit,warunek)
{
    var formularz=document.forms[form_id];
    
    document.getElementById(name).value=var_value;  
    
    var zmienna=formularz.elements[check_value].value;
    //alert(form_id);   
    if(zmienna!=warunek)
    { 
        formularz.submit(); 
    }
    else
    {
        document.getElementById(show_edit).style.display='block';   
    }
}
