var isInfinitScrollActivated = false;
var nbLoadMore = new Array();
var nbMaxLoadMore = new Array();
var nbMaxLoadMoreForProfile = 5;
var doIShowDetailPublication = true;
var clickedOnHubSelect = false;
var isDetailPublicationAnimating = false;
var isCommentsPublicationAnimating = false;
var publicationsLoaded = false;
var doIScrollPanel = false;
var commentsOpenedIsCanceled = false;
var cancelPanelClose = false;
onload = function(){
    updateHeightPage();
}
$(function(){
   
   
   //je n'active pas l infinite scroll et les autres javascript pour les robots'
   if($('.isRobot').length==0)
   {
       nbMaxLoadMore['universRightCollumn'] =  new Array();
       nbMaxLoadMore['universLeftCollumn'] =  new Array();
       nbLoadMore = new Array();

       nbMaxLoadMore['universRightCollumn']['followedNewsFeed'] = 1;
       nbMaxLoadMore['universRightCollumn']['generalNewsFeed'] = -1;
       nbMaxLoadMore['universRightCollumn']['questionNewsFeed'] = 1;
       nbMaxLoadMore['universRightCollumn']['reviewNewsFeed'] = 1;
       nbMaxLoadMore['universRightCollumn']['suggestionsByJob'] = 1;
       nbMaxLoadMore['universRightCollumn']['suggestionsByDepartment'] = 1;
       nbMaxLoadMore['universRightCollumn']['rndConcoursFeed'] = 1;
       nbMaxLoadMore['universRightCollumn']['goodDealsFeed'] = 4;
       nbMaxLoadMore['universRightCollumn']['mentionsFeed'] = -1;

       nbMaxLoadMore['universLeftCollumn']['shareHoldersNewsFeed'] = -1;
       nbMaxLoadMore['universLeftCollumn']['searchResultsFeed'] = -1;
       nbMaxLoadMore['universLeftCollumn']['searchContactsFeed'] = 1;
       nbMaxLoadMore['universLeftCollumn']['searchStatutsFeed'] = 4;
       nbMaxLoadMore['universLeftCollumn']['profileNewsFeed'] = -1;//-1 = infinie
       nbMaxLoadMore['universLeftCollumn']['concoursFeed'] = -1;//-1 = infinie
       nbMaxLoadMore['universLeftCollumn']['followedNewsFeed'] = 4;
       nbMaxLoadMore['universLeftCollumn']['generalNewsFeed'] = 2;

        activateInfiniteScroll();
        updateHeightPage(); 
        activateTweazTabs();
        
        
        if($('.publicationContainer').length>0) 
           activateCuteTime('.publishedAtTime','fr');

        $('.publicationsContainer').each(function()
        {
          var type = $(this).attr('type');
          nbLoadMore[type] = 0;
        });

        if($('.universLeftCollumn .publicationsContainer').length>0)
            loadMoreCollumn($('.universLeftCollumn .publicationsContainer').attr('type'));
       if($('.universRightCollumn .publicationsContainer').length>0)
           loadMoreCollumn($('.universRightCollumn .publicationsContainer').attr('type'));
       
       $('.universLeftPartHidder').click(function(){
          closeDetailPublication(); 
       });

       $('.universRightPartHidder').click(function(){
          closeCommentsPublication(); 
       });

       $('#topContentConnected').click(function(){
           cancelPanelClose = true;
       });
       $('#globalContainer').click(function(){
           cancelPanelClose = true;
       });
       $('body').click(function(){
           if(!cancelPanelClose)
           {
               if($('.universLeftPartHidder:visible').length>0)
                   closeDetailPublication();
               if($('.universRightPartHidder:visible').length>0)
                   closeCommentsPublication();
           }
           else
               cancelPanelClose = false;
       });
    }
    
       
    
   
   
        
        
   
   
   
   
   
});

function showHubSelect(){
    if(publicationsLoaded){
        clickedOnHubSelect = true;
        $('.universLeftCollumn #selectHub').css('overflow','visible');
        $('body').click(function(){if(clickedOnHubSelect){clickedOnHubSelect = false;}else{hideHubSelect(null)}});
    }
}

function hideHubSelect(chosenIdPageWithHub){
    $('.universLeftCollumn #selectHub').css('overflow','hidden');
    if(chosenIdPageWithHub!=null){
        $('.universLeftCollumn .selectHubsHub.selected').html($('.universLeftCollumn .selectHubsHub[rel='+chosenIdPageWithHub+']').html());
        $('.universLeftCollumn .selectHubsHub.selected').attr('rel',chosenIdPageWithHub);
        //Appel ajax pour changer les publications affichées
        $('.universLeftCollumn .publicationsContainer').attr('idpagewithhub',chosenIdPageWithHub);
        $('.universLeftCollumn .publicationsContainer').removeClass('insertNewPublicationHere');
        if(chosenIdPageWithHub=='0') $('.universLeftCollumn .publicationsContainer').addClass('insertNewPublicationHere');
        $('.universLeftCollumn .publicationsContainer .publicationsGoHere').html('');
        nbLoadMore['generalNewsFeed'] = 0;
        publicationsLoaded = false;
        loadMoreCollumn('generalNewsFeed');
    }
    $('body').unbind('click');
}






function activateInfiniteScroll()
{
    if(!isInfinitScrollActivated)
    {
           $(window).scroll(function(){
                if  ($(window).scrollTop() >= ($('#topContentConnected').height() + $('#postToWallDiv').height() + $('.universLeftCollumn .publicationsContainer').height() - 300 - $(window).height())){
                   loadMoreCollumn($('.universLeftCollumn .publicationsContainer:visible').attr('type'));
                }
                if  ($(window).scrollTop() >= ($('#topContentConnected').height() + $('#postToWallDiv').height() + $('.universRightCollumn .publicationsContainer').height() - 300 - $(window).height())){
                   loadMoreCollumn($('.universRightCollumn .publicationsContainer:visible').attr('type'));
                }

            });
            
        isInfinitScrollActivated = true;
    }

}


function cancelInfiniteScroll(){
    //$(window).unbind('scroll');
    isInfinitScrollActivated = false;
}



function loadMoreCollumn(type){
    var go = true;
    
    
    
    if($('.publicationsContainer[type='+type+']').attr('hasNoPreviousPost') != '1' && $('.publicationsContainer[type='+type+']').attr('isLoading') != '1' && $('.publicationsContainer[type='+type+']:visible').length>0)
    {
        var rand = Math.round(Math.random()*100);
        $('.publicationsContainer[type='+type+']').attr('isLoading','1');
       var collumnPlacement = 'universLeftCollumn';
       if($('.publicationsContainer[type='+type+']').parents('div').hasClass('universRightCollumn'))
            collumnPlacement = 'universRightCollumn';
        if(nbMaxLoadMore[collumnPlacement][type]!= -1 && nbLoadMore[type]>=nbMaxLoadMore[collumnPlacement][type])
         {
             go = false;
         }
        nbLoadMore[type] += 1;
        if(go)
            {
                var isProfile = 0;
                
                cancelInfiniteScroll();
                $('.publicationsContainer[type='+type+'] .publicationsGoHere').append('<center><img class="ajax-loader loaderMoreCollumn" src="/images/studio/ajax-loader-bar.gif"></center>');
                $('.publicationsContainer[type='+type+'] .loaderMoreCollumn').fadeIn();
                updateHeightPage();
                var idpagewithhub = $('.publicationsContainer[type='+type+']').attr('idpagewithhub');
                var fromtime = "";
                var id = 0;
                var numCollumn = 1;
                if($('.publicationsContainer[type='+type+']').parents('.classPlace').hasClass('universRightCollumn'))
                    numCollumn = 2;
                
                switch(type)
                {
                    case 'mostLikedNewsFeed':
                    case 'suggestionsByJob':
                    case 'suggestionsByDepartment':
                    case 'searchContactsFeed':
                    case 'sellYours':
                        if($('.publicationsContainer[type='+type+'] .publicationContainer').length>0)
                            {
                                
                                fromtime = $('.publicationsContainer[type='+type+'] .publicationContainer').length;
                            }
                        else
                            fromtime = 0;
                         
                        break;
                    case 'friendsSuggestionsFeed':
                        if($('.publicationsContainer[type='+type+'] .friendSuggestionLine').length>0)
                            {
                                
                                fromtime = $('.publicationsContainer[type='+type+'] .friendSuggestionLine').length;
                            }
                        else
                            fromtime = 0;
                         
                        break;
                    break;
                    case 'profileNewsFeed':
                            if($('.publicationsContainer[type='+type+'] .publicationContainer[iscontest=0]').length>0)
                                {
                                    fromtime = $('.publicationsContainer[type='+type+'] .publicationContainer[iscontest=0]:last').attr('created_at');
                                }
                            else
                                {
                                    var d = new Date();
                                    fromtime = d.toString();
                                }
                        break;
                    default:
                            if($('.publicationsContainer[type='+type+'] .publicationsGoHere .publicationContainer').length>0)
                                {
                                    fromtime = $('.publicationsContainer[type='+type+'] .publicationContainer:last').attr('created_at');
                                }
                            else
                                {
                                    var d = new Date();
                                    fromtime = d.toString();
                                }
                         break;
                }
               
                switch(type)
                {
                    case 'profileOtherNewsFeed':
                        id = $('.otherPublicationsWall').attr('id');
                        isProfile = 1;
                        break;
                    case 'profileNewsFeed':
                    case 'mentionsFeed':
                        id = ($('.myPublicationsWall').length>0)?$('.myPublicationsWall').attr('id'):0;
                        break;
                   case 'profileNewsFeed':
                         isProfile = 1;
                        break;
                }
               
                var href = indexPath+'/communWallAjaxActions';
                $.ajax(
                {
                    type: 'get',
                    url: href,
                    cache: false,
                    data: {
                        "part":"loadMoreCollumn",
                        "type":type,
                        "id":id,
                        "idpagewithhub":idpagewithhub,
                        "fromtime":fromtime,
                        "isProfile":isProfile,
                        "numCollumn":numCollumn
                    },
                    success: function(data)
                    {
                        if(type == "followedNewsFeed")
                            $('#nbUnreadNetwork').hide();
                        
                        if(type == "sellYours")
                        {
                            $('.publicationsContainer[type='+type+'] .publicationsGoHere .loaderMoreCollumn').fadeOut(function(){
                                $('.publicationsContainer[type='+type+'] .publicationsGoHere').append(data);
                                activateElastic(15);
                                activateAutoEmpty();
                                $('.publicationsContainer[type='+type+'] .publicationsGoHere #helpBubble1').fadeIn(1000,function(){
                                    $('.publicationsContainer[type='+type+'] .publicationsGoHere #helpBubble4').fadeIn(1000,function(){
                                        $('.publicationsContainer[type='+type+'] .publicationsGoHere #helpBubble3').fadeIn(1000,function(){
                                            $('.publicationsContainer[type='+type+'] .publicationsGoHere #helpBubble2').fadeIn(1000,function(){
                                            });
                                        });
                                    });
                                });
                            });
                        }
                        else
                        {
                            var maxLinesForHelp = 0;
                            switch(type)
                            {
                                case 'followedNewsFeed':
                                    maxLinesForHelp = 10;
                                    break;
                                default:
                                    maxLinesForHelp = 1;
                                    break;


                            }
                            var nbNewActus;
                           if(data.length>35)
                              nbNewActus = $(data).find('.publicationLeft').length;
                           else
                               nbNewActus = 0;
                           if(nbNewActus == 0)
                           {

                               $('.publicationsContainer[type='+type+'] .publicationsGoHere .loaderMoreCollumn').fadeOut(function(){
                                   $('.publicationsContainer[type='+type+']').attr('hasNoPreviousPost','1');
                                   if($('.publicationsContainer[type='+type+'] .publicationContainer').length < maxLinesForHelp)
                                   {
                                       $('.publicationsContainer[type='+type+'] .needMoreActus .noActu').show();
                                       $('.publicationsContainer[type='+type+'] .needMoreActus').fadeIn();
                                   }
                                    $(this).remove();
                                });


                           }
                           else
                           {


                                var nbActus = nbNewActus + $('.publicationsContainer[type='+type+'] .publicationContainer').length;

                                if(nbActus<maxLinesForHelp)
                                {
                                    if(nbActus == 0)
                                        $('.publicationsContainer[type='+type+'] .needMoreActus .noActu').show();
                                    $('.publicationsContainer[type='+type+'] .needMoreActus').fadeIn();
                                }
                                else
                                {
                                    $('.publicationsContainer[type='+type+'] .needMoreActus').hide();
                                }



                                $('.publicationsContainer[type='+type+'] .publicationsGoHere .loaderMoreCollumn').fadeOut(function(){
                                    $(this).remove();


                                    $('.publicationsContainer[type='+type+'] .publicationsGoHere').append(data);



                                    updateUniversLeftPartHidderHeight();



                                    $('.publicationsContainer[type='+type+']').attr('isLoading','0');
                                    activeToolTip();
                                    activateCuteTime('.publishedAtTime','fr');
                                    activateShowDeletePublicationOnOver();
                                    activateAutoEmpty();
                                   // activateCaracterLeftByElement($('.publicationsContainer[type='+type+'] .publicationContainer').find('textarea'), $('.publicationsContainer[type='+type+'] .publicationContainer').find('.caracterLeft'));
                                    activateShowDeleteCommentOnOver();


                                    if($('.firstCollumn').length>0 && $('.secondCollumn').length>0)
                                     {
                                        $('.firstCollumn .publicationsContainer').css('min-height',$('.secondCollumn .publicationsContainer').height());
                                    }

                                     if($('.secondCollumn').length>0 && $('.thirdCollumn').length>0)
                                     {
                                        $('.secondCollumn .publicationsContainer').css('min-height',$('.thirdCollumn .publicationsContainer').height());
                                     }

                                     activateInfiniteScroll();
                                     updateHeightPage();
                                     publicationsLoaded = true;
                                });
                            }
                        }
                        
                        
                        
                    }
                });
            }
            else
                $('.publicationsContainer[type='+type+']').attr('isLoading','0');
    }
}





function launchMediaInWall(token,obj,filetype,showOn){
    var collumnType = $(obj).parents('.publicationsContainer').attr('type');
    var elContainer = $(obj).parents('.publicationContainer');
    elContainer.find('.publicationContent').css('min-height',elContainer.find('.publicationContent').height()+5);
    elContainer.find('.publicationContent').html('');
    elContainer.find('.publicationContent').append('<center><img class="ajax-loader" src="/images/studio/ajax-loader-bar.gif"></center>');
    elContainer.find('.publicationContent .ajax-loader').fadeIn();
    var href = indexPath+'/communWallAjaxActions';
    var sizeMode = 13;
    

    $.ajax(
    {
        type: 'get',
        url: href,
        cache: false,
        data: {
            "part":"launchMediaInWall",
            "token":token,
            "sizeMode":sizeMode
        },
        success: function(data)
        {
            elContainer.find('.publicationContent .ajax-loader').fadeOut(function(){
                $(this).remove();
                if(showOn && filetype == 3)
                {
                     elContainer.find('.fullPublicationLink').fadeIn('slow');
                }
                 
                 elContainer.find('.publicationContent').append(data);
                 updateWindowHeightFromPanel();
                 updateHeightPage();
            });

        }
    });
}



function sharePublication(token)
{
    var href = indexPath+'/communWallAjaxActions';
    $.ajax(
    {
        type: 'get',
        url: href,
        cache: false,
        data: {
            "part":"popupSharePublication",
            "token":token
        },
        success: function(data)
        {
            if(data != '0')
            {
                $('#popup').html(data);
                $.fn.colorbox({
                    width:"520px",
                    inline:true,
                    href:"#popup",
                    overlayClose:false
                });
                activateAutoEmpty();
            }
            else
            {
                showNeedConnexionPopup();
            }
        }
    });
}

function upPublication(token){
    var href = indexPath+'/communWallAjaxActions';
    var isRetweet = $('#'+token).attr('rel');
    $.ajax(
    {
        type: 'get',
        url: href,
        cache: false,
        data: {
            "part":"popupUpPublication",
            "token":token,
            "isRetweet":isRetweet
        },
        success: function(data)
        {
            $('#popup').html(data);
            $.fn.colorbox({
                    inline:true,
                    href:"#popup",
                    overlayClose:false
                });
        }
    });
    
}

function submitSharePublication(token,doIHideButton)
{
    
    if(doIHideButton)
    {
        $('.publicationContainer[origineltoken='+token+']').find('.sharePublicationLink').remove();
    }
    
    $('#popup #bottomActionsContainer .bottomButtonsContainer').hide();
    $('#popup #bottomActionsContainer .ajaxLoaderSmall').show();
    var title = $('#publicationSharedTitle').val();
    if(title == $('#publicationSharedTitle').attr('rel'))
        title = "";
    var href = indexPath+'/communWallAjaxActions';

    var isBig = 0;
    if($('.otherPublicationsWall').length>0)
        isBig = 1;

    $.ajax(
    {
        type: 'get',
        url: href,
        cache: false,
        data: {
            "part":"submitSharePublication",
            "token":token,
            "isBig":isBig,
            "title":escape(title)
        },
        success: function(data)
        {
            if(data != '0')
            {
                if(!doIHideButton)
                closePopup();
            
                var collumn = "";

                $('.insertSharedPublicationHere').each(function(){
                    $(this).prepend(data);
                    $(this).find('.publicationContainer:last').fadeOut().remove();
                    $(this).find('.publicationContainer.hidden').fadeIn();
                });

                if($('.universLeftPartHidder').css('display') !='none')
                    closeDetailPublication();

                activateCuteTime('.publishedAtTime','fr');
                activeToolTip();
                activateShowDeletePublicationOnOver();
                activateAutoEmpty();
               // activateCaracterLeftByElement($('.'+collumn+' .publicationContainer').find('textarea'), $('.'+collumn+' .publicationContainer').find('.caracterLeft'));
                activateShowDeleteCommentOnOver();
            }
            else
            {
                showNeedConnexionPopup();
            }
            
        }
    }); 
}

function submitUpPublication(token)
{
    var href = indexPath+'/communWallAjaxActions';
    var isRetweet = $('#'+token).attr('rel');

    var isBig = 0;
    if($('.otherPublicationsWall').length>0)
        isBig = 1;

    $.ajax(
    {
        type: 'get',
        url: href,
        cache: false,
        data: {
            "part":"submitUpPublication",
            "token":token,
            "isBig":isBig,
            "isRetweet":isRetweet
        },
        success: function(data)
        {
            closePopup();
            var collumn = "";

            if(isRetweet==1){
                $('.insertSharedPublicationHere').each(function(){
                    //On enlève la publication en cours pour la remonter
                    //$(this).find('.publicationContainer:last').fadeOut().remove();
                    $(this).find('.publicationContainer[id="'+token+'"]').fadeOut().remove();
                    $(this).prepend(data);
                    $(this).find('.publicationContainer.hidden').fadeIn();
                });
            }else{
                $('.insertNewPublicationHere').each(function(){
                    //On enlève la publication en cours pour la remonter
                    //$(this).find('.publicationContainer:last').fadeOut().remove();
                    $(this).find('.publicationContainer[id="'+token+'"]').fadeOut().remove();
                    $(this).prepend(data);
                    $(this).find('.publicationContainer.hidden').fadeIn();
                });
            }


            activateCuteTime('.publishedAtTime','fr');
            activeToolTip();
            activateShowDeletePublicationOnOver();
            activateAutoEmpty();
          //  activateCaracterLeftByElement($('.'+collumn+' .publicationContainer').find('textarea'), $('.'+collumn+' .publicationContainer').find('.caracterLeft'));
            activateShowDeleteCommentOnOver();
        }
    });
} 

function showNewComment(obj)
{
    $(obj).parents('.publicationContainer').find('.newComment:hidden').fadeIn();
}
function cancelCommentsOpening()
{
    commentsOpenedIsCanceled = true;
}
function showComments(obj)
 {
     if(!commentsOpenedIsCanceled)
     {
         var linkObj;
         if(!$(obj).hasClass('showCommentsLink'))
             linkObj = $(obj).find('.showCommentsLink');
         else
              linkObj = $(obj);
            var tokenPublication = linkObj.attr('id');
            if($('.universLeftCollumn .publicationContainer[id='+tokenPublication+']').hasClass('leftTabLineSelected'))
                closeCommentsPublication();
            else
            { 
                var isReTweeted = linkObj.attr('rel');
                var mode = linkObj.attr('mode');

                var href = indexPath+'/communWallAjaxActions';

                var el = linkObj;
                $('#publicationCommentsPanelContent').css('min-height',$('#publicationCommentsPanelContent').height());
                $('#publicationCommentsPanelContent').html('<br/><center><img class="ajax-loader loaderMoreCollumn" src="/images/studio/ajax-loader-bar.gif"></center>');
                $('#publicationCommentsPanelContent .ajax-loader').show();

                $('.leftTabLineSelected').removeClass('leftTabLineSelected');
                el.parents('.publicationContainer').addClass('leftTabLineSelected');
                $.ajax(
                {
                    type: 'get',
                    url: href,
                    cache: false,
                    data: {
                        "part":"activateShowComments",
                        "tokenPublication":tokenPublication,
                        "isReTweeted":isReTweeted,
                        "mode":mode
                    },
                    success: function(data)
                    {
                        fillRightPanelFromData(data,showCommentsCompleted);
                    }
                });
            }
     }
     else
         {
             commentsOpenedIsCanceled = false;
         }
     
        
 }
 
function showCommentsCompleted()
{
    activateElastic(15);
    activateCuteTime('.publishedAtTime','fr');
    activeToolTip();
    activateAutoEmpty();
    activateShowDeleteCommentOnOver();
}

function showCommentButton(obj)
{
    $(obj).parents('.publicationContainer').find('.newCommentBottom:hidden').fadeIn(function(){
        updateWindowHeightFromPanel();
    });
}

function loadAllComments(obj)
{
   $(obj).parents('.publicationContainer').find('.comments .ajax-loader').fadeIn();
   var href = indexPath+'/communWallAjaxActions';
   var tokenPublication = $(obj).parents('.publicationContainer').attr('id');
   var isReTweeted = $(obj).parents('.publicationContainer').attr('rel');
   var el = $(obj);
   $.ajax(
    {
        type: 'get',
        url: href,
        cache: false,
        data: {
            "part":"loadAllComments",
            "tokenPublication":tokenPublication,
            "isReTweeted":isReTweeted
        },
        success: function(data)
        {
            el.parents('.publicationContainer').find('.commentsContainer').html(data);
            activateCuteTime('.publishedAtTime','fr');
            activeToolTip();
            activateAutoEmpty();
            activateShowDeleteCommentOnOver();
        }
    });
}

function submitComment(obj)
{
    if($(obj).parents('.newCommentSubmitDiv').css('display') != 'none')
    {
            var clickedElement = $(obj);

            var elCommentsContent = clickedElement.parents('.newComment').find('.newCommentContent');
            var comment = elCommentsContent.val();

            if(comment != "" && comment != elCommentsContent.attr('rel'))
            {
                $(obj).parents('.newCommentSubmitDiv').css('display','none');
                $(obj).parents('.newComment').find('.newCommentSubmitLoader').show();
                var token = clickedElement.parents('.newComment').attr('id');
                var isReTweeted = clickedElement.parents('.newComment').attr('rel');
                var href = indexPath+'/communWallAjaxActions';
                var elCommentsContainer = clickedElement.parents('.publicationContainer').find('.commentsContainer');
                $.ajax(
                {
                    type: 'get',
                    url: href,
                    cache: false,
                    data: {
                        "part":"newCommentSubmit",
                        "comment":comment,
                        "token":token,
                        "isReTweeted":isReTweeted
                    },
                    success: function(data)
                    {
                        if(data != '0')
                        {
                            elCommentsContainer.parents('.publicationContainer').find('.commentsContainer .noCommentsAvailable:visible').remove();
                            elCommentsContainer.parents('.publicationContainer').find('.commentsContainer').append(data);
                            activateCuteTime('.publishedAtTime','fr');
                            elCommentsContent.val(elCommentsContent.attr('rel'));
                            elCommentsContent.parents('.newComment').find('.caracterLeft').html(elCommentsContent.attr('maxlength'));
                            activateShowDeleteCommentOnOver();
                            
                            elCommentsContent.css('height','15px');
                            updateWindowHeightFromPanel();
                        }
                        else
                        {
                            showNeedConnexionPopup();
                        }
                        elCommentsContent.parents('.newComment').find('.newCommentSubmitLoader').hide(200, function(){
                                     $(this).parents('.newComment').find('.newCommentSubmitDiv').fadeIn();
                                     updateHeightPage();
                            });
                    }
                });
            }

    }
}


function activateShowDeletePublicationOnOver()
{
     $('.showDeletePublicationOnOver:not([activated=1])').each(function(){
        $(this).attr('activated','1');
        $(this).hover(
        function(){
            //hover
            $(this).find('.deletePublication a:not(visible)').css('display','block');
        },
        function(){
            //out
            $(this).find('.deletePublication a:visible').css('display','none');
        });
     });

     
}

function deletePublication(obj,tokenPublication,isReTweeted){
    var href = indexPath+'/communWallAjaxActions';
    $.ajax(
    {
        type: 'get',
        url: href,
        cache: false,
        data: {
            "part":"popupDeletePublication",
            "token":tokenPublication,
            "isReTweeted":isReTweeted
        },
        success: function(data)
        {
            $('#popup').html(data);
            $.fn.colorbox({width:"450px", inline:true, href:"#popup"});
        }
    });
}

function submitDeletePublication(tokenPublication,isReTweeted)
{
    closePopup();
    $('.publicationContainer[token='+tokenPublication+']').each(function(){

        $(this).fadeOut(function(){
            var publicationsContainer =  $(this).parents('.publicationsContainer');
            $(this).remove();
             if(publicationsContainer.find('.publicationContainer').length==0)
            {
                if(publicationsContainer.find('.needMoreActus').length>0)
                    publicationsContainer.find('.needMoreActus').fadeIn();
            }
        });
    });
    
    var href = indexPath+'/communWallAjaxActions';
    $.ajax(
    {
        type: 'get',
        url: href,
        cache: false,
        data: {
            "part":"deletePublication",
            "token":tokenPublication,
            "isReTweeted":isReTweeted
        },
        success: function(data)
        {
        }
    });
}

function activateShowDeleteCommentOnOver()
{
     $('.showDeleteCommentOnOver:not([activated=1])').each(function(){
        $(this).attr('activated','1');
        
        $(this).parents('.commentContainer').hover(
        function(){

            //hover
            $(this).find('.showDeleteCommentOnOver:visible').css('display','none');
            $(this).find('.deleteComment:not(visible)').css('display','block');
        },
        function(){
            //out
            $(this).find('.deleteComment:visible').css('display','none');
            $(this).find('.showDeleteCommentOnOver:not(visible)').css('display','block');
        });
     });

}

function deleteComment(obj){
    
    var href = indexPath+'/communWallAjaxActions';
    var tokenComment = $(obj).attr('id');
    $.ajax(
    {
        type: 'get',
        url: href,
        cache: false,
        data: {
            "part":"deleteComment",
            "token":tokenComment
        },
        success: function(data)
        {
            if(data == '1')
            {
                $('.commentContainer[id='+tokenComment+']').each(function(){
                    $(this).slideUp(function(){
                        //var container = $(this).parents('.publicationContainer');
                        $(this).remove();
                       // var nbComments = container.find('.nbComments');

                       // var newNbComment = container.find('.commentContainer').length;
                        //nbComments.html(newNbComment);

                    });
                });
            }
        }
    });
}




function iLikePost(obj)
{
    var el=$(obj);
    var tokenPublication = el.parents('.publicationContainer').attr('id');
    var isReTweeted = el.parents('.publicationContainer').attr('rel');

    var href = indexPath+'/communWallAjaxActions';
    if(el.attr('alreadyClicked')!='1')
    {
        el.attr('alreadyClicked','1')
        $.ajax(
        {
            type: 'get',
            url: href,
            cache: false,
            data: {
                "part":"iLikePost",
                "tokenPublication":tokenPublication,
                "isReTweeted":isReTweeted
            },
            success: function(data)
            {
                if(data != '0')
                {
                    var token = el.parents('.publicationContainer').attr('id');
                    var rel = el.parents('.publicationContainer').attr('rel');
                    var nbLike =  $('.publicationContainer[id='+token+'][rel='+rel+']').find('.publicationActionsLinks .nbLikes').html();

                    if(data =="1" || data == 1)
                    {
                        $('.publicationContainer[id='+token+'][rel='+rel+']').find('.publicationActionsLinks .iDoLikePost').css('display','none');
                        $('.publicationContainer[id='+token+'][rel='+rel+']').find('.publicationActionsLinks .iNotLikePost').show();
                        if(nbLike.length == 0)
                            {
                                $('.publicationContainer[id='+token+'][rel='+rel+']').find('.publicationActionsLinks .nbLikes').html('(1)');
                            }
                        else
                             $('.publicationContainer[id='+token+'][rel='+rel+']').find('.publicationActionsLinks .nbLikes').html(parseInt(nbLike,10)+1);

                    }
                    else
                    {
                        $('.publicationContainer[id='+token+'][rel='+rel+']').find('.publicationActionsLinks .iNotLikePost').css('display','none');
                        $('.publicationContainer[id='+token+'][rel='+rel+']').find('.publicationActionsLinks .iDoLikePost').show();
                        $('.publicationContainer[id='+token+'][rel='+rel+']').find('.publicationActionsLinks .nbLikes').html(parseInt(nbLike,10)-1);
                    }
                }
                else{
                    showNeedConnexionPopup();
                }
                
            }
        });
    }
}

function closeDetailPublication()
{
        isDetailPublicationAnimating = true;
        desactivatePanelScroll();
       $('body').unbind('keyup');
       $('.universLeftPartHidder').fadeOut(); 
       $('.publicationDetailPanel').animate( {
           left: '582px'
           },
           600,
           function(){
               isDetailPublicationAnimating = false;
               $('#publicationDetailPanelContent').html('')
                $('.rightTabLineSelected').removeClass('rightTabLineSelected');
           }
       );
}
function closeCommentsPublication()
{
        $('rightTabLineSelected').removeClass('rightTabLineSelected');
        isCommentsPublicationAnimating = true;
        desactivatePanelScroll();
       $('body').unbind('keyup');
       $('.universRightPartHidder').fadeOut(); 
       $('.publicationCommentsPanel').animate( {
           left: '-402px'
           },
           600,
           function(){
               isCommentsPublicationAnimating = false;
               $('#publicationCommentsPanelContent').html('')
                $('.leftTabLineSelected').removeClass('leftTabLineSelected');
           }
       );
}

function activatePanelForEditEquipments(){
        $('#typeDiv li').click(function(){
            $('#typeDiv li').removeClass('selected');
            $(this).addClass('selected');
            $('#categoryFilter').val($('#categoryFilter').attr('rel'));
            $('#brandFilter').val($('#brandFilter').attr('rel'));
            $('#referenceFilter').val($('#referenceFilter').attr('rel'));
            refreshCategories();
            $('#brandDiv ul').html('');
            $('#referenceDiv ul').html('');
        });

       activateSpinButtons();

        $('#categoryFilter').keyup(function(){
            $(document).stopTime();
            $(document).everyTime("0.4s", function() {
                refreshCategories();
            });
        })

        $('#brandFilter').keyup(function(){
            $(document).stopTime();
            $(document).everyTime("0.4s", function() {
                refreshBrands();
            });
        })

        $('#referenceFilter').keyup(function(){
            $(document).stopTime();
            $(document).everyTime("0.4s", function() {
                refreshReferences();
            });
        })

        activateJScrollPane('scrollableTypes');
        activateRadioBox();
        colorateTabs();

        activateAutoEmpty();
        //$('.emptyMessageDiv').hide();
        desactivatePanelScroll();
        updateWindowHeightFromPanel();
}

function fillLeftPanel(content, afterFillFunction){
    $('#publicationDetailPanelContent').fadeOut(200,function(){
            $('#publicationDetailPanelContent').html('<br/><center><img class="ajax-loader loaderMoreCollumn" src="/images/studio/ajax-loader-bar.gif"></center>');
            $('#publicationDetailPanelContent .ajax-loader').show();
            $('#publicationDetailPanelContent').fadeIn();
            var afterFillFun = false;
            if(afterFillFunction){
               afterFillFun = afterFillFunction;
            }
            var href = indexPath+'/communAjaxActions';
            $.ajax(
            {
                type: 'get',
                url: href,
                cache: false,
                data:{
                    "part":"fillLeftPanel",
                    "content":content
                },
                success: function(data)
                {
                    fillLeftPanelFromData(data, afterFillFun);
                }
            });
    }); 
}

function fillLeftPanelFromData(data, afterFillFunction){
    var afterFillFun = false;
    if(afterFillFunction){
       afterFillFun = afterFillFunction;
    }
   
    $('#publicationDetailPanelContent').fadeOut(200,function(){
                             
        $('#publicationDetailPanelContent').html(data);
       if(afterFillFun){
           afterFillFun();
       }
        $('#publicationDetailPanelContent').fadeIn();
         updateUniversLeftPartHidderHeight();
        updateWindowHeightFromPanel();
        var yDest;
        if($(window).scrollTop()>$('.universLeftCollumn').position().top)
        {
            yDest = $(window).scrollTop() + 15;
        }
        else
            yDest = $('.universLeftCollumn').position().top + 15;

        activatePanelScroll();

        
        $('.universLeftPartHidder').fadeIn();
        $('.publicationDetailPanel').animate( {
               top:yDest
           },
           600,
           function(){
               $('.publicationDetailPanel').animate( {
                   left: '12px'
                   },
                   600,
                   function(){

                       

                       $('body').keyup(function(event) {
                           if(event.which == 27)
                               closeDetailPublication();
                       });

                   }
               );
           }
       );
   });
}


function fillRightPanelFromData(data, afterFillFunction){
    var afterFillFun = false;
    if(afterFillFunction){
       afterFillFun = afterFillFunction;
    }

       var marginTop = 0;
       

        
    $('#publicationCommentsPanelContent').fadeOut(200,function(){
                            
        $('#publicationCommentsPanelContent').html(data);
       if(afterFillFun)
       {
           afterFillFun();
       }
        $('#publicationCommentsPanelContent').fadeIn();
        updateUniversRightPartHidderHeight(); 
        updateWindowHeightFromPanel();
        var yDest;
        if($(window).scrollTop()>$('.universRightCollumn').offset().top)
        {
             if($('.profileHeader').length>0)
                yDest = $(window).scrollTop() - $('.profileHeader').height() - $('#topContentConnected').height() + 45; 
              else
                  yDest = $(window).scrollTop() - $('#topContentConnected').height() + 45;
              
        }
        else
            {
                if($('.profileHeader').length>0)
                    yDest = 45;
                else
                    yDest = $('.universLeftCollumn .publicationsContainer:visible').offset().top - $('#topContentConnected').height();
                
            }
        
  
        activatePanelScroll(true);

        $('.universRightPartHidder').fadeIn();
        $('.publicationCommentsPanel').animate( {
               top:yDest
           },
           600,
           function(){
               $('.publicationCommentsPanel').animate( {
                   left: '0px'
                   },
                   600,
                   function(){

                       

                       $('body').keyup(function(event) {
                           if(event.which == 27)
                               closeCommentsPublication();
                       });

                   }
               );
           }
       );
   });
}

function showDetailPublication(token,mode)
{
    var yDest;
    
   
    
    if($(window).scrollTop()>$('.universRightCollumn').offset().top)
        {
             if($('.profileHeader').length>0)
                yDest = $(window).scrollTop() - $('.profileHeader').height() - $('#topContentConnected').height() + 45; 
              else
                  yDest = $(window).scrollTop() - $('#topContentConnected').height() + 45;
        }
    else
        {
            if($('#postToWallDiv:visible').length>0)
                yDest = $('.universLeftCollumn .publicationsContainer').offset().top - $('#topContentConnected').height();
            else
                yDest = 45;
        }
    
    if(doIShowDetailPublication && !isDetailPublicationAnimating)
    {
        
        if($('.universRightCollumn .publicationContainer[token='+token+']').hasClass('rightTabLineSelected'))
            closeDetailPublication();
        else
        {
            isDetailPublicationAnimating = true;
            $('#publicationDetailPanelContent').fadeOut(200,function(){
                $('#publicationDetailPanelContent').html('<br/><center><img class="ajax-loader loaderMoreCollumn" src="/images/studio/ajax-loader-bar.gif"></center>');
                $('#publicationDetailPanelContent .ajax-loader').show();
                $('#publicationDetailPanelContent').fadeIn();
                var href = indexPath+'/communWallAjaxActions';
                var isRetweeted = $('.universRightCollumn .publicationContainer[token='+token+']').attr('rel');
                $.ajax(
                {
                    type: 'get',
                    url: href,
                    cache: false,
                    data:{
                        "part":"showDetailPublication",
                        "token":token,
                        "mode":mode,
                        "isRetweeted":isRetweeted
                    },
                    success: function(data)
                    {
                        $('#publicationDetailPanelContent').fadeOut(200,function(){
                             
                            $('#publicationDetailPanelContent').html(data);
                            
                            $('#publicationDetailPanelContent').fadeIn();
                            
                            if($('#publicationDetailPanelContent .videoEmbed').length>0 || $('#publicationDetailPanelContent .soundCloudEmbed').length>0)
                                $('#publicationDetailPanelContent .fullPublicationLink').fadeIn();
                            activeToolTip();
                            activateCuteTime('.publishedAtTime','fr');
                            activateElastic(15,updateWindowHeightFromPanel);
                            activateAutoEmpty();
                         //   activateCaracterLeftByElement($('#publicationDetailPanelContent .publicationContainer').find('textarea'), $('#publicationDetailPanelContent .publicationContainer').find('.caracterLeft'));
                            activateShowDeleteCommentOnOver();
                            isDetailPublicationAnimating  = false;
                            
                            updateWindowHeightFromPanel();
                            activatePanelScroll();
                        });
                    }
                });
            });



            $('.publicationContainer').removeClass('rightTabLineSelected');
            $('.universRightCollumn .publicationContainer[id='+token+']').addClass('rightTabLineSelected');

            updateUniversLeftPartHidderHeight();
            $('.universLeftPartHidder').fadeIn();
            $('.publicationDetailPanel').animate( {
                   top:yDest
               },
               600,
               function(){
                   $('.publicationDetailPanel').animate( {
                       left: '12px'
                       },
                       600,
                       function(){

                           $('body').keyup(function(event) {
                               if(event.which == 27)
                                   closeDetailPublication();
                           });

                       }
                   );
               }
           );
        }
    }
    else
        doIShowDetailPublication = true;
}

function updateUniversLeftPartHidderHeight()
{
    var universLeftPartHidderHeight;
    if($('.universLeftPart').height()>$('.universRightPart').height())
        universLeftPartHidderHeight = $('.universLeftPart').height();
    else
        universLeftPartHidderHeight = $('.universRightPart').height()+20; 
    $('.universLeftPartHidder').height(universLeftPartHidderHeight*2);
    $('.universLeftPartHidder').css('top',0);
}
function updateUniversRightPartHidderHeight()
{
    var universRightPartHidderHeight;
    if($('.universLeftPart').height()>$('.universRightPart').height())
        universRightPartHidderHeight = $('.universLeftPart').height();
    else
        universRightPartHidderHeight = $('.universRightPart').height()+20; 
    $('.universRightPartHidder').height(universRightPartHidderHeight*2);
    $('.universRightPartHidder').css('top',0);
}

function cancelDetailPublication()
{
    doIShowDetailPublication = false;
}

function updateWindowHeightFromPanel()
{
    if($('.universLeftPartHidder:visible').length>0)
    {
        
        var bottomPanel = $('.publicationDetailPanel').offset().top + $('.publicationDetailPanel').height();
        var partLeftBottom = $('.universLeftCollumn').offset().top + $('.universLeftCollumn').height();
        if(bottomPanel>partLeftBottom)
        {
            $('.universLeftCollumn').animate( {
                   'min-height':bottomPanel - $('.universLeftCollumn').offset().top + 15
               },
               300,
               function(){
                updateHeightPage();
                updateUniversLeftPartHidderHeight();
               }
           );
            
        }
    }
}

function scrollPanel(isRightPart)
{
    var hidderClassName = "";
    var sideName = "";
    var panelName = "";
    if(isRightPart)
        {
            hidderClassName = "universRightPartHidder";
            sideName = "Right";
            panelName = "Comments";
        }
    else
        {
            hidderClassName = "universLeftPartHidder";
            sideName = "Left";
            panelName = "Detail";
        }
        
    
    if(doIScrollPanel && $('.'+hidderClassName+':visible').length>0)
    {
        var yDest;
        var scrollTop = $(window).scrollTop();
        var windowHeight = $(window).height();
        var panelHeight =  $('.publication'+panelName+'Panel').height();
        var leftColumnOffset =  $('.univers'+sideName+'Collumn').height();
        var panelOffset = $('.publication'+panelName+'Panel').offset();
        var leftCollumnHeight = $('.univers'+sideName+'Collumn').height();
        var leftCollumnPosition = $('.univers'+sideName+'Collumn').offset();
        var doScroll = true;
        
        
            if(scrollTop>leftCollumnPosition.top)
            {
                yDest = scrollTop - leftCollumnPosition.top;
            }
            else
                yDest = 0;   
            
            if(isRightPart)
            {
                yDest += 15;
            }

            if((yDest + panelHeight + 60) > leftColumnOffset.top + leftCollumnHeight)
                 yDest = leftColumnOffset.top + leftCollumnHeight - 60 - panelHeight;
             
         if(panelOffset.top  < scrollTop  && panelHeight >= windowHeight)
        {
            doScroll = false;
        }
        


         //if(panelOffset.top < scrollTop && (panelOffset.top + panelHeight) > scrollTop + windowHeight)
           //  doScroll = false;
         
         if(doScroll)
         {
            $('.publication'+panelName+'Panel').animate( {
                   top:yDest
               },
               1000,
               'easeInOutExpo',
               function(){
                updateWindowHeightFromPanel();
               }
           ); 
         }
           
        
        
    }
    
}


function activatePanelScroll(isRightPart)
{
    /*$(window).scroll(function(){
           $(this).stopTime();
           doIScrollPanel = false;
            $(this).oneTime(200, function() {
                doIScrollPanel  = true;
                scrollPanel(isRightPart);
            });
            
    });*/
}

function desactivatePanelScroll()
{
    //$(window).unbind('scroll');
}




function voteForPublication( vote , obj)
{
    var el= $(obj);
    
    var token = el.parents('.publicationContainer').attr('id');
    var rel = el.parents('.publicationContainer').attr('rel');
    

    $('.publicationContainer[id='+token+'][rel='+rel+']').find('.publicationActionsLinks .voteActions').fadeOut().remove();

    var href = indexPath+'/communWallAjaxActions';
    $.ajax(
    {
        type: 'get',
        url: href,
        cache: false,
        data: {
            "part":"voteForPublication",
            "vote":vote,
            "tokenPublication":token
        },
        success: function(data)
        {
            if(data != '0')
            {
                $('.publicationContainer[id='+token+'][rel='+rel+']').find('.publicationActionsLinks .voteResults').hide();
                $('.publicationContainer[id='+token+'][rel='+rel+']').find('.publicationActionsLinks .voteResults').html(data).fadeIn();
            }
            else
            {
                showNeedConnexionPopup();
            }
        }
    });
}


function voteForConcoursPublication(obj)
{
    var el = $(obj);
    
    var token = el.parents('.publicationContainer').attr('id');
    var rel = el.parents('.publicationContainer').attr('rel');
    

    $('.publicationContainer[id='+token+'][rel='+rel+']').find('.publicationActionsLinks .voteActions').fadeOut().remove();

    var href = indexPath+'/communWallAjaxActions';
    $.ajax(
    {
        type: 'get',
        url: href,
        cache: false,
        data: {
            "part":"voteForConcoursPublication",
            "tokenPublication":token
        },
        success: function(data)
        {
            if(data != '0')
            {
                window.location.href = data;
            }
            else
            {
                showNeedConnexionPopup();
            }
            
            /*var obj = eval(data);
            var score = obj[0];
            var redirectUrl = obj[1];
            $('.publicationContainer[id='+token+'][rel='+rel+']').find('.publicationActionsLinks .voteResults').hide();
            $('.publicationContainer[id='+token+'][rel='+rel+']').find('.publicationActionsLinks .voteResults').html(score).fadeIn();
            
            $('#popup').html(popupContent);
            
            $.fn.colorbox({
                    width:"450px", 
                    inline:true, 
                    href:"#popup"
                });*/
            
        }
    });
}

function seeAllConcoursPublications(){
    var href = indexPath+'/communWallAjaxActions';
    $.ajax(
    {
        type: 'get',
        url: href,
        cache: false,
        data:{
            "part":"seeAllConcoursPublications"
        },
        success: function(data)
        {
           $('.universLeftCollumn').html(data);
           loadMoreCollumn('concoursFeed');
        }
    });
}

function editAdInfos(sellToken)
{
    var href = indexPath + "/communWallAjaxActions";
    
    $.ajax(
    {
        type: 'get',
        url: href,
        cache: false,
        data:{
            "part":"editAdInfos",
            "sellToken":sellToken
        },
        success: function(data)
        {
           if(data!='0')
           {
               $('#popup').html(data);
               activateElastic(150,resizePopup,'#adInfos');
               activateAutoEmpty();
               $.fn.colorbox({
                        width:"450px", 
                        inline:true, 
                        href:"#popup",
                        overlayClose:false
                    });
           }
        }
    });
}

function saveAdInfos(sellToken)
{
    var href = indexPath + "/communWallAjaxActions";
    var adInfos = $('#adInfos').val();
    $.ajax(
    {
        type: 'post',
        url: href,
        cache: false,
        data:{
            "part":"saveAdInfos",
            "sellToken":sellToken,
            "adInfos":adInfos
        },
        success: function(data)
        {
           closePopup();
           if(data!='0')
           {
               if($('.publicationAdInfos[id='+sellToken+']').length>0)
               {
                   $('.publicationAdInfos[id='+sellToken+'] .adInfosText').html(data);
               }
           }
        }
    });
}

function popupIsSold(sellToken)
{
    var href = indexPath + "/communWallAjaxActions";
    $.ajax(
    {
        type: 'get',
        url: href,
        cache: false,
        data: {
            "part":"popupIsSold",
            "sellToken":sellToken
        },
        success: function(data)
        {
            $('#popup').html(data);
            $.fn.colorbox({
                        width:"450px", 
                        inline:true, 
                        href:"#popup",
                        overlayClose:false
                    });
        }
    });
}

function setIsSold(sellToken,soldOnTweaz)
{
    var href = indexPath + "/communWallAjaxActions";
    $.ajax(
    {
        type: 'get',
        url: href,
        cache: false,
        data: {
            "part":"setIsSold",
            "sellToken":sellToken,
            "soldOnTweaz":soldOnTweaz
        },
        success: function(data)
        {
            closePopup();
            $('.publicationContainer[origineltoken='+data+'] .productNotSold').fadeOut(function(){
                $('.publicationContainer[origineltoken='+data+'] .productSold').fadeIn();
            });
        }
    });
}

function gotoProductPage(url)
{
    if(!commentsOpenedIsCanceled) 
        window.location = url;
    else commentsOpenedIsCanceled= false;
}

function cancelConfirmSuggestion(el,token,doLoadOneMore)
{
    
     var forbiddenIdProfile = "";
    $('.friendsSuggestions .friendSuggestionLine').each(function(){
        if(forbiddenIdProfile!="")
            forbiddenIdProfile +=',';
       forbiddenIdProfile += $(this).attr('rel');
    });
    $(el).parents('.friendSuggestionLine').remove();
    var href = indexPath + "/communWallAjaxActions";
    $.ajax(
    {
        type: 'get',
        url: href,
        cache: false,
        data:{
            "part":"cancelSuggestion",
            "token":token,
            "doLoadOneMore":doLoadOneMore,
            "forbiddenIdProfile":forbiddenIdProfile
        },
        success: function(data)
        {
           $('.friendsSuggestionsContent').append(data);
        }
    });
}

function askConfirmSuggestion(el,token,doLoadOneMore)
{
    $(el).parents('.friendSuggestionLine').remove();
    var forbiddenIdProfile = "";
    if(doLoadOneMore)
    {
        $('.friendsSuggestions .friendSuggestionLine').each(function(){
              if(forbiddenIdProfile!="")
                  forbiddenIdProfile +=',';
             forbiddenIdProfile += $(this).attr('rel');
          });
    }
    else
        doLoadOneMore = 0;
    var href = indexPath + "/communWallAjaxActions";
    $.ajax(
    {
        type: 'get',
        url: href,
        cache: false,
        data:{
            "part":"askConfirmSuggestion",
            "token":token,
            "doLoadOneMore":doLoadOneMore,
            "forbiddenIdProfile":forbiddenIdProfile
        },
        success: function(data)
        {
            if(doLoadOneMore)
                $('.friendsSuggestionsContent').append(data);
        }
    });
}


function editMyPhone(obj){
    showFirstHelpBubble('2',obj);
}

function saveMyPhone(){
    
    
    var isOk = true;
    var phone = $('.addMyPhoneForm:visible #myPhone').val();
    if(!isPhoneValid(phone))
    {
        isOk = false;
        $('.addMyPhoneForm:visible #myPhone').effect('highlight', {color: 'red'}, 3000);
    }
    if(isOk)
    {
        $('.addMyPhoneForm:visible .addMyPhoneFormRightButton').hide();
        $('.addMyPhoneForm:visible .ajax-loader').show();
        
        
        var href = indexPath + "/communWallAjaxActions";
        $.ajax(
        {
            type: 'get',
            url: href,
            cache: false,
            data:{
                "part":"saveMyPhone",
                "phone":phone
            },
            success: function(data)
            {
                $('.addMyPhoneForm:visible .ajax-loader').hide();
                $('.addMyPhoneForm:visible .addMyPhoneFormRightSucceed').show();
                
                $('.addMyPhoneForm:visible #myPhone').attr('disabled','true');
                
                
                $('.editMyPhone').each(function(){
                    var newLink = $(this).parents('.publicationTopRight').find('.publicationPhoneLink.hidden');
                   $(this).remove(); 
                   newLink.removeClass('hidden');
                   newLink.show();
               });
                
                $('.moreInfosForAdLink').each(function(){
                   if($(this).attr('isfirstsell') == '2')
                       $(this).attr('isfirstsell',0);
                   else if($(this).attr('isfirstsell') == '3')
                       $(this).attr('isfirstsell',1);
                });
            }
        });
    }
    
}
