//group:Add an item as favorite of user
function addToGroup(groupUrl)
{
	$.ajax({
	  type: "POST",
	  url: BASEPATH + "groups/join/" + groupUrl,
	  success: function(msg){
		//alert(msg);
		Boxy.ask(msg, ["Close"], null, {title: "Join Group",closeable:true,closeText:"[Close]"});
		if (msg=='You have successfully joined this group. Enjoy!') {$("#action-join-group").hide(); }
		
	  }
	});
}
//group Is this your group?
function openIsThisYourGroupDialog(group_id) {
	var pos_top =null;
	var pos_left =null;
	$(function() {
		Boxy.load(BASEPATH + "ajaxpopup/group_admin_request", 
				{
					modal:true,fixed:false,title: 'Is this your group',center:true,
					afterShow: function() {
						//var pos = this.getPosition();
							var b = this.boxy[0];
							pos_top = b.offsetTop;
							pos_left = b.offsetLeft;
						},
					behaviours: function(c) {
							
							c.find('#takeoverForm').submit(function() {
								var dataString = $("#takeoverForm").serialize();
								$.ajax({
									type: "POST",
									url: BASEPATH+"groups/takeover",
									data: dataString,
									dataType: "json", 
									success: function(msg) {
										if(msg.success == "1")
										{
											var content = msg.message;
											$('#pop_request').html(content);
											pos_top = pos_top+300;
											pos_left =pos_left +200;
											$('.boxy-wrapper').css({'top': pos_top+'px' ,'left': pos_left+'px'} );
										}
										else
										{
											//failed
											$('#pop_failed').html(msg.message);
										}
									}
								});
								return false;
							});
					}
				},
				{group_id: group_id}	
		);
		
	});
}

//Add an item as favorite of user
function requestPermToJoinGroup(groupUrl)
{
	$.ajax({
	  type: "POST",
	  url: BASEPATH + "groups/request_permission/" + groupUrl,
	  success: function(msg){
		
		if (msg=='Request added!') 
		{
			Boxy.ask("Join request has been succesfully sent to the group owner.", ["Close"], null, {title: "Message",closeable:true,closeText:"[Close]"});
		}
		if (msg=='Problem occurred while adding your request!')
		{
			Boxy.ask("There has been a problem while sending a request to the group owner. Please try again later.", ["Close"], null, {title: "Message",closeable:true,closeText:"[Close]"});
		}
	  }
	});
}