var ml = ml || {}; ml.FlexCaptcha = {}; ml.FlexCaptcha.Ajax = { "MainDelimter": "~!" , "AttributeDelimter": "~|" , "RowDelimeter": "~:" , "ColumnDelimter": "~^" , https: [] , Pair: function (pName, pHttpRequest) { this.name = pName; this.httpRequest = pHttpRequest; } , getNewHttp: function () { //this function is a close copy from jibbering: http://jibbering.com/2002/4/httprequest.html //(however with the advent of XMLHttpRequest in IE7, the test object order is not good, but I need to keep it until I find a way to test IE7 myself) try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { //return null; } } if (typeof XMLHttpRequest != 'undefined') { try { return new XMLHttpRequest(); //Mozilla & Safari } catch (e) { //return null; } } if (window.createRequest) { try { return window.createRequest(); //IceBrowser } catch (e) { //return null; } } return null; } , addHttp: function (pName, pHttpRequest) { this.removeHttp(pName); var pair = new this.Pair(pName, pHttpRequest); this.https.push(pair); } , getHttp: function (pName) { for (var p = 0; p < this.https.length; p++) { if (this.https[p].name == pName) { return this.https[p].httpRequest; } } } , removeHttp: function (pName) { for (var p = 0; p < this.https.length; p++) { if (this.https[p].name == pName) { this.https.splice(p, 1); break; } } } } ml.FlexCaptcha.runtimes = {} ml.FlexCaptcha.getRuntime = function (pFlexCaptchaID) { if (ml.FlexCaptcha.runtimes[pFlexCaptchaID] == null) { var runtime = { "ID": pFlexCaptchaID , "CaptchaImageName": "" , "CaptchaCode" : "" } ml.FlexCaptcha.runtimes[pFlexCaptchaID] = runtime; } return ml.FlexCaptcha.runtimes[pFlexCaptchaID]; } ml.FlexCaptcha.initialize = function (pFlexCaptchaID, pConfig) { var runtime = ml.FlexCaptcha.getRuntime(pFlexCaptchaID); if (pConfig != null) { if (typeof (pConfig["CaptchaImageName"]) != undefined) { runtime["CaptchaImageName"] = pConfig["CaptchaImageName"]; } if (typeof (pConfig["CaptchaCode"]) != undefined) { runtime["CaptchaCode"] = pConfig["CaptchaCode"]; } } var ml_flexcaptcha_ids = document.getElementById("ml_flexcaptcha_ids"); //FlexCaptcha control array to submit back to validate functions to compare with ClientBaseID to get the correct index of ml_flexcaptcha_codes to pull out the captcha code if (ml_flexcaptcha_ids) { if (ml_flexcaptcha_ids.value != "") { ml_flexcaptcha_ids.value += ","; } ml_flexcaptcha_ids.value += pFlexCaptchaID; } var ml_flexcaptcha_codes = document.getElementById("ml_flexcaptcha_codes"); if (ml_flexcaptcha_codes) { if (ml_flexcaptcha_codes.value != "") { ml_flexcaptcha_codes.value += ","; } ml_flexcaptcha_codes.value += runtime["CaptchaCode"]; } } ml.FlexCaptcha.reloadCaptcha = function (pFlexCaptchaID) { var absolutePath = location.href.split("?")[0].split("#")[0]; var url = absolutePath + "?ml-fc-reloadCaptcha=" + encodeURIComponent(pFlexCaptchaID); // var cacheControl = "&cc=" + Math.random(); //solves the problem in IE6.0 that GET requests are cached (on exact url) url += cacheControl; var http = ml.FlexCaptcha.Ajax.getNewHttp(); ml.FlexCaptcha.Ajax.addHttp("reloadCaptcha" + cacheControl, http); http.open("GET", url, true); http.setRequestHeader("Content-Type", "text/plain;charset=UTF-8"); http.onreadystatechange = function () { ml.FlexCaptcha.reloadCaptcha_handler(pFlexCaptchaID, cacheControl); }; http.send(null); } ml.FlexCaptcha.reloadCaptcha_handler = function (pFlexCaptchaID, pCacheControl) { var http = ml.FlexCaptcha.Ajax.getHttp("reloadCaptcha" + pCacheControl); if (http.readyState == 4) { if (http.status == 200) { var responseText = http.responseText; if (responseText.indexOf("ERROR") == 0) { alert(responseText); } else { ml.FlexCaptcha.reloadCaptcha_update(pFlexCaptchaID, responseText); } } else { alert("Problem: status code: " + http.status + " " + http.statusText); } ml.FlexCaptcha.Ajax.removeHttp("reloadCaptcha" + pCacheControl); } } ml.FlexCaptcha.reloadCaptcha_update = function (pFlexCaptchaID, pResponseText) { var runtime = ml.FlexCaptcha.getRuntime(pFlexCaptchaID); var ml_flexcaptcha_codes = document.getElementById("ml_flexcaptcha_codes"); var ml_flexcaptcha_image = document.getElementById(pFlexCaptchaID + "captchaimage"); if (ml_flexcaptcha_codes == null || ml_flexcaptcha_image == null) { alert("Captcha could not be reloaded"); return; } var newCaptchaCode = pResponseText.split("#_#")[0]; var newCaptchaImageUrl = pResponseText.split("#_#")[1]; var allCaptchaCodes = ml_flexcaptcha_codes.value.split(","); for (c = 0; c < allCaptchaCodes.length; c++) { if (allCaptchaCodes[c] == runtime["CaptchaCode"]) { allCaptchaCodes[c] = newCaptchaCode; break; } } ml_flexcaptcha_codes.value = ""; for (var c = 0; c < allCaptchaCodes.length; c++) { if (ml_flexcaptcha_codes.value != "") { ml_flexcaptcha_codes.value += ","; } ml_flexcaptcha_codes.value += allCaptchaCodes[c]; } // ml_flexcaptcha_codes.value = newCaptchaCode; ml_flexcaptcha_image.src = newCaptchaImageUrl; }