function validateAuth() { $error = false; if(document.getElementById("fsync_auth_apikey").value == '') { document.getElementById("fsync_auth_apikey_error").style.display = "block"; $error = true; } else { document.getElementById("fsync_auth_apikey_error").style.display = "none"; } if(document.getElementById("fsync_auth_username").value == '') { document.getElementById("fsync_auth_username_error").style.display = "block"; $error = true; } else { document.getElementById("fsync_auth_username_error").style.display = "none"; } if(document.getElementById("fsync_auth_password").value == '') { document.getElementById("fsync_auth_password_error").style.display = "block"; $error = true; } else { document.getElementById("fsync_auth_password_error").style.display = "none"; } if(document.getElementById("fsync_auth_fiscalcode").value == '') { document.getElementById("fsync_auth_fiscalcode_error").style.display = "block"; $error = true; } else { document.getElementById("fsync_auth_fiscalcode_error").style.display = "none"; } if($error) { return false; } else { testAuth(); } } function submitAuthForm() { document.getElementById("authform_error").style.display = "none"; validateAuth(); } function ascii_to_hexa(str) { var arr1 = []; for (var n = 0, l = str.length; n < l; n ++) { var hex = Number(str.charCodeAt(n)).toString(16); arr1.push(hex); } return arr1.join(''); } function testAuth() { var params = ''; params += '&fsync_auth_apikey=' + document.getElementById("fsync_auth_apikey").value; params += '&fsync_auth_username=' + document.getElementById("fsync_auth_username").value; params += '&fsync_auth_password=' + document.getElementById("fsync_auth_password").value; params += '&fsync_auth_fiscalcode=' + document.getElementById("fsync_auth_fiscalcode").value; params = encodeURI(params); var xhttp; xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { if( this.responseText == '') { document.getElementById("fsync_auth_password").value = ascii_to_hexa(document.getElementById("fsync_auth_password").value); document.getElementById('save-auth-btn').classList.remove('btn-green'); document.getElementById('save-auth-btn').innerHTML = ''; document.getElementById('auth_form').submit(); } else { document.getElementById("authform_error").style.display = "block"; document.getElementById("authform_error").innerHTML = this.responseText; } } }; xhttp.open("GET","ajax.php?random=" + Math.random() + "&action=testAuth" + params,true); xhttp.send(); }