﻿// settings/methods for all propositions

//--------------------------------------------------------------------------------
function CliBuilOnlineUrl( urlSegment, useBrowserDomain, maintainProtocol, forceProtocol )
{
    ///<summary></summary>
    ///<param name="urlSegment">variable part of url such as '/page/hybridLaunch.do?requestedUrl='</param>
    ///<param name="useBrowserDomain">[optional] True if the build url should reference the browser domain. Defaults to false.</param>
    ///<param name="maintainProtocol">[optional] True if the build should detect the current protocol (http or https) and build the url with the same</param>
    ///<param name="forceProtocol">[optional] string value to replace the current protocol with, e.g. http, https</param>
    
    if (useBrowserDomain==null)
        useBrowserDomain=false;
        
    var domain = useBrowserDomain ? CliGetBrowserDomain() : CliGetClientDomain();
    if(maintainProtocol)
    {
        var curProtocol = location.href.substring(0,5);
        var domProtocol = domain.substring(0,5);
        if(curProtocol == "https" && domProtocol == "http:")
            domain = domain.replace("http:", "https:");
        else if(curProtocol == "http:" && domProtocol == "https")
            domain = domain.replace("https:", "http:");
    }
    if(forceProtocol)
    {
        domain = forceProtocol + domain.substring(domain.indexOf(":"));
    }
    return domain + CliGetAppRoot() + urlSegment;
}

//--------------------------------------------------------------------------------
var CliFlags_Debug     = 1;
var CliFlags_Test      = 2;
var CliFlags_Support   = 4;

//--------------------------------------------------------------------------------
function CliDebug( message )
{
    ///<summary>shows a debug message if debug messaging is enabled</summary>
    if( CliShowDebugMessages() )
        alert (message );
}

//--------------------------------------------------------------------------------
function CliShowDebugMessages()
{
    ///<summary>Returns true if debug messages should be shown</summary>
    return ( CliFlags() & (CliFlags_Debug + CliFlags_Support) ) != 0;
}

//--------------------------------------------------------------------------------
function CliDisableForceIntoClient()
{
    ///<summary>Returns true if the client indicates that switching to the hybrid
    ///client should be disabled.</summary>
    return ( CliFlags() & (CliFlags_Debug + CliFlags_Test) ) != 0;
}

//--------------------------------------------------------------------------------
function CliFlags()
{
    ///<summary>Gets the value of 'flags' stored for the current proposition.</summary>

    try
    {
        return _comProposition.Flags;
    }
    catch( e )
    {
        try
        {
            return _propInstance.Flags;
        }
        catch( e )
        {
            return 0;
        }
    }
}
