﻿function isResourcePending( resourceId )
{
    var resourceServiceEndPoint = resolveUrl("~/Apps/Syndication/ResourcePendingCheck.aspx?resourceId=" + resourceId);
    var result = false;
    
    try
    {
        new Ajax.Request(resourceServiceEndPoint, 
            {
                asynchronous: false,
                method:'get',
                onSuccess: function(transport)
                {
                    if (transport.responseText == 'true')
                    {
                        result = true;
                    }
                    else
                    {
                        result = false;
                    }
                }.bind(this)
            }); 
    } 
    catch( ex )
    {
    }
    
    return result;
}

function translateResourceUrl( url, width, height )
{
    var result;

    result =  url.replace( "~", "http://assets.loopd.com" );
    
    if (result.indexOf("loopd.com") != 0)
    {
        result = result.replace( 
            result.substring( result.lastIndexOf( "." ), result.length ),
            getRasterMediaExtension( width, height )
        );
    }
    
    return result;
}

function resolveUrl( url )
{
    return url.replace( "~", "http://www.loopd.com" );
}

function getRasterMediaExtension( width, height )
{
    var result;
    
    if ( (width <= 75) && (height <= 75) )
    {
        result = "i.jpg";        
    } 
    else if ( (width <= 250) && (height <= 250) )
    {
        result = "s.jpg";        
    } 
    else if ( (width <= 500) && (height <= 500) )
    {
        result = "l.jpg";        
    }     
    else if ( (width <= 775) && (height <= 775) )
    {
        result = "f.jpg";        
    }         
    else
    {
        result = ".jpg";        
    }           
    
    return result;
}

function getRasterMediaHtml( resource, maxWidth, maxHeight, link, cssClass )
{
    var result = "";
    var cssClassHtml;
    
    if ( cssClass != null  )
    {
        cssClassHtml = ' class="' + cssClass + '" ';
    }
    else
    {
        cssClassHtml = '';
    }       
    
    if ( link == null )
    {
        link = resolveUrl( '~/Search/ContentViewer.aspx?resourceId=' + resource.Id );
    }
    
    try
    {
        var tempWidth = resource.Width;
        var tempHeight = resource.Height;
        
        if (tempWidth > 0 && tempHeight > 0)
        {
            if (tempWidth > maxWidth)
            {
                tempHeight = (tempHeight * maxWidth) / tempWidth;
                tempWidth = maxWidth;
            }
            if (tempHeight > maxHeight)
            {
                tempWidth = (tempWidth * maxHeight) / tempHeight;
                tempHeight = maxHeight;
            }
        }        
        
        var rUrl = '';
        
        if ( (resource.ResourceType == 8) || (resource.ResourceSubType == 8001) ) //Widget-Mixercast
        {
            rUrl = resource.Url;
        }
        else if ( resource.ResourceType == 2 ) //video
        {
            if ( (resource.CheckPendingFlag == null) || (resource.CheckPendingFlag == 'undefined') || (resource.CheckPendingFlag == false) )
            {
                rUrl = translateResourceUrl(resource.Url, tempWidth, tempHeight);
            }
            else
            {
                if ( isResourcePending(resource.Id) )   
                {
                    rUrl = resolveUrl("~/assets/icons/videoProcessing.gif");
                }    
                else
                {
                    rUrl = translateResourceUrl(resource.Url, tempWidth, tempHeight);
                }
            }
        }        
        else
        {
            rUrl = translateResourceUrl(resource.Url, tempWidth, tempHeight);
        }
        
        if ( isNullOrEmpty( link )  )
        {
                result = formatString( 
                    '<img alt="{0}" width="{1}" height="{2}" src="{3}" {4}>',
                    new Array(
                        resource.Description,
                        tempWidth,
                        tempHeight,
                        rUrl,
                        cssClassHtml
                    )
                );
        }
        else
        {
            result = formatString( 
                    '<a href="{4}"><img alt="{0}" width="{1}" height="{2}" src="{3}" {5}></a>',
                    new Array(
                        resource.Description,
                        tempWidth,
                        tempHeight,
                        rUrl,
                        link,
                        cssClassHtml
                    )
                );
        }
    } catch ( exception )
    {
        result = exception;
    }
        
    return result;   
}

function getResourceHtml( resource, maxWidth, maxHeight, link )
{
    var result = "";
    
    try
    {
        switch( resource.ResourceType )
        {
            case 1: // photo 
            case 2: // video
            case 8: // widget
            {
                result = getRasterMediaHtml( resource, maxWidth, maxHeight, link );
            } break;
            case 3: // html
            {
                switch( resource.ResourceSubType )
                { 
                    case 3001: // blog
                    {
                        result = '';
                        
                        result += '<img style="border:0px; padding:3px;" src="' + resolveUrl( '~/Assets/icons/activityLogIconsV2/quote_open.gif' ) + '" />';
                        result += "&nbsp;<i>"+resource.Description+"</i>&nbsp;";                      
                        result += '<img style="border:0px; padding:3px;" src="' + resolveUrl( '~/Assets/icons/activityLogIconsV2/quote_close.gif' ) + '" />';      
                                                
                    } break;                
                    case 3006: // status
                    {
                        result = '';
                    } break;
                    default:
                    {
                        result = '';
                    } break;
                }   
            } break;
            default:
            {
                result = '';
            } break;
        }
    }
    catch( ex )
    {
    }
    
    return result;   
}

function formatNumberWithCommas( input )
{
    var x;
    var x1;
    var x2;
    var rgx;
    
	input += '';
	x = input.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	rgx = /(\d+)(\d{3})/;
	
	while (rgx.test(x1)) 
	{
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	
	return x1 + x2;
}

function formatString( str, args )
{
    var regEx;
    
    for( var i = 0; i < args.length; i++ )
    {
        regEx = new RegExp("[{]"+ i +"[}]", "g");
        str = str.replace( regEx,  args[i] );
    }

    return str;
}

function truncateString(input, len, trailingChars)
{
    var result;
    
    if (input.length <= len) 
    {
        result = input;
    }
    else
    {
        result = input.substring( 0, len );
        
        if ((trailingChars != null) && (trailingChars != 'undefined'))
        {
            result += trailingChars;
        }
    }
    
    return result;
}

function stringEndsWith(input, checkForValue)
{
    var lastIndexOf = input.lastIndexOf( checkForValue );
    return (input.length == lastIndexOf);
}

function replaceLast( str, oldValue, newValue )
{
    var result;
    var lastIndexOf = str.lastIndexOf( oldValue );

    if (lastIndexOf != null && lastIndexOf != 'undefined' && lastIndexOf > 0)
    {
        result = str.substring( 0, lastIndexOf );
        result += newValue;
        result += str.substring( lastIndexOf + oldValue.length, str.length )
    }
    else
    {
        result = str;
    }
    
    return result;
}

function getEntityPersonalPronoun( entity )
{
    var result;
    
    switch( entity.EntityType )
    {
        case 1: // Individual
        {
            if ( entity.Gender != null )
            {
                switch( entity.Gender )
                {
                    case 1:
                    {
                        result = "his";
                    } break;
                    case 2:
                    {
                        result = "her";
                    } break;
                    default:
                    {
                        result = "their";
                    }
                }
            }
            else
            {
                result = "their";
            }
        } break;
        case 2: // Organization
        case 3: // Event
        case 4: // Place
        case 5: // Team
        case 6: // Container
        {
            result = "their";
        } break;
    }
    
    return result;
}


function getSubject( activity )
{
    var result;
    
    result = activity.Entity.PublicLabel;
    
    return result;
}



function isNullOrEmpty( obj )
{
    if ( (obj == null) || (obj == '') )
    {
        return true;
    }
        else
    {
        return false;
    }
}

function getPlace( activity )
{
    var result;
    
    if ( isNullOrEmpty( activity.DomainEntity ) )
    {
        result = "";
    }
    else
    {
        result = " on the " + activity.DomainEntity.PublicLabel + " community";
    }
    
    return result;
}

function getEntityHtml( entity )
{
    var result;
        
    result = getRasterMediaHtml( 
                entity.Icon, 
                75, 
                75, 
                resolveUrl( '~/members/' + entity.DisplayName )
            );
    
    return result;
}

function getProfileLink( entity )
{
    var result;
    
    result = formatString( 
                '<a href="{0}">{1}</a>', 
                new Array( 
                    resolveUrl( '~/members/' + entity.DisplayName ),
                    entity.PublicLabel
                )
            );         

    
    return result;
}

function getRelationshipHtml( activity )
{
    var result;
    
    result = '';  
    
    switch( activity.Resources[0].RelationshipType )
    {
        case 2: // friend
        {
            if (activity.SourceEntity.EntityType == 2)
            {
                result += beginNetworkComment( activity );
                result += formatString( 
                    '{1} became an Insider of {0}{2}', 
                    new Array( 
                        getProfileLink( activity.SourceEntity ),
                        getProfileLink( activity.Entity ),
                        getActivityLocation( activity.DomainEntity )
                    )                
                );   
            }
            else if (activity.Entity.EntityType == 2)
            {
                result += beginNetworkComment( activity );
                result += formatString( 
                    '{0} became an Insider of {1}{2}', 
                    new Array( 
                        getProfileLink( activity.SourceEntity ),
                        getProfileLink( activity.Entity ),
                        getActivityLocation( activity.DomainEntity )
                    )                
                );   
            }
            else
            {
                result += beginNetworkComment( activity );
                result += formatString( 
                    '{0} and {1} became friends{2}', 
                    new Array( 
                        getProfileLink( activity.SourceEntity ),
                        getProfileLink( activity.Entity ),
                        getActivityLocation( activity.DomainEntity )
                    )                
                );   
            }
            result += endNetworkComment( activity );                            
        } break;
        case 131: //CommunityOf:
            {
                result += beginNetworkComment( activity );
                result += formatString( "{0} joined the {1} community",
                    new Array(
                            getProfileLink( activity.SourceEntity ),
                            getProfileLink( activity.Entity )
                        )
                    );
                result += endNetworkComment( activity );    
            } break;
        case 1006: // Sponsored
            {
                result += beginNetworkComment( activity );
                result += formatString( 
                    '{0} became sponsored by {1}', 
                    new Array( 
                        getProfileLink( activity.SourceEntity ),
                        getProfileLink( activity.Entity )
                    )         
                );                   
                result += endNetworkComment( activity );             
            } break;
        case 1009: // Sponsoring
            {
                result += beginNetworkComment( activity );
                result += formatString( 
                    '{0} is now sponsoring {1}',
                    new Array(                         
                        getProfileLink( activity.SourceEntity ),
                        getProfileLink( activity.Entity )                        
                    )         
                );            
                result += endNetworkComment( activity );

                result += formatString( 
                    '<div class="photoContainer">' + 
                    '<table>' + 
                    '<tr>' + 
                    '<td>{0}</td>' + 
                    '<td>' +                                         
                    '<a href="{2}">Apply for sponsorship</a>' + 
                    '</td>' + 
                    '</tr>' + 
                    '</table>' + 
                    '</div>', 
                    new Array(                           
                        getEntityHtml( activity.SourceEntity ),                        
                        activity.SourceEntity.Id,
                        resolveUrl( '~/members/' + activity.SourceEntity.DisplayName + '/Listings.aspx' ),
                        resolveUrl( '~/My/Dialogs/Interactions/AddFriend.aspx' )
                    )         
                );                            
                           
            } break;     
        case 101: // TeamMember
            {
                result += beginNetworkComment( activity );
                result += formatString( 
                    '{0} added {1} to their team{2}', 
                    new Array( 
                        getProfileLink( activity.SourceEntity ),
                        getProfileLink( activity.Entity ),
                        getActivityLocation( activity.DomainEntity )
                    )         
                );
                result += endNetworkComment( activity );       
            } break;
        case 111: // TeamMemberOf
            {
                result += beginNetworkComment( activity );
                result += formatString( 
                    '{0} joined the {1} team', 
                    new Array( 
                        getProfileLink( activity.SourceEntity ),
                        getProfileLink( activity.Entity )
                    )         
                );
                result += endNetworkComment( activity );        
            } break;
        case 191: // WorldOf:
            {
                result += beginNetworkComment( activity );
                result += formatString( 
                    '{0} joined the {1} community', 
                    new Array( 
                        getProfileLink( activity.SourceEntity ),
                        getProfileLink( activity.Entity )
                    )         
                );
                result += endNetworkComment( activity );    

            } break;               
        default:
        {
            result += beginNetworkComment( activity );
            result += formatString( 
                'A relationship of type ({2}) was created between {0} and {1}', 
                new Array( 
                    getProfileLink( activity.SourceEntity ),
                    getProfileLink( activity.Entity ),
                    activity.Resources[0].RelationshipType
                )
            );                                       
            result += endNetworkComment( activity );        
                     
        } break;        
    }
    
    
    
    return result;
}

function initJSONObject( jsonString )
{
    return eval( "(" + jsonString + ")" );
}



function beginNetworkComment( activity )
{
    var result = '';
    
    result += '<div class="networkComment">';    
    
    return result;
}

function getTimeStampHtml( activity )
{
    var result;
    var date;
    var hours;
    var minutes;
    var seconds;
    var suffix;
    
    date = getDateFromDotNetJSONString( activity.AddDate );
    var now = new Date();
    
    hours = date.getHours();
    minutes = date.getMinutes();
    seconds = date.getSeconds();
    
    if ( hours > 12 )
    {
        hours -= 12;
        suffix = "PM";
    }
    else
    {
        suffix = "AM";
    }
    
    var unitDiff;
    
    if ( minutes < 10 )
    {
        minutes = "0" + minutes;
    }
    
    result = hours + ":" + minutes + " " + suffix;
    
    return result;
}

function endNetworkComment( activity )
{
    var result = '';
    
    result += '<span>'+ getTimeStampHtml(activity) +'</span>';
    result += '</div>';    
    
    return result;
}

function getPhotoContainer( activity )
{
    var result = '';
    
    result += '<div class="photoContainer">';            
    result += '<table>';
    result += '<tr>';
    if ( activity.Resources.length > 0 )
    {
        for( i = 0; ((i < activity.Resources.length) && (i < 4)); i++ )
        {
            result += '<td>';
            result += getResourceHtml( activity.Resources[i], 75, 150 );
            result += '</td>';
        }
    }            
    result += '</tr>';
    result += '</table>';            
    result += '</div>';
    
    return result;
}

//TODO: refactor this method or change the name..sstetler
function getResourceLink( resource )
{
    var result;
    
    try
    {
        switch( resource.ResourceType )
        {
            case 1:
            {
                result = "photo";
            } break;
            case 2:
            {
                switch( resource.ResourceSubType )
                {
                    case 8001:
                    {
                        result = "mixed video";
                    } break;
                    default:
                    {
                        result = "video";
                    } break;
                }            
            } break;
            case 3:
            {
                switch( resource.ResourceSubType )
                {
                    case 3001:
                    {
                        result = "update";  
                    } break;
                    case 3005:
                    {
                        result = "article";
                    } break;
                    case 3006:
                    {
                        result = result = 
                            formatString( 
                                'status &quot;{0}&quot;', new Array( resource.Body ) )
                    } break;
                    default:
                    {
                        result = formatString( 'resourceType = {0}, resourceSubType = {1}', new Array( resource.ResourceType, resource.ResourceSubType ) )
                    } break;
                }
            } break;
            case 8:
            {
                result = "widget";
            } break;
            default:
            {           
                result = "resource";
            } break;
        }
    } 
        catch (exception)
    {
        result = "resource";
        //result = 'resourceType '+ resource.ResourceType + ' resourceSubType ' + resource.ResourceSubType;
    }

    
    return result;
}

function pluralizeString(input)
{
    if (input.length > 0)
    {
        if ((input[input.length - 1] == 's') || (input[input.length - 1] == 'S'))
        {
            return input + "'";
        }
        else
        {
            return input + "'s";
        }
    }

    return input;
}

function getTarget( activity, pluralize )
{
    var result;
    
    if ( activity.Entity.Id == activity.SourceEntity.Id )
    {
        result = getEntityPersonalPronoun( activity.Entity ) + ' own';
    }
        else
    {
        if ( pluralize )
        {
            result = pluralizeString( activity.Entity.PublicLabel );
        } 
        else
        {
            result = activity.Entity.PublicLabel;
        }        
    }
    
    return result;    
}


function getActivityLocation(domainEntity)
{
    var result = "";

    if (domainEntity != null)
    {
        result = formatString( " on the <a href='{0}'>{1}</a> community", 
                    new Array( 
                        domainEntity.MicrositeUrl,
                        domainEntity.PublicLabel
                    )        
                );
    }

    return result;
}

function getActivityText( activity )
{
    var result;
    
    result = "";
       
    switch( activity.ActivityType )
    {
        // Relationship
        case 1:
        {            
            result += getRelationshipHtml( activity );
        } break;
        
        // CommentV2
        case 15:
        {
            //currently only Blogs and EntityUpdates in this table so just goto blog page
            result += beginNetworkComment( activity );
            
            result += formatString( 
                    '{0} commented on {1} update{2}', 
                    new Array( 
                        getProfileLink( activity.SourceEntity ),
                        pluralizeString( getProfileLink( activity.Entity ) ),
                        getActivityLocation( activity.DomainEntity )
                    )
                );
                
            result += '<div class="photoContainer">';            
            result += '<table>';
            result += '<tr>';
                
            result += '<td>';                    
            
            if (activity.Comment.CommentType == 2) //ResourceComment 
            {
                //blog
                result += getResourceHtml( activity.Resources[0], 75, 150 );
            }
            else if (activity.Comment.CommentType == 3) //UpdateComment
            {
                //entityUpdate
                result += '<div class="userUpdate">';                
                result += '<img style="border:0px; padding:3px;" src="' + resolveUrl( '~/Assets/icons/activityLogIconsV2/quote_open.gif' ) + '" />';
                result += "<i>" + activity.Resources[0].Data + "</i>";      
                result += '<img style="border:0px; padding:3px;" src="' + resolveUrl( '~/Assets/icons/activityLogIconsV2/quote_close.gif' ) + '" />'; 
                result += '</div>';
            }
                       
            result += '</td>';
            result += '</tr>';
            
            //actual comment
            result += '<tr>';
            result += '<td>';
            result += '<img style="border:0px; padding:3px;" src="' + resolveUrl( '~/Assets/icons/activityLogIconsV2/quote_open.gif' ) + '" />';
            result += "&nbsp;<i>" + activity.Comment.Text + "</i>&nbsp;";                      
            result += '<img style="border:0px; padding:3px;" src="' + resolveUrl( '~/Assets/icons/activityLogIconsV2/quote_close.gif' ) + '" />'; 
            
            if (activity.Comment.CommentType == 2) //ResourceComment
            {
                result += formatString( ' <a style="padding:5px 0 0 0; font-size:10px;" href="{0}">[more]</a>',
                            new Array(
                                resolveUrl( '~/members/'+ activity.Entity.DisplayName +'/Blog.aspx?cid=' + activity.Comment.Id + '&resourceId=' + activity.Comment.ReferenceId )
                            )
                          );
            }
            else if (activity.Comment.CommentType == 3) //UpdateComment
            {
                result += formatString( ' <a style="padding:5px 0 0 0; font-size:10px;" href="{0}">[more]</a>',
                            new Array(
                                resolveUrl( '~/members/'+ activity.Entity.DisplayName +'/Blog.aspx?cid=' + activity.Comment.Id + '&euid=' +  activity.Comment.ReferenceId )
                            )
                          );         
            }
            
            result += '</td>';
            result += '</tr>';
            result += '</table>';            
            result += '</div>';   

            result += endNetworkComment( activity );    
            
        } break;
        
        // Comment
        case 2:
        {
            result += beginNetworkComment( activity );
            
            if ( activity.Resources.length > 1 )
            {
                result += formatString( 
                    '{0} commented on {1} {2}{3}', 
                    new Array( 
                        getProfileLink( activity.SourceEntity ),
                        pluralizeString( getProfileLink( activity.Entity ) ),
                        getResourceLink( activity.Resources[1] ),
                        getActivityLocation( activity.DomainEntity )
                    )
                );
                
                result += '<div class="photoContainer">';            
                result += '<table>';
                result += '<tr>';
                
                result += '<td>';                               
                result += getResourceHtml( activity.Resources[1], 75, 150 );
                result += '</td>';
                
                result += '</tr>';
                
                //actual comment
                result += '</tr>';
                result += '<td>';
                result += '<img style="border:0px; padding:3px;" src="' + resolveUrl( '~/Assets/icons/activityLogIconsV2/quote_open.gif' ) + '" />';
                result += "&nbsp;<i>"+activity.Resources[0].Body+"</i>&nbsp;";                      
                result += '<img style="border:0px; padding:3px;" src="' + resolveUrl( '~/Assets/icons/activityLogIconsV2/quote_close.gif' ) + '" />';      
                
                switch( activity.Resources[1].ResourceSubType )
                {
                    case 3001: // blog
                    {
                        result += formatString( ' <a href="{0}">[more]</a>',
                                    new Array(
                                        resolveUrl( '~/members/'+ activity.Entity.DisplayName +'/Blog.aspx?cid=' + activity.Resources[0].Id + '&resourceId=' + activity.Resources[0].Name )
                                    )
                                  );
                    } break;
                    
                    case 3005: // article
                    {
                        //do nothing
                    } break;        
                    
                    case 3006: // mystatus
                    {
                        result += formatString( ' <a class="readMore" href="{0}">[more]</a>',
                                    new Array(
                                        resolveUrl( '~/members/' + activity.Entity.DisplayName)
                                    )
                                  );
                    } break;
                     
                    default: //photos, videos, widgets
                    {
                        result += formatString( ' <a class="readMore" href="{0}">[more]</a>',
                                    new Array(
                                        resolveUrl( '~/Search/ContentViewer.aspx?cid=' + activity.Resources[0].Id + '&resourceId=' + activity.Resources[0].Name )
                                    )
                                  );                
                    } break;           
                }
                
                result += '</td>';
                
                result += '</tr>';
                result += '</table>';            
                result += '</div>';            
                
            }
            else
            {
                result += formatString( 
                    '{0} commented on {1} profile{2}', 
                    new Array( 
                        getProfileLink( activity.SourceEntity ),
                        pluralizeString( getProfileLink( activity.Entity ) ),
                        getActivityLocation( activity.DomainEntity )
                    )
                );   
                result += '<div class="photoContainer">';            
                result += '<table>';
                result += '<tr>';
                
                result += '<td>';
                result += '<img style="border: 0px none ; padding: 3px;" src="' + resolveUrl( '~/Assets/icons/activityLogIconsV2/quote_open.gif' ) + '" />';
                result += "&nbsp;<i>"+activity.Resources[0].Body+"</i>&nbsp;";      
                result += '<img style="border: 0px none ; padding: 3px;" src="' + resolveUrl( '~/Assets/icons/activityLogIconsV2/quote_close.gif' ) + '" />';                      
                result += formatString( ' <a class="readMore" href="{0}">[more]</a>',
                    new Array(
                        resolveUrl( '~/members/'+ activity.Entity.DisplayName +'/Comments.aspx?cid=' + activity.Resources[0].Id )
                    )
                  );                                               
                result += '</td>';
                
                result += '</tr>';
                result += '</table>';            
                result += '</div>';           
            }
                            
            result += endNetworkComment( activity );                     
            
            
        } break;
        // ResourceUpload
        case 3:
        {
            result += beginNetworkComment( activity );      
            result += formatString( 
                '{0} added a {1} to {2} profile{3}', 
                new Array( 
                    getProfileLink( activity.SourceEntity ),
                    getResourceLink( activity.Resources[0] ),
                    getEntityPersonalPronoun( activity.SourceEntity ),
                    getActivityLocation( activity.DomainEntity )
                )
            );
            result += endNetworkComment( activity );                  
            if ( activity.Resources.length > 0 )
            {
                result += getPhotoContainer( activity );
            }
            
            if ((activity.Resources.length == 1))
            {
                switch ( activity.Resources[0].ResourceSubType )
                {
                    case 3001: //blog - add readmore link
                    {
                        result += formatString( '<a href="{0}" style="display:block; padding:5px 0 0 0;">[more]</a>',
                                                new Array(
                                                    resolveUrl( '~/members/'+ activity.SourceEntity.DisplayName +'/Blog.aspx?resourceId=' + activity.Resources[0].Id )
                                                )
                                              );        
                    }
                        break;
                }
            }
        } break;
        // Profile
        case 6:
        {
            result += beginNetworkComment( activity );      
            result += formatString( 
                '{0} updated {1} profile{2}', 
                new Array( 
                    getProfileLink( activity.SourceEntity ),
                    getEntityPersonalPronoun( activity.SourceEntity ),
                    getActivityLocation( activity.DomainEntity )
                )
            );   
            result += endNetworkComment( activity );   
            result += getPhotoContainer( activity );
        } break;
        // Custom
        case 7:
        {
            
            result += beginNetworkComment( activity );      
            result += activity.Resources[0].Body;
            result += endNetworkComment( activity );                     
            
        } break;
        // ResourcePushedTo
        case 8:
        {
            result += beginNetworkComment( activity );
            result += formatString( 
                '{0} submitted a {1} to {2}', 
                new Array( 
                    getProfileLink( activity.SourceEntity ),
                    getResourceLink( activity.Resources[0] ),
                    getProfileLink( activity.Entity ),
                    getActivityLocation( activity.DomainEntity )
                )
            );   
            result += endNetworkComment( activity );
            result += '<div class="photoContainer">';            
            result += '<table>';
            result += '<tr>';

            result += '<td>';
            result += getResourceHtml( activity.Resources[0], 75, 150 );
            result += '</td>';

            result += '</tr>';
            result += '</table>';            
            result += '</div>'; 
        } break;
        // ResourcePushedFrom
        case 9:
        {
            result += beginNetworkComment( activity );
            result += formatString( 
                '{0} received a contributed {1} from {2}{3}', 
                new Array( 
                    getProfileLink( activity.SourceEntity ),
                    getResourceLink( activity.Resources[0] ),
                    getProfileLink( activity.Entity ),
                    getActivityLocation( activity.DomainEntity )
                )
            );   
            result += endNetworkComment( activity );
            result += '<div class="photoContainer">';            
            result += '<table>';
            result += '<tr>';

            result += '<td>';
            result += getResourceHtml( activity.Resources[0], 75, 150 );
            result += '</td>';

            result += '</tr>';
            result += '</table>';            
            result += '</div>'; 
        } break;
        // ResourcePulledFrom
        case 10:
        {
            result += beginNetworkComment( activity );
            result += formatString( 
                '{0} added a {1} from {2} profile{3}', 
                new Array( 
                    getProfileLink( activity.SourceEntity ),
                    getResourceLink( activity.Resources[0] ),
                    pluralizeString( getProfileLink( activity.Entity ) ),
                    getActivityLocation( activity.DomainEntity )
                )
            );   
            result += endNetworkComment( activity );
            result += '<div class="photoContainer">';            
            result += '<table>';
            result += '<tr>';

            result += '<td>';
            result += getResourceHtml( activity.Resources[0], 75, 150 );
            result += '</td>';

            result += '</tr>';
            result += '</table>';            
            result += '</div>';  
        } break;
        // ResourcePulledTo
        case 11:
        {
            result += beginNetworkComment( activity );
            result += formatString( 
                '{0} {1} was added to {2} profile{3}', 
                new Array( 
                    pluralizeString( getProfileLink( activity.SourceEntity ) ),
                    getResourceLink( activity.Resources[0] ),
                    pluralizeString( getProfileLink( activity.Entity ) ),
                    getActivityLocation( activity.DomainEntity )
                )
            );   
            result += endNetworkComment( activity );
            result += '<div class="photoContainer">';            
            result += '<table>';
            result += '<tr>';

            result += '<td>';
            result += getResourceHtml( activity.Resources[0], 75, 150 );
            result += '</td>';

            result += '</tr>';
            result += '</table>';            
            result += '</div>';  
        } break;
        // Result
        case 12:
        {
            result += beginNetworkComment( activity );
            result += formatString( 
                "{0} added a new <a href='{1}'>result ({2})</a> to {3} profile{4}", 
                new Array( 
                    getProfileLink( activity.SourceEntity ),
                    getSourcePage( activity.SourceEntity, "Results", "" ),
                    activity.Resources[0].Body,
                    getEntityPersonalPronoun( activity.SourceEntity ),
                    getActivityLocation( activity.DomainEntity )            
                )
            );    
            result += endNetworkComment( activity );          
        } break;
        // Status Update
        case 13:
        {
            var blogPageUrl = resolveUrl( '~/members/' + activity.SourceEntity.DisplayName + '/Blog.aspx?from=activityFeed');
            blogPageUrl += '&euid=' + activity.Resources[0].Id;
            
            result += beginNetworkComment( activity );
            result += formatString( 
                '{0} posted an Update', 
                new Array( 
                    getProfileLink( activity.SourceEntity )                    
                )
            );  
            
            result += endNetworkComment( activity );
            result += '<div class="userUpdate">';                
            result += '<img src="' + resolveUrl( '~/Assets/icons/activityLogIconsV2/quote_open.gif' ) + '" />';
            result += "<i>" + activity.Resources[0].Body + "</i>";      
            result += '<img src="' + resolveUrl( '~/Assets/icons/activityLogIconsV2/quote_close.gif' ) + '" />';      
            result += '<a class="readMore" href="' + blogPageUrl + '">[more]</a>';
            result += '</div>';
               
            result += '<div class="photoContainer">';            
            result += '<table>';
            result += '<tr>';
            
            if ( activity.Resources.length > 1 )
            {
                for( i = 1; ((i < activity.Resources.length) && (i < 5)); i++ )
                {
                    var resourceHtml = getResourceHtml( activity.Resources[i], 75, 150, blogPageUrl );
                    
                    if ( activity.Resources[i].ResourceType == 2 )
                    {
                        result += '<td class="photoWrap">';
                        if ( resourceHtml.lastIndexOf('/assets/icons/videoProcessing.gif') < 0 )
                        {
                            result += '<img src="http://Assets.loopd.com/Assets/Images/Buttons/play.gif" class="play"/>';
                        }
                    }
                    else
                    {
                        result += '<td>';
                    }                
                    result += resourceHtml;
                    result += '</td>';
                }
            }            
            result += '</tr>';
            
            result += '</table>';            
            result += '</div>';   
            
            
/*
    result += '<div class="photoContainer">';            
    result += '<table>';
    result += '<tr>';
    if ( activity.Resources.length > 0 )
    {
        for( i = 0; ((i < activity.Resources.length) && (i < 4)); i++ )
        {
            result += '<td>';
            result += getResourceHtml( activity.Resources[i], 75, 150 );
            result += '</td>';
        }
    }            
    result += '</tr>';
    result += '</table>';            
    result += '</div>';
*/            
                        

        } break;
        // ResourceBatch
        case 14:
        {
            result += beginNetworkComment( activity );      
            result += formatString( 
                '{0} added {1}s to {2} profile{3}', 
                new Array( 
                    getProfileLink( activity.SourceEntity ),
                    getResourceLink( activity.Resources[0] ),
                    getEntityPersonalPronoun( activity.SourceEntity ),
                    getActivityLocation( activity.DomainEntity )
                )
            );   
            result += endNetworkComment( activity );   
            result += getPhotoContainer( activity );
        } break;        
        default:
        {
            result += "Activity Log Type : " + activity.ActivityType;
        }
    }
    
    return result;
}

function getSourcePage(entity, pageName, querystring)
{
    var result;
    
    try
    {
    result = resolveUrl(
            formatString("~/Members/{0}/{1}.aspx?{2}",
                new Array(
                    entity.DisplayName,
                    pageName,
                    querystring 
                )
            )
        );   
    }
    catch( ex )
    {
        //alert( ex + " " + entity.DisplayName );
    }
       
    return result;                                 
}

function getDateFromDotNetJSONString( jsonDate )
{
    var ticks = parseInt( jsonDate.substr( 6, 13 ) );
    var result = new Date(ticks);
    
    return result;
}

function getFullDayOfWeek( day )
{
    switch( day )
    {
        case 0: return "Sunday";
        case 1: return "Monday";
        case 2: return "Tuesday";
        case 3: return "Wednesday";
        case 4: return "Thursday";
        case 5: return "Friday";
        case 6: return "Saturday";
    }
    
    return "";
}

function getFullMonth( month )
{
    switch( month )
    {
        case 0: return "January";
        case 1: return "February";
        case 2: return "March";
        case 3: return "April";
        case 4: return "May";
        case 5: return "June";
        case 6: return "July";
        case 7: return "August";
        case 8: return "September";
        case 9: return "October";
        case 10: return "November";
        case 11: return "December";
    }
    
    return "";
}

function getFullDate( date )
{
    var result;
    
    result = getFullDayOfWeek( date.getDay() ) + ", " + getFullMonth( date.getMonth() ) + " " + date.getDate() + ", " + date.getFullYear();
    
    return result;
}

function getDateMMDDYYYYFromDotNetJSONString( jsonDate )
{
    var date;
    var result;
    
    date = getDateFromDotNetJSONString( jsonDate )
    result = getDateMMDDYYYY(date);
    
    return result;
}

function getDateMMDDYYYY( date )
{
    var result;
    
    //NOTE: getMonth returns a 0 based value (i.e., 0 = January)
    result = (date.getMonth() + 1) + "/" + date.getDay() + "/" + date.getFullYear();
    
    return result;
}

function getDateMMDDYYYYWithTimeStamp( date )
{
    var result;
    
    result = getDateMMDDYYYY(date) + ' ' + getTimeStamp(date);
    
    return result;
}

function getTimeStamp(date)
{
    var result;
    var hours = date.getHours();
    var minutes = date.getMinutes();
    var seconds = date.getSeconds();
    var suffix;
    
    if ( minutes < 10 )
    {
        minutes = "0" + minutes;
    }
    
    if ( seconds < 10 )
    {
        seconds = "0" + seconds;
    }
    
    if ( hours > 12 )
    {
        hours -= 12;
        suffix = "PM";
    }
    else
    {
        suffix = "AM";
    }
    
    result = ' ' + hours + ':' + minutes + ':' + seconds + ' ' + suffix;
    
    return result;
}

function getFriendlyDateString( jsonDate )
{
    var date;
    var now = new Date();
    var result;
        
    date = getDateFromDotNetJSONString( jsonDate );
    
    result = getFullDate( date );
    if ( date.getFullYear() == now.getFullYear() ) 
    {
        if ( date.getMonth() == now.getMonth() ) 
        {
            if ( date.getDate() == now.getDate() )
            {
                result = "Today";
            }
            else if ( date.getDate() == now.getDate() - 1 )
            {      
                result = "Yesterday";  
            }
        }
    }
    
    return result;
}

function getActivityIcon( activity )
{
    var result;
    
    result = "";
       
    switch( activity.ActivityType )
    {
        // Relationship
        case 1:
        {        
            if ( activity.Resources[0].RelationshipType == 1006 )
            {
                return resolveUrl( '~/Assets/Icons/activityLogIconsV2/icoSponsor.png' );
            } 
            else if ( activity.Resources[0].RelationshipType == 1009 )
            {
                return resolveUrl( '~/Assets/Icons/activityLogIconsV2/icoSponsor.png' );
            } 
            else
            {
                return resolveUrl( '~/Assets/Icons/activityLogIconsV2/icoAddFriend.png' );
            }            
        } break;
        // Comment
        case 2:
        {
            return resolveUrl( '~/Assets/Icons/activityLogIcons/icoComments.gif' );
        } break;
        // ResourceUpload
        case 3:
        {
            return resolveUrl( '~/Assets/Icons/activityLogIconsV2/icoPhoto.png' );
        } break;
        // Sponsorship
        case 4:
        {
            return resolveUrl( '~/Assets/Icons/activityLogIcons/icoSponsor.gif' );
        } break;
        // Sponsorship
        case 5:
        {
            return resolveUrl( '~/Assets/Icons/activityLogIcons/icoSponsor.gif' );
        } break;
        // Profile
        case 6:
        {
            return resolveUrl( '~/Assets/Icons/activityLogIcons/icoProfile.gif' );
        } break;
        // Custom
        case 7:
        {
            return resolveUrl( '~/Assets/Icons/activityLogIconsV2/icoProfile.png' );
        } break;
        // ResourcePushedTo
        case 8:
        {
            return resolveUrl( '~/Assets/Icons/activityLogIconsV2/icoPhoto.png' );
        } break;
        // ResourcePushedFrom
        case 9:
        {
            return resolveUrl( '~/Assets/Icons/activityLogIconsV2/icoPhoto.png' );
        } break;
        // ResourcePulledFrom
        case 10:
        {
            return resolveUrl( '~/Assets/Icons/activityLogIconsV2/icoPhoto.png' );
        } break;
        // ResourcePulledTo
        case 11:
        {
            return resolveUrl( '~/Assets/Icons/activityLogIconsV2/icoPhoto.png' );
        } break;
        // Result
        case 12:
        {
            return resolveUrl( '~/Assets/Icons/activityLogIconsV2/icoResults.png' );
        } break;
        // Status Update
        case 13:
        {
            return resolveUrl( '~/Assets/Icons/activityLogIconsV2/icoProfile.png' );
        } break;
        // ResourceBatch
        case 14:
        {
            return resolveUrl( '~/Assets/Icons/activityLogIconsV2/icoPhoto.png' );
        } break;        
        default:
        {
            return resolveUrl( '~/Assets/Icons/activityLogIconsV2/icoPhoto.png' );
        }
    }    
}

function getActivityHeader( activity )
{
    var result = "";
        
    result += '<div class="activityWrap">';
    result += '<div class="iconContainer"><img name="" src="'+ getActivityIcon( activity ) +'" width="18" height="18" alt=""></div>';
    result += '<div class="networkCommentWrap">';

    return result;
}

function getActivityFooter( activity )
{
    var result = "";

    result += '</div>';                   
    result += '</div>';               

    return result;
}

function getActivityHtml( activity )
{
    var result = "";
        
    result += getActivityHeader( activity );
    result += getActivityText( activity );
    result += getActivityFooter( activity );
    
    return result;
}

function processPursuitsCsvString(input)
{
    var result;
    result = truncateString( input, 75, '...' );
    
    //in case there is a trailing comma
    if (stringEndsWith(result, ','))
    {
        result = replaceLast( result, ',', '' ); 
    }
    
    result = replaceLast( result, ',', ' and ' );
    
    return result;
}

function InvokeAndPopulate( jsonServiceEndPoint, targetElementId, loadingDivId )
{
    var d = new Date();
    
    try
    {
        new Ajax.Request(
            jsonServiceEndPoint, 
            {   
                method:'get',   
                onSuccess: function(transport)
                {
                    var html = "";
                    var currentGroupDate = "";
                    var activeDate = "";
                    var rowHtml;
                    var json = transport.responseText.evalJSON();
                                                    
                    html += '<div class="networkActivityWrap">';
                    
                    for( var i = 0; i < json.length; i++ )
                    {
                        rowHtml = "";
                        
                        try
                        {
                            activeDate = getFriendlyDateString( json[i].AddDate );
                            if ( (currentGroupDate != activeDate) )
                            {                       
                                currentGroupDate = activeDate;
                                rowHtml += '<h4 class="divclear">'+currentGroupDate+'</h4>';
                            }
                            rowHtml += getActivityHtml( json[i] );
                        }
                        catch( ex )
                        {
                            //alert( 'The following exception happened during tranformation: ' + ex );
                        }
                        
                        html += rowHtml;
                    }
                    
                    html += '</div>';
                    
                    document.getElementById( targetElementId ).innerHTML = html;
                    
                    if ( loadingDivId != null )
                    {
                        document.getElementById( loadingDivId ).innerHTML = '';
                    }
                } 
            }
        ); 
    } 
        catch( ex1 )
    {
        
    }
}

function InvokeAndPopulateSponsorshipOpportunities( jsonServiceEndPoint, targetElementId, loadingDivId )
{
    try
    {
        new Ajax.Request(
            jsonServiceEndPoint, 
            {   
                method:'get',   
                onSuccess: function(transport)
                {
                    var json = transport.responseText.evalJSON();
                    var html = BuildSponsorshipOpportunitiesHtml( json );                    
                    
                    document.getElementById( targetElementId ).innerHTML = html;
                    
                    if ( loadingDivId != null )
                    {
                        document.getElementById( loadingDivId ).innerHTML = '';
                    }
                } 
            }
        ); 
    } 
    catch( ex1 )
    {
    }
}

function BuildSponsorshipOpportunitiesHtml( json )
{
    var result;
    var rowHtml;
    
    result = '<div class="sponsorshipOpportunities">';
        
    if ((json != null) && (json != 'undefined'))
    {            
        for( var i = 0; i < json.length; i++ )
        {
            rowHtml = "";
            
            try
            {
                rowHtml = '<p>';
                rowHtml += '<a href="' + json[i].ListingsLink + '">';
                rowHtml += json[i].CompanyName;
                rowHtml += '</a>';
                rowHtml += ' is accepting sponsorship applications from ';
                rowHtml += '<strong>' + getDateMMDDYYYYFromDotNetJSONString( json[i].RecentStartDate ) + '</strong>';
                rowHtml += ' in <strong>' + processPursuitsCsvString( json[i].Pursuits ) + '</strong>.';
                rowHtml += '</p>'
            }
            catch( ex )
            {
                //alert( 'BuildSponsorshipOpportunitiesHtml function: The following exception occurred: ' + ex );
            }
            
            result += rowHtml;
        }
    }
    
    result += '</div>';
    
    return result;
}

function InvokeAndPopulateResourceFeed( jsonServiceEndPoint, targetElementId, loadingDivId )
{
    try
    {
        new Ajax.Request(
            jsonServiceEndPoint, 
            {   
                method:'get',   
                onSuccess: function(transport)
                {
                    var json = transport.responseText.evalJSON();
                    var html = BuildResourceFeedHtml( json );
                                        
                    document.getElementById( targetElementId ).innerHTML = html;
                    
                    if ( loadingDivId != null )
                    {
                        document.getElementById( loadingDivId ).innerHTML = '';
                    }
                } 
            }
        ); 
    } 
    catch( ex1 )
    {
        
    }
}

function BuildResourceFeedHtml( json )
{
    var result;
    var rowHtml;
    
    result = '<div>';
                    
    if ((json != null) && (json != 'undefined'))
    {
        for( var i = 0; i < json.Resources.length; i++ )
        {
            rowHtml = "";
            
            try
            {
                switch( json.Resources[i].ResourceType )
                {
                    case 1: // photo 
                    case 2: // video
                    {
                        rowHtml += '<div style="padding: 0 0 5px 0;">';
                        rowHtml += getRasterMediaHtml( json.Resources[i], 75, 75 );
                        rowHtml += '<br/>';
                        rowHtml += 'Posted on ' + getDateMMDDYYYYFromDotNetJSONString( json.Resources[i].AddDate );
                        rowHtml += '</div>';
                    } break;
                    
                    case 3: // html
                    {
                        switch( json.Resources[i].ResourceSubType )
                        { 
                            case 3001: // blog
                            {
                                rowHtml += '<div style="padding: 0 0 5px 0;">';
                                
                                rowHtml += formatString( '<a href="{0}">{1}</a>',
                                                new Array(
                                                    resolveUrl( '~/members/' + json.EntityDictionary[json.Resources[i].OwnerEntityId].DisplayName + '/Blog.aspx?resourceId=' + json.Resources[i].Id ),
                                                    json.Resources[i].Name
                                                )
                                            );
                                            
                                rowHtml += '<br/>';
                                rowHtml += 'Posted on ' + getDateMMDDYYYYFromDotNetJSONString( json.Resources[i].AddDate );
                                rowHtml += '</div>';
                            } break;                

                            default:
                            {
                                rowHtml = 'BuildResourceFeedHtml function: ResourceSubType=' + json.Resources[i].ResourceSubType + ' not supported ';
                            } break;
                        }   
                    } break;
                    
                    default:
                    {
                        rowHtml = 'BuildResourceFeedHtml function: ResourceType=' + json.Resources[i].ResourceType + ' not supported ';
                    } break;
                }
            }
            catch( ex )
            {
               //alert( 'BuildResourceFeedHtml function: The following exception occurred: ' + ex );
            }
            
            result += rowHtml;
        }
    }
    
    result += '</div>';
    
    return result;
}

/*
InvokeAndPopulateRelatedResources method:
    destinationPage parameter is optional and needs to have a "[[rid]]" merge field value.  If it does not come in, the destination page will be the global content viewer ( /Search/ContentViewer.aspx ).
*/
function InvokeAndPopulateRelatedResources( jsonServiceEndPoint, targetElementId, loadingDivId, destinationLink )
{
    try
    {
        new Ajax.Request(
            jsonServiceEndPoint, 
            {   
                method:'get',   
                onSuccess: function(transport)
                {
                    var json = transport.responseText.evalJSON();
                    var html = BuildRelatedResourcesHtml( json, destinationLink );                    
                                 
                    document.getElementById( targetElementId ).innerHTML = html;
                    
                    if ( loadingDivId != null )
                    {
                        document.getElementById( loadingDivId ).innerHTML = '';
                    }
                } 
            }
        ); 
    } 
    catch( ex1 )
    {
    }
}

function BuildRelatedResourcesHtml( json, destinationLink )
{
    var result = '';
    var resource;
    var destinationLinkWithValue;
    
    for( var i = 0; i < json.Resources.length; i++ )
    {   
        resource = json.Resources[i];
        
        if ((destinationLink == null) || (destinationLink == 'undefined'))
        {
            destinationLinkWithValue = resolveUrl( '~/Search/ContentViewer.aspx?resourceId=' + resource.Id + '&src=related' );
        }
        else
        {
            destinationLinkWithValue = destinationLink.replace( "[[rid]]", resource.Id );
        }
        
        result += '<div class="relatedRes" style="position:relative;">'; 
        
        if ( resource.ResourceType == 2 ) 
        {
            result += '<div style="height:32px; left:26px; position:absolute; top:27px; width:33px; z-index:10;" >';
            result += ' <a href="' + destinationLinkWithValue + '">';
            result +=     '<img src=' + resolveUrl("~/Assets/Images/Buttons/play.gif") + ' alt="select" />';
            result += ' </a>';
            result += '</div>';
        }
        
        if ( resource.ResourceType == 1 || resource.ResourceType == 2 || resource.ResourceType == 8 ) 
        {
            result +=   '<div class="image">';
            result +=       getResourceHtml( resource, 120, 120, destinationLinkWithValue );
            result +=   '</div>';
        }
        
        result +=   '<h3>';
        result +=   ' <a href="' + destinationLinkWithValue + '">';
        result +=       resource.Name;
        result +=   ' </a>';
        result +=   '</h3>';
        
        result +=   '<h4>';
        result +=   '   posted by: ' +  json.EntityDictionary[resource.OwnerEntityId].PublicLabel;            
        result +=   '</h4>';
        
        result += '</div>';
    }
    
    return result;
}

function InvokeAndPopulateCommunicationAlertsFeed( jsonServiceEndPoint, targetElementId, loadingDivId, noDataValue )
{
    try
    {
        new Ajax.Request(
            jsonServiceEndPoint, 
            {   
                method:'get',   
                onSuccess: function(transport)
                {
                    var json = transport.responseText.evalJSON();
                    var html = BuildCommunicationAlertsFeedHtml( json, noDataValue );
                                        
                    document.getElementById( targetElementId ).innerHTML = html;
                    
                    if ( loadingDivId != null )
                    {
                        document.getElementById( loadingDivId ).innerHTML = '';
                    }
                } 
            }
        ); 
    } 
    catch( ex1 )
    {
        
    }
}

function BuildCommunicationAlertsFeedHtml( json, noDataValue )
{
    var result;
    
    if ((json != null) && (json != 'undefined'))
    {
        if (( json.NewCommentCount <= 0 ) && 
            ( json.NewMessageCount <= 0 ) && 
            ( json.NewFriendRequestCount <= 0 ) &&
            ( json.SponsorshipOffersCount <= 0 ) &&
            ( json.SponsorshipSavedAppsCount <= 0 ))
        {
            //no data so pass back no data text if it comes in
            if ((noDataValue != null) && (noDataValue != 'undefined'))
            {
                result = noDataValue;
            }
        }
        else
        {
            result = '<ul class="alternating">';
           
            if (json.NewMessageCount > 0)
            {
                result += '<li>';
                result += '<a href="' + resolveUrl("~/Applications/Default.aspx?incmd=2,21,218?folder=1") + '">';
                result += 'New Messages';
                result += '</a>';
                result += ' (' + formatNumberWithCommas( json.NewMessageCount ) + ')';
                result += '</li>';
            }
            
            if (json.NewFriendRequestCount > 0)
            {
                result += '<li>';
                result += '<a href="' + resolveUrl("~/Applications/Default.aspx?incmd=2,22,218?folder=5") + '">';
                
                if (json.UserEntitySubType == "2")
                {
                    result += 'New Brand Insider Requests';
                }
                else
                {
                    result += 'New Friend Requests';                
                }
                
                result += '</a>';
                result += ' (' + formatNumberWithCommas( json.NewFriendRequestCount ) + ')';
                result += '</li>';
            }
            
            /* Removing this since the number is not accurate 
            if (json.NewCommentCount > 0)
            {
                result += '<li style="display:block;" >';
                result += '<a href="' + resolveUrl("~/Applications/Default.aspx?incmd=2,23,231?folder=0") + '">';
                result += 'New Comments';
                result += '</a>';
                result += ' (' + formatNumberWithCommas( json.NewCommentCount ) + ')';
                result += '</li>';
            }       
            */
            
            if (json.SponsorshipOffersCount > 0)
            {
                result += '<li>';
                result += '<a href="' + resolveUrl("~/Applications/Default.aspx?incmd=1,12,122?sas=3") + '">';
                result += 'Sponsorship Offers';
                result += '</a>';
                result += ' (' + formatNumberWithCommas( json.SponsorshipOffersCount ) + ')';
                result += '</li>';
            }       
            
            if (json.SponsorshipSavedAppsCount > 0)
            {
                result += '<li>';
                result += '<a href="' + resolveUrl("~/Applications/Default.aspx?incmd=1,12,121?sas=0") + '">';
                result += 'Saved Sponsorship Applications';
                result += '</a>';
                result += ' (' + formatNumberWithCommas( json.SponsorshipSavedAppsCount ) + ')';
                result += '</li>';
            }   
            
            if (json.DoNotContactList == true)
            {
                result += '<li class="unsubscribed">';
                
                result += formatString( 
                'You&#39;re unsubscribed from all emails <a href="{0}">Change</a>', 
                    new Array( 
                        resolveUrl( '~/Applications/Default.aspx?incmd=2,93' )
                    )
                );                   
                
                result += '</li>';
            }
            
            
            result += '</ul>';
        }
    }

    return result;
}