var i = 0; function byId(id) { return document.getElementById(id); } function setHtml(id, html) { var el = byId(id); if (el) el.innerHTML = html; } function showEl(id) { var el = byId(id); if (el) el.style.display = ''; } function hideEl(id) { var el = byId(id); if (el) el.style.display = 'none'; } function postRequest(action, data, onSuccess, onFailure) { var xhr = new XMLHttpRequest(); var body = []; var key; for (key in data) { if (Object.prototype.hasOwnProperty.call(data, key)) { body.push(encodeURIComponent(key) + '=' + encodeURIComponent(data[key])); } } xhr.open('POST', '/ajax.php?a=' + action, true); xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'); xhr.onreadystatechange = function () { if (xhr.readyState !== 4) return; if (xhr.status >= 200 && xhr.status < 300) onSuccess(xhr.responseText); else if (onFailure) onFailure(); }; xhr.send(body.join('&')); } function spr(a,b,c,d,e,f,g,h,i,j,k) { var button = byId('przycisk'); if (button) { button.disabled = (a === 0 || b === 0 || c === 0 || d === 0 || e === 0 || f === 0 || g === 0 || h === 0 || i === 0 || j === 0); } if (a===0) { setHtml('aw', 'Pole Reprezentant jest wymagane'); showEl('aw'); } else hideEl('aw'); if (b===0) { setHtml('bw', 'Pole NIP jest wymagane'); showEl('bw'); } else hideEl('bw'); if (c===0) { setHtml('cw', 'Pole E-mail jest wymagane'); showEl('cw'); } else hideEl('cw'); if (d===0) { setHtml('dw', 'Pole Ulica jest wymagane'); showEl('dw'); } else hideEl('dw'); if (e===0) { setHtml('ew', 'Pole Kod pocztowy jest wymagane'); showEl('ew'); } else hideEl('ew'); if (f===0) { setHtml('fw', 'Pole Miasto jest wymagane'); showEl('fw'); } else hideEl('fw'); if (g===0) { setHtml('gw', 'Pole Telefon jest wymagane'); showEl('gw'); } else hideEl('gw'); if (h===0) { setHtml('hw', 'Pole Nazwisko jest wymagane'); showEl('hw'); } else hideEl('hw'); if (i===0) { setHtml('iw', 'Pole Użytkownik jest wymagane'); showEl('iw'); } else hideEl('iw'); if (j===0) { setHtml('jw', 'Pole Hasło jest wymagane'); showEl('jw'); } else hideEl('jw'); } var a1=0, a2=0, a3=0, a4=0, a5=0, a6=0, a7=0, a9=0, a11=0, a12=0; function shouldUseBaseInstall(value, includeAbove102) { var num = parseInt(value, 10); if (isNaN(num)) return false; if (num < 9 || num === 31 || num === 99 || (num >= 23 && num <= 26) || (num >= 40 && num <= 42)) return true; return includeAbove102 && num > 102; } function updateSystemAndPeriod(pakietValue, includeAbove102) { postRequest('systemy', { pakiet: pakietValue }, function (responseText) { setHtml('so', responseText); if (shouldUseBaseInstall(pakietValue, includeAbove102)) { setHtml('instl', ''); } }, function () { setHtml('so', 'Wystąpił błąd, prosimy spróbować ponownie później'); }); postRequest('okresy', { pakiet: pakietValue }, function (responseText) { setHtml('okr', responseText); }, function () { setHtml('okr', 'Wystąpił błąd, prosimy spróbować ponownie później'); }); } function syst(s) { var pakiet = byId('pakiet'); postRequest('panele', { system: s, pakiet: pakiet ? pakiet.value : '' }, function (responseText) { setHtml('instl', responseText); }, function () { setHtml('instl', 'Wystąpił błąd, prosimy spróbować ponownie później'); }); } function lista_zmiana() { var pakiet = byId('pakiet'); updateSystemAndPeriod(pakiet ? pakiet.value : '', true); } function zmiana(id) { ['s1','s2','s3','s4','s5','s6','s7'].forEach(function (itemId) { var el = byId(itemId); if (el) el.classList.remove('klik'); }); var target = byId(id); if (target) target.classList.add('klik'); } document.addEventListener('DOMContentLoaded', function () { var pakiet = byId('pakiet'); var nip = byId('nip'); var pesel = byId('pesel'); var nazwisko = byId('nazwisko'); var reprezentant = byId('reprezentant'); var ulica = byId('ulica'); var kod = byId('kod'); var miasto = byId('miasto'); var telefon = byId('telefon'); var abonent = byId('abonent'); var email = byId('email'); var user = byId('user'); var haslo = byId('haslo'); var haslo2 = byId('haslo2'); if (pakiet) { pakiet.addEventListener('change', function () { updateSystemAndPeriod(pakiet.value, false); postRequest('packet_link', { id: pakiet.value }, function (responseText) { setHtml('link', responseText); }, function () { setHtml('link', 'Wystąpił błąd, prosimy spróbować ponownie później'); }); }); } if (nip && abonent) { nip.addEventListener('change', function () { if (nip.value.length === 10 && abonent.value === 'Firma') { setHtml('nipw', ""); a2=1; } else if (abonent.value === 'Prywatny') { setHtml('nipw', ""); a2=1; } else { setHtml('nipw', ""); a2=0; } spr(a1,a2,a3,a4,a5,a6,a7,a9,a11,a12); }); } if (pesel && abonent) { pesel.addEventListener('change', function () { if (pesel.value.length === 11 && abonent.value === 'Prywatny') setHtml('peselw', ""); else if (abonent.value === 'Firma') setHtml('peselw', ""); else setHtml('peselw', ""); }); } if (nazwisko) { nazwisko.addEventListener('change', function () { if (nazwisko.value.length < 6) { setHtml('nazwiskow', ""); a9=0; } else { setHtml('nazwiskow', ""); a9=1; if (abonent && abonent.value === 'Prywatny' && reprezentant) reprezentant.value = nazwisko.value; } spr(a1,a2,a3,a4,a5,a6,a7,a9,a11,a12); }); } if (abonent && reprezentant) { if (abonent.value === 'Firma') { reprezentant.addEventListener('change', function () { if (reprezentant.value.length < 6) { setHtml('reprezentantw', ""); a1=0; } else { setHtml('reprezentantw', ""); a1=1; } spr(a1,a2,a3,a4,a5,a6,a7,a9,a11,a12); }); } else { hideEl('reph'); setHtml('reprezentantw', ""); a1=1; spr(a1,a2,a3,a4,a5,a6,a7,a9,a11,a12); } } if (ulica) ulica.addEventListener('change', function () { if (ulica.value.length < 6) { setHtml('ulicaw', ""); a4=0; } else { setHtml('ulicaw', ""); a4=1; } spr(a1,a2,a3,a4,a5,a6,a7,a9,a11,a12); }); if (kod) kod.addEventListener('change', function () { var re1 = /^(\d{2}-\d{3})/; if (kod.value.search(re1)===-1) { setHtml('kodw', ""); a5=0; } else { setHtml('kodw', ""); a5=1; } spr(a1,a2,a3,a4,a5,a6,a7,a9,a11,a12); }); if (miasto) miasto.addEventListener('change', function () { if (miasto.value.length < 3) { setHtml('miastow', ""); a6=0; } else { setHtml('miastow', ""); a6=1; } spr(a1,a2,a3,a4,a5,a6,a7,a9,a11,a12); }); if (reprezentant) reprezentant.addEventListener('change', function () { if (reprezentant.value.length < 6) { setHtml('reprezentantw', ""); a1=0; } else { setHtml('reprezentantw', ""); a1=1; } spr(a1,a2,a3,a4,a5,a6,a7,a9,a11,a12); }); if (telefon) telefon.addEventListener('change', function () { var re1 = /^\+\d{2}\.\d{9}$/; if (telefon.value.search(re1)===-1) alert("Numer telefonu stacjonarnego musi być poprzedzony plusem (+), zawierać numer kierunkowy do kraju rozdzielony kropką\nnp. +48.221234567"); if (telefon.value.length !== 13) { setHtml('telefonw', ""); a7=0; } else { setHtml('telefonw', ""); a7=1; } spr(a1,a2,a3,a4,a5,a6,a7,a9,a11,a12); }); if (abonent) { abonent.addEventListener('change', function () { if (abonent.value === 'Firma') { hideEl('peselh'); setHtml('peselw', ""); if (nip && nip.value.length === 10) { setHtml('nipw', ""); a2=1; } if (nip && nip.value.length !== 10) { setHtml('nipw', ""); a2=0; } if (reprezentant && reprezentant.value.length < 6) { setHtml('reprezentantw', ""); a1=0; } else { setHtml('reprezentantw', ""); a1=1; } showEl('reph'); showEl('niph'); } if (abonent.value === 'Prywatny') { hideEl('niph'); hideEl('reph'); setHtml('nipw', ""); a2=1; if (pesel && pesel.value.length === 11) setHtml('peselw', ""); if (pesel && pesel.value.length !== 11) setHtml('peselw', ""); showEl('peselh'); setHtml('reprezentantw', ""); a1=1; } spr(a1,a2,a3,a4,a5,a6,a7,a9,a11,a12); }); } if (nip && abonent) { if (nip.value.length === 10 && abonent.value === 'Firma') { setHtml('nipw', ""); a2=1; } else if (abonent.value === 'Prywatny') { setHtml('nipw', ""); a2=1; } else { setHtml('nipw', ""); a2=0; } spr(a1,a2,a3,a4,a5,a6,a7,a9,a11,a12); } if (pesel && abonent) { if (pesel.value.length === 11 && abonent.value === 'Prywatny') setHtml('peselw', ""); else if (abonent.value === 'Firma') setHtml('peselw', ""); else setHtml('peselw', ""); } if (email) email.addEventListener('change', function () { var re1 = /(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/; if (email.value.search(re1)===-1) { setHtml('emailw', ""); a3=0; } else { setHtml('emailw', ""); a3=1; } spr(a1,a2,a3,a4,a5,a6,a7,a9,a11,a12); }); if (user) user.addEventListener('change', function () { postRequest('da_usercheck', { username: user.value }, function (responseText) { if (responseText === '1') { setHtml('username_wynik', " Nazwa użytkownika jest zajęta"); a11=0; } else if (responseText === '2') { setHtml('username_wynik', " Nazwa użytkownika musi mieć od 5 do 10 znaków"); a11=0; } else if (responseText === '3') { setHtml('username_wynik', " Nazwa użytkownika musi zaczynać się literą"); a11=0; } else if (responseText === '0') { setHtml('username_wynik', ""); a11=1; } spr(a1,a2,a3,a4,a5,a6,a7,a9,a11,a12); }, function () { setHtml('username_wynik', 'Wystąpił błąd, prosimy spróbować ponownie później'); }); }); if (haslo && haslo2) haslo2.addEventListener('change', function () { if (haslo.value !== haslo2.value) { a12=0; setHtml('haslo2_wynik', " Hasła są różne"); } else { a12=1; setHtml('haslo2_wynik', ""); if (haslo2.value.length < 5 || haslo2.value.length > 36) { a12=0; setHtml('haslo2_wynik', " Hasło zbyt krótkie"); } } spr(a1,a2,a3,a4,a5,a6,a7,a9,a11,a12); }); [['s1','s1'],['s2','s2'],['s3','s3'],['s4','s4'],['s5','s5'],['s6','s6'],['s7','s7'],['b1','s1'],['b2','s2'],['b3','s3'],['b4','s4'],['b5','s5'],['b6','s6'],['b7','s7']].forEach(function (pair) { var el = byId(pair[0]); if (el) el.addEventListener('click', function () { zmiana(pair[1]); }); }); });