    <?php if ($D->is_my_group) {?>
    
    <div id="areabjoing">
    	<div id="bteditprofile" class="bfriendly hand"><?php echo $this->lang('profile_group_editprofile'); ?></div>
    </div>

    <script>
        $('#bteditprofile').click(function(){
            location.href = siteurl + "dashboard/groups/edit/g:<?php echo $D->group->code?>";
        });
    </script>            
    
    <?php } else { ?>

    <div id="areabjoing">
        <div id="bactionjoin" class="<?php echo(($D->membership==0 || $D->membership==1)?'bfriendly2':'bfriendly')?>" <?php if ($D->membership==1) { ?> style="background-image:url(<?php echo $C->SITE_URL.'themes/'.$C->THEME.'/imgs/ico-check-black.png'?>); background-repeat:no-repeat; background-position:7px 8px;"<?php } ?>>
        <?php
        if ($D->membership==0) echo($this->lang('profile_areamember_join'));
        if ($D->membership==1) { echo('&nbsp;&nbsp;&nbsp;'.$this->lang('profile_areamember_joined')); }
        if ($D->membership==2) echo($this->lang('profile_areamember_pending'));
        ?>
        </div>
        <div id="preload-friend" class="hide"><img src="<?php echo $C->SITE_URL?>themes/<?php echo $C->THEME?>/imgs/loading.gif"></div>
        <input name="membership" type="hidden" id="membership" value="<?php echo $D->membership?>">
        <div id="smn1" class="boxsubmenu hide">
            <div id="opc-leavegroup" class="opcsm"><?php echo $this->lang('profile_areamember_leave');?></div>
        </div>
    
        <div id="smn2" class="boxsubmenu hide">
            <div id="opc-cancelrequest" class="opcsm"><?php echo $this->lang('profile_areamember_cancelrequest');?></div>
        </div>

	</div>

   	<?php if ($D->is_logged) { ?>

    <script>
	var dsm1, dsm2;
	var msg_norequest = '<?php echo $this->lang('dashboard_no_request')?>';
	var idgroup = <?php echo $D->group->idgroup; ?>;
	
	$('#bactionjoin').mouseover(function(){
		if ($('#membership').val() != 0) {
			$('#bactionjoin').css('cursor','default');
			$('#bactionjoin').css('background-color','#6D84B4');
			$('#bactionjoin').css('color','#FFF');
			
			if ($('#membership').val() == 1) {
				$('#bactionjoin').css('background-image','url(<?php echo $C->SITE_URL.'themes/'.$C->THEME.'/imgs/ico-check-white.png'?>)');
				$('#bactionjoin').css('background-repeat','no-repeat');
				$('#bactionjoin').css('background-position','7px 8px');
			}
			
		} else {
			$('#bactionjoin').css('cursor','pointer');
		}
		
		if ($('#membership').val() != 0) {
			showSmn('#smn' + $('#membership').val());
		}

	});
	
	$('#bactionjoin').mouseleave(function(){
		
		if ($('#membership').val() != 0) {
			
			hideSmn('#smn' + $('#membership').val());
		
		}
	});
	
	function keepSmnVisible() {
		clearInterval(dsm2);
	}
	
	function hideSmn(submenu) {
		clearInterval(dsm1);
		dsm2 = setInterval(function() {
			if ($('#membership').val() != 0) {
				$('#bactionjoin').css('cursor','default');
				$('#bactionjoin').css('background-color','#F3F4F6');
				$('#bactionjoin').css('color','#333');
				
				if ($('#membership').val() == 1) {
					$('#bactionjoin').css('background-image','url(<?php echo $C->SITE_URL.'themes/'.$C->THEME.'/imgs/ico-check-black.png'?>)');
					$('#bactionjoin').css('background-repeat','no-repeat');
					$('#bactionjoin').css('background-position','7px 8px');
				}
			} else {
				$('#bactionjoin').css('cursor','default');
			}
			$(submenu).hide();
			clearInterval(dsm2);	
		},200);
	}
	
	function hideSmnFast(submenu, value) {
		clearInterval(dsm1);
		clearInterval(dsm2);
		if ($('#membership').val() != 0) {
			$('#bactionjoin').css('cursor','default');
			$('#bactionjoin').css('background-color','#F3F4F6');
			$('#bactionjoin').css('color','#333');
		} else {
			$('#bactionjoin').css('cursor','default');
		}
		$(submenu).hide();
		$('#membership').val(value);
	}
	
	function showSmn(submenu) {
		clearInterval(dsm2);
		dsm1 = setInterval(function() {
			$(submenu).show();
		},50);
	}
	
	$('#smn1, #smn2').mouseover(function() {
		keepSmnVisible();
	});

	$('#smn1').mouseleave(function() {
		hideSmn('#smn1');
	});

	$('#smn2').mouseleave(function() {
		hideSmn('#smn2');
	});

	
	//////////////////////////////
	//Action CANCEL Request Group
	$('#opc-cancelrequest').click(function(){

		$('#bactionjoin').hide();
		$('#preload-friend').show();
		
		$.ajax({
			type: 'POST',
			url: siteurl + "ajax/members-actions/r:" + Math.round(Math.random()*1000),
			data: 'todo=2&idg=' + idgroup,
			success: function(resp){
				switch(resp.charAt(0)){
					case '0':
						alert(resp.substring(3));
						break;
					case '1':
						hideSmnFast('#smn2',0);
						$('#bactionjoin').html('<?php echo $this->lang('profile_areamember_join')?>');
						break;
					}
			},
			error: function(){
				alert(msg_norequest);
			} //end error
		}); // end ajax	
		
		$('#bactionjoin').show();
		$('#preload-friend').hide();			

		return false;
	});
	
	//////////////////////////////
	//Action LEAVE Group
	$('#opc-leavegroup').click(function(){		
		
		$('#bactionjoin').hide();
		$('#preload-friend').show();
		
		$.ajax({
			type: 'POST',
			url: siteurl + "ajax/members-actions/r:" + Math.round(Math.random()*1000),
			data: 'todo=3&idg=' + idgroup,
			success: function(resp){ 
				switch(resp.charAt(0)){
					case '0':
						alert(resp.substring(3));
						break;
					case '1':
						$('#spaceFollow').hide();
						hideSmnFast('#smn1',0);
						$('#bactionjoin').html('<?php echo $this->lang('profile_areamember_join')?>');
						$('#nummembers').html(parseInt($('#nummembers').html()) - 1);
						break;
					}
			},
			error: function(){
				alert(msg_norequest);
			} //end error
		}); // end ajax	
		
		$('#bactionjoin').show();
		$('#preload-friend').hide();
		
		return false;
	});
	
	//////////////////////////////
	// action SENT REQUEST GROUP
	$('#bactionjoin').click(function(){

		if ($('#membership').val() == 0) {
			
			$('#bactionjoin').hide();
			$('#preload-friend').show();
			
			$.ajax({
				type: 'POST',
				url: siteurl + "ajax/members-actions/r:" + Math.round(Math.random()*1000),
				data: 'todo=1&idg=' + idgroup,
				success: function(resp){
					switch(resp.charAt(0)){
						case '0':
							alert(resp.substring(3));
							break;
						case '1':
							$('#bactionjoin').html('<?php echo $this->lang('profile_areamember_pending')?>');
							$('#membership').val(2);
							break;
						}
				},
				error: function(){
					alert(msg_norequest);

				} //end error
			}); // end ajax	
			
			$('#bactionjoin').show();
			$('#preload-friend').hide();			
			return false;
		}
		
	});
	
	</script>

	<?php } else { ?>

    <div id="msgnotloggedin" class="hide">
		<div class="only-redbox"><?php echo $this->lang('profile_areafollow_youmustbe');?> <span class="linkblue"><a href="<?php echo $C->SITE_URL?>"><?php echo $this->lang('profile_areafollow_signed');?></a></span>.</div>
    </div>

	<script> 
	
	$('#bactionjoin').mouseover(function(){
		if ($('#membership').val() == 0) {
			$('#bactionjoin').css('cursor','pointer');
		}
	});
	
	$('#bactionjoin').one('click',function(){
	
		$("#areabjoing").fadeOut("slow",function(){
			$("#areabjoing").hide(function(){
				$("#msgnotloggedin").fadeIn('slow');
			});
		});			
	
	});  
	</script>
	
	<?php } //end isloged ?>
    

	<?php } // end is my group ?>
