// 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 9:54:26 PM (Central Daylight Time)

// Proxy version 1.0

function FastDueHandler(url)
{
    this["getAllCountries"] = function(callback)
    {
        return call("getAllCountries", [ ], callback);
    }
    
    this["getReminderOptionDates"] = function(option, date, callback)
    {
        return call("getReminderOptionDates", [ option, date ], callback);
    }
    
    this["getReminderOptionDatesForInvoice"] = function(option, date, paymentTermDays, callback)
    {
        return call("getReminderOptionDatesForInvoice", [ option, date, paymentTermDays ], callback);
    }
    
    this["getAllUnits"] = function(callback)
    {
        return call("getAllUnits", [ ], callback);
    }
    
    this["getAllCategories"] = function(callback)
    {
        return call("getAllCategories", [ ], callback);
    }
    
    this["getPaymentTermDays"] = function(paymentTermId, callback)
    {
        return call("getPaymentTermDays", [ paymentTermId ], callback);
    }
    
    this["getContact"] = function(contactId, callback)
    {
        return call("getContact", [ contactId ], callback);
    }
    
    this["isCurrencySupportedByPayPal"] = function(currencyId, callback)
    {
        return call("isCurrencySupportedByPayPal", [ currencyId ], callback);
    }
    
    this["getShortDateStringAddDays"] = function(datetime, days, callback)
    {
        return call("getShortDateStringAddDays", [ datetime, days ], callback);
    }
    
    this["getDateDiffInDays"] = function(datetime1, datetime2, callback)
    {
        return call("getDateDiffInDays", [ datetime1, datetime2 ], callback);
    }
    
    this["getEmailFromProfile"] = function(emailId, callback)
    {
        return call("getEmailFromProfile", [ emailId ], callback);
    }
    
    this["getLogoWidth"] = function(logoId, callback)
    {
        return call("getLogoWidth", [ logoId ], callback);
    }
    
    this["forwardForm"] = function(email, comment, formId, contactId, asAttachment, callback)
    {
        return call("forwardForm", [ email, comment, formId, contactId, asAttachment ], callback);
    }
    
    this["getContactById"] = function(contactId, callback)
    {
        return call("getContactById", [ contactId ], callback);
    }
    
    this["updateApprovalById"] = function(approvalId, isApproved, callback)
    {
        return call("updateApprovalById", [ approvalId, isApproved ], callback);
    }
    
    this["addApprovalByFormId"] = function(formId, isApproved, callback)
    {
        return call("addApprovalByFormId", [ formId, isApproved ], callback);
    }
    
    this["addCommentByFormId"] = function(formId, comment, callback)
    {
        return call("addCommentByFormId", [ formId, comment ], callback);
    }
    
    this["getCommentHistoryByFormId"] = function(formId, callback)
    {
        return call("getCommentHistoryByFormId", [ formId ], callback);
    }
    
    this["getDistinctLineItemDescriptions"] = function(callback)
    {
        return call("getDistinctLineItemDescriptions", [ ], callback);
    }
    
    this["getGmailContacts2"] = function(username, password, callback)
    {
        return call("getGmailContacts2", [ username, password ], callback);
    }
    
    this["getGmailContactsJson"] = function(username, password, callback)
    {
        return call("getGmailContactsJson", [ username, password ], callback);
    }
    
    this["getYahooContactsJson"] = function(startIndex, totalContacts, callback)
    {
        return call("getYahooContactsJson", [ startIndex, totalContacts ], callback);
    }
    
    /* Returns an array of method names implemented by this service. */
    
    this["system.listMethods"] = function(callback)
    {
        return call("system.listMethods", [ ], callback);
    }
    
    /* Returns the version server implementation using the major, minor, build and revision format. */
    
    this["system.version"] = function(callback)
    {
        return call("system.version", [ ], callback);
    }
    
    /* Returns a summary about the server implementation for display purposes. */
    
    this["system.about"] = function(callback)
    {
        return call("system.about", [ ], callback);
    }
    
    var url = typeof(url) === 'string' ? url : 'http://www.fastdue.com/FastDueHandler.ashx';
    var self = this;
    var nextId = 0;

    function call(method, params, callback)
    {
        var request = { id : nextId++, method : method, params : params };
        return callback == null ? 
            callSync(method, request) : callAsync(method, request, callback);
    }

    function callSync(method, request)
    {
        var http = newHTTP();
        http.open('POST', url, false, self.httpUserName, self.httpPassword);
        setupHeaders(http, method);
        http.send(JSON.stringify(request));
        if (http.status != 200)
            throw { message : http.status + ' ' + http.statusText, toString : function() { return message; } };
        var response = JSON.eval(http.responseText);
        if (response.error != null) throw response.error;
        return response.result;
    }

    function callAsync(method, request, callback)
    {
        var http = newHTTP();
        http.open('POST', url, true, self.httpUserName, self.httpPassword);
        setupHeaders(http, method);
        http.onreadystatechange = function() { http_onreadystatechange(http, callback); }
        http.send(JSON.stringify(request));
        return request.id;
    }

    function setupHeaders(http, method)
    {
        http.setRequestHeader('Content-Type', 'text/plain; charset=utf-8');
        http.setRequestHeader('X-JSON-RPC', method);
    }

    function http_onreadystatechange(sender, callback)
    {
        if (sender.readyState == /* complete */ 4)
        {
            var response = sender.status == 200 ? 
                JSON.eval(sender.responseText) : {};
            
            response.xmlHTTP = sender;
                
            callback(response);
        }
    }

    function newHTTP()
    {
        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 */
    }
}

FastDueHandler.rpcMethods = ["getAllCountries","getReminderOptionDates","getReminderOptionDatesForInvoice","getAllUnits","getAllCategories","getPaymentTermDays","getContact","isCurrencySupportedByPayPal","getShortDateStringAddDays","getDateDiffInDays","getEmailFromProfile","getLogoWidth","forwardForm","getContactById","updateApprovalById","addApprovalByFormId","addCommentByFormId","getCommentHistoryByFormId","getDistinctLineItemDescriptions","getGmailContacts2","getGmailContactsJson","getYahooContactsJson","system.listMethods","system.version","system.about"];
