function loadTrashComponents() {
	if (!AfianHandler.components['TrashBaseMenu'].loaded) {
		loadComponentData('TrashBaseMenu');
	}
	if (!AfianHandler.components['TrashContextMenus'].loaded) {
		loadComponentData('TrashContextMenus');
	}
}

function openTrash() {
	loadTrashComponents();
	focusOpened = false;
		for (var i = 0 ; i < AfianHandler.allTabs.length; i++) {
			if (AfianHandler.allTabs[i] != undefined) {
				if (AfianHandler.allTabs[i].section == 'trash') {
					AfianHandler.allTabs[i].load();
					focusOpened = true;
					break;
				}
			}
		}
	if (!focusOpened) {
		trash = new Afian_Tab(AfianMessages['Trash'], 'trash@afian', 'images/tree/trash.gif');
		trash.viewMode = 'list';
		trash.section = 'trash';
		trash.onload = TrashOnLoad;
		trash.onselect = TrashOnSelect;
		trash.baseMenu = 'TrashBaseMenu';
		trash.detailHTML = AfianHandler.TrashDetailsTemplate;
		trash.load();
		trash.Trash_Browse();
	}
}

function TrashOnLoad() {
	loadTrashComponents();
	if (AfianHandler.activeTab == this) {
	AfianHandler.showBaseMenu('TrashBaseMenu');
	AfianHandler.hideBaseMenu('MyFilesBaseMenu');
	AfianHandler.hideBaseMenu('SearchBaseMenu');
	AfianHandler.hideBaseMenu('MySharesBaseMenu');
	AfianHandler.hideBaseMenu('BShareBaseMenu');
	AfianHandler.hideBaseMenu('BrowseZipBaseMenu')
	
	/*admin stuff*/
	AfianHandler.hideBaseMenu('AdmGroupsBaseMenu');
	AfianHandler.hideBaseMenu('AdmUsersBaseMenu');
	AfianHandler.hideBaseMenu('AdmLogsBaseMenu');
	
	if (activeMenu) {
		hideMenu(activeMenu);
	}
	toggleTreeByPath('trash@afian');
	AfianHandler.titleBar.innerHTML = AfianHandler.activeTab.title;
	TrashStatusBar();
	}
}


function TrashStatusBar() {
	if (AfianHandler.activeTab.countSelected == 0) {
		if (AfianHandler.activeTab.countAll == 0) {
			if (AfianHandler.activeTab.browsed) {
			AfianHandler.statusBar.innerHTML = AfianMessages['Trash empty'];
			} else {
			AfianHandler.statusBar.innerHTML = AfianMessages['Accessing Trash...'];
			}
		} else {
		AfianHandler.statusBar.innerHTML =  AfianMessages['%1 deleted objects (%2)'].replace('%1', AfianHandler.activeTab.countAll).replace('%2', formatFileSize(AfianHandler.activeTab.totalSize));
		}
	} else if (AfianHandler.activeTab.countSelected == 1) {
		AfianHandler.statusBar.innerHTML =  AfianMessages['One object selected (%1)'].replace('%1', formatFileSize(AfianHandler.activeTab.selSize));
	} else {
		AfianHandler.statusBar.innerHTML =  AfianMessages['%1 objects selected (%2)'].replace('%1', AfianHandler.activeTab.countSelected).replace('%2', formatFileSize(AfianHandler.activeTab.selSize));
	}
}

function TrashOnSelect() {
	showfuncname = showMenu;
	hidefuncname = hideMenu;
if (AfianHandler.components['TrashContextMenus'].loaded) {
	if (this.countSelected == 0) {
		hidefuncname('afian_trash_context_dir');
		hidefuncname('afian_trash_context_file');
		hidefuncname('afian_trash_context_multiple');
	} else if (this.countSelected == 1) {
		sel = this.selectedItem();
		
		if (sel.isdir) {
		showfuncname('afian_trash_context_dir');
		hidefuncname('afian_trash_context_file');
		hidefuncname('afian_trash_context_multiple');
		} else {
		showfuncname('afian_trash_context_file');
		hidefuncname('afian_trash_context_dir');
		hidefuncname('afian_trash_context_multiple');
		}

	} else {
		showfuncname('afian_trash_context_multiple');
		hidefuncname('afian_trash_context_dir');
		hidefuncname('afian_trash_context_file');
	}
}
	TrashStatusBar();
}



function TrashRestore() {
	tb = AfianHandler.activeTab;
	fromtabid = tb.id;
	document.hiddenForm.action='?file=trashacting';
	document.hiddenForm.action += '&act=restore';
	document.hiddenForm.action += '&fromtabid='+fromtabid;
	fillHiddenFormItemList();
	document.hiddenForm.target = 'hifrm_'+fromtabid;
	if (document.hiddenForm.itemlist.value.length > 1) {
	tb.unselectAll();
	tb.showHourGlass();
	document.hiddenForm.submit();
	}
}

function TrashDelete() {
	tb = AfianHandler.activeTab;
	fromtabid = tb.id;
	document.hiddenForm.action='?file=trashacting';
	document.hiddenForm.action += '&act=delete';
	document.hiddenForm.action += '&fromtabid='+fromtabid;
	fillHiddenFormItemList();
	document.hiddenForm.target = 'hifrm_'+fromtabid;
	if (document.hiddenForm.itemlist.value.length > 1) {
	tb.unselectAll();
	tb.showHourGlass();
	document.hiddenForm.submit();
	}
}

function EmptyTrash() {
	tb = AfianHandler.activeTab;
	document.hiddenForm.action='?file=trashacting';
	document.hiddenForm.action += '&act=empty';
	document.hiddenForm.action += '&fromtabid='+tb.id;
	document.hiddenForm.target = 'hifrm_'+tb.id;
	document.hiddenForm.submit();
	tb.showHourGlass();
}