var items = { name: 'form_name', addr: 'form_addr', subj: 'form_subj', text: 'form_text', }; var server = getServer(); var token = ""; var lang = {}; var xhr = { lang: new XMLHttpRequest(), token: new XMLHttpRequest(), send: new XMLHttpRequest() } // XHR callbacks xhr.token.onreadystatechange = function() { if(xhr.token.readyState == XMLHttpRequest.DONE) { token = xhr.token.responseText; } }; xhr.lang.onreadystatechange = function() { if(xhr.lang.readyState == XMLHttpRequest.DONE) { lang = JSON.parse(xhr.lang.responseText); } }; xhr.send.onreadystatechange = function() { if(xhr.send.readyState == XMLHttpRequest.DONE) { let status = document.getElementById('form_status'); status.setAttribute('class', ''); if(xhr.send.status === 200) { cleanForm(); status.setAttribute('class', 'success'); status.innerHTML = lang.send_status_success; } else { status.setAttribute('class', 'failure'); status.innerHTML = lang.send_status_failure; } } }; // Returns the server's base URI based on the user's script tag // return: the SMAM server's base URI function getServer() { var scripts = document.getElementsByTagName('script'); // Parsing all the