
function openAdmGroups() {
	if (!AfianHandler.components['AdmGroupsBaseMenu'].loaded) {
		loadComponentData('AdmGroupsBaseMenu');
	}
	if (!AfianHandler.components['AdmGroupsContextMenus'].loaded) {
		loadComponentData('AdmGroupsContextMenus');
	}
	focusOpened = false;
		for (var i = 0 ; i < AfianHandler.allTabs.length; i++) {
			if (AfianHandler.allTabs[i] != undefined) {
				if (AfianHandler.allTabs[i].section == 'admin-groups') {
					AfianHandler.allTabs[i].load();
					focusOpened = true;
					break;
				}
			}
		}
	
	if (!focusOpened) {
		groups = new Afian_Tab(AfianMessages['Admin: Groups'], 'admin_groups@afian', 'images/tree/admin.gif');
		groups.viewMode = 'list';
		groups.singleSelection = true;
		groups.section = 'admin-groups';
		groups.onload = AdmGroupsOnLoad;
		groups.onselect = AdmGroupsOnSelect;
		groups.baseMenu = 'AdmGroupsBaseMenu';
		groups.detailHTML = AfianHandler.AdmGroupsTemplate;
		groups.load();
		groups.AdmGroups_Browse();
	}
}

function AdmGroupsOnLoad() {
	tb = AfianHandler.activeTab;
	if (tb == this) {
	/* show the menu */
	AfianHandler.showBaseMenu('AdmGroupsBaseMenu');
	AfianHandler.hideBaseMenu('AdmUsersBaseMenu');
	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(this.basepath);
	/* change the title */
	AfianHandler.titleBar.innerHTML = this.title;
		if (!this.showHG) {
		AdmGroupsStatusBar();
		} else {
		this.showHourGlass();
		}
	}
}

function AdmGroupsStatusBar() {
	tb = AfianHandler.activeTab;
	if (tb.countSelected == 0) {
		if (tb.countAll == 0) {
			if (tb.browsed) {
			AfianHandler.statusBar.innerHTML = AfianMessages['server problem'];
			} else {
			AfianHandler.statusBar.innerHTML = AfianMessages['listing groups'];
			}
		} else {
		if (tb.countAll == 1) {
			AfianHandler.statusBar.innerHTML =  AfianMessages['one group'];
		} else {
			AfianHandler.statusBar.innerHTML =  AfianMessages['%1 groups'].replace('%1', tb.countAll);
		}
		}
	} else if (tb.countSelected == 1) {
		AfianHandler.statusBar.innerHTML = AfianMessages['Group %1 selected'].replace('%1', tb.selectedItem().icon_title);
	}
}

function AdmGroupsOnSelect() {
	showfuncname = showMenu;
	hidefuncname = hideMenu;
if (AfianHandler.components['AdmGroupsContextMenus'].loaded) {
	if (this.countSelected == 0) {
		hidefuncname('afian_admgroups_contextmenu');
	} else {
		showfuncname('afian_admgroups_contextmenu');
	}
}
	AdmGroupsStatusBar();
}


function AdmGroupsAddUser(gid) {
gid = gid?gid:AfianHandler.activeTab.selectedItem().input_value;
popup(baseURL+'?admin=1&sub=adduser&tabid='+AfianHandler.activeTab.id+'&gid='+gid, 'add_user', '600', '700', 'yes');
}

function AdmGroupsAdd() {
popup(baseURL+'?admin=1&sub=addgroup&tabid='+AfianHandler.activeTab.id, 'add_group', '600', '680', 'yes');
}

function AdmGroupsEdit() {
popup(baseURL+'?admin=1&sub=editgroup&gid='+AfianHandler.activeTab.selectedItem().input_value, 'edit_group', '500', '680', 'yes');
}

function AdmGroupsDeletePrompt(gid) {
	hideMenu('afian_admgroups_contextmenu');

	gid = gid?gid:AfianHandler.activeTab.selectedItem().input_value;
	b = new Array;
	b[0] = new Array;
	b[0]['title'] = 'Ok';
	b[0]['onclick'] = 'AdmGroupsDelete(\''+gid+'\')';
	b[1] = new Array;
	b[1]['title'] = AfianMessages['Cancel'];
	b[1]['onclick'] = 'hideMenu(\'popmenu-prompt\');AfianHandler.activeTab.onselect()';
	AfianPrompt(AfianMessages['group delete notice'], b);
}
function AdmGroupsDelete(gid) {
	hideMenu('popmenu-prompt');
	tb = AfianHandler.activeTab;
	if (!tb.isBusy()) {
	document.hiddenForm.action='?admin=1&section=groups&sub=acting';
	document.hiddenForm.action += '&act=delete';
	document.hiddenForm.action += '&tabid='+tb.id;
	document.hiddenForm.action += '&gid='+gid;
	document.hiddenForm.target = 'hifrm_'+tb.id;
	tb.unselectAll();
		document.hiddenForm.submit();
		tb.showHourGlass();
		/* timers */
		tabStartTimer(tb);
	}
}