var selection = []; var captchaid = ""; function httpGet(url) { var xmlHttp = new XMLHttpRequest(); xmlHttp.open("GET", url, false); // false for synchronous request xmlHttp.send(null); return xmlHttp.responseText; } function httpPost(url, data) { var xmlHttp = new XMLHttpRequest(); xmlHttp.open("POST", url, false); xmlHttp.setRequestHeader("Access-Control-Allow-Origin", "*"); xmlHttp.send(data); return xmlHttp.responseText; } function getCaptcha() { data = httpGet(goCaptchaURL + "/captcha") captcha = JSON.parse(data); captchaid = captcha.id; showCaptcha(captcha); selection=[]; for(k in captcha.imgs){ selection.push(0); } } function showCaptcha(captcha) { var html; html = ""; html += "

Select all " + captcha.question + "

"; for (k in captcha.imgs) { html += ""; } html += "
Validate
"; document.getElementById("goCaptcha").innerHTML = html; } function selectCaptchaImg(elem) { if (selection[elem.id] == 0) { selection[elem.id] = 1; document.getElementById(elem.id).className = "g_selected"; } else { selection[elem.id] = 0; document.getElementById(elem.id).className = "g_unselected"; } } function validateCaptcha() { var answer = { selection: selection, captchaid: captcha.id }; data = httpPost(goCaptchaURL + "/answer", JSON.stringify(answer)); resp = JSON.parse(data); var html = ""; if (resp) { html += "

goCaptcha validated

"; html += "
Reload Captcha
"; } else { html += "

goCaptcha failed

"; html += "
Reload Captcha
"; } document.getElementById("goCaptcha").innerHTML = html; } if (document.getElementById("goCaptcha")) { getCaptcha(); }