        if ("undefined" === typeof window.UserAccess) {
            window.UserAccess = {};
        }

        UserAccess.showStatus = function(message,timeout)
        {        
            alert(message);
        };

        UserAccess.onPageError = function(xhr,errorMsg,thrown)
        {
            if ("string" === typeof xhr)
            {
                UserAccess.showStatus(xhr, 5000);
                return;
            }

            if (errorMsg && (errorMsg !== "error"))
            {
                UserAccess.showStatus("errormsg: " + errorMsg, 5000);
            }
            else if (("string" === typeof xhr.responseText) && (xhr.responseText !== ""))
            {
				alert(xhr.responseText);
                var err = JSON.parse(xhr.responseText);
                if ("object" === typeof err)
                {
                    UserAccess.showStatus(err.Message, 5000);
                }
                else    
                    UserAccess.showStatus("Unknown server error.", 5000);
            }
            else
                UserAccess.showStatus("Unknown error occurred in callback.", 5000);
        };

        // *** Service Calling Proxy Class
        UserAccess.setupServiceProxy = function(serviceUrl) {
            UserAccess.serviceUrl = serviceUrl;
         
            // *** Call a wrapped object
            UserAccess.invokeServiceMethod = function(method,data,callback,bare)
            {
                // *** Convert input data into JSON - REQUIRES Json2.js
                var json = JSON.stringify(data);

                // *** The service endpoint URL        
                var url = UserAccess.serviceUrl + method;

                $.ajax( { 
                    url: url,
                    data: json,
                    type: "POST",
                    processData: false,
                    contentType: "application/json; charset=utf-8",
                    timeout: 10000,
                    dataType: "json",
                    success: 
                    function(result) 
                    {
                        if (!callback) return;

						//var result = JSON.parse(res);

                        if (result.ExceptionDetail)
                        {
                            UserAccess.onPageError(result.Message);
                            return;
                        }
                        
                        // *** Bare message IS result
                        if (bare)
                        { callback(result); return; }
                        
                        // *** Wrapped message contains top level object node
                        // *** strip it off
                        for(var property in result)
                        {
                            callback( result[property] );
                            break;
                        }                    
                    },
                    error: UserAccess.onPageError
                 });
            }
        };

        if ("undefined" === typeof UserAccess.serviceUrl) {
            UserAccess.setupServiceProxy("Wcf/UserAccess.svc/");
        }