﻿// JScript File
//NOTE: loading this file manually instead of having js in MyStatus skin control to fix "operation aborted..." js error..sstetler

function InvokeAndPopulateUpdates( jsonServiceEndPoint, targetElementId, loadingDivId, memberBlogUrl )
{
    try
    {
        new Ajax.Request(
            jsonServiceEndPoint, 
            {   
                method:'get',   
                onSuccess: function(transport)
                {
                    var json = transport.responseText.evalJSON();
                    var html = BuildUpdatesHtml( json, memberBlogUrl );                    
                    
                    document.getElementById( targetElementId ).innerHTML = html;
                    
                    if ( loadingDivId != null )
                    {
                        document.getElementById( loadingDivId ).innerHTML = '';
                    }
                } 
            }
        ); 
    } 
    catch( ex1 )
    {
    }
}

function BuildUpdatesHtml( updates, memberBlogUrl )
{
    var result;
    var update;
    var overrideBlogLink;
    
    result = '';
    result += '<div class="networkActivityWrap">';    
    
    try
    {
        for( i = 0; i < updates.length; i++ )
        {
            overrideBlogLink = memberBlogUrl + '?euid=' + updates[i].EntityUpdateId;
            
            result += '<h4 class="divclear">'; 
            result += getFriendlyDateString( updates[i].AddDate );
            result += '</h4>';
            
            result += '<div class="activityWrapProfile">';
            
                result += '<div class="networkCommentWrap">';            
                    result += '<div class="networkComment">';
                    result += updates[i].Text;
                    result += '</div>';            
                result += '</div>';
                
                if ( updates[i].TotalAttachments > 0 )
                {
                    result += '<div class="photoContainer">';                
                        result += '<table>';                
                            result += '<tr>';
                            
                            for( y = 0; y < updates[i].Attachments.length; y++ )
                            {
                                result += '<td>';
                                result += getResourceHtml( updates[i].Attachments[y], 75, 150, overrideBlogLink );
                                result += '</td>';
                            }
                            
                            result += '<tr>';                
                        result += '</table>';                
                    result += '</div>';                      
                }
                
                result += '<div class="networkControls">'; 
                    result += '<a href="' + overrideBlogLink + '">Comment</a>';
                    
                    if ( updates[i].TotalAttachments > 0 )
                    {                
                        result += ' | <a href="' + overrideBlogLink + '">('+ updates[i].TotalAttachments +') Attachments</a>';                
                    }
                        
                    result += ' | <a href="' + overrideBlogLink + '">More</a>';                
                                
                result += '</div>';      
                        
            result += '</div>';
                
        }
    }
        catch( ex )
    {
    }
    
    result += '</div>';
    
    
    return result;    
}

if( typeof(Sys) != "undefined" && typeof(Sys.Application) != "undefined" )
{
  Sys.Application.notifyScriptLoaded();
}
