/* - - - - - - - - - - - - - - - - - - - - - - -
 JavaScript
 3 listopad 2007 17:01:00
 - - - - - - - - - - - - - - - - - - - - - - - */
 function popUp(URL) {
 day = new Date();
 id = day.getTime();
 eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=800,height=450,left =0,top =0');");
 }

 function get_data(link)
 {
   if (typeof window.ActiveXObject != 'undefined' )
   { doc = new ActiveXObject("Microsoft.XMLHTTP"); } else  { doc = new XMLHttpRequest(); }

   doc.open("GET", link, false);
   doc.send(null);
   if (doc.responseText==1) { document.register.form_uname.value=''; alert('Użytkownik istnieje !'); document.register.form_uname.focus; return false; }
   //document.getElementById("reisebeginn").innerHTML=doc.responseText;
 }

 function get_services(link)
 {
   if (typeof window.ActiveXObject != 'undefined' )
   { doc = new ActiveXObject("Microsoft.XMLHTTP"); } else  { doc = new XMLHttpRequest(); }

   doc.open("GET", link, false);
   doc.send(null);
   return doc.responseText;
   //if (doc.responseText==0) { alert('Musisz dodać conajmniej jedną usługę !'); return false; }
   //document.getElementById("reisebeginn").innerHTML=doc.responseText;
 }

 function checkEmail(myForm) {
 if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.ok_email.value)){
 return (true)
 } else
 {myForm.ok_email.value=''; myForm.ok_email.focus();
 return (false)}
 }
 function checkEmail1(myForm) {
 if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.alert_email.value)){
 return (true)
 } else
 { myForm.alert_email.value='';
 return (false)}
 }
 function checkEmail2(myForm) {
 if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.email.value)){
 return (true)
 } else
 {alert("Podano błędny adres email !"); myForm.email.value=''; myForm.email.focus();
 return (false)}
 }


 function format_numeric(input){
  var num = input.value.replace(/\,/g,'');
  if(isNaN(num)){alert('W tym polu można wpisać tylko cyfry !');
  //input.value = input.value.substring(0,input.value.length-1);}
  input.value = '';}
 }

 function validate(which,test)
 {
     if (which.form_uname.value=='') { alert ('Proszę wpisać Login !'); which.form_uname.focus(); return false; }
     if (which.form_haslo.value=='') { alert ('Proszę wpisać Hasło !'); which.form_haslo.focus(); return false; }
     if (which.form_haslo.value.length<6) { alert ('Hasło jest za krótkie !'); which.form_haslo.value=''; which.form_haslo.focus(); return false; }
     if (which.form_haslo.value != which.form_hasloo.value) { alert ('Weryfikacja hasła nie powiodła się !');  which.form_haslo.focus(); return false; }
     if (which.ok_imie.value=='') { alert ('Proszę wpisać Imię !'); which.ok_imie.focus(); return false; }
     if (which.ok_nazwisko.value=='') { alert ('Proszę wpisać Nazwisko !'); which.ok_nazwisko.focus(); return false; }
     if (which.firm_validate.value==1 && which.nazwa.value=='') { alert ('Proszę Nazwę firmy !'); which.nazwa.focus(); return false; }
     if (which.ulica.value=='') { alert ('Proszę wpisać Ulicę !'); which.ulica.focus(); return false; }
     if (which.kod.value=='') { alert ('Proszę wpisać Kod !'); which.kod.focus(); return false; }
     if (which.miasto.value=='') { alert ('Proszę wpisać Miasto !'); which.miasto.focus(); return false; }
     if (which.firm_validate.value==1 && which.nip.value=='') { alert ('Proszę NIP !'); which.nip.focus(); return false; }
     if (which.ok_email.value=='') { alert ('Proszę wpisać e-mail kontaktowy !'); which.ok_email.focus(); return false; }
     //if (which.ok_telefon.value=='') { alert ('Proszę wpisać Telefon kontaktowy !'); which.ok_telefon.focus(); return false; }
     if (which.alert_email.value=='') { alert ('Proszę wpisać e-mail do powiadomień !'); which.alert_email.focus(); return false; }
     //if (which.sms_tel.value=='') { alert ('Proszę wpisać Telefon komórkowy do powiadomień !'); which.sms_tel.focus(); return false; }
     if (which.services_count.value==0) { alert('Musisz dodać conajmniej jedną usługę !'); return false; }
     opt = -1;
     for (i=which.pay_type.length-1; i > -1; i--) {if (which.pay_type[i].checked) {opt = i; i = -1;}}
     if (opt== -1 && which.pay_type.value=='') { alert('Proszę wybrać formę płatności !'); return false; }
     return true;
 }

 function validate_new(which,test)
 {
     var validated=true;
     if (which.form_uname.value=='') { document.getElementById("form_uname").style.background="red"; validated=false; }
     if (which.form_haslo.value=='') { document.getElementById("form_haslo").style.background="red"; validated=false; }
     if (which.form_haslo.value.length<8) { document.getElementById("form_haslo").style.background="red"; validated=false; }
     if (which.form_haslo.value != which.form_hasloo.value ) { document.getElementById("form_haslo").style.background="red"; validated=false; }
     if (which.form_hasloo.value=='') { document.getElementById("form_hasloo").style.background="red"; validated=false; }
     if (which.ok_imie.value=='') { document.getElementById("ok_imie").style.background="red"; validated=false; }
     if (which.ok_nazwisko.value=='') { document.getElementById("ok_nazwisko").style.background="red"; validated=false; }
     if (which.firm_validate.value==1 && which.nazwa.value=='') { document.getElementById("nazwa").style.background="red"; validated=false; }
     if (which.ulica.value=='') { document.getElementById("ulica").style.background="red"; validated=false; }
     if (which.kod.value=='') { document.getElementById("kod").style.background="red"; validated=false; }
     if (which.miasto.value=='') { document.getElementById("miasto").style.background="red"; validated=false; }
     if (which.firm_validate.value==1 && which.nip.value=='') { document.getElementById("nip").style.background="red"; validated=false; }
     if (which.ok_email.value=='' || !checkEmail(document.register)) { document.getElementById("ok_email").style.background="red"; validated=false; }
     //if (which.ok_telefon.value=='') { alert ('Proszę wpisać Telefon kontaktowy !'); which.ok_telefon.focus(); return false; }
     if (which.alert_email.value=='' || !checkEmail1(document.register)) { document.getElementById("alert_email").style.background="red"; validated=false; }
     //if (which.sms_tel.value=='') { alert ('Proszę wpisać Telefon komórkowy do powiadomień !'); which.sms_tel.focus(); return false; }
     if (which.services_count.value==0) { alert('Musisz dodać conajmniej jedną usługę !'); return false; }
     opt = -1;
     for (i=which.pay_type.length-1; i > -1; i--) {if (which.pay_type[i].checked) {opt = i; i = -1;}  }
     if (!which.pay_type.value) { if (opt== -1) { alert('Proszę wybrać formę płatności !');  return false; } }
     return validated;
 }


 function validate1(which)
 {
     opt = -1;
     for (i=which.pay_type.length-1; i > -1; i--) {if (which.pay_type[i].checked) {opt = i; i = -1;}}
     if (!which.pay_type.value) {if (opt== -1) { alert('Proszę wybrać formę płatności !'); return false; }}
     return true;
 }

 function clear_form(which)
 {
    which.form_uname.value='';
    which.form_haslo.value='';
    which.form_hasloo.value='';
    which.ok_imie.value='';
    which.ok_nazwisko.value='';
    which.ulica.value='';
    which.kod.value='';
    which.miasto.value='';
    which.ok_email.value='';
    which.ok_telefon.value='';
    which.alert_email.value='';
    which.sms_tel.value='';
    for (i=which.pay_type.length-1; i > -1; i--) {which.pay_type[i].checked=false;}
    which.form_uname.focus();
 }

function isUrl(s) {
         var parts=s.split('.');
         if (parts[1] && parts[1].length>1) { return true; } else { return false; }
}


function validate_part(which)
{

  var validated=true;
  var rodz=which.form_rodzaj.value;
  if (which.form_uname.value.length<6) { document.getElementById("form_uname").style.background="red"; validated=false; }
  if (which.form_pass.value.length<8) { document.getElementById("form_pass").style.background="red"; validated=false; }
  if (which.form_pass.value!=which.form_pass1.value) { document.getElementById("form_pass").style.background="red"; document.getElementById("form_pass1").style.background="red"; validated=false; }
  if (which.imie.value=="") { document.getElementById("imie").style.background="red"; validated=false; }
  if (which.nazwisko.value=="") { document.getElementById("nazwisko").style.background="red"; validated=false; }
  if (which.email.value=="") { document.getElementById("email").style.background="red"; validated=false; }
  if (which.telefon.value=="") { document.getElementById("telefon").style.background="red"; validated=false; }
  if (which.firma.value=="" && rodz=="firma") { document.getElementById("firma").style.background="red"; validated=false; }
  if (which.ulica.value=="") { document.getElementById("ulica").style.background="red"; validated=false; }
  if (which.kod.value=="") { document.getElementById("kod").style.background="red"; validated=false; }
  if (which.miasto.value=="") { document.getElementById("miasto").style.background="red"; validated=false; }
  if (which.nip.value=="" && rodz=="firma") { document.getElementById("nip").style.background="red"; validated=false; }
  if (which.org_rejestrowy.value=="" && rodz=="firma") { document.getElementById("org_rejestrowy").style.background="red"; validated=false; }
  if (which.krs.value=="" && rodz=="firma") { document.getElementById("krs").style.background="red"; validated=false; }
  if (which.pesel.value=="" && rodz=="osoba") { document.getElementById("pesel").style.background="red"; validated=false; }
  if (which.nr_dowodu.value=="" && rodz=="osoba") { document.getElementById("nr_dowodu").style.background="red"; validated=false; }
  if (which.urls.value=="" || (!isUrl(which.urls.value))) { document.getElementById("urls").style.background="red"; validated=false; }
  if (which.regulaminc.checked==false) {  document.getElementById("regulamin").style.background="red"; validated=false; }
  if (!validated) { return false; } else { return true; }
}

function rebuild_part(which)
{
  if(document.all)
          myDisplay = 'block';
        else
          myDisplay = 'table-row';
  if (which.form_rodzaj.value=="firma")
  {
      document.getElementById("tit_firma").style.display=myDisplay;
      document.getElementById("tit_org_rejestrowy").style.display=myDisplay;
      document.getElementById("tit_krs").style.display=myDisplay;
      document.getElementById("tit_pesel").style.display="none";
      document.getElementById("tit_nr_dowodu").style.display="none";
  }
  else
  {
      document.getElementById("tit_firma").style.display="none";
      document.getElementById("tit_org_rejestrowy").style.display="none";
      document.getElementById("tit_krs").style.display="none";
      document.getElementById("tit_pesel").style.display=myDisplay;
      document.getElementById("tit_nr_dowodu").style.display=myDisplay;
  }
}
