function AddProfileStatusUpdate(Sender, ContainerID)
{
	AddNewsStatusUpdate(Sender, ContainerID, 'personal', function() {GetCurrentStatusUpdate()});
}

function AddNewsStatusUpdate(Sender, ContainerID, NewsTypeVal, Callback)
{
    var MaxLength= 412;
	var Output = $("#statusupdates");
	var Input = $(".statusupdateinput");
	var Container = $('#'+ContainerID);
	var ResponseContainer = "span#ajaxresponse";
	var DefaultTextVal = $('#defaultstatustext').val();
	var LoadingImage = $("#statusupdateloading");
	
	var MessageVal = jQuery.trim(Input.eq(1).val());
		
	if (MessageVal == "" || DefaultTextVal == MessageVal)
	    return;
	    
	if (MessageVal.length > MaxLength)
	{
	    var updateOverflow= MessageVal.length - MaxLength;
	    var overflowMessage= "Your update is "+ updateOverflow +" characters too long. Click OK to truncate, Cancel to edit.";
	    
	    if (!confirm(overflowMessage))
	        return;
	}
	    
    $(Sender).hide();
	LoadingImage.show();
	
	$.post("statusupdate_news_add.aspx",
        { message: MessageVal, newstype:NewsTypeVal},
            
           function(response){
            
            if (Callback!=null)
            {
                Callback();
            }
             
            if ($(response).is(ResponseContainer))
            {
                var row = "<tr class=\"row-1\"><td class=\"cell-3\" id=\"statusupdate-item\"></td></tr>";
                Output.prepend(row);
                
                var display = $(response);
                var plc = Output.find("#statusupdate-item").eq(0);
                
                Output.find('.thumb-block').hide();
                
                display.hide();
                plc.html(display);
                
                Container.show();
                
                display.slideDown('slow',
                function (){
                    LoadingImage.hide();
                    $(Sender).show();
                });
                
                
                Output.find('.commentinput').eq(0).growfield({max: 175});     
                Input.eq(1).val(DefaultTextVal);
                Input.growfield('restart');
            }
        }
    ); 
}

function GetCurrentStatusUpdate()
{
    var ResponseContainer = "span#ajaxresponse";
    var Output = $("#statusupdate");
    
    $.post("statusupdates/statusupdate_profile_get.aspx",
        {a: 'a' },

        function(response){
            
            response = jQuery.trim(response);
            
            if (response == "" || $(response).is(ResponseContainer))
            {
                var display = $(response).html();
                Output.html(display);
            }
        }
    ); 
}

function RemoveStatusUpdate( Sender, StatusUpdateIDVal )
{
	if (!confirm('Are you sure you want to remove this status update?'))
	    return;
	
	$.post("statusupdates/statusupdate_remove.aspx",
        { statusupdateid:StatusUpdateIDVal} ,
        function(response){
            $(Sender).closest(".row-1").hide();
            GetCurrentStatusUpdate();
        } 
    );
}

function ClearStatusUpdate( ContainerID )
{
	$.post("statusupdates/statusupdate_clear.aspx",
        { },
            function(response){
                 $("#"+ContainerID).hide();
          }
    );	
}

function SetDefaultStatusText()
{
   var DefaultTextVal = $('#defaultstatustext').val();
   $(".statusupdateinput").val(DefaultTextVal);
}

function OnStatusFocus(txt)
{
    if (txt.value == $('#defaultstatustext').val())
        txt.value='';
}

$(function() { 
    SetDefaultStatusText();
    $('.statusupdateinput').growfield({max: 175});
});
