// -- dane docelowe var qf_formnamelist = new Array('zapis'); // -- zmienne globalne formhideajaxinterval = 0; itemajaxinfo = document.getElementById('ajaxinfo'); itemajaxbox = document.getElementById('ajaxbox'); wyslano = 0; // dla zapobiegania wysyłania kilka razy // -- funkcje do komunikacji z modułem ajax function formServerReply(code, data) { if (code == -2) { formUpdateAjaxInfo('Błąd w czasie pobierania danych!'); } else { formUpdateAjaxInfo('Pobieranie zakończone.'); itemajaxbox.innerHTML = data; itemajaxbox.style.visibility = 'visible'; if (code == 200) { wyslano = 1; itemajaxbox.className = 'ajaxboxok'; window.location="/wysłano"; } else itemajaxbox.className = 'ajaxboxerror'; } formHideAjaxInfoDelayed(); return true; }; function formHideAjaxInfoDelayed() { if (formhideajaxinterval > 0) { clearInterval(formhideajaxinterval); }; formhideajaxinterval = setInterval('formHideAjaxInfo();', 2000); return true; }; function formHideAjaxInfo() { if (formhideajaxinterval > 0) { clearInterval(formhideajaxinterval); formhideajaxinterval = 0; }; itemajaxinfo.style.visibility = 'hidden'; return true; }; function formShowAjaxInfo() { itemajaxinfo.style.visibility = 'visible'; return true; }; function formUpdateAjaxInfo(txt) { itemajaxinfo.innerHTML = txt; return true; }; function formAjaxProgress(e) { if (e.position < 819) { s = e.position+' B'; } else if (e.position < 838860) { s = Math.round(e.position/1024*100)/100+' KB'; } else { s = Math.round(e.position/1024/1024*100)/100+' MB'; }; formUpdateAjaxInfo('Pobieranie danych. Pobrano: '+s); } function formAjaxError(e) { formUpdateAjaxInfo('Błąd ' + e.target.status + ' w czasie pobierania dokumentu.'); } // -- podczepianie funkcji do ajax'a if (XAJAX_LOADED) { xAjaxServerReply = formServerReply; xHideAjaxInfo = formHideAjaxInfo; xShowAjaxInfo = formShowAjaxInfo; xUpdateAjaxInfo = formUpdateAjaxInfo; xAjaxProgress = formAjaxProgress; xAjaxError = formAjaxError; xAjaxLoad = null; } // -- pobieranie wartości z formularza function getFormValues(formName) { var res = new Array(); var s = ''; for (var i = 0; i < document.forms[formName].elements.length; i++) { var input = document.forms[formName].elements[i]; if (input.name != '') { var insert = true; if ((input.type == 'radio') || (input.type == 'checkbox')) { insert = input.checked; } if (insert) { res.push(new Array( input.name, input.value )); } } } return res; } // -- funkcja wysyłania formularza function sendForm(formName) { if (wyslano) alert('Formularz został już wysłany! Aby wysłać kolejny przeładuj stronę.'); else if (XAJAX_LOADED) xAjaxExecuteActionPost('sendform', getFormValues(formName), '/form/form.php'); else alert('Moduł AJAX nie został załadowany.'); }