//var pendingMask;
var pendingitems = {};
pendingitems.pendingMask = "";

pendingitems.showPendingItems = function(pendingItemsID)
{
    // Update the form field
    document.getElementById('pendingItemsSelected').value = pendingItemsID;
    // Clear everything
    document.getElementById('pendingitems').innerHTML='';
    pendingitems.PluginPendingItems();
}

pendingitems.PluginPendingItems =  function()
{
    // Clean the DIV used for showing the data
    document.getElementById('pendingitems').innerHTML = '';
    pendingitems.showMask();
    
    var pendingItemsID = document.getElementById('pendingItemsSelected').value;
    
    switch(pendingItemsID){
        case 'orders':
            // Load a single JavaScript file and execute a callback when it finishes loading.
            LazyLoad.js(
                '../plugins/dashboard/pendingitems/ViewPendingOrders.js',
                function(){
                    pendingitems.hideMask();
                    pendingorders.ViewPendingOrders();
                }
            );
            break;
        case 'cc':
            // Load a single JavaScript file and execute a callback when it finishes loading.
            LazyLoad.js(
                '../plugins/dashboard/pendingitems/ViewPendingCC.js',
                function(){
                    pendingitems.hideMask();
                    pendingccs.ViewPendingCC();
                }
            );
            break;
			
		case 'autoclose':
			LazyLoad.js(
                '../plugins/dashboard/pendingitems/ViewTicketsAutoClosing.js',
                function(){
                    pendingitems.hideMask();
                    ticketsclosing.ViewTickets();
                }
            );
			break;
			
		case 'pendingusers':
			LazyLoad.js(
                '../plugins/dashboard/pendingitems/ViewDeletePendingUsers.js',
                function(){
                    pendingitems.hideMask();
                    pendingusers.ViewPendingUsers();
                }
            );
		
			break;
			
		case 'invoicegenerator':
			LazyLoad.js(
                '../plugins/dashboard/pendingitems/ViewInvoiceGenerator.js',
                function(){
                    pendingitems.hideMask();
                    invoices.ViewInvoices();
                }
            );
		
			break;
			
		case 'mailer':
			LazyLoad.js(
                '../plugins/dashboard/pendingitems/ViewQueuedEmails.js',
                function(){
                    pendingitems.hideMask();
                    mailer.ViewQueuedEmails();
                }
            );
		
			break;
			
		case 'rebiller':
			LazyLoad.js(
                '../plugins/dashboard/pendingitems/Rebiller.js',
                function(){
                    pendingitems.hideMask();
                    rebiller.ViewInvoiceReminders();
                }
            );
		
			break;
			
		case 'autosuspend':
			LazyLoad.js(
                '../plugins/dashboard/pendingitems/AutoSuspend.js',
                function(){
                    pendingitems.hideMask();
                    suspender.ViewSuspender();
                }
            );
		
			break;
			
		case 'batchnotifier':
			LazyLoad.js(
                '../plugins/dashboard/pendingitems/BatchNotifier.js',
                function(){
                    pendingitems.hideMask();
                    batchnotifier.ViewEntries();
                }
            );

			break;

		default:
            pendingitems.hideMask();
            document.getElementById('pendingitems').innerHTML = '&nbsp;&nbsp;<font color=red>These items are not available yet.</font>';
            break;
    }
}

pendingitems.showMask = function()
{
    if(!pendingitems.pendingMask){
        pendingitems.pendingMask = new Ext.LoadMask('pendingmask', {msg:"Please wait..."});
    }
    
    document.getElementById('pendingmask').style.display = '';
    pendingitems.pendingMask.show();
}

pendingitems.hideMask = function()
{
    pendingitems.pendingMask.hide();
    document.getElementById('pendingmask').style.display = 'none';
}