﻿// settings just for goview or specificially tailored for goview

var CliErrorAction_Download     = 1;
var CliErrorAction_General      = 2;
var CliErrorAction_Bookmark     = 3;
var CliErrorAction_SetPcName    = 4;
var CliErrorAction_Delete       = 5;
var CliErrorAction_Sort         = 6;
var CliErrorAction_Pause        = 7;
var CliErrorAction_Sync         = 8;
var CliErrorAction_Resume       = 9;

//--------------------------------------------------------------------------------
function CliDisplayError( errorAction, errorCode, errorAttributes )
{
    ///<param name="errorAttributes">Parseable string of error attributes that will be
    ///processed as appropriate to the errorCode</param>

    var ErrorStr_AppName = "GO!VIEW";
    var ErrorStr_IfPersistsCallCode = "If the problem persists, please call Customer Services on 08448 222 048 and quote the following error code.";
    
    try{ hide_waiting(); } catch( e ){}
    
    if( errorAttributes == null )
        errorAttributes = "";
        
    var errorMessage;
    
    if( errorCode == null || errorAction == null )
    {
        errorMessage = "Unspecified error occurred [?].";
    }
    else
    {
        switch( errorAction )
        {
            case CliErrorAction_Download:  errorMessage = ErrorStr_AppName + " has encountered a problem starting your download.\n"; break;
            case CliErrorAction_Bookmark:  errorMessage = ErrorStr_AppName + " has encountered a problem bookmarking your item.\n"; break;
            case CliErrorAction_SetPcName: errorMessage = ErrorStr_AppName + " has encountered a problem completing your installation.\n"; break;
            case CliErrorAction_Delete:    errorMessage = ErrorStr_AppName + " has encountered a problem deleting your item.\n"; break;
            case CliErrorAction_Sort:      errorMessage = ErrorStr_AppName + " has encountered a problem sorting.\n"; break;
            case CliErrorAction_Pause:     errorMessage = ErrorStr_AppName + " has encountered a problem pausing download(s).\n"; break;
            case CliErrorAction_Sync:      errorMessage = ErrorStr_AppName + " has encountered a problem transferring.\n"; break;
            case CliErrorAction_Resume:    errorMessage = ErrorStr_AppName + " has encountered a problem resuming paused download(s).\n"; break;


            case CliErrorAction_General:  errorMessage = "There has been a problem with " + ErrorStr_AppName + ".\n"; break;
            
            default: errorMessage = ErrorStr_AppName + " has encountered a problem.\n"; break;
        }
        
        if( errorCode < 1 )
            errorCode *= -1;
        
        var sonyCode = 0;
        if( errorCode >= 30020 && errorCode <= 30038 )
        {
            sonyCode = CliGetSonyLibErrorFromAttributes( errorAttributes );
        }
        
        switch( errorCode )
        {
            case  1  : errorMessage += "Download manager initialisation failed. Please exit " + ErrorStr_AppName + ", re-start your PC and try again. \n" + ErrorStr_IfPersistsCallCode; break;
            case  2  : errorMessage += "Setting(s) are not available. Please exit " + ErrorStr_AppName + ", re-start your PC and try again. \n" + ErrorStr_IfPersistsCallCode; break;
            case  3  : errorMessage += "Settings appear invalid. Please exit " + ErrorStr_AppName + ", re-start your PC and try again. \n" + ErrorStr_IfPersistsCallCode; break;
            case  4  : errorMessage += "Saving settings failed. Please exit " + ErrorStr_AppName + ", re-start your PC and try again. \n" + ErrorStr_IfPersistsCallCode; break;
            case  5  : errorMessage += "Loading initialisation settings failed. Please exit " + ErrorStr_AppName + ", re-start your PC and try again. \n" + ErrorStr_IfPersistsCallCode; break;
            case  6  : errorMessage += "It was not possible to load the installation configuration file. Please exit " + ErrorStr_AppName + ", re-start your PC and try again. \n" + ErrorStr_IfPersistsCallCode; break;
            case  7  : errorMessage += "It was not possible to load the subscriber settings. Please exit " + ErrorStr_AppName + ", re-start your PC and try again. \n" + ErrorStr_IfPersistsCallCode; break;
            case  8  : errorMessage += "Failed To Create TraceFile. Please exit " + ErrorStr_AppName + ", re-start your PC and try again. \n" + ErrorStr_IfPersistsCallCode; break;
            case  9  : errorMessage += "The item is already in the library."; break; 
            case  10 : errorMessage += "You have bookmarked too many videos. Please remove some old bookmarks, then try again."; break;
            case  11 : errorMessage += "The bookmark is not allowed. Please exit " + ErrorStr_AppName + ", re-start your PC and try again. \n" + ErrorStr_IfPersistsCallCode; break;
            case  12 : errorMessage += "The video has already downloaded - unable to download. Please review the status of the video in your Library. " + ErrorStr_IfPersistsCallCode; break;
            case  13 : errorMessage += "You are downloading the maximum number of videos at once. You can monitor the progress of downloads in your Library. Hint: you can bookmark this video so you can easily find it and remember to download it later."; break;
            case  14 : errorMessage += "The download is not allowed. Please exit " + ErrorStr_AppName + ", re-start your PC and try again. \n" + ErrorStr_IfPersistsCallCode; break;
            case  19 : errorMessage += "An error occurred with your specified download location. Please check that the download location is set to your PC drive. " + ErrorStr_IfPersistsCallCode; break;
            case  21 : errorMessage += "There is not enough disk space to download this video. Select My Profile to choose a new download location, or delete some old videos from your Library, and try again."; break;
            case  22 : errorMessage += "Some of the characters of your PC friendly name are invalid. Please re-try with letters A-Z."; break;
            case  23 : errorMessage += "There is an error processing the PIN. Please exit " + ErrorStr_AppName + ", re-start your PC and try again. \n" + ErrorStr_IfPersistsCallCode; break;
            case  24 : errorMessage += "There is a Download manager failure. Please exit " + ErrorStr_AppName + ", re-start your PC and try again. \n" + ErrorStr_IfPersistsCallCode; break;
            case  30 : errorMessage += "There is a Download manager failure. Please exit " + ErrorStr_AppName + ", re-start your PC and try again. \n" + ErrorStr_IfPersistsCallCode; break;
            case  31 : errorMessage += "There is a Download manager failure. Please exit " + ErrorStr_AppName + ", re-start your PC and try again. \n" + ErrorStr_IfPersistsCallCode; break;
            case  32 : errorMessage += "There is a Download manager failure. Please exit " + ErrorStr_AppName + ", re-start your PC and try again. \n" + ErrorStr_IfPersistsCallCode; break;


            case  10000 : errorMessage += "Please exit " + ErrorStr_AppName + ", re-start your PC and try again. \n" + ErrorStr_IfPersistsCallCode; break;
            case  10001 : errorMessage += "Please exit " + ErrorStr_AppName + ", re-start your PC and try again. \n" + ErrorStr_IfPersistsCallCode; break;
            case  10003 : errorMessage += "Please exit " + ErrorStr_AppName + ", re-start your PC and try again. \n" + ErrorStr_IfPersistsCallCode; break;
            case  10004 : errorMessage += "It is not possible to pause the requested download. Please exit " + ErrorStr_AppName + ", re-start your PC and try again. \n" + ErrorStr_IfPersistsCallCode; break;
            case  10005 : errorMessage += "It is not possible to pause the requested download. Please exit " + ErrorStr_AppName + ", re-start your PC and try again. \n" + ErrorStr_IfPersistsCallCode; break;
            case  10006 : errorMessage += "It was not possible to resume the requested download. Please exit " + ErrorStr_AppName + ", re-start your PC and try again. \n" + ErrorStr_IfPersistsCallCode; break;
            case  10007 : errorMessage += "It was not possible to resume the requested download. Please exit " + ErrorStr_AppName + ", re-start your PC and try again. \n" + ErrorStr_IfPersistsCallCode; break;
            case  10008 : errorMessage += "Please exit " + ErrorStr_AppName + ", re-start your PC and try again. \n" + ErrorStr_IfPersistsCallCode; break;
            case  10009 : errorMessage += "Please exit " + ErrorStr_AppName + ", re-start your PC and try again. \n" + ErrorStr_IfPersistsCallCode; break;
            case  10010 : errorMessage += "You cannot sort this column."; break;
            case  10011 : errorMessage += "Please allow the download to complete."; break;
            case  10012 : errorMessage += "Please exit " + ErrorStr_AppName + ", re-start your PC and try again. \n" + ErrorStr_IfPersistsCallCode; break;
            case  10013 : errorMessage += "Please exit " + ErrorStr_AppName + ", re-start your PC and try again. \n" + ErrorStr_IfPersistsCallCode; break;
            case  10015 : errorMessage += "Please exit " + ErrorStr_AppName + ", re-start your PC and try again. \n" + ErrorStr_IfPersistsCallCode; break;

            // duplicate from LicenseAquisitionPage, for completion
            case  20000 : errorMessage += "Sorry, this video requires a DRM license to allow you to watch it, and it seems that your license has either expired or has not yet been delivered to your computer. Please log on to GO!VIEW and try again."; break;
            case  20001 : errorMessage += "Please exit " + ErrorStr_AppName + ", re-start your PC and try again. \n" + ErrorStr_IfPersistsCallCode; break; // this is for general errors that we dont want to tell the user much about.  typicially with CliErrorAction_General
            
            case 30001 : errorMessage += "It was not possible to sort the library on this column."; break;

            case 30009 : errorMessage += "An error occured displaying the channels."; break;
            case 30010 : errorMessage += "It was not possible to sort the library on this column."; break;
            case 30011 : errorMessage += "An error occurred displaying the library."; break;
            case 30012 : errorMessage += "The PSP is not currently connected.  Please ensure you're using your mini USB cable to connect your PC."; break;
            case 30013 : errorMessage += "There has been a failure to set the secure time on the PSP.  Please exit " + ErrorStr_AppName + ", re-start your PC and try again. \n" + ErrorStr_IfPersistsCallCode; break;
            case 30014 : errorMessage += "There is already a PSP transfer in progress.  Once the transfer has completed exit " + ErrorStr_AppName + ", re-start your PC and try again. \n" + ErrorStr_IfPersistsCallCode; break;
            case 30015 : errorMessage += "There has been a PSP related error.  Please exit " + ErrorStr_AppName + ", re-start your PC and try again. \n" + ErrorStr_IfPersistsCallCode; break;
             
            case 30020 :
            case 30021 : 
            case 30022 : 
            case 30023 : 
            case 30024 : 
            case 30025 : 
            case 30026 : 
            case 30027 : 
            case 30028 : 
            case 30029 : 
            case 30030 : 
            case 30031 : 
            case 30032 : 
            case 30033 : 
            case 30034 : 
            case 30035 : 
            case 30036 : 
            case 30037 : 
            case 30038 : errorMessage += "There has been a PSP related error.  Please exit " + ErrorStr_AppName + ", re-start your PC and try again. \nIf the problem persists, please call Customer Services on 08448 222 048 and quote the following error codes.\nPSP error code: " + sonyCode; break;

            case 30100 : errorMessage += "There has been a problem with " + ErrorStr_AppName + "\n" + ErrorStr_IfPersistsCallCode; break; break; // general error with processing a continuation for bookmarking or downloading
            case 30101 : errorMessage += ErrorStr_AppName + " has encountered a problem starting your download.  " + ErrorStr_IfPersistsCallCode; break;
            case 30102 : errorMessage += ErrorStr_AppName + " has encountered a problem bookmarking your item.  " + ErrorStr_IfPersistsCallCode; break;
            
            case 30200 : // continuation manager: async action - _Run
            case 30201 : // continuation manager: continue running after async action
            case 30202 : // continuation manager: async action - ExecuteAfterShortDelay
            case 30203 : "There has been a problem with " + ErrorStr_AppName + "  " + ErrorStr_IfPersistsCallCode; break; // continuation manager: async action - repeat until true and continue
            
            default: errorMessage += "Please exit " + ErrorStr_AppName + ", re-start your PC and try again. \n" + ErrorStr_IfPersistsCallCode; break; 
        }
        
        errorMessage += " [" + errorCode + "]";
    }
    
    CliPspDisplayErrorWithLink( errorMessage, "", "", document.body );
}

//--------------------------------------------------------------------------------
function CliIsInstalled( propositionName )
{
    ///<summary>Determines if the current client is installed</summary>
    ///<param name="propositionName"></param>
    
    var obj;
    var installed;
    try
    {
        //TODO: client specific code
        obj = new ActiveXObject( "GoView.InstalledDetectionObject" );
        if (obj != null && obj.PropositionPresent( propositionName ) )
            installed = true;
        else
            installed = false;
    }
    catch (e)
    {
        installed = false;
    }   
    
    obj = null;
    return installed;
}

//--------------------------------------------------------------------------------
function CliSwitchToOfflineMode()
{
    ///<summary>Jump to offline mode</summary>
    new CliKontikiHost( CliGetProfileAuthToken(), CliGetProfileAuthSig() ).LaunchPage( "cache:pspOfflineMode.htm" );
}

//--------------------------------------------------------------------------------
function CliGetSyncPageOpenProperties()
{
    return "class=browser,height=768,width=694,maxbtn=false,minbtn=false,sysmenu=false,position=33";
}

//--------------------------------------------------------------------------------
function CliGetPlayerPageOpenProperties()
{
    return "class=browser,width=640,height=585,position=1,resize=1,scrollbars=1,visible=1";
}

//--------------------------------------------------------------------------------
function CliGetSonyLibErrorFromAttributes( errorAttributes )
{
    var splits = errorAttributes.Split( ";" );
    
    for( var i = 0; i < splits.length; i++ )
    {
        if( splits[ i ].substring( 0, 15 ) == "SonyPspLibCode[" )
        {
            return parseInt( splits[ i ].substring( 15, splits[ i ].length - 2 ), 10 );
        }
    }
    
    return 0;
}

//--------------------------------------------------------------------------------
function CliGetNewWindowPage( name )
{
    return "cache:pspNewRequestWindow.htm?requestName=" + name;
}
