/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
jQuery(document).ready(function ($) {
        
//    
//         if($("#timeline_view").val() == 'no_friend'){
//         $(".jfeeddisplay_div").hide();
//         $(".jpost_comment_div").hide();
//       // alert("hdhdd");
//       // $("#jdisplay_div").hide();
//        $('#jDivDisplayEdit').hide();
//        $('#tagg-business').hide();
//        $("#tab-Friends").hide();
//        $("#jFeedSearch").hide();
////        $('#myprofile').show();
////        $( "#myprofile" ).removeClass( "fade" ).addClass( "active in" );
//        var uid=$("#user_id").val();
//        var alias   =$("#user_alias").val();
//        $.blockUI({ message: '' }); 
//        $.ajax({
//            type    : "POST",
//            url     : mainUrl+"myprofile",
//            data    : 'uid='+uid+"&alias="+alias,
//            cache   : false,
//            success : function(data){
//               //  $(".jfeedtimelinedisplay_div").hide();
//                $('#jMyProfile').html(data);
//                $(".jfeedtimelinedisplay_div").hide();
//                $("#jMyProfile").show();
//                $(".jGallary_div").hide();
//                $(".jfeeddisplay_div").hide();
//                $(".jpost_comment_div").hide();
//                $(".jFriends_div").hide();
//                if($('.member_prof_abt_row').find('.member_prof_abt_col1:contains(Country)').length>0){
//                    var country = $('.member_prof_abt_row').find('.member_prof_abt_col1:contains(Country)').parent().children('.member_prof_abt_col3').html();
//                    if(country.length>0){
//                         country = country.trim();
//                    }
//
//                    if(country=='UK'){
//                        $('.member_prof_abt_row').find('.member_prof_abt_col1:contains(Zip Code)').html('Postal Code');
//                    }else{
//                        $('.member_prof_abt_row').find('.member_prof_abt_col1:contains(Zip Code)').html('Zip Code');
//                    }
//                }
//                if(location.hash=='#Edit'){
//                    $(".jedit").trigger("click");
//                }
//            }
//        }); 
//    }
     //$("#jDisplayInviteGrp").hide();
    if($("#slider1_container").length > 0){
        //Define an array of slideshow transition code
       var _SlideshowTransitions = [
   {$Duration:1000,y:-0.3,$During:{$Top:[0.3,0.7]},$Easing:{$Top:$JssorEasing$.$EaseInCubic,$Opacity:$JssorEasing$.$EaseLinear},$Opacity:2,$Outside:true}    ];
    // And you can add more transitions to the array. 
    var options = {
        $AutoPlay: true,
        $SlideshowOptions: {
                $Class: $JssorSlideshowRunner$,
                $Transitions: _SlideshowTransitions,
                $TransitionsOrder: 1,
                $ShowLink: true
            }
    };
    var jssor_slider1 = new $JssorSlider$('slider1_container', options);
}
    });
$( window ).load(function() {
   
   // $('.blueberry').blueberry();
    $('#share_button').click(function(e){
e.preventDefault();
FB.ui(
{
method: 'feed',
name: 'This is the content of the "name" field.',
link: 'https://connect10.iscriptsdemo.com/',
picture: 'http://www.hyperarts.com/external-xfbml/share-image.gif',
caption: 'This is the content of the "caption" field.',
description: 'This is the content of the "description" field, below the caption.',
message: ''
},
function(response) {
     if (response && response.post_id) {
     //  alert('Post was published.');
     } else {
      // alert('Post was not published.');
     }
   }
);
});
//

//
//     $('.profile_pic_sec').share({
//        networks: ['pinterest','facebook','googleplus','twitter','linkedin','email'],
//        data:window.location.href
//      // urlToShare:
//    });
     //$(".loading").hide();
     $('textarea .watermark').autogrow();
     $('.jDisplayReply').hide();
    $('#jDisplayInviteGrp').hide();
    /*
      * About profile
      */
     //jmessage
      if(location.hash=='#Friends'){
         $('#myTab li.active').removeClass('active');
        $('.jShowFriends ').addClass('active');
        $( ".jShowFriends" ).trigger('click');
    }
    
    $('#jMorephotos').click(function(){
         $('#myTab li.active').removeClass('active');
        $('.jShowFriends ').addClass('active');
        $( ".jShowFriends" ).trigger('click');
    })
    
    
     if(location.hash=='#Gallery'){
         $('#myTab li.active').removeClass('active');
        $('.jshowtimeline ').addClass('active');
         setTimeout(function () {
            $(".jshowtimeline").trigger("click");
        }, 10);
        //$( ".jshowtimeline" ).trigger('click');
    }
    $('#jMoreGallery').click(function(){
         $('#myTab li.active').removeClass('active');
        $('.jshowtimeline ').addClass('active');
        $( ".jshowtimeline" ).trigger('click');
    })
    
    
    
     $('.jShowProfile ,#jProfile').click(function(){
        $('#jDivDisplayEdit').hide();
        $('#tagg-business').hide();
        $("#tab-Friends").hide();
        $("#jFeedSearch").hide();
        $('#myprofile').show();
        $( "#myprofile" ).removeClass( "fade" ).addClass( "active in" );
        var uid=$(this).attr('uid');
        var alias   =$(this).attr('alias');
        $.blockUI({ message: '' }); 
        $.ajax({
            type    : "POST",
            url     : mainUrl+"myprofile",
            data    : 'uid='+uid+"&alias="+alias,
            cache   : false,
            success : function(data){
               //  $(".jfeedtimelinedisplay_div").hide();
                $('#jMyProfile').html(data);
                $(".jfeedtimelinedisplay_div").hide();
                $("#jMyProfile").show();
                $(".jGallary_div").hide();
                $(".jfeeddisplay_div").hide();
                $(".jpost_comment_div").hide();
                $(".jFriends_div").hide();
                if($('.member_prof_abt_row').find('.member_prof_abt_col1:contains(Country)').length>0){
                    var country = $('.member_prof_abt_row').find('.member_prof_abt_col1:contains(Country)').parent().children('.member_prof_abt_col3').html();
                    if(country.length>0){
                         country = country.trim();
                    }

                    if(country=='UK'){
                        $('.member_prof_abt_row').find('.member_prof_abt_col1:contains(Zip Code)').html('Postal Code');
                    }else{
                        $('.member_prof_abt_row').find('.member_prof_abt_col1:contains(Zip Code)').html('Zip Code');
                    }
                }
                if(location.hash=='#Edit'){
                    $(".jedit").trigger("click");
                }
            }
        }); 
     });
     
     
     setTimeout(function() {
        $("#jmessage").hide;
    	},10000);
		 
	$(".content").hide();
	if(CURRENT_USER_ALIAS == LOGGED_USER_ALIAS){
            
            //$("#tab-Feed").show();
	}
	else{
         
//       setTimeout(function() {
//        $(".jShowProfile").trigger( "click" );
//    	},10);
	}
	$("abbr.timeago").timeago();
    //$("#msgDisplay").delay(3200).fadeOut(300);
    //date picker
    $('#user_date_of_birth').datepicker({
        maxDate:-1, 
        changeMonth: true,
        changeYear: true,
        dateFormat: 'mm/dd/yy',
        yearRange: "-100:+0"
    });
    
    /*
     * Tab functionailty
     */
    
    $("a.jtab").click(function () { 
        // switch all tabs off  
        $(".active").removeClass("active");  
          
        // switch this tab on  
        //$(this).addClass("active");
        $(this).parent().addClass("active");
          
        // slide all elements with the class 'content' up  
        $(".content").slideUp();  
          
        // Now figure out what the 'title' attribute value is and find the element with that id.  Then slide that down.  
        var content_show = $(this).attr("title");  
        $("#"+content_show).slideDown();  
        
    });
    
    /*
     * Profile edit
     */
   
    $('.jedit').live('click',function(){
        $(".spn_asterisk").show();
        $(".spn_asterisk").html('');
        $('#jDivDisplayEdit').show();
        $('#jDivDisplayAbout').hide();
        $('#tagged').hide();
    });  
    
    $('#user_country').live('change',function(){
    	var country = $(this).val();
    	if(country=='GB'){
    		$('#user_zipcode').parent().find('.abtlabel > label').text('Postal Code');
    	}else{
    		$('#user_zipcode').parent().find('.abtlabel > label').text('Zip Code');
    	}
    });
    
    $('.jedittag').live('click',function(){
      $("#jMyProfile").hide();
      $("#tagList").hide();
        $('#jDivDisplayEdit').hide();
        $('#jDivDisplayAbout').hide();
        $('#profile-edit').hide();
        $("#tab-Profile").hide();
         $('#tagged').hide();
        $('#tagg-business').show();
    });  
    
 
    //$("#msgDisplay").fadeIn('slow').delay(5000).fadeOut(5000);

    /*
     * Profile update
     */
   $('#jUpdate').click(function(){
       
    if($("#frmprofile_edit").valid()){
        var user_firstname       = $("#user_firstname").val();
        var user_lastname       = $("#user_lastname").val();
        var user_email          = $("#user_email").val();
        var user_date_of_birth  = $("#user_date_of_birth").val();
        var user_address        = $("#user_address").val();
        var user_city           = $("#user_city").val();
        var user_gender         = $("#user_gender").val();
        var user_state          = $("#user_state").val();
        var user_country        = $("#user_country").val();
        var user_phone          = $("#user_phone").val();
        var user_zipcode        = $("#user_zipcode").val();
        var user_id             = $("#user_id").val();
        var user_alias          = $("#user_alias").val();
        var user_privacy        = $("#user_privacy").val();
        var dataString          = 'user_firstname='+ user_firstname +'&user_lastname='+user_lastname+'&user_email='+user_email+'&user_date_of_birth='+user_date_of_birth+'&user_address='+user_address+'&user_city='+user_city+'&user_state='+user_state+'&user_country='+user_country+'&user_phone='+user_phone+'&user_zipcode='+user_zipcode+'&user_privacy='+user_privacy+'&user_id='+user_id+'&user_gender='+user_gender;
//        if(user_firstname==''){
//            $("#spn_asterisk_cnamemsg").html('Please enter first name');
//            return false;
//        }
//        if(user_lastname==''){
//            $("#spn_asterisk_clnamemsg").html('Please enter last name');
//            return false;
//        }
//        if(user_email==''){
//            $("#spn_asterisk_emailmsg").html('Please enter email');
//            return false;
//        }
        
        
      // else{ 
            $.blockUI({ message: '' });
       $.ajax({
            type    : "POST",
            dataType: 'json',
            url     : mainUrl+"timeline/"+user_alias+"/ajaxTrue",
            data    : dataString,
            cache   : false,
            success : function(data){
                if(data.cls == 'success_div'){
                   $('#jDivDisplayEdit').hide();
                   $.ajax({
                        type    : "POST",
                        url     : mainUrl+"myprofile",
                        data    : 'uid='+user_id+'&alias='+user_alias,
                        cache   : false,
                        success : function(data){
                            $('#jMyProfile').html(data);
                        }
                    }); 
                }
                //$("$jtimelinepic_user").html(user_firstname+" "+user_lastname)
                $('#msgDisplay').removeClass();
                $('#msgDisplay').html(data.msg);
                $('#msgDisplay').addClass(data.cls);
		$('#msgDisplay').fadeIn('fast');
                $("#jMyProfile").hide();
                 $('.spn_asterisk').hide();
                setTimeout(function() {$('#msgDisplay').fadeOut('fast');
				}, 5000);
                $("html, body").animate({ scrollTop: '0px' }, 1000);
                location.reload();
            }
        });
    } 
     })
     
     
     
     
     /*
      * List friends
      */
     
     $('.jShowFriends').click(function(){
        var uid=$(this).attr('uid');
        var alias   =$(this).attr('alias');
        var groupby   =$(this).attr('groupby');
        $( "#myprofile" ).hide();
        $("#jFeedSearch").hide();
        $.blockUI({ message: '' }); 
        $.ajax({
            type    : "POST",
            url     : mainUrl+"listfriends",
            data    : 'uid='+uid+"&alias="+alias+"&groupby="+groupby,
            cache   : false,
            success : function(data){
//                $('#tab-Friends').html(data);
//                $('#tab-Friends').show();
//                $(".jShowFriends_tab").show();
//                $(".Jtabfriends_data").hide();
            $(".jfeedtimelinedisplay_div").hide();
            $(".jfeeddisplay_div").hide();
            $('.jFriends_div').html(data);
            $('.jFriends_div').show();
            $("#jMyProfile").hide();
            $(".jGallary_div").hide();
            $(".jpost_comment_div").hide();
        
                
            }
        }); 
     });
     
     
        $('.jshowtimeline').click(function(){
        var uid=$(this).attr('uid');
        var alias   =$(this).attr('alias');
        var groupby   =$(this).attr('groupby');
        $( "#myprofile" ).hide();
        $("#jFeedSearch").hide();
        $.blockUI({ message: '' }); 
        $.ajax({
            type    : "POST",
            url     : mainUrl+"my-gallary",
            data    : 'uid='+uid+"&alias="+alias+"&groupby="+groupby,
            cache   : false,
            success : function(data){
//                $('#tab-Friends').html(data);
//                $('#tab-Friends').show();
//                $(".jShowFriends_tab").show();
//                $(".Jtabfriends_data").hide();
            $(".jfeedtimelinedisplay_div").hide();
            $(".jfeeddisplay_div").hide();
            $('.jGallary_div').html(data);
            $('.jGallary_div').show();
             $(".jpost_comment_div").hide();
            $("#jMyProfile").hide();
            $(".jFriends_div").hide();
                
            }
        }); 
     });
     /*
      *  friends
      */
     
     $('.jUnfriend').live('click',function(){
         if(confirm("Are you sure you want to unfriend?")){
           if($(this).data('clicked') == 'yes')return;
         $(this).data('clicked', 'yes');
        var uid=$(this).attr('uid');
        $.blockUI({ message: '' }); 
        $.ajax({
            type    : "POST",
            url     : mainUrl+"unfriend",
            data    : 'uid='+uid,
            cache   : false,
            success : function(data){
            	 $('#jmessage').html('Friend is removed...');
                 $('#jmessage').addClass('success_div');
                 location.reload();
                 //window.location.href = mainUrl+"profile";
                setTimeout(function() {
                $(".jShowFriends").trigger( "click" );
                },10);
               
            }
        });   
         }
    	 
     });
     
      $('#jAffilateRequest').live('click',function(){
         var user_id         =$(this).attr('uid');
            var business_id     =$(this).attr('bid');
            $.blockUI({ message: '' }); 
            $.ajax({
                type    :   'POST',
                url     : mainUrl+'user/affiliate_request',
                data    : 'user_id='+user_id+'&business_id='+business_id,
                cache   : false,
                success : function(data){
                     $('#jmessage').html("Affiliation request sent");
                    $('#jmessage').addClass("success_div");
                    $('#affiliatediv_'+user_id).html('<font color="red">Pending</font>');
                return false;
                    
                }
            })
    });
     
    /*
     * States display on country change
     */
    
    var stateHtml       = $("#user_state").html(); 
    var countryVal      = $("#user_country").val();
    var userId          = $("#user_id").val();
    if(countryVal != 'US' && countryVal != 'IN' && $("#user_country").val() != 'CA' ){ 
       
        $("#user_state").parent().html("<div class='abtlabel'></div><input class='form-control' type='text' name='user_state' id='user_state' />&nbsp");
        $.get(mainUrl+'cmshelper/ajaxGetUserState/'+userId, function(result) {
            $('#user_state').val(result);
        });
    }else{ 
            $.get(mainUrl+'cmshelper/ajaxGetStatesByCountryUser/'+$("#user_country").val()+'/'+userId+'/edit', function(result) {
                $("#user_state").parent().html("<div class='abtlabel'></div><select class='form-control' name='user_state' id='user_state'>"+result+"</select>&nbsp");
            });
        }

    $("#user_country").live("change", function() {

        if($("#user_country").val() != 'US' && $("#user_country").val() != 'IN' && $("#user_country").val() != 'CA' ){
            $("#user_state").parent().html("<div class='abtlabel'></div><input class='form-control' type='text' name='user_state' id='user_state' />&nbsp");
            $.get(mainUrl+'cmshelper/ajaxGetUserState/'+userId, function(result) {
                $('#user_state').val(result);
            });
        }
        else{  
            $.get(mainUrl+'cmshelper/ajaxGetStatesByCountryUser/'+$("#user_country").val(), function(result) {
                $("#user_state").parent().html("<div class='abtlabel'></div><select class='form-control' name='user_state' id='user_state'>"+result+"</select>&nbsp ");
            });
        }
    });
    
    setTimeout(function() {
        $("#jmessage").hide;
    	},10000);
    $('#jInviteFriends').live('click',function(){
      $('#jDisplayInviteGrp').show();
      $("#jDisplayInviteMain").hide();
       // $("#jDivEmail").hide();
    })
    
    $("#jBackToMainInvite").live('click',function(){
         $("#jDisplayInviteMain").show();
         $('#jDisplayInviteGrp').hide();
    });
    
    $("#jBackToSubInvite").live('click',function(){
         $('#jDisplayInviteMail').hide();
         $('#jDisplayInviteGrp').show();
    });
    
    $('#jdisplayEmailOption').live('click',function(){
        //$('#jDisplayInviteGrp').hide();
        $('#jDisplayInviteGrp').hide();
        $('#jDisplayInviteMail').show();
    })
    
    $('#jFeedSearch').change(function(){
        var alias =$(this).attr('alias');
        window.location = mainUrl+"timeline/"+alias+"/?search=" + $(this).val();
    });
    $('#jbusiness_community_type').change(function(){
        //alert("here");
        var alias =$(this).attr('alias');
        window.location = mainUrl+"timeline/"+alias+"/?business_type=" + $(this).val();
    });
    //-------------like button click----------
    $('.jLikeFeed').live('click',function(){
        $.blockUI({ message: '' }); 
        var community_id    =   $(this).attr('cid');
        var announcement_id =   $(this).attr('aid');
        var old = $('#jcountlike_'+announcement_id).html().split(' ');
        var old_val = old[0];
        if(old_val == ''){
            old_val = 0;
        }
       // alert(old_val);
        $.ajax({
            type    :'POST',
            url     : mainUrl+'user/postMyLike',
            data    :'community_id='+community_id+'&announcement_id='+announcement_id,
            dataType : 'json',
            cache    : false,
                success : function(data){
                    
                    if(data.count != '1 Like' && data.count != '1 Likes' && old_val>0){
                      old_val = old_val - 1;  
                    }
                    else{
                       old_val = Number(old_val) + 1;  
                    }
                   //$('#jlike_'+announcement_id).html(data.type);
                    $('#jlike_'+announcement_id).removeClass();
                   if(data.classtype==''){
                      $('#jlike_'+announcement_id).addClass('unliked jLikeFeed'); 
                   }
                   else{
                     $('#jlike_'+announcement_id).addClass(data.classtype+' jLikeFeed');  
                   }
                  
                   $('#jcountlike_'+announcement_id).html(old_val+' Likes');
                }
        });
        return false;
    })
    
       $('.jLikeAdminFeed').live('click',function(){
        $.blockUI({ message: '' }); 
        var community_id    =   $(this).attr('cid');
        var admin_announcement_id =   $(this).attr('aid');
       // alert(admin_announcement_id);
        $.ajax({
            type    :'POST',
            url     : mainUrl+'user/postMyLikeAdmin',
            data    :'admin_announcement_id='+admin_announcement_id,
            dataType : 'json',
            cache    : false,
                success : function(data){
                   // alert(data.count);
                   //$('#jlike_'+announcement_id).html(data.type);
                    $('#jlikeadmin_'+admin_announcement_id).removeClass();
                   if(data.classtype==''){
                      $('#jlikeadmin_'+admin_announcement_id).addClass('unliked jLikeFeed'); 
                   }
                   else{
                     $('#jlikeadmin_'+admin_announcement_id).addClass(data.classtype+' jLikeFeed');  
                   }
                  
                   
                   $('#jcountlikeadmin_'+admin_announcement_id).html(data.count); 
                }
        })
        return false;
    })
    
    //------------share button click-----------
    $('.jShareFeed').live('click',function(){
        $.blockUI({ message: '' }); 
        var community_id    =   $(this).attr('cid');
        var announcement_id =   $(this).attr('aid');
        $.ajax({
            type    :'POST',
            url     : mainUrl+'user/shareFeed',
            data    :'community_id='+community_id+'&announcement_id='+announcement_id,
            dataType : 'json',
            cache    : false,
                success : function(data){
                   $('#jmessage').html('Shared with your friends successfully'); 
                   $('#jmessage').addClass('success_div');
                    $('#jcountshare_'+announcement_id).html(data.count); 
                }
        })
    })
   //--------Join button click---------- 
    $('.jFeedCommunityJoin').live('click',function(){
        var community_id        = $(this).attr('cid');
        var type                = 'join';
        var dataString          = 'community_id='+community_id +'&type='+type;
        $(this).attr('disabled','disabled'); 
        $("#loading").show();
        $.ajax({
            type    : "POST",
            dataType: 'json',
            url     : mainUrl+"index/joingroup",
            data    : dataString,
            cache   : false,
            success : function(data){
               if(data.status=='SUCCESS')
                   {
                       $("#jDisplayCommunityJoin").html(data.message);
                       $("#loading").hide();
                   }else{
                  }
             }
        });
    })
    
    //--------------Post comments-----
    $('body').on('click','.jPostCommentButton',function(){
        var id = $('#image_id').val();
        var comment_id          = $(this).attr('cmid');
        var announcement_id     = $(this).attr('aid');
        var community_id        = $(this).attr('cid');
        var count = $('#reply_'+comment_id).val();
        var new_count = Number(count)+1;
        //console.log(comment_id)
        if(comment_id>0){
            var comments            = $.trim($("#watermark_"+announcement_id+'_'+comment_id).val());
        }
        else{
          var comments              = $.trim($("#watermark_"+announcement_id).val());  
        }
        $.ajax({
            type: 'POST',
            url: mainUrl + 'user/postfeedcomment',
            data: 'announcement_id=' + announcement_id + '&comments=' + comments + '&community_id=' + community_id + '&comment_id=' + comment_id + '&image_id=' + id,
            cache: false,
            success: function (data) {
                console.log(data);
                if (comment_id > 0) {
                    var comments = $('#jcountreply_' + comment_id).html().split(' ');
                    var numcomments = Number(comments[0]) + 1;
                    // alert(numcomments);
                    $('#postingReply_' + comment_id).prepend(data);
                    $("#watermark_" + comment_id).val("");
                    $('#jcountreply_' + comment_id).html(new_count + ' Replies');
                    //$('#'+comment_id).text(new_count+' Replies');
                }
                else {
                    // alert(data);
                    var comments = $('#jcountcomment_' + announcement_id).html().split(' ');
                    var numcomments = Number(comments[0]) + 1;
                    $('#posting_' + announcement_id).prepend(data);
                    $("#watermark_" + announcement_id).val("");
                    $('#jcountcomment_' + announcement_id).html(numcomments + ' Comments');
                    $('.emoji-wysiwyg-editor').html('');
                }
                $('#reply_' + comment_id).val(new_count);
                magnificPopupSingleFn();
                $(".register_form").remove();
                $(".emoji-wysiwyg-editor .fa-camera").html(" ");
                return false;
            }
        });
    });
  //---------Delete post comment------  
  $('body').on('click','.jFeedCommentDelete',function(){
        var comment_id        = $(this).attr('id');
        var announcement_id     = $(this).attr('aid');
        var dataString          = 'comment_id='+comment_id+'&announcement_id='+announcement_id;
        $(this).attr('disabled','disabled'); 
        $("#loading_"+announcement_id).show();
        $.ajax({
            type    : "POST",
            url     : mainUrl+"user/feedCommentDelete",
            data    : dataString,
            cache   : false,
            success : function(data){
                $("#loading_"+announcement_id).show();
                $('.jCommentDisplayDiv #posting_'+announcement_id+' #jdivComment_'+comment_id).remove();
               //$('#jdivComment_'+comment_id).remove();
               $('#jcountcomment_'+announcement_id).html(data+' comments');
               
             }
           
        });
        //  window.location.reload();
        return false;
    }) 
    
    $('body').on('click','.jNewsFeedCommentDelete',function(){
        var comment_id        = $(this).attr('id');
        var announcement_id     = $(this).attr('aid');
        var dataString          = 'comment_id='+comment_id+'&announcement_id='+announcement_id;
        $(this).attr('disabled','disabled'); 
        $("#loading_"+announcement_id).show();
        $.ajax({
            type    : "POST",
            url     : mainUrl+"user/newsFeedCommentDelete",
            data    : dataString,
            cache   : false,
            success : function(data){
                $("#loading_"+announcement_id).show();
                $('.jCommentDisplayDiv #posting_'+announcement_id+' #jdivComment_'+comment_id).remove();
              //  $('.jCommentDisplayDiv #posting_'+announcement_id+' #jdivComment_'+comment_id).remove();
               //$('#jdivComment_'+comment_id).remove();
               $('#jcountcomment_'+announcement_id).html(data+' comments');
               
             }
           
        });
        //  window.location.reload();
        return false;
    }) 
    
        $('body').on('click','.jOrgFeedCommentDelete',function(){
           // alert("jdkjgd");exit;
        var comment_id        = $(this).attr('id');
        var announcement_id     = $(this).attr('aid');
        var dataString          = 'comment_id='+comment_id+'&announcement_id='+announcement_id;
        $(this).attr('disabled','disabled'); 
        $("#loading_"+announcement_id).show();
        $.ajax({
            type    : "POST",
            url     : mainUrl+"user/orgFeedCommentDelete",
            data    : dataString,
            cache   : false,
            success : function(data){
                $("#loading_"+announcement_id).show();
                $('.jCommentDisplayDiv #posting_'+announcement_id+' #jdivComment_'+comment_id).remove();
              //  $('.jCommentDisplayDiv #posting_'+announcement_id+' #jdivComment_'+comment_id).remove();
               //$('#jdivComment_'+comment_id).remove();
               $('#jcountcomment_'+announcement_id).html(data+' comments');
               
             }
           
        });
        //  window.location.reload();
        return false;
    }) 
    
    $('.jNewsFeedReplyDelete').live('click',function(){
        var comment_id        = $(this).attr('id');
        var announcement_id     = $(this).attr('aid');
        var dataString          = 'comment_id='+comment_id+'&announcement_id='+announcement_id;
        var x = $('#reply_'+announcement_id).val();
        x = x-1;
        //alert(announcement_id);
        //exit;
      //  alert($('#jcountreply_'+announcement_id).innerHTML);
        $(this).attr('disabled','disabled'); 
       $("#loading_"+announcement_id).show();
        $.ajax({
            type    : "POST",
            url     : mainUrl+"user/newsFeedReplyDelete",
            data    : dataString,
            cache   : false,
            success : function(data){
                $("#loading_"+announcement_id).hide();
                $('#jcountreply_'+announcement_id).html(x+' Replies');
                $('#reply_'+announcement_id).val(x);
               // console.log ("jgj"+announcement_id);
                $('#jdivComment_'+comment_id).hide();
               // $('#jcountreply_'+announcement_id).html(" ");
               
              //  $('#jcountreply_'+announcement_id).innerHTML("6 Replies");
               //$('#jdivComment_'+comment_id).remove();
              // $('#jcountcomment_'+announcement_id).html(data+' comments');
               
             }
           
        });
         // window.location.reload();
        return false;
    })
    
        $('.jOrgReplyDelete').live('click',function(){
        var comment_id        = $(this).attr('id');
        var announcement_id     = $(this).attr('aid');
        var dataString          = 'comment_id='+comment_id+'&announcement_id='+announcement_id;
        var x = $('#reply_'+announcement_id).val();
        x = x-1;
        //alert(announcement_id);
        //exit;
      //  alert($('#jcountreply_'+announcement_id).innerHTML);
        $(this).attr('disabled','disabled'); 
       $("#loading_"+announcement_id).show();
        $.ajax({
            type    : "POST",
            url     : mainUrl+"user/OrgFeedReplyDelete",
            data    : dataString,
            cache   : false,
            success : function(data){
                $("#loading_"+announcement_id).hide();
                $('#jcountreply_'+announcement_id).html(x+' Replies');
                $('#reply_'+announcement_id).val(x);
               // console.log ("jgj"+announcement_id);
                $('#jdivComment_'+comment_id).hide();
               // $('#jcountreply_'+announcement_id).html(" ");
               
              //  $('#jcountreply_'+announcement_id).innerHTML("6 Replies");
               //$('#jdivComment_'+comment_id).remove();
              // $('#jcountcomment_'+announcement_id).html(data+' comments');
               
             }
           
        });
         // window.location.reload();
        return false;
    })
    //------------show comment box---------
    $('.jCommentButton').live('click',function(){
        var announcemnet_id     = $(this).attr('aid');
        //alert(announcemnet_id);
       $('#jCommentBoxDisplayDiv_'+announcemnet_id).toggle();
       if($("#val_"+announcemnet_id).val()>0){
       $('#jCommentDisplayDiv_'+announcemnet_id).toggle();
   }
       return false;
    })
    
    //---------Load more comments------
    $('#jMorecommentsButton').live('click',function(){
        var announcement_id = $(this).attr('aid');
        var pagenum         = $(this).attr('pid');
        $(this).hide();
         $.ajax({
                type    :'POST',
                url     : mainUrl+'user/loadMoreFeedComments',
                data    :'announcement_id='+announcement_id+'&pagenum='+pagenum,
                cache    : false,
                success : function(data){
                    $('#posting_'+announcement_id).append(data);
                    //exit;
                }
            })
        return false;
    })
    //----------------Comment Like------------
     $('.jFeedCommentLike').live('click',function(){
        var announcement_id     = $(this).attr('aid');
        var comment_id           = $(this).attr('cid');
         $.ajax({
                type    :'POST',
                url     : mainUrl+'user/postCommentLike',
                data    :'announcement_id='+announcement_id+'&comment_id='+comment_id,
                dataType : 'json',
                cache    : false,
                success : function(data){
                    //console.log(data);
                   //$('#jlike_'+announcement_id).html(data.type); 
                   $('#jlikeComment_'+comment_id).removeClass();
                   if(data.classtype==''){
                      $('#jlikeComment_'+comment_id).addClass('unliked jFeedCommentLike'); 
                   }
                   else{
                     $('#jlikeComment_'+comment_id).addClass(data.classtype+' jFeedCommentLike');  
                   }
                   $('#jcountcommentlike_'+comment_id).html(data.count); 
                }
        })
      return false;  
    })
    
        //----------------Newsfeed Comment Like------------
     $('.jNewsFeedCommentLike').live('click',function(){
        var newsfeed_id     = $(this).attr('aid');
        var newsfeed_comment_id           = $(this).attr('cid');
         $.ajax({
                type    :'POST',
                url     : mainUrl+'user/postNewsfeedCommentLike',
                data    :'newsfeed_id='+newsfeed_id+'&newsfeed_comment_id='+newsfeed_comment_id,
                dataType : 'json',
                cache    : false,
                success : function(data){
                    //console.log(data);
                   //$('#jlike_'+announcement_id).html(data.type); 
                   $('#jlikeComment_'+newsfeed_comment_id).removeClass();
                   if(data.classtype==''){
                      $('#jlikeComment_'+newsfeed_comment_id).addClass('unliked jNewsFeedCommentLike'); 
                   }
                   else{
                     $('#jlikeComment_'+newsfeed_comment_id).addClass(data.classtype+' jNewsFeedCommentLike');  
                   }
                   
                   $('#jcountfeedcommentlike_'+newsfeed_comment_id).html(data.count); 
                }
        })
      return false;  
    })
    
    $('.jDeleteTagged').live('click',function(){
        //alert("dfjf");exit;
        var id=$(this).attr('id');
       
        $.blockUI({ message: '' }); 
        $.ajax({
            type    : "POST",
            url     : mainUrl+"user/deletetagged",
            data    : 'id='+id,
            cache   : false,
            success : function(data){
              //  alert(data);exit;
//                $('#tab-Friends').html(data);
//                $('#tab-Friends').show();
//                $(".jShowFriends_tab").show();
//                $(".Jtabfriends_data").hide();
           $("#tagged_"+id).remove();
           if($('div.tagged').length <1)
           {
             $(".tagged_msg").html('No pages found.');
           }
           else{
                $(".tagged_msg").html('');
           }
        
                
            }
        }); 
     });
    //------------------Reply------------------
    $('body').on('click', '.jFeedCommentReply', function () {
        var comment_id = $(this).attr('cid');
        $('.jDisplayReply').hide();
        $('.jCommentDisplayDiv #jdivReply_' + comment_id).toggle();
        return false;
    })

    $(".jworkflow_div").on('click',function(){

     var mlink=mainUrl+"user/work_flow";
     $.colorbox({width:"500px", height:"450px", iframe:true, href:mlink, overlayClose: false});
     return false;
});

    //-------------like button click----------
    $('.jLikeNewsFeed').live('click',function(){
        $.blockUI({ message: '' }); 
        var news_feed_id    =   $(this).attr('cid');
       // var announcement_id =   $(this).attr('aid');
//        var old = $('#jcountlike_'+announcement_id).html().split(' ');
       // var old_val = old[0];
        var old_val = '';
//        if(old_val == ''){
//            old_val = 0;
//        }
       // alert(old_val);
        $.ajax({
            type    :'POST',
            url     : mainUrl+'user/postMyNewsfeedLike',
            data    :'news_feed_id='+news_feed_id,
            dataType : 'json',
            cache    : false,
                success : function(data){
                    
//                    if(data.count != '1 Like' && data.count != '1 Likes'){
//                      old_val = old_val - 1;  
//                    }
//                    else{
//                       old_val = Number(old_val) + 1;  
//                    }
//                   //$('#jlike_'+announcement_id).html(data.type);
//                    $('#jlike_'+announcement_id).removeClass();
                   if(data.classtype==''){
                      $('#jlike_'+news_feed_id).removeClass('liked'); 
                      $('#jlike_'+news_feed_id).addClass('unliked'); 
                   }
                   else{
                        $('#jlike_'+news_feed_id).removeClass('unliked'); 
                     $('#jlike_'+news_feed_id).addClass(data.classtype);  
                   }
                  
                   $('#jcountlike_'+news_feed_id).html(data.count);
                }
        });
        return false;
    });
    
//    $('body').on('click','.jShowReply',function(){
//        var comment_id =$(this).attr('id');
//        var replyexist =$('#postingReply_'+comment_id).text().length;
//       if(replyexist >0){
//          $('#postingReply_'+comment_id).toggle();
//          return false
//       }
//       else{
//        $.ajax({
//                type    :'POST',
//                url     : mainUrl+'user/showCommentReply',
//                data    :'comment_id='+comment_id,
//                cache    : false,
//                success : function(data){
//                        var comments     =$('#jcountreply_'+comment_id).html().split(' ');
//                        var numcomments = Number(comments[0])+1;
//                        $('#postingReply_'+comment_id).prepend(data);
//                        $("#watermark_"+comment_id).val("");
//                }
//            })
//       }
//        return false;
//    });  


    $('body').on('click', '.jShowFeedReply', function () {
        console.info('Clicked Feed Comment Replty');
        var comment_id = $(this).attr('id');
        var replyexist = $('#postingReply_' + comment_id).text().length;
        if (replyexist > 0) {
            $('#postingReply_' + comment_id).toggle();
            return false
        }
        else {
            $.ajax({
                type: 'POST',
                url: mainUrl + 'user/showfeedcommentreply',
                data: 'comment_id=' + comment_id,
                cache: false,
                success: function (data) {

                    var html = $.parseHTML(data);
                    enableEmojiOn(html);

                    $('#postingReply_' + comment_id).prepend(html);
                    $("#watermark_" + comment_id).val("");
                }
            })
        }
        return false;
    });

   
    
     $('.jCommentImageUpload').live('change', function(){
        var announcement_id = $(this).attr('aid');
        $(".jCommentImagePreview").html('');
        $("#jCommentImagePreview_"+announcement_id).html('<img src="loader.gif" alt="Uploading...."/>');
//         var data1 =new FormData(this);
//         console.log(data1);
        //$("#jCommentImageForm_"+announcement_id).submit
        $("#jCommentImageForm_"+announcement_id).ajaxForm({
            target: '#jCommentImagePreview_'+announcement_id
        }).submit();
//        var announcement_id = $(this).attr('aid');
//         $(".jCommentImageForm").submit();
    });
    
    $('.jShowFeeds').on('click',function(){
         $(".jfeeddisplay_div").show();
          $(".jpost_comment_div").show();
        $(".jfeedtimelinedisplay_div").show();
        $("#jMyProfile").hide();
        $(".jGallary_div").hide();
        $(".jFriends_div").hide();
        
        $('#jDivDisplayEdit').hide();
        $('#tagg-business').show();
        $("#jFeedSearch").show();
        $('#myprofile').hide();
    })

    $('.jNewsfeedCommentButton').live('click', function () {

        var news_feed_id = $(this).attr('aid');
        $('#jNewsfeedCommentBoxDisplayDiv_' + news_feed_id).toggle();
        if($("#val_"+news_feed_id).val()>0){
        $('#jNewsfeedCommentDisplayDiv_' + news_feed_id).toggle();
    }
        return false;
    });

    $('.jtxtSearchProdAssign').keyup(function (e) {
        var key = e.which;
        if (key == 13)  // the enter key code
        {
            var id = $('#image_id').val();
            var comment_id = $(this).attr('cmid');
            var announcement_id = $(this).attr('aid');
            var community_id = $(this).attr('cid');
            var count = $('#reply_' + comment_id).val();
            var new_count = Number(count) + 1;
            var valu = "#watermark_" + announcement_id;
            var comments;
            if (comment_id > 0) {
                comments = $.trim($("#watermark_" + announcement_id + '_' + comment_id).val());
            }
            else {
                comments = $.trim($("#watermark_" + announcement_id).val());
            }
            $.ajax({
                type: 'POST',
                url: mainUrl + 'user/postnewsfeedcomment',
                data: 'news_feed_id=' + announcement_id + '&comments=' + comments + '&community_id=' + community_id + '&comment_id=' + comment_id + '&image_id=' + id,
                cache: false,
                success: function (data) {
                    if (comment_id > 0) {
                        var comments = $('#jcountreply_' + comment_id).html().split(' ');
                        var numcomments = Number(comments[0]) + 1;
                        // alert(numcomments);
                        $('#postingReply_' + comment_id).append(data);
                        $("#watermark_" + comment_id).val("");
                        $('#jcountreply_' + comment_id).html(new_count + ' Replies');
                        //$('#'+comment_id).text(new_count+' Replies');
                    }
                    else {
                        var comments = $('#jcountcomment_' + announcement_id).html().split(' ');
                        var numcomments = Number(comments[0]) + 1;
                        $('#posting_' + announcement_id).append(data);
                        $("#watermark_" + announcement_id).val("");
                        $('#jcountcomment_' + announcement_id).html(numcomments + ' Comments');
                        $('.emoji-wysiwyg-editor').html('');
                    }
                    $('#reply_' + comment_id).val(new_count);
                    magnificPopupSingleFn();
                    $(".register_form").remove();
                    $(".emoji-wysiwyg-editor .fa-camera").html(" ");
                    return false;
                }
            })
        }
    });

    /**
     * Post comments and replies to comments
     */
    $('body').on('click', '.jPostNewsfeedCommentButton', function (e) {
        $.blockUI({ message: '' }); 
        e.preventDefault();
        var id = $('#image_id').val();
        var comment_id = $(this).attr('cmid');
        var announcement_id = $(this).attr('aid');
        var community_id = $(this).attr('cid');
        var count = $('#reply_' + comment_id).val();
        var new_count = Number(count) + 1;
        var comments = '';
        if (comment_id > 0) {
            var comments = $.trim($("#watermark_" + announcement_id + '_' + comment_id).val());
        }
        else {
            var comments = $.trim($("#watermark_" + announcement_id).val());
        }
        if (!comment_id) {
            if (comments == '' && isNaN(id)) {
                $("#msg_display_" + announcement_id).html('Please enter comments/images');
                $("#msg_display_" + announcement_id).addClass('error_div');
                return false;
            }
        } else {
            if (comments == '' && isNaN(id)) {
                $("#msg_display_" + comment_id).html('Please enter comments/images');
                $("#msg_display_" + comment_id).addClass('error_div');
                return false;
            }
        }

       

        // function to handle success data on comment post
        var successCallBack = function (data) {
            $('#jdivReply_'+comment_id).unblock();
            var html = $.parseHTML(data);
            enableEmojiOn(html);

            $('#image_id').remove();
            $(".member_profile_pic").html('');
            $("#watermark_" + announcement_id + '_' + comment_id).val('');
            $("#watermark_" + announcement_id).val('');
            if (comment_id > 0) {
                var comments = $('#jcountreply_' + comment_id).html().split(' ');
                var numcomments = Number(comments[0]) + 1;
                $('#jNewsfeedCommentDisplayDiv_' + announcement_id).show();
                $('#postingReply_' + comment_id).prepend(html);
                $("#watermark_" + comment_id).val("");
                $('#jcountreply_' + comment_id).html(new_count + ' Replies');
                $(".emoji-wysiwyg-editor").html('');
            }
            else {
                var comments = $('#jcountcomment_' + announcement_id).html().split(' ');
                var numcomments = Number(comments[0]) + 1;
                $('#jNewsfeedCommentDisplayDiv_' + announcement_id).show();
                $('#posting_' + announcement_id).prepend(html);
                $("#watermark_" + announcement_id).val("");
                $('#jcountcomment_' + announcement_id).html(numcomments + ' Comments');
                $('.emoji-wysiwyg-editor').html('');
            }
            $('#reply_' + comment_id).val(new_count);
            $(".register_form").remove();
            $(".emoji-wysiwyg-editor .fa-camera").html(" ");
            return false;
        };

        if (comment_id > 0) {
            comments = $.trim($("#watermark_" + announcement_id + '_' + comment_id).val());
        } else {
            comments = $.trim($("#watermark_" + announcement_id).val());
        }

        var submitUrl = 'user/postnewsfeedcomment';
        var data = 'news_feed_id=' + announcement_id + '&comments=' + comments + '&community_id=' + community_id + '&comment_id=' + comment_id + '&image_id=' + id;
       //  $('#jdivReply_'+comment_id).block({ message:null });
        postCommentContents(submitUrl, data, successCallBack);
    });

});

function mutual_friends(user_id, session_id){
            // $( "#myprofile" ).hide();
        $.blockUI({ message: '' }); 
        $.ajax({
            type    : "POST",
            url     : mainUrl+"user/listmutualfriends",
            data    : 'user_id='+user_id+"&session_id="+session_id,
            cache   : false,
            success : function(data){
                  $(".jfeedtimelinedisplay_div").hide();
            $(".jfeeddisplay_div").hide();
            $('.jFriends_div').html(data);
            $('.jFriends_div').show();
            $("#jMyProfile").hide();
            $(".jGallary_div").hide();
            $(".jpost_comment_div").hide();
                 
            }
        });    
    }
    
//    var globalFacebookShareObject = {} //will be set when I click on a product, on a picture, on a comment or post, or whatever I want to share on Facebook or when I load the page

function shareOnFacebook(){
   //    FB.ui({
//        method: 'feed',
//        name: 'Image Share',
//        link: 'https://iscriptsdemo.com/bbf/'
//       // caption: 'R$ '+globalFacebookShareObject.caption,
//       // picture: globalFacebookShareObject.picture,
//      //  description: globalFacebookShareObject.description
//    }, function(response) {
//        if(response && response.post_id){}
//        else{}
//    });
FB.ui({ method: 'feed', link: 'https://connect10.iscriptsdemo.com/', caption: 'An example caption',redirect_uri: 'https://connect10.iscriptsdemo.com/'}, function(response){});
}

 $(function(){


$("i#jcam").bind('click',function() {
    $("#jtimelinepic").trigger('click');
});

$("i#jcamProfile").bind('click',function() {
    $("#file_profile").trigger('click');
});


 // Initiate upload flow on file selection of group timeline background image
 $('#jtimelinepic').change(function () {
     var uploadUrl = 'user/timelineimageupload/';
    validImageMaximumAndMinimumCheck('jtimelinepic', 2000, 452, 1140, 258, uploadUrl, 'cover-wrapper');
    //validImageCheck('jtimelinepic', 1140, 258, uploadUrl, 'cover-wrapper');
 });

 $('#file_profile').bind('change', function () {
     var uploadUrl = 'index/addProfilePic/'+$("#user_id").val();
     validImageCheck('file_profile',150, 150, uploadUrl,'timeline_left_pic');
 });

    
    $('.jNewsfeedDeletetButton').live('click', function () {
        if(confirm("This post will be deleted. Are you sure to continue?")){
        //  var comment_id        = $(this).attr('id');
        var announcement_id = $(this).attr('aid');
        var dataString = 'announcement_id=' + announcement_id;
        $(this).attr('disabled', 'disabled');
        $("#loading_" + announcement_id).show();
        $.ajax({
            type: "POST",
            url: mainUrl + "user/newsfeeddelete",
            data: dataString,
            cache: false,
            success: function (data) {
                $("#loading_" + announcement_id).hide();
                $('#news_feed_' + announcement_id).remove();
                //$('#jdivComment_'+comment_id).remove();
                //  $('#jcountcomment_'+announcement_id).html(data+' comments');

            }

        });
        //  window.location.reload();
      //  return false;
    }
     return false;
    })
    
    $('.jProfileDeletetButton').live('click', function () {
      //  alert("here");exit;
    if (confirm("Your profile picture will be deleted. Are you sure to continue?")) {
        //  var comment_id        = $(this).attr('id');
//        var announcement_id = $(this).attr('aid');
//        var dataString = 'announcement_id=' + announcement_id;
        $(this).attr('disabled', 'disabled');
//        $("#loading_" + announcement_id).show();
        $.ajax({
            type: "POST",
            url: mainUrl + "user/profiledelete",
            data: '',
            cache: false,
            success: function (data) {
                window.location.reload();
                //$('#jdivComment_'+comment_id).remove();
                //  $('#jcountcomment_'+announcement_id).html(data+' comments');

            }

        });
        //  window.location.reload();

    }
    return false;
})

$(".jShowFeedLikeUsers").live('mouseover',function(){
    var id = $(this).attr("id");
    var news_feed_id = id.split("_");
    $("#feed_like_users_"+news_feed_id[1]).toggle();
});

$(".jShowOrgLikeUsers").live('mouseover',function(){
    var id = $(this).attr("id");
    var news_feed_id = id.split("_");
    $("#org_like_users_"+news_feed_id[1]).toggle();
});

$(".jShowGroupLikeUsers").live('mouseover',function(){
    var id = $(this).attr("id");
    var news_feed_id = id.split("_");
    $("#group_like_users_"+news_feed_id[1]).toggle();
});

 });
function processJson1(){
  alert("helloooooooo")  ;
}
//$('#jfrmtimelineimageupload').submit(function(){
//    $(this).ajaxSubmit()
//})


//Sticky js
//function sticky_relocate() {
//    var window_top = $(window).scrollTop();
//    var div_top = $('#sticky-anchor').offset().top;
//    if (window_top > div_top) {
//        $('#sticky').addClass('stick');
//        $('#sticky-anchor').height($('#sticky').outerHeight());
//    } else {
//        $('#sticky').removeClass('stick');
//        $('#sticky-anchor').height(0);
//    }
//}

$(function() {
//    $(window).scroll(sticky_relocate);
//    sticky_relocate();
});

var dir = 1;
var MIN_TOP = 200;
var MAX_TOP = 350;

function autoscroll() {
    var window_top = $(window).scrollTop() + dir;
    if (window_top >= MAX_TOP) {
        window_top = MAX_TOP;
        dir = -1;
    } else if (window_top <= MIN_TOP) {
        window_top = MIN_TOP;
        dir = 1;
    }
    $(window).scrollTop(window_top);
    window.setTimeout(autoscroll, 100);
}
function nl2br(string1) { 
    console.log(string1);
string1 = string1.replace("\r\n", "<br>"); 
string1 = string1.replace("\r", "<br>"); 
string1 = string1.replace("\n", "<br>"); 
return string1; 
} 