
function openAdmUsers(gid, gname) {
	if (!gid) {
		selected = AfianHandler.activeTab.selectedItem();
	}
	gid = gid?gid:selected.input_value;
	gname = gname?gname:selected.icon_title;
	if (!AfianHandler.components['AdmUsersBaseMenu'].loaded) {
		window.setTimeout('loadComponentData(\'AdmUsersBaseMenu\', \'gid='+gid+'\')', 300);
	}
	if (!AfianHandler.components['AdmUsersMenus'].loaded) {
			window.setTimeout('loadComponentData(\'AdmUsersMenus\')', 300);
	}
	if (!AfianHandler.components['AdmUsersContextMenus'].loaded) {
		window.setTimeout('loadComponentData(\'AdmUsersContextMenus\')', 300);
	}
	focusOpened = false;
		for (var i = 0 ; i < AfianHandler.allTabs.length; i++) {
			if (AfianHandler.allTabs[i] != undefined) {
				if (AfianHandler.allTabs[i].section == 'admin-users') {
					if (AfianHandler.allTabs[i].gid == gid) {
						AfianHandler.allTabs[i].load();
						focusOpened = true;
						break;
					}
				}
			}
		}
	
	if (!focusOpened) {
		users = new Afian_Tab(AfianMessages['\"%1\" user group'].replace('%1', gname), 'admin_users@afian', 'images/tree/groups.gif');
		users.viewMode = 'list';
		users.section = 'admin-users';
		users.onload = AdmUsersOnLoad;
		users.onselect = AdmUsersOnSelect;
		users.baseMenu = 'AdmUsersBaseMenu';
		users.detailHTML = AfianHandler.AdmUsersTemplate;
		users.load();
		users.gid = gid;
		users.gname = gname;
		users.AdmUsers_Browse(gid);
	}
}



function AdmUsersOnLoad() {
	tb = AfianHandler.activeTab;
	if (tb == this) {
	/* show the menu */
	AfianHandler.showBaseMenu('AdmUsersBaseMenu');
	AfianHandler.hideBaseMenu('AdmGroupsBaseMenu');
	AfianHandler.hideBaseMenu('MyFilesBaseMenu');
	AfianHandler.hideBaseMenu('TrashBaseMenu');
	AfianHandler.hideBaseMenu('SearchBaseMenu');
	AfianHandler.hideBaseMenu('MySharesBaseMenu');
	AfianHandler.hideBaseMenu('BShareBaseMenu');
	AfianHandler.hideBaseMenu('BrowseZipBaseMenu');
		if (activeMenu) {
			hideMenu(activeMenu);
		}
	
	/* toggle the tree */
	toggleTreeByPath('admin_groups@afian');
	/* change the title */
	AfianHandler.titleBar.innerHTML = tb.title;
		if (!tb.showHG) {
		AdmUsersStatusBar();
		} else {
		tb.showHourGlass();
		}
	}
}


function AdmUsersStatusBar() {
	tb = AfianHandler.activeTab;
	if (tb.countSelected == 0) {
		if (tb.countAll == 0) {
			if (AfianHandler.activeTab.browsed) {
			AfianHandler.statusBar.innerHTML = AfianMessages['Group empty'];
			} else {
			AfianHandler.statusBar.innerHTML = AfianMessages['Listing users...'];
			}
		} else {
		AfianHandler.statusBar.innerHTML =  AfianMessages['%1 users'].replace('%1', tb.countAll);
		}
	} else if (tb.countSelected == 1) {
		AfianHandler.statusBar.innerHTML =  AfianMessages['One user selected'];
	} else {
		AfianHandler.statusBar.innerHTML =  AfianMessages['%1 users selected'].replace('%1', tb.countSelected);
	}
}

function AdmUsersOnSelect() {
	showfuncname = showMenu;
	hidefuncname = hideMenu;
if (AfianHandler.components['AdmUsersContextMenus'].loaded) {
	if (this.countSelected == 0) {
		hidefuncname('afian_admusers_contextmenu');
		hidefuncname('afian_admusers_context_multiple');
	} else if (this.countSelected == 1) {
		showfuncname('afian_admusers_contextmenu');
		hidefuncname('afian_admusers_context_multiple');
	} else {
		showfuncname('afian_admusers_context_multiple');
		hidefuncname('afian_admusers_contextmenu');
	}
}
	AdmUsersStatusBar();
}

function AdmUsersDeletePrompt() {

	hideMenu('afian_admusers_contextmenu');
	hideMenu('afian_admusers_context_multiple');

	b = new Array;
	b[0] = new Array;
	b[0]['title'] = AfianMessages['Ok'];
	b[0]['onclick'] = 'AdmUsersDelete()';
	b[1] = new Array;
	b[1]['title'] = AfianMessages['Cancel'];
	b[1]['onclick'] = 'hideMenu(\'popmenu-prompt\');AfianHandler.activeTab.onselect()';
	AfianPrompt(AfianMessages['user delete notice'], b);
}

function AdmUsersDelete() {
	hideMenu('popmenu-prompt');
	tb = AfianHandler.activeTab;
	if (!tb.isBusy()) {
	document.hiddenForm.action='?admin=1&section=users&sub=acting';
	document.hiddenForm.action += '&act=delete';
	document.hiddenForm.action += '&tabid='+tb.id;
	document.hiddenForm.action += '&gid='+tb.gid;
	document.hiddenForm.target = 'hifrm_'+tb.id;
	fillHiddenFormItemList();
	tb.unselectAll();
	if (document.hiddenForm.itemlist.value.length > 1) {
		document.hiddenForm.submit();
		tb.showHourGlass();
		/* timers */
		tabStartTimer(tb);
	}
	}
}


function AdmUsersTransferPrompt() {
hideMenu('afian_admusers_contextmenu');
hideMenu('afian_admusers_context_multiple');
centeredMenu('popmenu-adm_users_transfer');
}

function AdmUsersTransfer() {
	hideMenu('popmenu-adm_users_transfer');
	tb = AfianHandler.activeTab;
	if (!tb.isBusy()) {
	document.hiddenForm.action = '?admin=1&section=users&sub=acting';
	document.hiddenForm.action += '&act=transfer';
	document.hiddenForm.action += '&tabid='+tb.id;
	document.hiddenForm.action += '&fromgid='+tb.gid;
	document.hiddenForm.action += '&togid='+document.getElementById('transfer2gid').value;
	document.hiddenForm.target = 'hifrm_'+tb.id;
	fillHiddenFormItemList();
	tb.unselectAll();
	if (document.hiddenForm.itemlist.value.length > 1) {
		document.hiddenForm.submit();
		tb.showHourGlass();
		/* timers */
		tabStartTimer(tb);
	}
	}
}

function AdmUsersViewActivityLog() {
centeredMenu('popmenu-activity_logs');
AdminLoadCalendar(AfianHandler.activeTab.selectedItem().input_value);
}

function AdmUsersSummary(uid) {
uid = uid?uid:AfianHandler.activeTab.selectedItem().input_value;
popup(baseURL+'?file=adm_user_summary&uid='+uid, 'summary', '650', '600', 'yes');
}


function AdmUsersEditUser() {
	selected = AfianHandler.activeTab.selectedItem();
	popup(baseURL+'?admin=1&sub=edituser&uid='+selected.input_value, 'edit_user', 500, 680, 'yes');
}


function AdmUsersEndAction(tb) {
	if (tb != undefined) {
		if (tb.active) {
			AdmUsersStatusBar();
		}
		tb.hideHourGlass();
		cancelTimeOut(tb.id);
	}
}