﻿///<reference path="..\..\core\jscript\clikontikihost6.js" />
///<reference path="..\..\core\jscript\clipropconfig6.js" />
///<reference path="..\..\core\jscript\CliBasePages6.js" />

//--------------------------------------------------------------------------------
function CliPspPageLoader( authToken, authSignature, iOffline )
{
    this._iOffline = iOffline;  // may be null
    this._base = new CliBasePages();
    this._kdxHost = new CliKontikiHost( authToken, authSignature );

    this.RootFrameName = "root";
    this.RootFrameStyle = "class=browser,width=1024,height=768,position=1,resize=1,scrollbars=1,visible=1,name=" + this.RootFrameName;
    
    //- known urls -------------------------------------------------------------------
    this.UrlOnlineHomePage = CliBuilOnlineUrl( "/" );
    
    this.UrlOfflineHomePage       = "OfflineLibrary.htm";//cache:
    this.UrlOfflineNoSettingsPage = "MissingSettings.htm";//cache:
    this.UrlOfflineEulaPage       = "pspEula.htm";//cache:
    this.UrlOfflineModePage       = "pspOfflineMode.htm";//cache:

    this.OnlineBrowserDomainHybridLaunchPage = CliBuilOnlineUrl( "/page/hybridLaunch.do?requestedUrl=", true );
    //- known urls end ---------------------------------------------------------------
}

//--------------------------------------------------------------------------------
CliPspPageLoader.prototype =
{
    //--------------------------------------------------------------------------------
    SetOfflineObject : function( iOffline )
    {
        this._iOffline = iOffline;
    },
    
    //--------------------------------------------------------------------------------
    LaunchPage : function( url )
    {
        ///<summary>Open a specified url in a new window.  this is likley to cause
        ///a new kontiki frame to be opened to host the page</summary>
        ///<param name="url"></param>
        
        this._kdxHost.LaunchPage( url );
    },
    
    LaunchPageEx : function( url, name , pageStyle)
    {
        this._kdxHost.LaunchPageEx( url , name , pageStyle);
    },

    //--------------------------------------------------------------------------------
    GotoPage : function( url )
    {
        ///<summary>Navigate to the specified url in the current window.</summary>
        ///<param name="url"></param>

        if( this._AreOnline() == false )
        {
            url = this.UrlOfflineModePage;
        }
        
        try
        {
            var template = window.external.param( "template" );
            
            if( template != null && template.length > 0 && ( url.substring( 0, 4 ) != "http" ) )
            {
                window.external.navigate( "cache:" + url );
                return;
            }
        }
        catch( e ){}
            
        document.location.href = url;
    },
    
    //--------------------------------------------------------------------------------
    _AreOnline : function()
    {
        return this._iOffline.CheckIsOnline( "" );
    },
    
    //- exposed base functions -------------------------------------------------------
    IsUrlInClientDomain : function( url )
    {
        return this._base.IsUrlInClientDomain( url );
    },
    
    //--------------------------------------------------------------------------------
    IsUrlInBrowserDomain : function( url )
    {
        return this._base.IsUrlInBrowserDomain( url );
    },
    //- exposed base functions end ---------------------------------------------------
    
    //- iBasePages methods -----------------------------------------------------------
    //--------------------------------------------------------------------------------
    OpenOnlineHomePage : function()
    {
        this.GotoPage( this.UrlOnlineHomePage );
    },

    //--------------------------------------------------------------------------------
    OpenOfflineHomePage : function()
    {
        this.GotoPage( this.UrlOfflineHomePage );
    },
    
    //--------------------------------------------------------------------------------
    OpenOfflineNoSettingsPage : function()
    {
        this.GotoPage( this.UrlOfflineNoSettingsPage );
    }
    
    //- iBasePages end ---------------------------------------------------------------

}//
