function select_all(chbox){
    if( chbox.checked ){
        formularz = chbox.form;
        var i = 0;
        while(typeof(formularz.elements['checkbox_name['+ i +']']) == 'object'){
            formularz.elements['checkbox_name['+ i +']'].checked = true;
            i++;
        }
    }else{
        formularz = chbox.form;
        var i = 0;
        while(typeof(formularz.elements['checkbox_name['+ i +']']) == 'object'){
            formularz.elements['checkbox_name['+ i +']'].checked = false;
            i++;
        }
    }
}

function otworz_okno(adres){
     var width = 800;
     var height = 600;
     cx=(screen.availWidth-width)/2;
     cy=(screen.availHeight-height)/2;
     okno = window.open(adres,"","height="+height+",width="+width+",top="+cy+",left="+cx+",status=0,scrollbars,resizable;");
     okno.focus();
}


function zmien_kolor_obramowania(el, error, komunikat){
  if(!error){
          el.onmouseover=function anonymous(){}
          el.onmouseout=function anonymous(){}
          el.style.borderColor='#D4DFE4';
          return true;
  }else{
          el.style.borderColor='red';
          el.onmouseover=function anonymous(){ return overlib(komunikat); }
          el.onmouseout=function anonymous(){nd();}
          el.onclick=function anonymous(){ nd(); this.onmouseover=function anonymous(){} }
          return false;
  }
}


function checkInput(el, zezwalajNaPuste, wyrazenie, komunikat){
  var wartosc = el.value;

  //usuwamy spacje z poczatku i końca ciagu
  wartosc=wartosc.replace(/^(\s)+/,"");
  wartosc=wartosc.replace(/(\s)+$/,"");
  if( wartosc == ""){
   if(zezwalajNaPuste){
     el.onmouseover=function anonymous(){}
     el.onmouseout=function anonymous(){}
     el.style.borderColor='#D4DFE4';
     return true;
   }else{
     el.style.borderColor='red';
     el.onmouseover=function anonymous(){
                                  return overlib('To pole nie może być puste.');
                          }
     el.onmouseout=function anonymous(){
                                  nd();
                          }
     el.onclick=function anonymous(){
                                  nd();
                                  this.onmouseover=function anonymous(){}
                          }
     return false;
   }
  }else{
    if(typeof(wyrazenie)!="string") {
       if(wyrazenie.test(wartosc)){
          el.onmouseover=function anonymous(){}
          el.onmouseout=function anonymous(){}
          el.style.borderColor='#D4DFE4';
          return true;
       }else{
          el.style.borderColor='red';
          el.onmouseover=function anonymous(){
                                  return overlib(komunikat);
                          }
          el.onmouseout=function anonymous(){
                                  nd();
                          }
          el.onclick=function anonymous(){
                                  nd();
                                  this.onmouseover=function anonymous(){}
                          }
          return false;
       }
    }else{
          el.onmouseover=function anonymous(){}
          el.onmouseout=function anonymous(){}
          el.style.borderColor='#D4DFE4';
          return true;
    }
  }
}


function checkNIP( nip_input ){
 var  suma = 0;
 var error = false;
 
 var  nip  = new String(nip_input.value.replace(/-/g,""));
 nip = nip.replace(/^(\s)+/,"");
 nip = nip.replace(/(\s)+$/,"");
 var  kontrol = parseInt(nip.charAt(nip.length-1));
 error = !checkInput(nip_input,true,/^(\d{3}\-\d{3}-\d{2}-\d{2})|(\d{3}\-\d{2}-\d{2}-\d{3})$/,'NIP powinien mieć następujący format: 999-999-99-99 lub 999-99-99-999');

 if(error){
    return false;
 }

 wartosc = nip_input.value;
 wartosc = wartosc.replace(/^(\s)+/,"");
 wartosc = wartosc.replace(/(\s)+$/,"");
 if( wartosc == ""){
     nip_input.onmouseover=function anonymous(){}
     nip_input.onmouseout=function anonymous(){}
     nip_input.style.borderColor='#CFCFCF';
     return true;
 }
  

 suma  = parseInt(nip.charAt(0)) * 6;
 suma += parseInt(nip.charAt(1)) * 5;
 suma += parseInt(nip.charAt(2)) * 7;

 suma += parseInt(nip.charAt(3)) * 2;
 suma += parseInt(nip.charAt(4)) * 3;
 suma += parseInt(nip.charAt(5)) * 4;

 suma += parseInt(nip.charAt(6)) * 5;
 suma += parseInt(nip.charAt(7)) * 6;

 suma += parseInt(nip.charAt(8)) * 7;

 suma-=(Math.floor(suma / 11) * 11);
 if(suma == 10){
   suma = 0;
 }
 
 if(suma == kontrol){
    zmien_kolor_obramowania(nip_input, false, "");
    return true;
 }else{
    zmien_kolor_obramowania(nip_input, true, "NIP jest niepoprawny!");
    return false;
 }
}


function rejestracja(f){
 var error = false;

 if(!checkInput(f.login,false,/^[^\%\\\/`"\'\s ~]{6,64}$/,'Login powinien składaś się przynajmniej z 6-ciu znaków, innych niż: \' \\ % ` " ~!')){
    error = "true";
 }

 if(!checkInput(f.password,false,/^[^\%\\\/`"\s ~]{6,16}$/,'Hasło powinno zawierać jedną cyfrę i składać się z minimum 6 znaków, innych niż: % \\ / ` " ~ i spacji.')){
    error = "true";
 }
 
 if( f.password.value != f.rePassword.value){
    zmien_kolor_obramowania(f.rePassword, true, 'Hasła się nie zgadzają!!!');
    error = "true";
 }else{
    zmien_kolor_obramowania(f.rePassword, false, '');
 }

 if(!checkInput(f.odpowiedz,false,'','')){
    error = "true";
 }

 if(!checkInput(f.lastName,false,'','')){
    error = "true";
 }

 if(!checkInput(f.firstName1,false,'','')){
    error = "true";
 }

 if(!checkInput(f.elements["title"],false,'','')){
    error = "true";
 }

 if(!checkInput(f.office,false,'','')){
    error = "true";
 }

 if(!checkInput(f.post,false,'','')){
    error = "true";
 }

 if(!checkInput(f.postCode, false, /^[0-9][0-9]-[0-9][0-9][0-9]$/,'Nieprawidłowy format kodu pocztowego!','')){
    error = "true";
 }

 if(!checkInput(f.city, false, '', '')){
    error = "true";
 }

 if(!checkInput(f.address, false, '','')){
    error = "true";
 }
 
 if(!checkInput(f.email, false, /^[\w\-\.]+@[^\.]+(\.\w+)+$/,'Nieprawidłowy format adresu email.')){
    error = "true";
 }

 if(!f.zgoda1.checked){
     el = document.getElementById('zgoda1_label');

     el.onmouseover=function anonymous(){ return overlib('Musisz zaznaczyc tę opcję!!!'); }
     el.onmouseout=function anonymous(){nd();}
     el.onclick=function anonymous(){ nd(); this.onmouseover=function anonymous(){} }

     error = true;
 }else{
     el = document.getElementById('zgoda1_label');

     el.onmouseover=function anonymous(){}
     el.onmouseout=function anonymous(){}
     el.style.borderColor='#B1B8BE';
 }

 if(!f.zgoda2.checked){
     el = document.getElementById('zgoda2_label');

     el.onmouseover=function anonymous(){ return overlib('Musisz wyrazić zgodę na przetwarzanie swoich danych osobowych, przez komitet Sympozjum!!!'); }
     el.onmouseout=function anonymous(){nd();}
     el.onclick=function anonymous(){ nd(); this.onmouseover=function anonymous(){} }

     error = "true";
 }else{
     el = document.getElementById('zgoda2_label');

     el.onmouseover=function anonymous(){}
     el.onmouseout=function anonymous(){}
     el.style.borderColor='#B1B8BE';
 }
 

 if(error){
    alert('Popraw formularz!');
    return false;
 }else{
    return true;
 }
 
}


function rejestracja(f){
 var error = false;
 if(f.password != ""){
     if(!checkInput(f.newPassword,false,/^[^\%\\\/`"\s ~]{6,16}$/,'Hasło powinno zawierać jedną cyfrę i składać się z minimum 6 znaków, innych niż: % \\ / ` " ~ i spacji.')){
         error = "true";
     }
     
     if( f.newPassword.value != f.rePassword.value){
        zmien_kolor_obramowania(f.rePassword, true, 'Hasła się nie zgadzają!!!');
        error = "true";
     }else{
        zmien_kolor_obramowania(f.rePassword, false, '');
     }
 }

 if(!checkInput(f.odpowiedz, false, '', '')){
    error = "true";
 }

 if(!checkInput(f.lastName, false, '', '')){
    error = "true";
 }

 if(!checkInput(f.firstName1,false,'','')){
    error = "true";
 }

 if(!checkInput(f.elements["title"],false,'','')){
    error = "true";
 }

 if(!checkInput(f.office,false,'','')){
    error = "true";
 }

 if(!checkInput(f.post,false,'','')){
    error = "true";
 }

 if(!checkInput(f.postCode, false, /^[0-9][0-9]-[0-9][0-9][0-9]$/,'Nieprawidłowy format kodu pocztowego!','')){
    error = "true";
 }

 if(!checkInput(f.city, false, '', '')){
    error = "true";
 }

 if(!checkInput(f.address, false, '','')){
    error = "true";
 }

 if(!checkInput(f.email, false, /^[\w\-\.]+@[^\.]+(\.\w+)+$/,'Nieprawidłowy format adresu email.')){
    error = "true";
 }

 if(error){
    alert('Popraw formularz!');
    return false;
 }else{
    return true;
 }

}


function rejestracja1(f){
 var error = false;

 if(!checkInput(f.email, false, /^[\w\-\.]+@[^\.]+(\.\w+)+$/,'Nieprawidłowy format adresu email.')){
    error = "true";
 }

if(typeof(f.fakturaVAT[0]) != 'undefined'){
 if( f.fakturaVAT[0].checked){
    if(!checkInput(f.nazwa,false,'','')){
       error = "true";
    }

    if(!checkInput(f.kod, false, /^[0-9][0-9]-[0-9][0-9][0-9]$/,'Nieprawidłowy format kodu pocztowego!','')){
        error = "true";
    }

    if(!checkInput(f.miejscowosc,false,'','')){
        error = "true";
    }

    if(!checkInput(f.adres,false,'','')){
        error = "true";
    }

    if(!checkNIP(f.nip)){
        error = "true";
    }

 }
}


 if(error){
    alert('Popraw formularz!');
    return false;
 }else{
    return true;
 }


 
}


function sprawdz_fakture(f){
var error = false;

if( f.fakturaVAT[0].checked  ){

 if(!checkInput(f.nazwa,false,'','')){
    error = "true";
 }

 if(!checkInput(f.kod, false, /^[0-9][0-9]-[0-9][0-9][0-9]$/,'Nieprawidłowy format kodu pocztowego!','')){
    error = "true";
 }

 if(!checkInput(f.miejscowosc,false,'','')){
    error = "true";
 }

 if(!checkInput(f.adres,false,'','')){
    error = "true";
 }

 if(!checkNIP(f.nip)){
    error = "true";
 }

}

 if(error){
    alert('Popraw formularz!');
    return false;
 }else{
    return true;
 }


}

function przelicz(formularz){
   var doby  = parseInt(formularz.termin_do.value) - parseInt(formularz.termin_od.value);
   if( doby <= 0){
      return false;
   }
   kwota = doby * parseFloat(formularz.cena.value);
   kwota = parseFloat(kwota);
   formularz.kwota.value = kwota.toFixed(2);
   formularz.kwota.value = formularz.kwota.value.replace("\.",",");
}

function informacja(){
     var width = 800;
     var height = 600;
     cx=(screen.availWidth-width)/2;
     cy=(screen.availHeight-height)/2;
     okno = window.open('info.html',"","height="+height+",width="+width+",top="+cy+",left="+cx+",status=0,scrollbars,resizable;");
     okno.focus();
}



function komunikat(id){
     var width = 500;
     var height = 350;
     cx=(screen.availWidth-width)/2;
     cy=(screen.availHeight-height)/2;
     okno = window.open("zjazd-informacje.php?action=komunikat&komunikatID="+id,"komunikat","height="+height+",width="+width+",top="+cy+",left="+cx+",status=0,scrollbars,resizable;");
     okno.focus();
}


function pokaz_ukryj(el_id){
     var el = document.getElementById(el_id);

     if(el.style.display == 'none'){
         el.style.display = 'block';
     }else{
         el.style.display = 'none';
     }
}

function show_hide_faktura(show_hide){
     var fakturaTab = document.getElementById('fakturaTab');
     
     if(show_hide == 'show'){
         fakturaTab.style.display = 'block';
     }
     if(show_hide == 'hide'){
         fakturaTab.style.display = 'none';
     }

}

function go2page(el){
      el.submit();
}
