/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


$( window ).load(function() {
		  // alert(CUR_SESSION_USER_ALIAS);
    
    $(".jaddfriend").live("click",function () { 
    	var a =$('.friends_btn').removeClass('jaddfriend');
        // switch all tabs off  
       var uid=$(this).attr('uid');
       $("#loading_"+uid).show();
//       $.blockUI({ message: '' }); 
	 //alert(uid)  ;
	   $.ajax({
            type    : "POST",
	    dataType: 'json',
            url     : mainUrl+"user/sendfriendrequest",
            data    : 'fid='+uid,
            cache   : false,
            success : function(data){
				if(data.cls == 'success'){
                                    $('#jFriend_'+uid).html('Friend request sent');
                                        var a =$('.friends_btn').removeClass('jaddfriend');
				}
				else{
					var a =$('.friends_btn').addClass('jaddfriend');
					$('#msgDisplay').removeClass();
                $('#msgDisplay').html(data.msg);
				$('#msgDisplay').addClass(data.cls);
				$('#msgDisplay').fadeIn('fast');
                setTimeout(function() {
					$('#msgDisplay').fadeOut('fast');
				}, 5000);
					
				}
			$("#loading_"+uid).hide();	
			}
              
        });
        
   
    });
    
    $(".jaddfriend1").live("click",function () { 
        // switch all tabs off  

       var uid=$(this).attr('uid');
       var inviteid=$(this).attr('inviteid');
       $("#loading_"+uid).show();
       $.blockUI({ message: '' }); 
//	 alert(uid);
	   $.ajax({
            type    : "POST",
	    dataType: 'json',
            url     : mainUrl+"user/acceptfriendrequest",
            data    : 'fid='+uid+'&inviteid='+inviteid,
            cache   : false,
            success : function(data){
				if(data.cls == 'success'){ 

                                    $('#jFriend_'+uid).html('Friends');                               
                                    var a =$('.friends_btn').removeClass('jaddfriend1');
                                    var c =$('.friends_btn span:first').removeClass('addfriend_icon').addClass('tik_icon');
				}
				else{
					$('#msgDisplay').removeClass();
                $('#msgDisplay').html(data.msg);
				$('#msgDisplay').addClass(data.cls);
				$('#msgDisplay').fadeIn('fast');
                setTimeout(function() {
					$('#msgDisplay').fadeOut('fast');
				}, 5000);
					
				}
				$("#loading_"+uid).hide(); 
			}
	   
        });
        
   
    });
});  

