<!--
/************************************************************************

FILE: kdx.js
DESCRIPTION: Utility functions used by the KDM 4.02.

Copyright (c) 2004-2005 Kontiki Inc.

*************************************************************************/

//////////////////////////////////////////////////////////////////////////
//
// Include file.
//
//////////////////////////////////////////////////////////////////////////
document.write('<script src="kdx_init.js"><\/script>');

//////////////////////////////////////////////////////////////////////////
//
// FUNCTION: getApi()
//
// DESCRIPTION: Instantiate global API object.
//
//////////////////////////////////////////////////////////////////////////
var gKDXApi = null;
function getApi()
{
	if (gKDXApi == null)
	{
        var api = new ActiveXObject("KDX.SecureApi");
        api.authorize(gAuthToken, gAuthSignature); 
        gKDXApi = api;
	}
	return gKDXApi;
}

//////////////////////////////////////////////////////////////////////////
//
// FUNCTION: getPref(i_name, i_default)
//
// DESCRIPTION: Generic get pref method. You can supply a default
// in case it fails.
//
//////////////////////////////////////////////////////////////////////////
function getPref(i_name, i_default)
{
    var theValue = i_default;
    try
    {
        theValue = getApi().pref( i_name );
    }
    catch( e ){}
    
    return theValue;
}

//////////////////////////////////////////////////////////////////////////
//
// FUNCTION: setPref(i_name, i_value)
//
// DESCRIPTION: Generic set pref "i_name" with value "i_value".
//
//////////////////////////////////////////////////////////////////////////
function setPref(i_name, i_value)
{
	var theValue;
    try
    {
        theValue = getApi().pref( i_name ) =  i_value;
    }
    catch( e ){}
    
    return theValue;
}

//////////////////////////////////////////////////////////////////////////
//
// FUNCTION: getPrefAsString(i_name)
//
// DESCRIPTION: Converts pref value to string.
//
//////////////////////////////////////////////////////////////////////////
function getPrefAsString(i_name)
{
    try
    {
        return getApi().prefstr( i_name );
    }
    catch( e )
    {
        return "";
    }
}

//////////////////////////////////////////////////////////////////////////
//
// FUNCTION: isPrefLocked(i_name)
//
// DESCRIPTION: Returns true if pref is locked by NetManager.
//
//////////////////////////////////////////////////////////////////////////
function isPrefLocked(i_name)
{
    return getApi().isPrefLocked( i_name );
}

//////////////////////////////////////////////////////////////////////////
//
// FUNCTION: getFrame(i_moid, i_name)
//
// DESCRIPTION: Returns null if KFrame window does not exist.
//
//////////////////////////////////////////////////////////////////////////
function getFrame(i_moid, i_name)
{
    try
    {
        return getApi().getFrame(i_moid,  i_name );
    }
    catch(e)
    {
        return null;
    }
}

//////////////////////////////////////////////////////////////////////////
//
// Central place to launch key system elements.
//
//////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////
//
// FUNCTION: launchAbout()
//
// DESCRIPTION: Launches About dialog.
//
//////////////////////////////////////////////////////////////////////////
function launchAbout()
{
    getApi().launchTemplate( "cache:kdmx_about.html", "class=dialog,width=380,height=210,position=1,resize=1", "", "about");
}

//////////////////////////////////////////////////////////////////////////
//
// FUNCTION: launchComplete(i_moid)
//
// DESCRIPTION: Launches Delivery Complete dialog for a given delivery,
// passed in via "i_moid".
//
//////////////////////////////////////////////////////////////////////////
function launchComplete(i_moid)
{
    getApi().launchTemplate("cache:kdmx_complete.html", "class=dialog,position=1,visible=0", i_moid, "complete");
}

//////////////////////////////////////////////////////////////////////////
//
// FUNCTION: launchEmail(i_moid, i_url)
//
// DESCRIPTION: Launches Email This dialog for a given delivery,
// passed in via "i_moid". The Email This URL is also passed in.
//
//////////////////////////////////////////////////////////////////////////
function launchEmail(i_moid, i_url)
{
    if (getApi().isOnline() && i_url != "")
    {
        var emailUrl = i_url + i_moid;
        window.open(emailUrl, "emailthis", "height=555,width=455,status=no,toolbar=no,location=no,scrollbars=yes", true);
    }
    else launchOffline();
}

//////////////////////////////////////////////////////////////////////////
//
// FUNCTION: launchError(data)
//
// DESCRIPTION: Launches Error dialog for a given error, passed in via
// "data" object.
//
//////////////////////////////////////////////////////////////////////////
function launchError(data)
{
    //stash the event data away for use in the following page...
    window.external.ui.param("eventData") = data;     
    window.external.navigate("cache:kdmx_error.html");
}

//////////////////////////////////////////////////////////////////////////
//
// FUNCTION: launchInfo(i_moid)
//
// DESCRIPTION: Launches More Info dialog for a given delivery, passed in
// via "i_moid".
//
//////////////////////////////////////////////////////////////////////////
function launchInfo(i_moid)
{
    getApi().launchTemplate( "cache:kdmx_info.html", "class=dialog,width=410,height=410,position=1,resize=1", i_moid, "info");
}

//////////////////////////////////////////////////////////////////////////
//
// FUNCTION: launchMain()
//
// DESCRIPTION: Launches My Deliveries.
//
//////////////////////////////////////////////////////////////////////////
function launchMain()
{
    getApi().launchTemplate( "cache:kdmx_mainFrame.html", "class=dialog,width=800,height=500,position=1,resize=1", "", "main");
}

//////////////////////////////////////////////////////////////////////////
//
// FUNCTION: launchOffline()
//
// DESCRIPTION: Launches Offline dialog.
//
//////////////////////////////////////////////////////////////////////////
function launchOffline()
{
    getApi().launchTemplate( "cache:kdmx_offline.html", "class=dialog,position=1", "", "offline");
}

//////////////////////////////////////////////////////////////////////////
//
// FUNCTION: launchPlayer(i_moid)
//
// DESCRIPTION: Launches Player for a given delivery, passed in via
// "i_moid".
//
//////////////////////////////////////////////////////////////////////////
function launchPlayer(i_moid)
{
    getApi().launchTemplate("cache:kdmx_template.html", "class=dialog,position=1,visible=0", i_moid, "player");
}

//////////////////////////////////////////////////////////////////////////
//
// FUNCTION: launchPrefs()
//
// DESCRIPTION: Launches Preferences.
//
//////////////////////////////////////////////////////////////////////////
function launchPrefs()
{
    getApi().launchTemplate( "cache:kdmx_prefs.html", "class=dialog,width=700,height=400,minbtn=0,maxbtn=0,position=2", "", "prefs" );
}

//////////////////////////////////////////////////////////////////////////
//
// FUNCTION: launchProgress(i_moid)
//
// DESCRIPTION: Launches Progress dialog for a given delivery, passed in
// via "i_moid".
//
//////////////////////////////////////////////////////////////////////////
function launchProgress(i_moid)
{
    getApi().launchTemplate("cache:kdmx_progress.html", "class=dialog,position=1,visible=0", i_moid);
}

//////////////////////////////////////////////////////////////////////////
//
// FUNCTION: launchResTemplate(i_moid)
//
// DESCRIPTION: Launches Resurrection Template for a given delivery,
// passed in via "i_moid".
//
//////////////////////////////////////////////////////////////////////////
function launchResTemplate(i_moid)
{
    getApi().launchTemplate("cache:kdmx_template.html", "class=dialog,position=1,visible=0", i_moid);
}

//////////////////////////////////////////////////////////////////////////
//
// FUNCTION: launchDownloadMonitor()
// 
// DESCRIPTION: Launches the Download Monitor.
//
//////////////////////////////////////////////////////////////////////////
function launchDownloadMonitor()
{
	getApi().downloadMonitor(true);
}

//////////////////////////////////////////////////////////////////////////
//
// FUNCTION: launchDeleteDialog(i_moid)
//
// DESCRIPTION: Launches Delete Confirmation dialog for a given delivery,
// passed in via "i_moid".
//
//////////////////////////////////////////////////////////////////////////
function launchDeleteDialog(i_moid)
{
    var confirmDelete = getPref("ui.confirm-before-delete", true);
    
    if (confirmDelete)
	    getApi().launchTemplate("cache:kdmx_delete.html", "class=dialog,position=1,visible=0,deleteMoid=" + i_moid, "");
	else
	    getApi().deleteMoid(i_moid);
}

//////////////////////////////////////////////////////////////////////////
//
// Central place for frequently used methods.
//
//////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////
//
// FUNCTION: getThumbLarge(i_moid)
//
// DESCRIPTION: Gets 158x118 Large Thumbnail (aka Medium Icon in NetPub)
// for a given delivery, passed in via "i_moid".
//
//////////////////////////////////////////////////////////////////////////
function getThumbLarge(i_moid)
{
    var dlitem = new KDXDownload(i_moid);
    var url = dlitem.getStrValue("file_thumbnail");
    if(url == "") url = dlitem.getStrValue("image");
    if(url == "") url = dlitem.getStrValue("smallIcon");
    return url;
}

//////////////////////////////////////////////////////////////////////////
//
// FUNCTION: menuover( o )
//
// DESCRIPTION: Used by tray menu and context menus.
//
//////////////////////////////////////////////////////////////////////////
function menuover( o )
{
    o.style.backgroundColor = "#003366";
    o.style.color = "white";
}

//////////////////////////////////////////////////////////////////////////
//
// FUNCTION: menuover( o )
//
// DESCRIPTION: Used by tray menu and context menus.
//
//////////////////////////////////////////////////////////////////////////
function menuout( o )
{
    o.style.backgroundColor = "#CCCCCC";
    o.style.color = "black";
}

//////////////////////////////////////////////////////////////////////////
//
// Media types
//
//////////////////////////////////////////////////////////////////////////
var kPlayerType_Unknown         = 0;
var kPlayerType_WMP             = 1;
var kPlayerType_WMP6            = 2;
var kPlayerType_Real            = 3;
var kPlayerType_Quicktime       = 4;
var kPlayerType_Acrobat         = 5;
var kPlayerType_Winzip          = 6;

//////////////////////////////////////////////////////////////////////////
//
// Throttle Events
//
//////////////////////////////////////////////////////////////////////////
var KDX_THROTTLE_STATE_UNKNOWN      = -1;
var KDX_THROTTLE_STATE_NOTTHROTTLED = 0;
var KDX_THROTTLE_STATE_USERACTIVITY = 1 << 0;
var KDX_THROTTLE_STATE_NETACTIVITY  = 1 << 1;
var KDX_THROTTLE_STATE_ENFORCED     = 1 << 2;
var KDX_THROTTLE_STATE_NOTIN        = 1 << 3;
var KDX_THROTTLE_STATE_GENERIC      = 1 << 7;
var KDX_THROTTLE_STATE_ACCELERATED  = 1 << 8;

//////////////////////////////////////////////////////////////////////////
//
// Download Events
//
//////////////////////////////////////////////////////////////////////////
var KDX_STATE_NEW              = 0;
var KDX_STATE_QUEUED           = 1;
var KDX_STATE_CONNECTING       = 2;
var KDX_STATE_BACKOFF          = 3;
var KDX_STATE_PROGRESS         = 4;
var KDX_STATE_UNPACKING        = 5;
var KDX_STATE_COMPLETE         = 6;
var KDX_STATE_UPDATE           = 7;
var KDX_STATE_DELETED          = 8;
var KDX_STATE_PLAYABLE         = 9;
var KDX_STATE_PRIORITIZED      = 10;
var KDX_STATE_UNPRIORITIZED    = 11;
var KDX_STATE_DODEFAULTACTION  = 12;
var KDX_STATE_ERROR            = 13;
var KDX_STATE_PAUSE            = 14;
var KDX_STATE_RESUME           = 15;

var KDX_STATE_ATTACHED         = 16;
var KDX_STATE_PASSWORD         = 17;
var KDX_STATE_CHANGEPASSWORD   = 18;
var KDX_STATE_SHOWHELPERAPP    = 19;
var KDX_STATE_SELECTSTREAMING  = 20; 
var KDX_STATE_EMBARGOED        = 21;
 
//////////////////////////////////////////////////////////////////////////
//
// FUNCTION: getEventData(obj)
//
// DESCRIPTION: Returns map of data passed via an event.
//
//////////////////////////////////////////////////////////////////////////
function getEventData(obj)
{     
    try 
    {
        var map = new Array();
        var m = obj.toArray();
        for (var i = 0; i < m.length; i+=2 )
            map[m[i]] = m[i+1];
        return map;
    }
    catch (e)
    {
        return obj;
    }      
}

//////////////////////////////////////////////////////////////////////////
//
// FUNCTION: KDXDownloadStatusMessage(i_kdxevent, i_eventdata, i_default)
//
// DESCRIPTION: Handles UI for the different download states.
//
//////////////////////////////////////////////////////////////////////////
function KDXDownloadStatusMessage(i_kdxevent, i_eventdata, i_default)
{
    switch (i_kdxevent)
    {
        case KDX_STATE_PAUSE: return "Paused";
        case KDX_STATE_RESUME:
        case KDX_STATE_QUEUED: return "Queued";
        case KDX_STATE_CONNECTING: return "Connecting";
        case KDX_STATE_ERROR: 
        {
            var errorMap = getEventData(i_eventdata);
            var errorType = errorMap["errorType"];    
            var errorText = gErrorMsgMap[errorType];
            if (errorText != "") return errorText;
        }
    }
    return (i_default == null? "": i_default);
}

//////////////////////////////////////////////////////////////////////////
//
// FUNCTION: KDXDefaultEventHandler(i_moid, i_event, i_data)
//
// DESCRIPTION: Default event handler for the different states of the
// client. Acts as "switchboard" that redirects user to different pages
// driven by events.
//
//////////////////////////////////////////////////////////////////////////
function KDXDefaultEventHandler(i_moid, i_event, i_data)
{
    // For debugging:
    // if(i_event != KDX_STATE_PROGRESS)alert(i_event);
    
    switch(i_event)
    {
        case KDX_STATE_NEW:
        {
            // No splash dlg for streamed files.
            var dlitem = new KDXDownload(i_moid);
            
            if (dlitem.isMandatory() || dlitem.isMetaDataReload()) 
                window.external.closeWindow();
                
            // Don't show splash/progress dlg during blackout.
            else if (getApi().isBlackout())
            {
                var error = new Array();
                error["errorType"] = "ERROR_BLACKOUT"; 
                window.external.ui.param("eventData") = error;                    
                window.external.navigate("cache:kdmx_error.html");
            }
            else if(!dlitem.isStreaming()) 
                window.external.navigate("cache:kdmx_splash.html");
            break;
        }
        case KDX_STATE_PROGRESS:
        {
            // No progress dlg for streamed files.
            var dlitem = new KDXDownload(i_moid);
            if(!dlitem.isStreaming()) window.external.navigate("cache:kdmx_progress.html");
            break;
        }
        
        case KDX_STATE_DELETED:
        case KDX_STATE_EMBARGOED:
        {
            // Close window for deleted and embargoed deliveries           
            window.external.closeWindow();
            break;
        }
        case KDX_STATE_UNPACKING:
        {
			break;
        }
        case KDX_STATE_COMPLETE:
        {
            var dlitem = new KDXDownload(i_moid);
            // Don't show complete dlg for mandatory subs, http-streams,
            // and gridstream-nonsave files
            if (!dlitem.isMandatory() && !dlitem.isHttpStreaming() && !dlitem.isGridStreamNoSave() && !dlitem.isMetaDataReload())
            {
                // Don't show sub activated dlg during blackout.
                if (dlitem.isSubscription() && getApi().isBlackout())
                {
                    var error = new Array();
                    error["errorType"] = "ERROR_BLACKOUT"; 
                    window.external.ui.param("eventData") = error;                    
                    window.external.navigate("cache:kdmx_error.html");
                }
                else window.external.navigate("cache:kdmx_complete.html");
            }
            else
                window.external.closeWindow();
            break;
        }
        case KDX_STATE_PASSWORD:
            // Stash the event data away for use in the following page.
            window.external.ui.param("eventData") = i_data;
            var dopreauth = getPref("download.preAuthenticationEnabled", false);
            var preauthUrl = getPref("download.preAuthenticationUrl","");

            if (dopreauth && preauthUrl != "")
                window.external.navigate("cache:kdmx_preauth.html");
            else
                window.external.navigate("cache:kdmx_auth.html");
            break;
        case KDX_STATE_CHANGEPASSWORD:
            // Stash the event data away for use in the following page.
            window.external.ui.param("eventData") = i_data;
            window.external.navigate("cache:kdmx_changepassword.html");
            break;
        case KDX_STATE_PLAYABLE:
            // If this is an external play, simply close the window.
            tempData = getEventData(i_data);
            if (tempData["external"])
                window.external.closeWindow();
            else
            {  
                var theFrame = getFrame(window.external.ui.moid, "player");
                
                // If there is a frame and it is not ours...
                if (theFrame != null && theFrame != window.external) 
                {   
                    theFrame.showWindow(1);
                    window.external.closeWindow();
                }
                else
                {
                    // Stash the event data away for use in the following page.
                    window.external.ui.param("eventData") = i_data;
                    window.external.navigate("cache:kdmx_player.html");
                }
            }
            break;
        case KDX_STATE_SHOWHELPERAPP:
            window.external.navigate("cache:kdmx_helperApp.html");
            break;
        case KDX_STATE_SELECTSTREAMING:
            window.external.navigate("cache:kdmx_streamOrDl.html");
            break;  
        case KDX_STATE_ERROR:
            launchError(i_data);
        break;       
    }    
}

//////////////////////////////////////////////////////////////////////////
//
// Download Objects
//
//////////////////////////////////////////////////////////////////////////

//download type
var ZMD_DownloadType              = "download_type";
var ZMD_DownloadType_Subscription = "KontikiSubscriptionType";
var ZMD_DownloadType_Known        = "KontikiKnownType";
var ZMD_DownloadType_Streaming    = "KontikiStreamingType";

//schema types
var ZMD_SchemaType							= "schema_type";
var ZMD_SchemaType_FileDescription			= "FileDesc";
var ZMD_SchemaType_ContentDescription		= "ContentDesc";
var ZMD_SchemaType_SubscriptionDescription	= "Subscription";

// delivery method
var ZMD_DeliveryMethod_Streaming      = "Streaming";
var ZMD_DeliveryMethod_GridStreaming  = "GridStreaming";
var ZMD_DeliveryMethod_Standard	      = "Standard";

//////////////////////////////////////////////////////////////////////////
//
// FUNCTION: KDXDownload(i_moid)
//
// DESCRIPTION: Instantiates a Download Object for a given delivery,
// passed in via "i_moid". This object can be used to get metadata and
// other info about the delivery
//
//////////////////////////////////////////////////////////////////////////
function KDXDownload(i_moid)
{
    // Member variables.
    this.mMoid = null;
    this.mIsSubscription = false;
    this.mDownloadType = null;
    this.mIsSubscriptionContent = -1;
    this.mIsSecure = -1;
    
    // Initialization function.
    this.init = function KDXDownload_initialize(i_moid)
    {
	    var schemaType = getApi().value(i_moid, ZMD_SchemaType);
	    if (schemaType == ZMD_SchemaType_FileDescription)
	    {
		    var formatMoid =  getApi().value(i_moid, "child_id");
		    if (formatMoid == "")
			    throw "FormatlessContent:" + i_moid;
    		
		    this.mMoid = i_moid;	
	    }
	    else if (schemaType == ZMD_SchemaType_SubscriptionDescription)
	    {	
		    this.mMoid = i_moid;
		    this.mIsSubscription = true;
	    }
	    else
		    throw "UnknownMoid:" + i_moid;
    }
    
    // Returns moid.
    this.getMoid = function() {return this.mMoid;} 

    // Generic get method for any property.
    this.getValue = function(i_prop) 
    { 
        if (getApi().valueExists(this.mMoid, i_prop))
            return getApi().value(this.mMoid, i_prop);
        else return null;
    }
    
    // Returns value of property as a string.
    this.getStrValue = function (i_prop)
    {
        if (getApi().valueExists(this.mMoid, i_prop))
            return getApi().valuestr(this.mMoid, i_prop);
        else return "";
    }

    // Returns values of property as an array.
    this.getMap  = function(i_prop) 
    {
       var val = getApi().value(this.mMoid, i_prop);
       var map = new Array();
       try 
       {
          var m = val.toArray();
          for (var i = 0; i < m.length; i+=2 )
              map[m[i]] = m[i+1];
       }
       catch (e) {}
       return map;
    }

    // Returns true if delivery is a Kontiki Package.
    this.isPackageReaderFile = function()
    {
        var str = this.getStrValue("filename_physical");
        var ext = '.kpg';
        return ((str.lastIndexOf(ext) + ext.length) == str.length);
    }

    // Returns true if Kontiki Package is unpacking.
    this.isKPGUnPacking = function()
    {
        return getApi().isKPGUnPacking(this.mMoid);
    }

    // Returns true if download is prioritized.
    this.isPrioritized = function()
    {
        return getApi().isPrioritized(this.mMoid);
    }

    // Returns true if delivery is a subscription.
    this.isSubscription = function () 
    { 
        return this.mIsSubscription;
    }
    
    // Returns true if delivery is a mandatory subscription.
    this.isMandatory = function () 
    { 
        return (this.isSubscription() && this.getValue("isMandatory") == 1);
    }

    // Returns true if content has been delivered as part of a subscription.
    this.isSubscriptionContent = function()
    {
        if (this.mIsSubscriptionContent == -1)
            this.mIsSubscriptionContent = (getApi().valueExists(this.mMoid, "parent_id"))?1:0;
        return (this.mIsSubscriptionContent == 1);
    }

    // Returns true if delivery is a secure item (ACL).
    this.isSecureItem = function()
    {
        if (this.mIsSecure == -1)
            this.mIsSecure = (getApi().valueExists(this.mMoid, "secure"))?1:0;
        return (this.mIsSecure == 1);
    }

    // Returns true if delivery is locked from automatic deletion.
    this.isLockedItem = function()
    {
        if (getApi().valueExists(this.mMoid, "cstore_purge_policy"))
            return (getApi().value(this.mMoid, "cstore_purge_policy") == -1);
        return false;
    }

    // Locks delivery against being automatically deleted.
    this.lockItem = function (dolock)
    {
	    if (this.isSubscription() == false)
            getApi().value(this.mMoid, "cstore_purge_policy") = (dolock?-1:0);
    }
    
    // Returns download type of the delivery.
    this.getDownloadType = function()
    {
        if (this.mDownloadType == null) 
            this.mDownloadType = getApi().value(this.mMoid, "delivery_method");
        return this.mDownloadType;
    }

    // Returns true if download is in paused state.
    this.isPaused = function()
    {
        return this.getValue("download_state") == "Suspended";
    }

    // Returns true if delivery is complete for the item. Note: All subscriptions
    // are considered "complete".
    this.isComplete = function()
    {
        return (this.isSubscription() || this.getStrValue("download_state") == "Complete");
    }

    // Returns true if download has failed for the item.
    this.isFailedDownload = function()
    {
        return (this.getStrValue("download_state") == "Error");
    }    
    
    // Returns true if metadata needs to be reloaded because we are missing
    // information. For example, we need to revisit authentication for ACL subs
    // after user has cleared all passwords.
    this.isMetaDataReload = function()
    {
        return (this.getStrValue("get_metadata_again") == "true");
    }    

    // Returns true if delivery is a streaming content (HTTP or Grid Stream).
    this.isStreaming = function()
    {
        if (this.isSubscription()) return false;   
        return ((this.getDownloadType() == ZMD_DeliveryMethod_Streaming) ||
                (this.getDownloadType() == ZMD_DeliveryMethod_GridStreaming));
    }
    
    // Returns true if delivery is an HTTP Streaming content.
    this.isHttpStreaming = function()
    {
        if (this.isSubscription()) return false;
        return (this.getDownloadType() == ZMD_DeliveryMethod_Streaming);
    }
    
    // Returns true if delivery is a Grid Streaming content.
    this.isGridStreaming = function()
    {
        if (this.isSubscription()) return false;
        return (this.getDownloadType() == ZMD_DeliveryMethod_GridStreaming);
    }

    // Returns true if delivery is a Streaming Playlist content.
    this.isStreamingPlayList = function()
    {
        return (this.getStrValue("streaming_playlist") == "true");
    }

    // Returns true if delivery is a Grid Streaming content that cannot be saved.
    this.isGridStreamNoSave = function()
    {
        if (this.isSubscription()) return false;
        if (this.getDownloadType() == ZMD_DeliveryMethod_GridStreaming)
            return (this.getValue("allowSaveStream") != "true");

        return false;
    }

    // Returns the Email This URL for a the delivery.
    this.getEmailUrl = function()
    {
        return getApi().value(this.mMoid, "tell_a_friend_url");
    }
    
    // Returns number of times delivery has been played.
    this.getPlayCount = function()
    {
        if(getApi().valueExists(this.mMoid, "cstore_play_count"))
        {
            var playCount = getApi().value(this.mMoid, "cstore_play_count");
            return playCount;
        }
        else return 0;
    }
    
    // Returns 55x41 Small Thumbnail (aka Small Icon in NetPub) for the delivery.
    this.getSmallIcon = function()
    {
        var url =  this.getValue("smallIcon");
        if (url == "")
            url =  this.getValue("image");
        if (url == "")
            url =  this.getValue( "file_thumbnail");
        
        return url;
    }
    
    // Returns title of the delivery.
    this.getShortTitle = function()
    {
        return this.getValue("short_title");
    }

    // Returns true if delivery is an executable
    this.isApplication = function()
    {
        str = this.getStrValue("filename_physical");
        var extensions = [ ".exe", ".com" ];
        for (i = 0; i < extensions.length; ++i)
        {
            var ext = extensions[i];
            if ((str.lastIndexOf(ext)+ ext.length) == str.length) return true;
         }
         return false;        
    }

    // Initialize the object.
    this.init(i_moid);
    return true;
}



//-->
