function loadSearchComponents() {
	if (!AfianHandler.components['SearchBaseMenu'].loaded) {
		window.setTimeout('loadComponentData(\'SearchBaseMenu\')',300);
	}
	if (!AfianHandler.components['SearchContextMenus'].loaded) {
		window.setTimeout('loadComponentData(\'SearchContextMenus\')',300);
	}
}

function MyFilesSearch() {
	loadSearchComponents();
	search = new Afian_Tab(AfianMessages['Search'], '', 'images/icons/taskbar/search.gif');
	search.viewMode = 'list';
	search.section = 'search';
	search.singleSelection = true;
	search.q = '';
	search.frompath = AfianHandler.activeTab.basepath;
	search.detailHTML = AfianHandler.SearchDetailsTemplate;
	search.onload = MyFilesSearchOnLoad;
	search.onselect = SearchOnSelect;
	search.baseMenu = 'SearchBaseMenu';
	search.load();
}

function MyFilesSearchOnLoad() {
	loadSearchComponents();
	if (AfianHandler.activeTab == this) {
	AfianHandler.showBaseMenu('SearchBaseMenu');
	AfianHandler.hideBaseMenu('MyFilesBaseMenu');
	AfianHandler.hideBaseMenu('TrashBaseMenu');
	AfianHandler.hideBaseMenu('MySharesBaseMenu');
	AfianHandler.hideBaseMenu('BShareBaseMenu');
	AfianHandler.hideBaseMenu('BrowseZipBaseMenu');
		/*admin stuff*/
	AfianHandler.hideBaseMenu('AdmGroupsBaseMenu');
	AfianHandler.hideBaseMenu('AdmUsersBaseMenu');
	AfianHandler.hideBaseMenu('AdmLogsBaseMenu');
	
	if (activeMenu) {
		hideMenu(activeMenu);
	}
	
	AfianHandler.titleBar.innerHTML = AfianMessages['Search'];
		if (AfianHandler.components['SearchBaseMenu'].loaded) {
		searchFromDisplay = document.getElementById('searchFrom');
		searchFromDisplay.innerHTML = AfianHandler.activeTab.frompath;
		searchFromDisplay.title = AfianHandler.activeTab.frompath;
		}
	SearchStatusBar();
	}
}

function SearchOnSelect() {
	if (AfianHandler.components['SearchContextMenus'].loaded) {
		showfuncname = showMenu;
		hidefuncname = hideMenu;
		if (this.countSelected == 0) {
				hidefuncname('afian_search_context_dir');
				hidefuncname('afian_search_context_file');
		} else {
			sel = AfianHandler.activeTab.selectedItem();
			if (sel.isdir) {
			showfuncname('afian_search_context_dir');
			hidefuncname('afian_search_context_file');
			} else {
			showfuncname('afian_search_context_file');
			hidefuncname('afian_search_context_dir');
			}
		}
	}
	SearchStatusBar();
}

function MyFilesGoSearch(q) {
	AfianHandler.activeTab.ifram.src = '?search=1&sub=listing&tabid='+AfianHandler.activeTab.id+'&path='+AfianHandler.activeTab.frompath+'&q='+q;
	AfianHandler.activeTab.showHourGlass();
}

function SearchStatusBar() {
	if (AfianHandler.activeTab.countAll == 0) {
		if (AfianHandler.activeTab.browsed) {
		AfianHandler.statusBar.innerHTML = AfianMessages['No search results'];
		} else {
		AfianHandler.statusBar.innerHTML = '';
		}
	} else {
	AfianHandler.statusBar.innerHTML = AfianMessages['%1 objects'].replace('%1', AfianHandler.activeTab.countAll);
	}
}

function SearchGet() {
	tb = AfianHandler.activeTab;
	selected = tb.selectedItem();
	document.hiddenForm.action = '?file=myfilesacting';
	document.hiddenForm.action += '&act=download';
	document.hiddenForm.action += '&path='+gluePath([tb.frompath, selected.input_value]);
	document.hiddenForm.target = 'hifrm_'+tb.id;
	document.hiddenForm.submit();
	tb.unselectAll();
}

function SearchGoTo() {
	selected = AfianHandler.activeTab.selectedItem();
	path = selected.filetype_descr;
	if (selected.isdir) {
		title = AfianMessages['Locating folder...'];
	} else {
		title = AfianMessages['Locating file...'];
	}
	newTab = new Afian_Tab(title, path);
	newTab.section = 'myfiles';
	newTab.viewMode = 'icons';
	newTab.onload = MyFilesOnLoad;
	newTab.detailHTML = AfianHandler.MyFilesDetailsTemplate;
	newTab.load();
	newTab.MyFiles_Browse(encodeURIComponent(path));
	newTab.onselect = MyFilesOnSelect;
	newTab.showHourGlass();
}

function SearchSortName() {
	if (tb.sortBy != 'name'){
	tb = AfianHandler.activeTab;
	tb.destroyItems();
	tb.sortItems('name', 'desc');
	tb.buildItems();
	tb.showItems();
	}
}

function SearchSortSize() {
	tb = AfianHandler.activeTab;
	if (tb.sortBy != 'size'){
	tb.destroyItems();
	tb.sortItems('size', 'desc');
	tb.buildItems();
	tb.showItems();
	}
}

function SearchSortType() {
	tb = AfianHandler.activeTab;
	if (tb.sortBy != 'type'){
	tb.destroyItems();
	tb.sortItems('type', 'desc');
	tb.buildItems();tb.showItems();
	}
}