function createXMLHttp() { var xmlhttp=false; /*@cc_on @*/ /*@if (@_jscript_version >= 5) // JScript gives us Conditional compilation, we can cope with old IE versions. // and security blocked creation of the objects. try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { xmlhttp = false; } } @end @*/ if (!xmlhttp && typeof XMLHttpRequest!='undefined') { try { xmlhttp = new XMLHttpRequest(); } catch (e) { xmlhttp=false; } } if (!xmlhttp && window.createRequest) { try { xmlhttp = window.createRequest(); } catch (e) { xmlhttp=false; } } return xmlhttp; } function genericAjax(url) { var ajaxObj=createXMLHttp(); //Use this function when no response is needed ajaxObj.open("GET", url+'&rand='+Math.random(),true); ajaxObj.open("GET", url,true); ajaxObj.send(null); } //Pass the web service a reference to the function to call when it returns //Callback must be a function accepting a single argument, which will be the response text function MakeAjaxCall(url, callback) { var ajaxObj=createXMLHttp(); ajaxObj.open("GET", url+'&rand='+Math.random(),true); ajaxObj.onreadystatechange=function() { if (ajaxObj.readyState==4) { callback(ajaxObj.responseText); } } ajaxObj.send(null); } //Pass the web service a reference to the function to call when it returns //Callback must be a function accepting a single argument, which will be the response text function MakeAjaxPost(url, postData, callback) { var ajaxObj=createXMLHttp(); ajaxObj.open("POST", url+'&rand='+Math.random(),true); ajaxObj.onreadystatechange=function() { if (ajaxObj.readyState==4) { callback(ajaxObj.responseText); } } ajaxObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); ajaxObj.send(postData); } /* Sets a session variable - callback should expect a simple result code ("0" for success, else "ERROR:[errortext]") Make sure that the value you are setting stringifies nicely, or has been pre-stringified */ function SetSessionVariable(url, key, value, callback) { var ajaxObj=createXMLHttp(); ajaxObj.open("POST", url+"?cmd=setcookie&rand="+Math.random(),true); ajaxObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); ajaxObj.onreadystatechange=function() { if (ajaxObj.readyState==4) { callback(ajaxObj.responseText); } } ajaxObj.send("key="+key+"&value="+value); } /* sets a .NET application variable (global variable) */ function SetApplicationVariable(url, key, value, callback) { var ajaxObj=createXMLHttp(); ajaxObj.open("POST", url+"?cmd=setappvar&rand="+Math.random(),true); ajaxObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); ajaxObj.onreadystatechange=function() { if (ajaxObj.readyState==4) { callback(ajaxObj.responseText); } } ajaxObj.send("key="+key+"&value="+value); } /*... and gets it back :) */ function GetApplicationVariable(url, key, callback) { var ajaxObj=createXMLHttp(); ajaxObj.open("POST", url+"?cmd=getappvar&rand="+Math.random() ,true); ajaxObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); ajaxObj.onreadystatechange=function() { if (ajaxObj.readyState==4) { callback(ajaxObj.responseText); } } ajaxObj.send("key="+key); } /*... destroys (sets to null) an application variable */ function KillApplicationVariable(key) { var ajaxObj=createXMLHttp(); ajaxObj.open("POST", "/app_info/ajaxendpoint/default.aspx?cmd=killappvar&rand="+Math.random() ,true); ajaxObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); ajaxObj.send("key="+key); } /* Retrieves a previously set session variable. The callback should expect the string value of the cookie if it exists, "null" if it does not, else the standard error format */ function GetSessionVariable(url, key, callback) { var ajaxObj=createXMLHttp(); ajaxObj.open("POST", url+"?cmd=getcookie&rand="+Math.random() ,true); ajaxObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); ajaxObj.onreadystatechange=function() { if (ajaxObj.readyState==4) { callback(ajaxObj.responseText); } } ajaxObj.send("key="+key); } /* Quickie Validation Methods - Requires that JQuery be loaded and available to call */ /* Error messages should be of class sn_visibleInlineError */ function HideAllErrors() { /* var $j= jQuery.noConflict(); $$(".sn_visibleInlineError").each(Element.hide); */ } function ShowAllErrors() { $$(".sn_visibleInlineError").each(Element.show); } //id = ID of error message container function ShowError(id) { $(id).show(); } function HideError(id) { $(id).hide(); } /* UI Methods - Requires that JQuery be loaded and available to call */ function ClearTextFields() { //TODO: write in prototype or regular JS. } /* Methods involving "Hanging Gets" (server callbacks) */ function WaitForCondition(url, key, value, callback) { var ajaxObj=createXMLHttp(); ajaxObj.open("POST", url+"?cmd=RegisterEvent&rand="+Math.random(),true); ajaxObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); ajaxObj.onreadystatechange=function() { if (ajaxObj.readyState==4) { callback(ajaxObj.responseText); } } ajaxObj.send("key="+key+"&value="+value); }