//------------------------------------------------------------------------------------------------------------------------------------------------
function CallbackPage_ExecuteAsyncCallback(serverFunction, clientFunction) {    

    //Set the hidden CallbackPage ReturnValue control current flag to true so we know what hidden control to get the
    //return value from after the async callback returns a value:
    document.getElementById("hidCallbackPage_ReturnValue").setAttribute("currentflag", "1");

    //HtmlEncode the serverFunction arg or ASP.NET will consider it a security violation due to the column delimiters and
    //then we must URL Encode the string since HtmlEncode will put in "&" characters which are part of a url:
    serverFunction = Callback_Escape(Callback_HtmlEncode(serverFunction));

    //Instantiate the browser specific XmlHttp object:      
    var xmlHttp = Callback_CreateXmlHttpObject();

    //Open an Asynchronous post to the current page and set the request header:
    xmlHttp.open("POST", document.location.href, true);
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

    //Set the Xml object's OnReadyStateChange handler will will wait for the Aysnc request to return a value:
    xmlHttp.onreadystatechange = function() {

        if (xmlHttp.readyState == 4) {

            //Set the returnValue:
            var returnValue = "";
            var xmlHttpException = null;
            if (xmlHttp.status == 200) {

                returnValue = xmlHttp.responseText;

            }
            else {

                //NOTE: Most of these exceptions are caused by server timeouts or other server unexpected server issues,
                //the default server timeout in ASP.NET is 120 seconds, but the developer can extend this in the
                //site's web.config:
                returnValue = null;
                xmlHttpException = xmlHttp.statusText;

            }

            //Finally, trigger the client side callback handler function passed by the developer:
            CallbackPage_Internal_GetReturnValue(returnValue, clientFunction, xmlHttpException);

        }

    };

    //Send the callback async method to the server which will be executed via reflection:    
    xmlHttp.send("InenviXmlHttpCallbackMethod=" + serverFunction);

}
//------------------------------------------------------------------------------------------------------------------------------------------------
function CallbackPage_Internal_GetReturnValue(returnValue, clientFunction, xmlHttpException) {

    //Check the xmlHttpException to see if its not null, if so, then an unhandled exception occured so we need
    //to pass it to the ClientFunction and then its up to the developer to check for its presence as it will only
    //be there if an unhandled xmlHttpException occurred (for example, a server timeout is the most frequent cause:
    if (xmlHttpException == null) {

        document.getElementById("hidCallbackPage_ReturnValue").value = returnValue;
        eval(clientFunction + "();");

    }
    else {

        document.getElementById("hidCallbackPage_ReturnValue").value = ""; //Set the return value to an empty string
        eval(clientFunction + "(\"" + xmlHttpException + "\");");

    }

}
//------------------------------------------------------------------------------------------------------------------------------------------------