// This JavaScript was automatically generated by
// Jayrock.JsonRpc.Web.JsonRpcProxyGenerator, Jayrock, Version=0.9.8316.0, Culture=neutral, PublicKeyToken=null
// on Wednesday, September 08, 2010 at 5:43:07 PM (Pacific Daylight Time)

function UserServices(url)
{
    var self = this;
    var m = ["logInUser","logOutCurrentUser","changeUserPassword","system.listMethods","system.version","system.about"];
    var idems = [true,true,true,true,true,true];
    
    this[m[0]] = function /* logInUser */ (UserName, Password, callback)
    {
        if (self.kwargs) return rpc(new Call(0, { UserName: UserName, Password: Password }, callback));
        return rpc(new Call(0, [ UserName, Password ], callback));
    }
    
    this[m[1]] = function /* logOutCurrentUser */ (callback)
    {
        if (self.kwargs) return rpc(new Call(1, { }, callback));
        return rpc(new Call(1, [ ], callback));
    }
    
    this[m[2]] = function /* changeUserPassword */ (UserId, Password, callback)
    {
        if (self.kwargs) return rpc(new Call(2, { UserId: UserId, Password: Password }, callback));
        return rpc(new Call(2, [ UserId, Password ], callback));
    }
    
    // Returns an array of method names implemented by this service.
    
    this[m[3]] = function /* system.listMethods */ (callback)
    {
        if (self.kwargs) return rpc(new Call(3, { }, callback));
        return rpc(new Call(3, [ ], callback));
    }
    
    // Returns the version server implementation using the major, minor, build and revision format.
    
    this[m[4]] = function /* system.version */ (callback)
    {
        if (self.kwargs) return rpc(new Call(4, { }, callback));
        return rpc(new Call(4, [ ], callback));
    }
    
    // Returns a summary about the server implementation for display purposes.
    
    this[m[5]] = function /* system.about */ (callback)
    {
        if (self.kwargs) return rpc(new Call(5, { }, callback));
        return rpc(new Call(5, [ ], callback));
    }
    
    var url = typeof(url) === 'string' ? url : 'http://www.davis-events.com/rpcservices/userservices.ashx';
    var nextId = 0;

    function Call(method, params, callback)
    {
        this.url = url;
        this.callback = callback;
        this.proxy = self;
        this.idempotent = idems[method];
        this.request = 
        { 
            id     : ++nextId, 
            method : m[method], 
            params : params 
        };
    }

    function rpc(call)
    {
        return self.channel != null && typeof(self.channel.rpc) === 'function' ?
            self.channel.rpc(call) : call;
    }

    this.kwargs = false;
    this.channel = new JayrockChannel();

    function JayrockChannel()
    {
        this.rpc = function(call)
        {
            var async = typeof(call.callback) === 'function';
            var xhr = newXHR();
            xhr.open('POST', call.url, async, this.httpUserName, this.httpPassword);
            xhr.setRequestHeader('Content-Type', this.contentType || 'application/json; charset=utf-8');
            xhr.setRequestHeader('X-JSON-RPC', call.request.method);
            if (async) xhr.onreadystatechange = function() { xhr_onreadystatechange(xhr, call.callback); }
            xhr.send(JSON.stringify(call.request));
            call.handler = xhr;
            if (async) return call;
            if (xhr.status != 200) throw new Error(xhr.status + ' ' + xhr.statusText);
            var response = JSON.eval(xhr.responseText);
            if (response.error != null) throw response.error;
            return response.result;
        }

        function xhr_onreadystatechange(sender, callback)
        {
            if (sender.readyState == /* complete */ 4)
            {
                sender.onreadystatechange = null; // Avoid IE leak

                var response = sender.status == 200 ? 
                    JSON.eval(sender.responseText) : {};
                
                callback(response, sender);
            }
        }

        function newXHR()
        {
            if (typeof(window) !== 'undefined' && window.XMLHttpRequest)
                return new XMLHttpRequest(); /* IE7, Safari 1.2, Mozilla 1.0/Firefox, and Netscape 7 */
            else
                return new ActiveXObject('Microsoft.XMLHTTP'); /* WSH and IE 5 to IE 6 */
        }
    }
}

UserServices.rpcMethods = ["logInUser","logOutCurrentUser","changeUserPassword","system.listMethods","system.version","system.about"];
