/*--------------------------------------------------------------------*\
| This file is part of Videocore 3.1                                  *|
|---------------------------------------------------------------------*|
| Copyright (C) 2008 Silversoft Solutions Ltd. All Rights Reserved    *|
| This file may not be redistributed in whole or significant part     *|
| Videocore is not Free Software | http://www.videocore.com           *|
|-------------------------------------------------------------------- *|
| For more information see http://www.videocore.com/license.html      *|
\*--------------------------------------------------------------------*/

var Member =
{
	AddBuddy: function (buddy_id)
	{
		// ##### MAKE AJAX CALL #####
		load_ajax (BASE_URL + 'user.php?ajax=1&do=add_buddy&buddy_id=' + buddy_id, 'Member._addBuddyReturned');
	},

	_addBuddyReturned: function (array)
	{
		// ##### CHECK FOR ERROR #####
		if (ajax_returned_error (array))
		{
			return false;
		}

		// ##### SHOW SUCCESS MESSAGE #####
		Dialog.Message (array['message'][0]);
	},

	Files: function (page, user_id)
	{
		// ##### HIDE CONTENT #####
		Animation.blindUp (get_element ('list[files]'));		
		
		// ##### MAKE AJAX CALL #####
		window.setTimeout (function () { load_ajax (BASE_URL + 'ajax.php?do=member_files&page=' + page + '&id=' + user_id, 'Member._filesReturned'); }, 1500);
		
	},

	_filesReturned: function (array)
	{
		Member._updateContent (array, 'files');
	},

	Comments: function (page, user_id)
	{
		// ##### HIDE CONTENT #####
		Animation.blindUp (get_element ('list[comments]'));
		
		// ##### MAKE AJAX CALL #####
		window.setTimeout (function () { load_ajax (BASE_URL + 'ajax.php?do=member_comments&page=' + page + '&id=' + user_id, 'Member._commentsReturned'); }, 1500);
	},

	_commentsReturned: function (array)
	{
		Member._updateContent (array, 'comments');
	},
	
	_updateContent: function (array, type)
	{
		// ##### UPDATE FILE LIST #####
		var content = array['update'][0][type][0];
		get_element ('list[' + type + ']').innerHTML = content;	
		
		// ##### HIDE CONTENT #####
		Animation.blindDown (get_element ('list[' + type + ']'));	

		// ##### UPDATE PAGE #####
		var page = array['update'][2]['page'][0];
		var pagination = get_element ('pagination[' + type + ']');
		pagination.getElementsByTagName('li')[0].firstChild.innerHTML = page;

		// ##### GET FIRST AND LAST OF PAGINATION #####
		var children = pagination.getElementsByTagName('li');
		var first = pagination.removeChild(children[0]);
		var last = pagination.removeChild(children[children.length - 1]);

		// ##### REMOVE ALL CHILDREN #####
		while (pagination.firstChild)
		{
			var child = pagination.removeChild(pagination.firstChild);
		}

		// ##### ADD LINKS #####
		pagination.appendChild (first);
		for (var link = 0; link < array['update'][1]['links'].length; link++)
		{
			pagination.innerHTML += array['update'][1]['links'][link]['link'][0];
		}
		pagination.appendChild (last);
	}
}

