//-------------------------------------------------------------------------------
//
// proposition : An initialised ComPropositionInstance
// licenseActions : instance of CliLicenseActions
//
function CliLogon( proposition, licenseActions )
{
    this._proposition = proposition;
    this._licenseActions = licenseActions;
}

//-------------------------------------------------------------------------------
//
CliLogon.prototype =
{
    //-------------------------------------------------------------------------------
    //
    getPcFingerprint : function()
    {
        return this._proposition.PlatformInformation.PCFingerprint;
    },

    //-------------------------------------------------------------------------------
    //
    getApplicationVersion : function()
    {
        return this._proposition.PlatformInformation.ClientVersion;
    },
    
    //-------------------------------------------------------------------------------
    //
    getDrmSystemInfo : function() 
    {
        if(window.ActiveXObject)
        {
            var ni = new ActiveXObject("DRM.GetLicense");
            return ni.GetSystemInfo();
        }
    },

    //-------------------------------------------------------------------------------
    //  revokes licenses for a list of channels
    //
    // csvChannel : comma seperated list of channels to revoke
    //
    RevokeLicenses : function( csvChannel )
    {
        if( csvChannel == null || csvChannel.length == 0 )
            return;

        var licenseRevoker = this._proposition.LicenseRevoker;
        
        var channels = csvChannel.split( ',' );
        
        if( channels.length == 0 )
            return;
            
        var i;
        for( i = 0; i < channels.length; i++ )
        {
            licenseRevoker.AddChannel( channels[ i ] );
        }
        
        var challenges = licenseRevoker.GenerateRevocationChallenges();
        var responses = this._Revoke_SendChallenges( challenges );
        var confirms = licenseRevoker.ApplyRevocationResponses( responses );
        this._Revoke_SendConfirmations( confirms );
    },
       
    //-------------------------------------------------------------------------------
    // calls 'complete download' on the server for all items requireing it
    //
    CompleteDownloads : function()
    {
        var itemsIterator = this._proposition.VideoLibraryActions.ListItemsRequiringCompletion();
        
        while( itemsIterator.More )
        {
            var videoId = itemsIterator.Current.VideoId;
            var purchaseRef = itemsIterator.Current.PurchaseReference;
            _cliController.completeItem( videoId, purchaseRef, itemsIterator.Current.MediaContentId );
            
            itemsIterator.Next();
        }
    },
    
    //-------------------------------------------------------------------------------
    //
    RegisterRemoteDownloadId : function(remoteDownloadId)
    {
        try
        {
            this._proposition.VideoLibraryActions.RegisterRemoteDownloadId(remoteDownloadId);
        }
        catch( e )
        {
        }
    },

    //-------------------------------------------------------------------------------
    //
    _Revoke_SendChallenges : function( challenges )
    {
        CliDebug( "implement sending challenges to server for license revocation" );
        return "";
    },

    //-------------------------------------------------------------------------------
    //
    _Revoke_SendConfirmations : function( confirmations )
    {
//        alert( "implement sending confirmations to server for license revocation" );
    }
}//


