// Javascript Document

var m = new dmenu();

// Wrapper functions

function pm_user(id){
	window.location='user_cp.php?mode=pm&user='+id;
}

function remove_post(id,container){
	var c = confirm("Are you sure you want to remove this post? \n\n All contained replies and subscriptions will also be removed, proceed?");
	if(c){	
		window["r_post_"+id] = new ajax('id='+id,'ajax_delete_post.xml.php','post','xml',window.ajax_response, window.ajax_load, window.ajax_no_data,{ 'id' : "r_post_"+id , 'mode' : 'remove_item' , 'container' : container },{ 'id': "r_post_load_"+id },null,true);
	}
}

function remove_pc2(id,container){
	var c = confirm("Are you sure you want to remove this Category? \n\n All contained posts and memberships will also be removed, proceed?");
	if(c){	
		window["r_pc2_"+id] = new ajax('id='+id,'ajax_delete_pc2.xml.php','post','xml',window.ajax_response, window.ajax_load, window.ajax_no_data,{ 'id' : "r_pc2_"+id , 'mode' : 'remove_item' , 'container' : container },{ 'id': "r_pc2_load_"+id },null,true);
	}
}


function remove_item(table,type,id,prefix,user_ref_col,container){
	var c = confirm("Are you sure you want to remove this "+type+" ?");
	if(c){	
		window["r_"+table+"_"+id] = new ajax('id='+id+'&table='+table+'&prefix='+prefix+'&user_ref_col='+user_ref_col,'ajax_remove_item.xml.php','post','xml',window.ajax_response, window.ajax_load, window.ajax_no_data,{ 'id' : "r_"+table+"_"+id , 'mode' : 'remove_item' , 'container' : container },{ 'id': "r_load_"+table+"_"+id },null,true);
	}
}

function remove_user(id){
	var c = confirm("Are you sure you want to remove this user?");
	if(c){	
		window["r_"+id] = new ajax('id='+id,'ajax_friend_request.xml.php','get','xml',window.ajax_response, window.ajax_load, window.ajax_no_data,{ 'id' : 'r_a_'+id , 'mode' : 'fl_friendship_modification' },{ 'id': 'fl_load' },null,true);
	}
}

function block_user(id,no_reload,load_id){
	var c = confirm("Are you sure you want to block / unblock this user?");
	if(c){
		var response_args = { 'id' : 'b_a_'+id };
		var load_id = (load_id) ? load_id : 'fl_load' ;
		if(no_reload!=true){ response_args.mode = 'fl_friendship_modification'; }
		window["b_"+id] = new ajax('id='+id,'ajax_block_user.xml.php','get','xml',window.ajax_response, window.ajax_load, window.ajax_no_data,response_args,{ 'id': load_id },null,true);
	}
}

function friend_add_remove(id){
	var c = confirm("Are you sure you want to add / remove this user?");
	if(c){	
		window["f_"+id] = new ajax('id='+id,'ajax_friend_request.xml.php','get','xml',window.ajax_response, window.ajax_load, window.ajax_no_data,{ 'id': 'f_a_'+id },{ 'id': 'f_load_'+id },null,true);
	}
}

function p_block_user(id,user){
	var c = confirm("Are you sure you want to block / unblock this user?");
	if(c){
		// Block Control
		window["b_"+user+"_"+id] = new ajax("id="+user,'ajax_block_user.xml.php','get','xml',window.ajax_response, window.ajax_load, window.ajax_no_data,{ 'id': 'b_a_'+user+'_'+id, 'mode' : 'group', 'grp_prefix' : 'b_a_'+user+'_' },{ 'id': 'f_load_'+user+'_'+id },null,true);		
	}
}

function p_friend_add_remove(id,user){
	var c = confirm("Are you sure you want to add / remove this user?");
	if(c){
		//Friend Control
		window["f_"+user+"_"+id] = new ajax("id="+user,'ajax_friend_request.xml.php','get','xml',ajax_response, ajax_load, ajax_no_data,{ 'id': 'f_a_'+user+'_'+id, 'mode' : 'group', 'grp_prefix' : 'f_a_'+user+'_' },{ 'id': 'f_load_'+user+'_'+id },null,true);			
	}
}

function reload_friend_list(){
	//define new object
	window.rfl = new ajax('','ajax_friend_list.xml.php','get','xml',window.ajax_response_fl, window.ajax_load_fl, window.ajax_no_data_fl,null,null,null,true);
	//close any open menus
	if(window.m.active){
		window.m.close_or();
	}
}