var showTabCloseBtnTimer = new Array;

AfianHandler = {
	debug : false,
	allTabs : new Array,
	allItems : new Array,
	iframesContainer : false,
	tray : false,
	baseMenuContainer : false,
	taskBar : false,
	components : new Array,
	shiftpressed : false,
	uploadType : 'clasic',
	currentUserId : false,
	itemonclick : function() {
		AfianHandler.allItems[this.id].onclick();
	},
	itemondblclick : function() {
		AfianHandler.allItems[this.id].ondblclick();
	},
	itemonmouseup : function() {
		AfianHandler.allItems[this.id].onmouseup();
	},
	itemonmouseover : function() {
		AfianHandler.allItems[this.id].onmouseover();
	},
	itemonmouseout : function() {
		AfianHandler.allItems[this.id].onmouseout();
	},
	loadtab : function(tid) {
		tabid = (tid)?tid:this.id;
		AfianHandler.allTabs[tabid].load();
	},
	closetab : function(tid) {
		if(AfianHandler.allTabs.has4ValidElms()){
			tid = tid ? tid : this.id;
			AfianHandler.allTabs[tid].close(true);
		} else {
			AfianBubbleMessage('You must have at least one tab opened.');
		}
	},
	deleteTab : function(tab) {
		for (var i = 0 ; i < AfianHandler.allTabs.length; i++) {
			if (AfianHandler.allTabs[i] != undefined) {
				if (AfianHandler.allTabs[i].id == tab.id) {	
					delete AfianHandler.allTabs[i];
					delete AfianHandler.allTabs[tab.id];
				}
			}
		}
	},
	showTabCloseBtn : function(tid) {
		if (showTabCloseBtnTimer[tid]) {
			window.clearTimeout(showTabCloseBtnTimer[tid]);
		}
		document.getElementById('tabclosebtn_'+tid).style.visibility='visible';
	},
	hideTabCloseBtn : function(tid) {
		showTabCloseBtnTimer[tid] = window.setTimeout( function(){
		document.getElementById('tabclosebtn_'+tid).style.visibility='hidden';
		}, 100);
	}
};

var firstActive = true;
AfianHandler.addComponent = function (componentName, componentType) {
	AfianHandler.components[componentName] = new Array;
	AfianHandler.components[componentName]['loaded'] = false;
	o = document.createElement('DIV');
	o.id = componentName;
	io = document.createElement('DIV');
	if (componentType == 'basemenu') {
		if (firstActive) {
			o.className = 'activeBaseMenu';
			firstActive = false;
		} else {
			o.className = 'hiddenBaseMenu';
		}
		io.className ='baseMenuContainer';
		io.innerHTML = AfianMessages['Building menu..'];
	}
	o.appendChild(io);
	if (componentType == 'basemenu') {
		getById('baseMenuContainer').appendChild(o);
	} else {
		getById('HTMLComponentContainer').appendChild(o);
	}
	AfianHandler.components[componentName]['obj'] = o;
}


function Afian_Init() {

	if (AfianHandler.debug) {
		debugWindow = popup('javascript:;', 'debugWindow', 60, 100, 'yes');
	}


	AfianHandler.iframesContainer = getById('iframesContainer');
	AfianHandler.tray = getById('afian_file_list');
	AfianHandler.taskBar = getById('taskBar');
	AfianHandler.baseMenuContainer = getById('baseMenuContainer');
	AfianHandler.statusBar = getById('afian_status_bar');
	AfianHandler.titleBar = getById('titleBar');
	AfianHandler.dragListContainer = getById('dragcontainer');
	AfianHandler.dragList = getById('draglist');
/* aici ai ramas */
	allComponents = new Array(
		new Array('MyFilesBaseMenu', 'basemenu'), 
		new Array('MyFilesContextMenus', 'contextmenus'), 
		new Array('TrashBaseMenu', 'basemenu'), 
		new Array('TrashContextMenus', 'contextmenus'), 
		new Array('MySharesBaseMenu', 'basemenu'), 
		new Array('MySharesContextMenus', 'contextmenus'), 
		new Array('BShareBaseMenu', 'basemenu'), 
		new Array('BShareContextMenus', 'contextmenus'), 
		new Array('SearchBaseMenu', 'basemenu'), 
		new Array('SearchContextMenus', 'contextmenus'), 
		new Array('BrowseZipBaseMenu', 'basemenu'), 
		new Array('BrowseZipBaseMenu', 'basemenu'), 
		new Array('BrowseZipContextMenus', 'contextmenus'), 
		new Array('AdmGroupsBaseMenu', 'basemenu'), 
		new Array('AdmGroupsContextMenus', 'contextmenus'), 
		new Array('AdmUsersBaseMenu', 'basemenu'), 
		new Array('AdmUsersContextMenus', 'contextmenus'), 
		new Array('AdmLogsBaseMenu', 'basemenu'),
		/*'AdmLogsContextMenus',*/
		new Array('AdmUsersMenus', 'menus')
	);

for (var i = 0 ; i < allComponents.length; i++) {
	AfianHandler.addComponent(allComponents[i][0], allComponents[i][1]);
}
	
	
AfianHandler.MyFilesDetailsTemplate = '<table width="350" border="0" cellpadding="0" cellspacing="0"><tr><td width="70" align="right" nowrap>FORMATEDSIZE</td><td align="right">FTYPEDESCR</td><td width="90" align="right">EXTRA</td></tr></table>';

AfianHandler.SearchDetailsTemplate = '<table width="350" border="0" cellpadding="0" cellspacing="0"><tr><td><div style="white-space:nowrap;overflow:hidden;width:350px;">FTYPEDESCR</div></td></tr></table>';

AfianHandler.TrashDetailsTemplate = '<table width="350" border="0" cellpadding="0" cellspacing="0"><tr><td><div style="white-space:nowrap;overflow:hidden;width:210px;">FTYPEDESCR</div></td><td width="140" align="right">EXTRA</td></tr></table>';

AfianHandler.MySharesDetailsTemplate = '<table width="350" border="0" cellpadding="0" cellspacing="0"><tr><td><div style="white-space:nowrap;overflow:hidden;width:350px;" selectable="1">FTYPEDESCR</div></td></tr></table>';

AfianHandler.BShareDetailsTemplate = '<table width="350" border="0" cellpadding="0" cellspacing="0"><tr><td width="70" align="right" nowrap>FORMATEDSIZE</td><td align="right">FTYPEDESCR</td><td width="140" align="right">EXTRA</td></tr></table>';

AfianHandler.BrowseZipDetailsTemplate = '<table width="350" border="0" cellpadding="0" cellspacing="0"><tr><td><div style="white-space:nowrap;overflow:hidden;width:350px;">FTYPEDESCR</div></td></tr></table>';




/* admin stuff */
AfianHandler.AdmGroupsTemplate = '<table width="350" border="0" cellpadding="0" cellspacing="0"><tr><td><div style="white-space:nowrap;overflow:hidden;width:350px;">FTYPEDESCR</div></td></tr></table>';
AfianHandler.AdmUsersTemplate = '<table width="350" border="0" cellpadding="0" cellspacing="0"><tr><td><div style="white-space:nowrap;overflow:hidden;width:350px;">FTYPEDESCR</div></td></tr></table>';



}

/*creates a new tab*/
function Afian_Tab(title, basepath, taskBarIcon) {
	this.title = title;
	this.basepath = basepath;
	this.countSelected = 0;
	this.items = new Array;
	this.countAll = 0;
	cookieViewMode = getCookie('AfianViewMode');
	this.viewMode = cookieViewMode?cookieViewMode:'icons';
	this.sortBy = 'name';
	this.active = false;
	this.busy = false;
	this.showHG = false;
	this.sortBy = false;
	this.sortDirection = false;
	this.onselect = function() {};
	this.onload = function() {};
	this.baseMenu = false;
	this.selSize = 0;
	this.totalSize = 0;
	this.browsed = false;
	AfianHandler['allTabs'][AfianHandler['allTabs'].length] = this;
	this.id = AfianHandler['allTabs'].length;
	AfianHandler['allTabs'][this.id] = this;
	

	this.ifram = createTabsHIframe(this.id);
	
	if (taskBarIcon) {
		this.taskBarIcon = taskBarIcon;
	}
	this.taskBarOption();
	return this;
}

function createTabsHIframe(tid) {
	/*
	this.ifram = document.createElement('IFRAME');
	this.ifram.name = 'hifrm_'+this.id;
	this.ifram.id = 'hifrm_'+this.id;
	AfianHandler.iframesContainer.appendChild(this.ifram);
	*/
	insertHTMLBeforeEnd(AfianHandler.iframesContainer, '<iframe src="blank.html" id="hifrm_'+tid+'" name="hifrm_'+tid+'"></iframe>');
	return getById('hifrm_'+tid+'');	
}

/*add an item to the tab, no dom changes*/
Afian_Tab.prototype.addItem = function (item) {
	index = this.items.length;
	this.items[index] = item;
	this.items[index].tab = this;
	this.countAll++;
	this.totalSize = this.totalSize+item.fsize;
	preloadImg(item.icon_img_src);
	preloadImg(item.list_img_src);
	preloadImg(item.thumb_img_src);
}

/*remove an item from the tab*/
Afian_Tab.prototype.removeItem = function (inputValue) {
	for (var i=0; i < this.items.length; i++) {
		if (this.items[i] != undefined) {
			if (this.items[i].input_value == inputValue) {
			this.totalSize = this.totalSize-this.items[i].fsize;
			this.items[i].unbuild();
			delete this.items[i];
			this.countAll--;
			}
		}
	}
}

Afian_Tab.prototype.focusItem = function (inputValue) {
	return false;
	for (var i=0; i < this.items.length; i++) {
		if (this.items[i] != undefined) {
			if (this.items[i].input_value == inputValue) {
				/*alert(this.items[i].id);*/
				document.location.hash = '#'+this.items[i].id;
			}
		}
	}
}

/*remove an item from the tab*/
Afian_Tab.prototype.removeItemArray = function (inputValue) {
	for (var i=0; i < this.items.length; i++) {
		if (this.items[i] != undefined) {
			if (this.items[i].input_value == inputValue) {
			this.totalSize = this.totalSize-this.items[i].fsize;
			delete this.items[i];
			this.countAll--;
			}
		}
	}
}

/*remove all items from the tab*/
Afian_Tab.prototype.removeAll = function () {
	for (var i=0; i < this.items.length; i++) {
		if (this.items[i] != undefined) {
			this.items[i].unbuild();
			delete this.items[i];
		}
	}
	this.selSize = 0;
	this.totalSize = 0;
	this.countAll = 0;
	this.countSelected = 0;
}

/* custom selection */
Afian_Tab.prototype.customSel = function(attr, val, substr) {
	for (var i=0; i < this.items.length; i++) {
		if (this.items[i] != undefined) {
			if (substr) {
				if (this.items[i][attr].toLowerCase().indexOf(val.toLowerCase())!=-1) {
					if (!this.items[i].selected) {
						this.items[i].select();
					}
				} else {
					if (this.items[i].selected) {
						this.items[i].unselect();
					}
				}
			} else {
				if (this.items[i][attr] == val) {
					if (!this.items[i].selected) {
						this.items[i].select();
					}
				} else {
					if (this.items[i].selected) {
						this.items[i].unselect();
					}
				}
			}
		}
	}
}

/*unselect item*/
Afian_Tab.prototype.unselectAll = function() {
	for (var i=0; i < this.items.length; i++) {
		if (this.items[i] != undefined) {
			if (this.items[i].selected) {
			this.items[i].unselect();
			}
		}
	}
	this.onselect();
}

/*select item*/
Afian_Tab.prototype.selectAll = function() {
	for (var i=0; i < this.items.length; i++) {
		if (this.items[i] != undefined) {
			if (!this.items[i].selected) {
			this.items[i].select();
			}
		}
	}
	this.onselect();
}



Afian_Tab.prototype.debugItems = function() {
	w = window.open();
	debugtxt = '';
	for (var i = 0 ; i < this.items.length; i++) {
		if (this.items[i] != undefined) {
		debugtxt += i+' => '+this.items[i].title+'<br>';
		} else {
		debugtxt += i+' => undefined'+'<br>';
		}	
	}
	w.document.write(debugtxt);
}


Afian_Tab.prototype.buildItems = function() {
	for (var i = 0 ; i < this.items.length; i++) {
		if (this.items[i] != undefined) {
			this.items[i].build();
		}
	}
}


Afian_Tab.prototype.destroyItems = function() {
	for (var i = 0 ; i < this.items.length; i++) {
		if (this.items[i] != undefined) {
			this.items[i].unbuild();
		}
	}
}


Afian_Tab.prototype.showItems = function() {
	for (var i = 0 ; i < this.items.length; i++) {
		if (this.items[i] != undefined) {
			this.items[i].show();
		}
	}
}


Afian_Tab.prototype.hideItems = function() {
	for (var i = 0 ; i < this.items.length; i++) {
		if (this.items[i] != undefined) {
			this.items[i].hide();
		}
	}
}


Afian_Tab.prototype.selHasOnlyDirs = function() {
	var temp1 = 0;
	var temp2 = 0;
	for (var i=0; i < this.items.length; i++) {
		if (this.items[i] != undefined) {
			if (this.items[i].selected) {
				if (this.items[i].isdir) {
					temp1++;
				}
				temp2++;
			}
		}
	}
	if (temp1 == temp2) {
		return true;
	} else {
		return false;
	}
}

/*create a basemenu - not used yet*/
AfianHandler.createBaseMenu = function() {
b = document.createElement('div');
b['td'].className = 'hiddenBaseMenu';
AfianHandler.baseMenuContainer.insertBefore(b, Afian.bm.lastChild);
this.baseMenu = b;
}

/**/
AfianHandler.insertBaseMenuHTML = function(componentName, content) {
	AfianHandler.components[componentName]['obj'].innerHTML = content;
}
AfianHandler.loadHTMLComponent = function(componentName, content) {
	getById('HTMLComponentContainer').innerHTML += content;
}



AfianHandler.showBaseMenu = function(componentName) {
	AfianHandler.components[componentName]['obj'].className='activeBaseMenu';
}
AfianHandler.hideBaseMenu = function(componentName) {
	AfianHandler.components[componentName]['obj'].className='hiddenBaseMenu';
}

/*create taskbar option (button) for this tab*/
Afian_Tab.prototype.taskBarOption = function() {
	if (!this.taskBarIcon) {
	this.taskBarIcon = 'images/icons/taskbar/folder.gif';
	}
/*width="16" height="13"*/
html = '<div id="tabdiv_'+this.id+'" class="tab" onclick="AfianHandler.loadtab('+this.id+')" onmouseup="AfianHandler.check4drop('+this.id+');AfianHandler.check4dragout('+this.id+')" onmouseover="AfianHandler.check4dragover('+this.id+');AfianHandler.showTabCloseBtn('+this.id+')" onmouseout="AfianHandler.check4dragout('+this.id+');AfianHandler.hideTabCloseBtn('+this.id+')"><table border="0" cellspacing="0" cellpadding="3" width="100%"><tr><td width="18"><img src="'+this.taskBarIcon+'" border="0" alt="" height="16" width="16" id="tabimg_'+this.id+'"></td><td><div id="tabtxt_'+this.id+'">'+this.title+'</div></td><td id="tabclosebtn_'+this.id+'" style="visibility:hidden"><a href="javascript:;" onclick="AfianHandler.closetab('+this.id+')"><img src="images/interface/tab_close_button.gif" width="8" height="8" alt="" border="0"></a></td></tr></table></div>';
insertHTMLBeforeEnd(AfianHandler.taskBar, html);

this.taskBarOpt = new Object;
this.taskBarOpt.img = getById('tabimg_'+this.id);
this.taskBarOpt.div = getById('tabdiv_'+this.id);
this.taskBarOpt.txt = getById('tabtxt_'+this.id);
}

/*load tab, display its icons, etc...*/
Afian_Tab.prototype.load = function() {
	if (AfianHandler.activeTab == this) {
		return;
	}		
		if (this.showHG) {
			this.showHourGlass();
		} else {
			this.hideHourGlass();
		}
	
	this.select();
	if (AfianHandler.activeTab != undefined) {
		AfianHandler.activeTab.unselect();
		AfianHandler.activeTab.hideItems();
		AfianHandler.activeTab.unselectAll();
		AfianHandler.activeTab.active = false;
		hideMenu('popmenu-prompt');
	}
	this.showItems();
	this.active = true;
	AfianHandler.activeTab = this;
	if (this.onload) {
		/* user may switch the tabs before loading */
			this.onload();
	}
	
	if (this.section == 'myfiles') {
		styleEnableButton('newtabbtn')
	} else {
		styleDisableButton('newtabbtn');
	}
}

/* close/delete tab */
Afian_Tab.prototype.close = function(loadanother) {
	if (!this.isBusy(true)) {
		AfianHandler.iframesContainer.removeChild(this.ifram);
		if (this.timer) {
		window.clearTimeout(this.timer);
		}
		this.removeTaskBarOpt();
		this.destroyItems();
		AfianHandler.deleteTab(this);
			if (loadanother) {
				for (var i = AfianHandler.allTabs.length ; i > 0; i--) {
					if (AfianHandler.allTabs[i] != undefined) {
						AfianHandler.allTabs[i].load();
						return true;
					}
				}
			}
	}
}

/* force close/delete tab */
Afian_Tab.prototype.forceClose = function(loadanother) {
	this.busy = false;
	this.close(loadanother);
}

Afian_Tab.prototype.isBusy = function(closeAction) {
	if (this.busy) {
	
	if (closeAction) {
		b = new Array;
		b[0] = new Array;
		b[0]['title'] = AfianMessages['Close anyway'];
		b[0]['onclick'] = 'AfianHandler.allTabs[\''+this.id+'\'].forceClose(true);hideMenu(\'popmenu-prompt\')';
		b[1] = new Array;
		b[1]['title'] = AfianMessages['Cancel'];
		b[1]['onclick'] = 'hideMenu(\'popmenu-prompt\')';
		AfianPrompt(AfianMessages['This tab has tasks in progress.'], b);
	} else {
		AfianAlert(AfianMessages['This tab has tasks in progress.']);
	}
		return true;
	} else {
		return false;
	}
}

deleteTabFromHandler = function() {
	AfianHandler.iframesContainer.removeChild(this.ifram);
	this.removeTaskBarOpt();
	this.destroyItems();
		for (var i = 0 ; i < AfianHandler.allTabs.length; i++) {
			if (AfianHandler.allTabs[i] != undefined) {
				AfianHandler.allTabs[i].load();
				return true;
			}
		}
}

/*get first selected item */
Afian_Tab.prototype.selectedItem = function() {
	for (var i = 0 ; i < this.items.length; i++) {
		if (this.items[i] != undefined) {
			if (this.items[i].selected) {
				return this.items[i];
			}
		}
	}
}

/*select taskbar option*/
Afian_Tab.prototype.select = function() {
	this.taskBarOpt.div.className = 'selectedtab';
}

/*unselect taskbar option*/
Afian_Tab.prototype.unselect = function() {
	this.taskBarOpt.div.className = 'tab';
}

/*remove tab from taskbar*/
Afian_Tab.prototype.removeTaskBarOpt = function() {
	AfianHandler.taskBar.removeChild(this.taskBarOpt.div);
}

/*adds the tab to the taskBar*/
Afian_Tab.prototype.changeTaskBarOptTitle = function(title) {
	this.taskBarOpt.txt.innerHTML=title;
}

/*create a new item*/
function Afian_Item(data) {
	this.selected = false;
	this.isdir = data.isdir;
	this.txt = data.txt;
	this.cnr = false;
	this.fsize = data.fsize;
	this.formatedSize = formatFileSize(data.fsize);
	this.iszip = (data.iszip)?true:false;
	this.ondblclk = data.ondblclk;
	this.input_value = data.input_value;
	this.icon_img_src = data.icon_img_src;
	this.list_img_src = data.list_img_src;
	this.thumb_img_src = data.thumb_img_src;
	this.img_title = data.input_value;
	this.icon_title = data.icon_title;
	this.filetype_descr = data.filetype_descr;
	this.builded = false;
	this.inserted = false;
	this.ext = data.ext;
	this.extra = data.extra;
	this.id = AfianHandler['allItems'].length;
	this.bigthumb = data.bigthumb;
	AfianHandler['allItems'][this.id] = this;
	AfianHandler['allItems'][AfianHandler['allItems'].length] = this;
}

/*item onclick*/
Afian_Item.prototype.onclick = function() {
	if (!this.selected) {
		this.select(true);
	} else {
		this.unselect(true);
	}
}

/*item ondblclick*/
Afian_Item.prototype.ondblclick = function() {
	eval(this.ondblclk);
}

Afian_Item.prototype.onmouseup = function() {
	if (dragstarted) {
			if (this.isdir) {
				MyFilesDropDrag(gluePath([this.tab.basepath,this.input_value]));
				if (this.dragOverHilight) {
					this.onmouseout();
				}
			}
	}
}

Afian_Item.prototype.onmouseover = function() {
	if (dragstarted && this.isdir) {
			this.origClassName = this.obj.table.className;
			if (this.tab.viewMode == 'icons') {
				postfix = "";
			} else if (this.tab.viewMode == 'thumbs') {
				postfix = "_thumbs";
			} else {
				postfix = "_list";
			}
			this.obj.table.className='dragOverIcon'+postfix;
			this.dragOverHilight = true;
	}
}

Afian_Item.prototype.onmouseout = function() {
	if (dragstarted && this.isdir) {
			if (this.origClassName != undefined) {
				this.obj.table.className=this.origClassName;
				this.dragOverHilight = false;
				delete this.origClassName;
			}
	}
}


/*select item*/
Afian_Item.prototype.select = function(onsel) {
		if (this.tab.singleSelection) {
			this.tab.unselectAll();
		}
	this.tab.countSelected++;
	this.tab.selSize = this.tab.selSize+this.fsize;
	
	this.selected = true;
	this.check();
	this.highlight('on');
	if (onsel) {
		this.tab.onselect(this);
	}
	AfianHandler.lastSelectedItem = this;
}

/*unselect item*/
Afian_Item.prototype.unselect = function(onsel) {
	this.tab.countSelected--;
	this.tab.selSize = this.tab.selSize-this.fsize;
	this.selected = false;
	this.uncheck();
	this.highlight('off');
	if (onsel) {
		this.tab.onselect(this);
	}
}



/*build html item*/
Afian_Item.prototype.build = function() {
	if (this.tab.viewMode == 'icons') {
		this.buildDOMobject_icon();
	} else if (this.tab.viewMode == 'thumbs') {
		this.buildDOMobject_thumb();
	} else {
		this.buildDOMobject_list();
	}
	if (this.selected) {
		this.highlight('on');
	}
	AfianHandler.tray.appendChild(this.obj.table);
	
	
/* drag & drop */

if (this.tab.section == 'myfiles') {
	if (!AfianUserPermissions['readonly']) {
	Drag.init(this.obj.table, AfianHandler.dragListContainer);
	}
}

AfianHandler.dragListContainer.onDragStart = function(x,y) {
	movementCounter = 0;
}

AfianHandler.dragListContainer.onDrag = function(x, y) {
movementCounter++;
	if (movementCounter > 4) {
		if (AfianHandler.activeTab.countSelected > 0) {
			/* allow dragging 1 unselected item */
			if (AfianHandler.activeTab.countSelected == 1) {
				if (Drag.obj.id != AfianHandler.lastSelectedItem.id) {
					AfianHandler.lastSelectedItem.unselect();
					AfianHandler.allItems[Drag.obj.id].select();
					return;
				}
			}
			
			
			if (!dragstarted) {
			BuildDragList();
			this.style.top=currentY+10;
			this.style.left=currentX+10;
			}
			dragstarted = true;
		} else {
			/* allow dragging 1 unselected item */
			/*AfianBubbleMessage('You must first select the items you want to drag.');*/
			AfianHandler.allItems[Drag.obj.id].select();
		}
	}
}

AfianHandler.dragListContainer.onDragEnd = function(x, y) {
	if (dragstarted) {
		AfianHandler.dragListContainer.style.display='none';
		movementCounter = 0;
		dragListBuilded = false;
		
		AfianHandler.HideShowSelected('show');
		
			if (AfianHandler.activeTab.countSelected == 1) {
				AfianHandler.lastSelectedItem.unselect();
			}
		
		AfianHandler.activeTab.onselect();
		dragstarted = false;
	}
}

this.obj.table.onmouseup = AfianHandler.itemonmouseup;
/* ca sa compenseze faptul ca am scos return-ul din dom-drag cand tragi imagini */
this.obj.img.ondrag = new Function('return false;');
this.obj.table.onmouseover = AfianHandler.itemonmouseover;
this.obj.table.onmouseout = AfianHandler.itemonmouseout;
}

function BuildDragList() {
if (!dragListBuilded) {
		dc = AfianHandler.dragListContainer;
		dl = AfianHandler.dragList;
		dl.innerHTML = '';
			if (AfianHandler.activeTab.countSelected > 10) {
				dl.innerHTML += '<table border="0" cellpadding="0" cellspacing="0" style="border: 1px solid #87ceeb;height:22px;background-color:#B3E8FE;clear:both;margin-bottom:2px"><tr><td nowrap style="padding:3px;">'+AfianHandler.activeTab.countSelected+' items</td></tr></table>';
			} else {
				for (var i = 0 ; i < AfianHandler.activeTab.items.length; i++) {
					if (AfianHandler.activeTab.items[i] != undefined) {
						if (AfianHandler.activeTab.items[i].selected) {
							dl.innerHTML += '<table border="0" cellpadding="1" cellspacing="0" class="dragListItem"><tr><td width="17"><img src="'+AfianHandler.activeTab.items[i].list_img_src+'" width="16" height="16"></td><td><div style="white-space:nowrap;overflow:hidden;width:110px;"> '+AfianHandler.activeTab.items[i].icon_title+'</div></td></tr></table>';

						}
					}
				}
			}
		AfianHandler.HideShowSelected('hide');
		dc.style.display='block';
		hideMenu('afian_context_dir');
		hideMenu('afian_context_file');
		hideMenu('afian_context_multiple');
		dragListBuilded = true;
}
}

AfianHandler.HideShowSelected = function(how) {
	for (var i = 0 ; i < AfianHandler.activeTab.items.length; i++) {
		if (AfianHandler.activeTab.items[i] != undefined) {
			if (AfianHandler.activeTab.items[i].selected) {
				if (how == 'show') {
					AfianHandler.activeTab.items[i].show(true);
				} else {
					AfianHandler.activeTab.items[i].hide(true);
				}
			}
		}
	}
}

AfianHandler.check4drop = function(tid) {
	if (dragstarted) {
		/*AfianHandler.loadtab(tid);*/
		if (AfianHandler.allTabs[tid].section == 'myfiles') {
			MyFilesDropDrag(AfianHandler.allTabs[tid].basepath);
		} else if (AfianHandler.allTabs[tid].section == 'trash') {
			MyFilesDel();
		}
	}
}

AfianHandler.check4dragover = function(tid) {
	tb = AfianHandler.allTabs[tid];
	if (tb != AfianHandler.activeTab) {
		if (dragstarted) {
			if (tb.section == 'myfiles' || tb.section == 'trash') {
				tb.taskBarOpt.div.style.backgroundColor='#d7d7d7';
			}
		}
	}
}

AfianHandler.check4dragout = function(tid) {
	tb = AfianHandler.allTabs[tid];
	if (tb != AfianHandler.activeTab) {
		if (dragstarted) {
			if (tb.section == 'myfiles' || tb.section == 'trash') {
				if (AfianHandler.activeTab == tb) {
				tb.taskBarOpt.div.style.backgroundColor='whitesmoke';
				} else {
				tb.taskBarOpt.div.style.backgroundColor='';
				}
			}
		}
	}
}


Afian_Item.prototype.unbuild = function() {
	AfianHandler.tray.removeChild(this.obj.table);
}

Afian_Item.prototype.show = function(vis) {
	if (vis) {
	this.obj.table.style.visibility='visible';
	return true;
	}
	this.obj.table.style.display='block';
}

Afian_Item.prototype.hide = function(vis) {
	if (vis) {
	this.obj.table.style.visibility='hidden';
	return true;
	}
	this.obj.table.style.display='none';
}

Afian_Item.prototype.check = function () {
	this.obj.chkbox.checked = true;
}

Afian_Item.prototype.uncheck = function () {
	this.obj.chkbox.checked = false;
}

Afian_Item.prototype.highlight = function (how) {
	var postfix='';
	if (this.tab.viewMode == 'list') {
		postfix = '_list';
	} else if (this.tab.viewMode == 'thumbs') {
		postfix = '_thumbs';
	}
	if (how == 'on') {
	this.obj.table.className='selIcon'+postfix;
	this.obj.tr1_td.className='selthumb'+postfix;
	} else {
	this.obj.table.className='icon'+postfix;
	this.obj.tr1_td.className='thumb'+postfix;
	}
}

Afian_Tab.prototype.MyFiles_Browse = function (path) {
	path = (path!=null)?path:this.basepath;
	this.showHourGlass();
	this.ifram.src = '?file=listing&tabid='+this.id+'&path='+path;
	tabStartTimer(this);
}
Afian_Tab.prototype.Trash_Browse = function () {
	this.showHourGlass();
	this.ifram.src = '?trash=1&sub=listing&tabid='+this.id;
	tabStartTimer(this);
}
Afian_Tab.prototype.MyShares_Browse = function () {
	this.showHourGlass();
	this.ifram.src = '?myshares=1&sub=listing&tabid='+this.id;
	tabStartTimer(this);
}
Afian_Tab.prototype.BShare_Browse = function () {
	this.showHourGlass();
	this.ifram.src = '?browseshare=1&sub=listing&tabid='+this.id+'&path='+encodeURIComponent(this.basepath)+'&uid='+this.uid;
	tabStartTimer(this);
}

Afian_Tab.prototype.AdmGroups_Browse = function () {
	this.showHourGlass();
	this.ifram.src = '?admin=1&section=groups&sub=listing&tabid='+this.id;
	tabStartTimer(this);
}
Afian_Tab.prototype.AdmUsers_Browse = function (gid, gname) {
	this.showHourGlass();
	this.ifram.src = '?admin=1&section=users&sub=listing&tabid='+this.id+'&gid='+gid;
	tabStartTimer(this);
}


Afian_Tab.prototype.sortItems = function (by, direction) {
	dirs = new Array;
	files = new Array;
	for (var i = 0 ; i < this.items.length; i++) {
		if (this.items[i] != undefined) {
			if (this.items[i].isdir) {
			dirs[dirs.length] = this.items[i];
			} else {
			files[files.length] = this.items[i];
			}
		}
	}
		function byName(a, b) {
		  var anew = a.input_value.toLowerCase();
		  var bnew = b.input_value.toLowerCase();
		  if (anew < bnew) return -1;
		  if (anew > bnew) return 1;
		  return 0;
		}
		
		function bySize(a, b) {
		  if (a.fsize > b.fsize) return -1;
		  if (a.fsize < b.fsize) return 1;
		  return 0;
		}
		
		function byType(a, b) {
		  if (a.ext < b.ext) return -1;
		  if (a.ext > b.ext) return 1;
		  return 0;
		}
		
		if (by == 'name') {
			func = byName;
		} else if (by == 'size') {
			func = bySize;
		} else if (by == 'type') {
			func = byType;
		} else {
			func = byName;
		}
		
		dirs.sort(func);
		files.sort(func);
		
		if (direction == 'desc') {
			this.items.reverse();
		}
		this.items = dirs.concat(files);
		this.sortBy = by;
		this.sortDirection = direction;
}


function closeTabByPath(path) {
	for (var i = 0 ; i < AfianHandler.allTabs.length; i++) {
		if (AfianHandler.allTabs[i] != undefined) {
			if (AfianHandler.allTabs[i].basepath == path) {
				AfianHandler.allTabs[i].close(false);
			}
		}
	}
}


Afian_Tab.prototype.showHourGlass = function(msg) {
	this.showHG = true;
	this.busy = true;
	if (this.active) {
		AfianHandler.statusBar.innerHTML = '<img src="images/interface/hourglass.gif" width="16" height="15" border="0" alt="">';
	}
	this.taskBarOpt.img.src = 'images/interface/hourglass.gif';
	if (msg) {
			AfianHandler.statusBar.innerHTML += msg; 
	}
}

Afian_Tab.prototype.hideHourGlass = function() {
	this.showHG = false;
	this.busy = false;
	if (this.active) {
		AfianHandler.statusBar.innerHTML = '';
		this.onselect();
	}
	this.taskBarOpt.img.src = this.taskBarIcon;
}

function loadComponentData(component, extra) {
		tmpiframe = newHiddenIframe('');
		tmpiframe.src = 'components_loader/'+component+'.php'+(extra?'?'+extra:'');
}

function tabStartTimer(tb) {
	tb.timer = window.setTimeout('tabHasTimedOut(\''+tb.id+'\')', 30000);
}

function cancelTimeOut(tabid) {
	window.clearTimeout(AfianHandler.allTabs[tabid].timer);
}

function tabHasTimedOut(tabid) {
	/*
	if (AfianHandler.allTabs[tabid]) {
	AfianHandler.allTabs[tabid].load();
	b = new Array;
	b[0] = new Array;
	b[0]['title'] = 'Wait for server response';
	b[0]['onclick'] = 'continueWaiting(\''+tabid+'\')';
	b[1] = new Array;
	b[1]['title'] = 'Cancel action';
	b[1]['onclick'] = 'cancelAction(\''+tabid+'\')';
	AfianPrompt('This tab has timed out.', b);
	}
	*/
}

function continueWaiting(tabid) {
	tabStartTimer(AfianHandler.allTabs[tabid]);
	hideMenu('popmenu-prompt');
}

function cancelAction(tabid) {
tb = AfianHandler.allTabs[tabid];
	if (tb.section == 'myfiles') {
		MyFilesEndAction(tb);
	} else {
		tb.hideHourGlass();
		cancelTimeOut(tb.id);
	}
stopIframe(tabid);
hideMenu('popmenu-prompt');
}



function stopIframe(tabid) {
	tb = AfianHandler.allTabs[tabid];
	ifram = tb.ifram;
	if (is.IE) {
		window.frames[ifram.name].location.replace('javascript:;');
	} else if (is.Opera) {
		AfianHandler.iframesContainer.removeChild(ifram);
		tb.ifram = createTabsHIframe(tb.id);
	} else {
		ifram.contentDocument.location.replace('javascript:;');
	}
}