﻿//service URLs.
var serviceUrlJsonQueuePage = "/FCWSite/Features/WebBinder/Services/webbinderjson.svc/binder/queue/";
var serviceUrlJsonDequeuePage = "/FCWSite/Features/WebBinder/Services/webbinderjson.svc/binder/dequeue/";
var serviceUrlJsonClearQueue = "/FCWSite/Features/WebBinder/Services/webbinderjson.svc/binder/clear/";
                
//queue page.
function queuePage(pageUrl, pagePrintUrl, pageTitle,  pageData, pageSection, callback, errorCallback)
{
    callJsonService(serviceUrlJsonQueuePage,
    {
        pageUrl: pageUrl,
        pagePrintUrl: pagePrintUrl,
        pageTitle: pageTitle,
        pageData: pageData,
        pageSection: pageSection
    },
    callback,
    errorCallback);
}
        
//dequeue page.
function dequeuePage(pageUrl, callback, errorCallback)
{        
    callJsonService(serviceUrlJsonDequeuePage, { pageUrl: pageUrl }, callback, errorCallback);                        
}

//dequeue page.
function dequeuePageByHandle(pageHandle, callback, errorCallback)
{
    callJsonService(serviceUrlJsonDequeuePage, { pageHandle: pageHandle }, callback, errorCallback);
}

//clear queue.
function clearQueue(callback, errorCallback)
{
    callJsonService(serviceUrlJsonClearQueue, null, callback, errorCallback);
}
        
//call JSON service.
function callJsonService(url, data, callback, errorCallback)
{    
    $.ajax(
    {
        url: url,
        data: data,
        dataType: "json",
        contentType: "application/json",
        cache: false,
        success:
            function(webBinderResponse)
            {                                        
                if (callback != null)    
                    callback(webBinderResponse);                        
            },
        error:
            function(response)
            {                            
                if (errorCallback != null)
                    errorCallback(response);                    
            }                
    });
}
