Index: sandbox/filemanager/js/draw_api.js
===================================================================
--- sandbox/filemanager/js/draw_api.js	(revision 1727)
+++ sandbox/filemanager/js/draw_api.js	(revision 1730)
@@ -11,4 +11,25 @@
 document.onmousemove = getPointer;
 
+function loadHistory(filename){
+	cExecute('/index.php?menuaction=filemanager.uifilemanager.history&file='+base64_encode(filename)+"&path="+base64_encode(currentPath),draw_window);
+}
+
+function loadPermissions(data){
+	var permission = parseInt(data);
+	var ACL_READ = 1;
+	var ACL_ADD = 2;
+	var ACL_EDIT = 4;
+	var ACL_DELETE = 8;
+	var ACL_PRIVATE = 16;
+
+	permissions['read']=(permission & ACL_READ);
+	permissions['add']=(permission & ACL_ADD);
+	permissions['edit']=(permission & ACL_EDIT);
+	permissions['delete']=(permission & ACL_DELETE);
+	permissions['private']=(permission & ACL_PRIVATE);
+	toolbar.load();
+	loadPreferences();
+	toolbar.control('reload');
+}
 function close_window(){
 	var menu =  document.getElementById('dwindow');
@@ -115,6 +136,4 @@
 	preferences = unserialize(preferencesEl.value);
 }
-
-
 function reloadFiles(newCriteria){
 	if (newCriteria == criteria)
@@ -122,33 +141,40 @@
 	else
 		criteria = newCriteria;
-	toolbar_control('reload');
-}
-function selectAll(el){
-	checkBoxes = document.getElementsByName('fileman');
-	if (el.checked)
-		for (i=0; i < checkBoxes.length; i++)
-			checkBoxes[i].checked = true;
-	else
-		for (i=0; i < checkBoxes.length; i++)
-			checkBoxes[i].checked = false;
-
-}
-function borkb(size){
-		kbyte = 1024;
-		mbyte = kbyte*1024;
-		gbyte = mbyte*1024;
-		if (!size)
-			size = 0;
-		if (size < kbyte)
-			return size + 'B';
-		else if (size < mbyte)
-			return parseInt(size/kbyte) + 'KB';
-		else if (size < gbyte)
-			return (size/mbyte).toFixed(1) + 'MB';
-		else
-			return parseInt(size/gbyte).toFixed(1) + 'GB';
-}
-function drawSearch(data){
-	var fmFileWindow = document.getElementById('fmFileWindow');
+	toolbar.control('reload');
+}
+
+function initDrawApi(){
+	currentPath = document.getElementById('currentPath').value;
+	cExecute('/index.php?menuaction=filemanager.uifilemanager.get_permissions&path='+base64_encode(currentPath),loadPermissions);
+	quotaSize = document.getElementById('quotaSize').value;
+	usedSpace = document.getElementById('usedSpace').value;
+
+	document.getElementById('divAppboxHeader').innerHTML = title_app;
+
+	if (parseInt(quotaSize) != 0)
+		document.getElementById('content_quota').innerHTML = '<table width="102" cellspacing="0" cellpadding="0" border="0" id="table_quota"><tbody><tr><td width="102" nowrap="true" height="15" background="../phpgwapi/templates/default/images/dsunused.gif"><table cellspacing="0" cellpadding="0" border="0" style="width: '+parseInt((usedSpace/quotaSize)*100)+'%;"><tbody><tr><td height="15" class="dsused"/></tr></tbody></table></td><td nowrap="true" align="center"><span class="boxHeaderText">'+parseInt(usedSpace/quotaSize*100)+'% ('+(usedSpace/1024/1024).toFixed(1)+'M/'+(quotaSize/1024/1024)+'M)</span></td></tr></tbody></table></td></tr></table>';
+	displayMessages();
+	resizeDiv();
+	window.onresize = resizeDiv;
+	document.body.style.overflow = "hidden";
+
+	// Disabled for now
+	// document.getElementById('main_table').style.visibility = "";
+
+}
+
+
+function folderList(){
+	this.td = '<td style="padding-left: 2px; padding-right: 2px;" valign="middle">';
+}
+folderList.prototype.init = function(){
+	this.element = document.getElementById('fmFileWindow');
+}
+folderList.prototype.clear = function(){
+	this.element.innerHTML = "";
+}
+
+folderList.prototype.drawSearch = function(data){
+	var fl = folderList;
 	var files = unserialize(data);
 	if (files == null)
@@ -157,90 +183,86 @@
 		return
 	}
-	var toolbar = document.getElementById('fmMenu');
-	toolbar.innerHTML = "";
-	fmFileWindow.innerHTML = "";
+	toolbar.clear();
+	fl.init();
+	fl.clear();
 	var newpage;
-	var td_hd = '<td style="padding-left: 2px; padding-right: 2px;" valign="middle">';
 	var sp_hd = '<span name="head" style="cursor: pointer; cursor: hand;"';
 	var sp_tl = '</span></td>';
 	newpage = '<table cellspacing="0" cellpadding="2"><tbody><tr class="message_header">';
-	newpage += td_hd+'<input onclick="selectAll(this)" type="checkbox"></td><td></td><td></td>';
-	newpage += td_hd+sp_hd+' id="name">'+get_lang('file name')+sp_tl;
-	newpage += td_hd+sp_hd+' id="folder">'+get_lang('folder')+sp_tl;
+	newpage += fl.td+'<input onclick="selectAll(this)" type="checkbox"></td><td></td><td></td>';
+	newpage += fl.td+sp_hd+' id="name">'+get_lang('file name')+sp_tl;
+	newpage += fl.td+sp_hd+' id="folder">'+get_lang('folder')+sp_tl;
     	if (preferences.mime_type =='1')
-		newpage += td_hd+sp_hd+' id="mime">'+get_lang('mime type')+sp_tl;
+		newpage += fl.td+sp_hd+' id="mime">'+get_lang('mime type')+sp_tl;
 	if (preferences.size =='1')
-		newpage += td_hd+sp_hd+' id="size">'+get_lang('size')+'</a>'+sp_tl;
+		newpage += fl.td+sp_hd+' id="size">'+get_lang('size')+'</a>'+sp_tl;
 	if (preferences.created =='1')
-		newpage += td_hd+sp_hd+' id="created">'+get_lang('created')+'</a>'+sp_tl;
+		newpage += fl.td+sp_hd+' id="created">'+get_lang('created')+'</a>'+sp_tl;
 	if (preferences.modified =='1')
-		newpage += td_hd+sp_hd+' id="modified">'+get_lang('modified')+'</a>'+sp_tl;
+		newpage += fl.td+sp_hd+' id="modified">'+get_lang('modified')+'</a>'+sp_tl;
 	if (preferences.createdby_id =='1')
-		newpage += td_hd+sp_hd+' id="creatdby">'+get_lang('created by')+'</a>'+sp_tl;
+		newpage += fl.td+sp_hd+' id="creatdby">'+get_lang('created by')+'</a>'+sp_tl;
 	if (preferences.modifiedby_id =='1')
-		newpage += td_hd+sp_hd+' id="modifdby">'+get_lang('modified by')+'</a>'+sp_tl;
+		newpage += fl.td+sp_hd+' id="modifdby">'+get_lang('modified by')+'</a>'+sp_tl;
 	if (preferences.comment =='1')
-		newpage += td_hd+sp_hd+' id="comm">'+get_lang('comment')+'</a>'+sp_tl;
-	if (preferences.version =='1') newpage += td_hd+sp_hd+' id="vers">'+get_lang('version')+'</a>'+sp_tl+'</tr>';
-	
-	var classTr = "tr_msg_read";
+		newpage += fl.td+sp_hd+' id="comm">'+get_lang('comment')+'</a>'+sp_tl;
+	if (preferences.version =='1') newpage += fl.td+sp_hd+' id="vers">'+get_lang('version')+'</a>'+sp_tl+'</tr>';
+
 	for (var i=0; i < files.length; i++)
 	{
-		newpage += '<tr class="'+classTr+'">'+td_hd;
+		newpage += '<tr>'+fl.td;
 		newpage += '<input name="fileman" value="'+files[i].name+'" type="checkbox"></td>';
 		newpage += '<td></td><td></td>';
-		newpage += td_hd+'<img src="'+templatePath+'images/mime16_unknown.png">';
+		newpage += fl.td+'<img src="'+files[i].icon+'">';
 		newpage += '<a id="name_'+files[i].name+'" href="/index.php?menuaction=filemanager.uifilemanager.view&file='+base64_encode(files[i].name)+'&path='+base64_encode(files[i].directory)+'" target="_blank">'+files[i].name+'</a>&nbsp;</td>';
-		newpage += td_hd+files[i].directory+'</td>';
-		if (preferences.mime_type =='1') newpage += td_hd+files[i].mime_type+'</td>';
-		if (preferences.size =='1') newpage += td_hd+borkb(files[i].size)+'</td>';
-		if (preferences.created =='1') newpage += td_hd+files[i].created+'</td>';
-		if (preferences.modified =='1') newpage += td_hd+files[i].modified+'</td>';
-		if (preferences.createdby_id =='1') newpage += td_hd+files[i].createdby_id+'</td>';
-		if (preferences.modifiedby_id =='1') newpage += td_hd+files[i].modifiedby_id+'</td>';
+		newpage += fl.td+files[i].directory+'</td>';
+		if (preferences.mime_type =='1') newpage += fl.td+files[i].mime_type+'</td>';
+		if (preferences.size =='1') newpage += fl.td+borkb(files[i].size)+'</td>';
+		if (preferences.created =='1') newpage += fl.td+files[i].created+'</td>';
+		if (preferences.modified =='1') newpage += fl.td+files[i].modified+'</td>';
+		if (preferences.createdby_id =='1') newpage += fl.td+files[i].createdby_id+'</td>';
+		if (preferences.modifiedby_id =='1') newpage += fl.td+files[i].modifiedby_id+'</td>';
 		if (files[i].comment == null || files[i].comment.length == 0)
 			files[i].comment = "&lt;"+get_lang("no comments")+"&gt;";
-		if (preferences.comment =='1') newpage += td_hd+'<span id="'+files[i].name+'">'+files[i].comment+'</span></td>';
-		if (preferences.version =='1') newpage += td_hd+'<span>'+files[i].version+'</span></td></tr>';
-		classTr = (classTr == "tr_msg_read"?"tr_msg_read2":"tr_msg_read");
-
-	}
-	fmFileWindow.innerHTML = newpage;
-}
-
-
-function drawFiles(data){
-	var fmFileWindow = document.getElementById('fmFileWindow');
+		if (preferences.comment =='1') newpage += fl.td+'<span id="'+files[i].name+'">'+files[i].comment+'</span></td>';
+		if (preferences.version =='1') newpage += fl.td+'<span>'+files[i].version+'</span></td></tr>';
+
+	}
+	fl.element.innerHTML = newpage;
+	fl.drawStripes();
+}
+
+folderList.prototype.drawFiles = function(data){
+	var fl = folderList;
 	var files = unserialize(data);
-	fmFileWindow.innerHTML = "";
+	fl.init();
+	fl.clear();
 	var newpage;
-	var td_hd = '<td style="padding-left: 2px; padding-right: 2px;" valign="middle">';
 	var sp_hd = '<span name="head" style="cursor: pointer; cursor: hand;" onclick="reloadFiles(\'';
 	var sp_tl = '</span></td>';
 	newpage = '<table cellspacing="0" cellpadding="2"><tbody><tr class="message_header">';
-	newpage += td_hd+'<input onclick="selectAll(this)" type="checkbox"></td><td></td><td></td>';
-	newpage += td_hd+sp_hd+'name\')" id="name">'+get_lang('file name')+sp_tl;
+	newpage += fl.td+'<input onclick="selectAll(this)" type="checkbox"></td><td></td><td></td>';
+	newpage += fl.td+sp_hd+'name\')" id="name">'+get_lang('file name')+sp_tl;
     	if (preferences.mime_type =='1')
-		newpage += td_hd+sp_hd+'mime\')" id="mime">'+get_lang('mime type')+sp_tl;
+		newpage += fl.td+sp_hd+'mime\')" id="mime">'+get_lang('mime type')+sp_tl;
 	if (preferences.size =='1')
-		newpage += td_hd+sp_hd+'size\')" id="size">'+get_lang('size')+'</a>'+sp_tl;
+		newpage += fl.td+sp_hd+'size\')" id="size">'+get_lang('size')+'</a>'+sp_tl;
 	if (preferences.created =='1')
-		newpage += td_hd+sp_hd+'creatd\')" id="creatd">'+get_lang('created')+'</a>'+sp_tl;
+		newpage += fl.td+sp_hd+'creatd\')" id="creatd">'+get_lang('created')+'</a>'+sp_tl;
 	if (preferences.modified =='1')
-		newpage += td_hd+sp_hd+'modifd\')" id="modifd">'+get_lang('modified')+'</a>'+sp_tl;
+		newpage += fl.td+sp_hd+'modifd\')" id="modifd">'+get_lang('modified')+'</a>'+sp_tl;
 	if (preferences.owner =='1')
-		newpage += td_hd+sp_hd+'owner\')" id="owner">'+get_lang('owner')+'</a>'+sp_tl;
+		newpage += fl.td+sp_hd+'owner\')" id="owner">'+get_lang('owner')+'</a>'+sp_tl;
 	if (preferences.createdby_id =='1')
-		newpage += td_hd+sp_hd+'creatdby\')" id="creatdby">'+get_lang('created by')+'</a>'+sp_tl;
+		newpage += fl.td+sp_hd+'creatdby\')" id="creatdby">'+get_lang('created by')+'</a>'+sp_tl;
 	if (preferences.modifiedby_id =='1')
-		newpage += td_hd+sp_hd+'modifdby\')" id="modifdby">'+get_lang('modified by')+'</a>'+sp_tl;
+		newpage += fl.td+sp_hd+'modifdby\')" id="modifdby">'+get_lang('modified by')+'</a>'+sp_tl;
 	if (preferences.comment =='1')
-		newpage += td_hd+sp_hd+'comm\')" id="comm">'+get_lang('comment')+'</a>'+sp_tl;
-	if (preferences.version =='1') newpage += td_hd+sp_hd+'vers\')" id="vers">'+get_lang('version')+'</a>'+sp_tl+'</tr>';
-	
-	var classTr = "tr_msg_read";
+		newpage += fl.td+sp_hd+'comm\')" id="comm">'+get_lang('comment')+'</a>'+sp_tl;
+	if (preferences.version =='1') newpage += fl.td+sp_hd+'vers\')" id="vers">'+get_lang('version')+'</a>'+sp_tl+'</tr>';
+
 	for (var i=0; i < files.length; i++)
 	{
-		newpage += '<tr class="'+classTr+'">'+td_hd;
+		newpage += '<tr>'+fl.td;
 		newpage += '<input name="fileman" value="'+files[i].name+'" type="checkbox"></td>';
 		if (permissions['private']) {
@@ -255,8 +277,8 @@
 		else
 			newpage += '<td></td>';
-		newpage += td_hd+'<img src="'+(files[i].icon)+'">';
+		newpage += fl.td+'<img src="'+(files[i].icon)+'">';
 		newpage += '<a id="name_'+files[i].name+'" href="/index.php?menuaction=filemanager.uifilemanager.view&file='+base64_encode(files[i].name)+'&path='+base64_encode(currentPath)+'" target="_blank">'+files[i].name+'</a>&nbsp;</td>';
-		if (preferences.mime_type =='1') newpage += td_hd+files[i].mime+'</td>';
-		if (preferences.size =='1') newpage += td_hd+borkb(files[i].size)+'</td>';
+		if (preferences.mime_type =='1') newpage += fl.td+files[i].mime+'</td>';
+		if (preferences.size =='1') newpage += fl.td+borkb(files[i].size)+'</td>';
 		var now = new Date();
 		var dtString = "";
@@ -268,5 +290,5 @@
 			else
 				dtString = created.getDate()+"/"+created.getMonth()+"/"+created.getFullYear();
-			newpage += td_hd+dtString+'</td>';
+			newpage += fl.td+dtString+'</td>';
 		}
 		if (preferences.modified =='1'){
@@ -280,17 +302,15 @@
 			else
 				dtString = "";
-			newpage += td_hd+dtString+'</td>';
+			newpage += fl.td+dtString+'</td>';
 		}
-		if (preferences.owner =='1') newpage += td_hd+files[i].owner+'</td>';
-		if (preferences.createdby_id =='1') newpage += td_hd+files[i].creatdby+'</td>';
-		if (preferences.modifiedby_id =='1') newpage += td_hd+files[i].modifdby+'</td>';
+		if (preferences.owner =='1') newpage += fl.td+files[i].owner+'</td>';
+		if (preferences.createdby_id =='1') newpage += fl.td+files[i].creatdby+'</td>';
+		if (preferences.modifiedby_id =='1') newpage += fl.td+files[i].modifdby+'</td>';
 		if (files[i].comm == null || files[i].comm.length == 0)
 			files[i].comm = "&lt;"+get_lang("no comments")+"&gt;";
-		if (preferences.comment =='1') newpage += td_hd+'<span id="'+files[i].name+'" onclick="setComments(this)">'+files[i].comm+'</span></td>';
-		if (preferences.version =='1') newpage += td_hd+'<span onclick="loadHistory(\''+files[i].name+'\')">'+files[i].vers+'</span></td></tr>';
-		classTr = (classTr == "tr_msg_read"?"tr_msg_read2":"tr_msg_read");
-
-	}
-	fmFileWindow.innerHTML = newpage;
+		if (preferences.comment =='1') newpage += fl.td+'<span id="'+files[i].name+'" onclick="setComments(this)">'+files[i].comm+'</span></td>';
+		if (preferences.version =='1') newpage += fl.td+'<span onclick="loadHistory(\''+files[i].name+'\')">'+files[i].vers+'</span></td></tr>';
+	}
+	fl.element.innerHTML = newpage;
 	header = document.getElementsByName('head');
 	for (var i=0; i < header.length; i++)
@@ -306,13 +326,30 @@
 		}
 	}
-}
-
-
-function loadToolbar(){
+	fl.drawStripes();
+}
+folderList.prototype.drawStripes = function(){
+	var classTr = "tr_msg_read";
+	folderList.init();
+	var elements = folderList.element.firstChild.firstChild.childNodes;
+	for (var i = 1; i < elements.length; i++){
+		elements[i].className = classTr;
+		classTr = (classTr == "tr_msg_read"?"tr_msg_read2":"tr_msg_read");
+	}
+}
+var folderList = new folderList();
+
+function toolbar()
+{
+	var element;
+}
+toolbar.prototype.clear = function (){
+	this.element.innerHTML = "";
+}
+toolbar.prototype.load = function (){
+	this.element = document.getElementById('fmMenu');
 	if (permissions['read'] == 0)
 		return;
-	var toolbar = document.getElementById('fmMenu');
 	var pageContent = '<table><tbody><tr>';
-	var createButton = function(name) { return '<td name="'+name+'" class="toolButton" onclick="toolbar_control(\''+name+'\');" title="'+name+'"><img src="'+templatePath+'images/button_'+name+'.png" alt="'+name+'"><small>'+get_lang(name.replace('_',' '))+'</small></td>'; }
+	var createButton = function(name) { return '<td name="'+name+'" class="toolButton" onclick="toolbar.control(\''+name+'\');" title="'+name+'"><img src="'+templatePath+'images/button_'+name+'.png" alt="'+name+'"><small>'+get_lang(name.replace('_',' '))+'</small></td>'; }
 
 	if (permissions['edit'] != 0){
@@ -326,49 +363,158 @@
 	pageContent += createButton('copy_to');
 
-	toolbar.innerHTML = pageContent+'</tr></tbody></table>';
-
-
-}
-
-function loadHistory(filename){
-	cExecute('/index.php?menuaction=filemanager.uifilemanager.history&file='+base64_encode(filename)+"&path="+base64_encode(currentPath),draw_window);
-}
-
-function loadPermissions(data){
-	var permission = parseInt(data);
-	var ACL_READ = 1;
-	var ACL_ADD = 2;
-	var ACL_EDIT = 4;
-	var ACL_DELETE = 8;
-	var ACL_PRIVATE = 16;
-
-	permissions['read']=(permission & ACL_READ);
-	permissions['add']=(permission & ACL_ADD);
-	permissions['edit']=(permission & ACL_EDIT);
-	permissions['delete']=(permission & ACL_DELETE);
-	permissions['private']=(permission & ACL_PRIVATE);
-	loadToolbar();
-	loadPreferences();
-	toolbar_control('reload');
-}
-
-function initDrawApi(){
-	currentPath = document.getElementById('currentPath').value;
-	cExecute('/index.php?menuaction=filemanager.uifilemanager.get_permissions&path='+base64_encode(currentPath),loadPermissions);
-	quotaSize = document.getElementById('quotaSize').value;
-	usedSpace = document.getElementById('usedSpace').value;
-
-	document.getElementById('divAppboxHeader').innerHTML = title_app;
-
-	if (parseInt(quotaSize) != 0)
-		document.getElementById('content_quota').innerHTML = '<table width="102" cellspacing="0" cellpadding="0" border="0" id="table_quota"><tbody><tr><td width="102" nowrap="true" height="15" background="../phpgwapi/templates/default/images/dsunused.gif"><table cellspacing="0" cellpadding="0" border="0" style="width: '+parseInt((usedSpace/quotaSize)*100)+'%;"><tbody><tr><td height="15" class="dsused"/></tr></tbody></table></td><td nowrap="true" align="center"><span class="boxHeaderText">'+parseInt(usedSpace/quotaSize*100)+'% ('+(usedSpace/1024/1024).toFixed(1)+'M/'+(quotaSize/1024/1024)+'M)</span></td></tr></tbody></table></td></tr></table>';
-	displayMessages();
-	resizeDiv();
-	window.onresize = resizeDiv;
-	document.body.style.overflow = "hidden";
-
-	// Disabled for now
-	// document.getElementById('main_table').style.visibility = "";
-
-}
-
+	this.element.innerHTML = pageContent+'</tr></tbody></table>';
+
+}
+toolbar.prototype.control = function (arg)
+{
+	//Used to get button position
+	var button = document.getElementsByName(arg);
+	button = button[0];
+	switch (arg) {
+		case 'new':
+			elements = new Array();
+			elements[0] = new Array();
+			elements[0]['text'] = get_lang('empty file');
+			elements[0]['url'] = 'javascript:newEmptyFile();';
+			elements[1] = new Array();
+			elements[1]['text'] = get_lang('File from model');
+			address = document.location.toString();
+			address = address.split("?");
+			elements[1]['url'] = address[0]+"?menuaction=filemanager.uifilemanager.fileModels";
+			elements[2] = new Array();
+			elements[2]['text'] = get_lang('Upload');
+			address = document.location.toString();
+			address = address.split("?");
+			elements[2]['url'] = address[0]+"?menuaction=filemanager.uifilemanager.index&upload=clicked&upload.x=1&path="+base64_encode(currentPath);
+			draw_menu(arg,elements);
+			break;
+		case 'rename':
+			var one_checked = false;
+			files=document.getElementsByName('fileman');
+			for (i = 0; i <  files.length; i++)
+				if (files[i].checked){
+					one_checked = true;
+					files[i].checked = false;
+					var nameLink = document.getElementById('name_'+files[i].value);
+					var inputName = document.createElement('INPUT');
+					inputName.id = 'input_'+files[i].value;
+					var filename = nameLink.innerHTML;
+					inputName.value = filename;
+					inputName.onblur = function () { cExecute('/index.php?menuaction=filemanager.vfs_functions.rename&file='+base64_encode(this.id.substr(6))+'&to='+base64_encode(this.value)+"&path="+base64_encode(currentPath),updateRename) };
+					nameLink.parentNode.appendChild(inputName);
+					nameLink.parentNode.removeChild(nameLink);
+				}
+			if (!one_checked)
+				write_msg(get_lang('Please select a file'));
+			break;
+		case 'edit':
+			var one_checked = false;
+			files=document.getElementsByName('fileman');
+			for (i = 0; i <  files.length; i++)
+				if (files[i].checked){
+					one_checked = true;
+					var filename=files[i].value;
+				}
+			if (one_checked){
+				address = document.location.toString();
+				address = address.split("&");
+				document.location = address[0]+"&"+arg+".x=1&filename="+base64_encode(filename)+".&path="+base64_encode(currentPath);
+			}
+			else
+			{
+				write_msg(get_lang('Please select a file'));
+				return;
+			}
+			break;
+		case 'delete':
+			filesUrl = "";
+			var one_checked = false;
+			files=document.getElementsByName('fileman');
+			var j=0;
+			for (i = 0; i <  files.length; i++)
+				if (files[i].checked){
+					one_checked = true;
+					filesUrl += "&fileman["+j+"]="+files[i].value;
+					j++;
+				}
+			if (!one_checked)
+			{
+				write_msg(get_lang('Please select a file'));
+				return;
+			}
+
+			cExecute('/index.php?menuaction=filemanager.vfs_functions.delete&path='+
+					base64_encode(currentPath)+filesUrl,handlerDelete);
+			break;
+		case 'move_to':
+		case 'copy_to':
+			filesUrl = "";
+			var one_checked = false;
+			files=document.getElementsByName('fileman');
+			var j=0;
+			for (i = 0; i <  files.length; i++)
+				if (files[i].checked){
+					one_checked = true;
+					filesUrl += "&fileman["+j+"]="+files[i].value;
+					j++;
+				}
+			if (!one_checked)
+			{
+				write_msg(get_lang('Please select a file'));
+				return;
+			}
+			var elements = new Array();
+			inputEl = document.getElementById('content_folders');
+			for(i=0; i< inputEl.childNodes.length; i++)
+			{
+				if (inputEl.childNodes[i].nodeName != 'SPAN')
+					continue;
+				elements[i] = new Array();
+				elements[i]['text']=inputEl.childNodes[i].innerHTML;
+				address = document.location.toString();
+				address = address.split("&");
+				elements[i]['url'] = address[0]+
+					"&"+escape(arg)+".x=10"+
+					"&to="+base64_encode(inputEl.childNodes[i].innerHTML)+
+					filesUrl;
+
+			}
+			draw_menu(arg,elements);
+			break;
+		case 'reload':
+			cExecute('/index.php?menuaction=filemanager.uifilemanager.dir_ls&path='+base64_encode(currentPath)+'&criteria='+criteria+'&otype='+order_type,folderList.drawFiles);
+			return;
+		case 'tools':
+			elements = new Array();
+			elements[0] = new Array();
+			elements[0]['text'] = get_lang('Preferences');
+			elements[0]['url'] = 'preferences/preferences.php?appname=filemanager';
+			elements[0]['img'] = templatePath+'images/preferences.png';
+			elements[1] = new Array();
+			elements[1]['text'] = get_lang('Search');
+			elements[1]['url'] = 'javascript:\
+				document.getElementById("menu_newFiletools").style.visibility="hidden";\
+				document.getElementById("em_message_search").focus();';
+			elements[1]['img'] = templatePath+'images/search.gif';
+			/*
+			   elements[2] = new Array();
+			   elements[2]['text'] = get_lang('Edit Folders');
+			   elements[2]['url'] = 'javascript:EditFolders()';
+			   elements[2]['img'] = 'images/mime16_directory.png';
+			   */
+			elements[3] = new Array();
+			elements[3]['text'] = get_lang('Share Folders');
+			elements[3]['url'] = "index.php?menuaction=preferences.uiaclprefs.index&acl_app=filemanager";
+			elements[3]['img'] = templatePath+'images/mime16_directory.png';
+			elements[4] = new Array();
+			elements[4]['text'] = get_lang('Edit Columns');
+			elements[4]['url'] = "javascript:EditColumns()";
+			elements[4]['img'] = templatePath+'images/editpaste.png';
+			draw_menu(arg,elements);
+			break;
+		default:
+			return;
+	}
+}
+var toolbar = new toolbar();
+
Index: sandbox/filemanager/js/common_functions.js
===================================================================
--- sandbox/filemanager/js/common_functions.js	(revision 1727)
+++ sandbox/filemanager/js/common_functions.js	(revision 1730)
@@ -2,156 +2,4 @@
 	currentPath = path;
 	cExecute('/index.php?menuaction=filemanager.uifilemanager.get_permissions&path='+base64_encode(path),loadPermissions);
-}
-
-function toolbar_control(arg)
-{
-	//Used to get button position
-	var button = document.getElementsByName(arg);
-        button = button[0];
-	switch (arg) {
-		case 'new':
-			elements = new Array();
-			elements[0] = new Array();
-			elements[0]['text'] = get_lang('empty file');
-			elements[0]['url'] = 'javascript:newEmptyFile();';
-			elements[1] = new Array();
-			elements[1]['text'] = get_lang('File from model');
-			address = document.location.toString();
-	                address = address.split("?");
-			elements[1]['url'] = address[0]+"?menuaction=filemanager.uifilemanager.fileModels";
-			elements[2] = new Array();
-			elements[2]['text'] = get_lang('Upload');
-			address = document.location.toString();
-			address = address.split("?");
-			elements[2]['url'] = address[0]+"?menuaction=filemanager.uifilemanager.index&upload=clicked&upload.x=1&path="+base64_encode(currentPath);
-			draw_menu(arg,elements);
-			break;
-		case 'rename':
-			var one_checked = false;
-			files=document.getElementsByName('fileman');
-			for (i = 0; i <  files.length; i++)
-				if (files[i].checked){
-					one_checked = true;
-					files[i].checked = false;
-					var nameLink = document.getElementById('name_'+files[i].value);
-					var inputName = document.createElement('INPUT');
-					inputName.id = 'input_'+files[i].value;
-					var filename = nameLink.innerHTML;
-					inputName.value = filename;
-					inputName.onblur = function () { cExecute('/index.php?menuaction=filemanager.vfs_functions.rename&file='+base64_encode(this.id.substr(6))+'&to='+base64_encode(this.value)+"&path="+base64_encode(currentPath),updateRename) };
-					nameLink.parentNode.appendChild(inputName);
-					nameLink.parentNode.removeChild(nameLink);
-				}
-			if (!one_checked)
-				write_msg(get_lang('Please select a file'));
-			break;
-		case 'edit':
-			var one_checked = false;
-			files=document.getElementsByName('fileman');
-			for (i = 0; i <  files.length; i++)
-				if (files[i].checked){
-					one_checked = true;
-					var filename=files[i].value;
-				}
-			if (one_checked){
-				address = document.location.toString();
-                                address = address.split("&");
-				document.location = address[0]+"&"+arg+".x=1&filename="+base64_encode(filename);
-			}
-			else
-			{
-				write_msg(get_lang('Please select a file'));
-				return;
-			}
-			break;
-		case 'delete':
-			filesUrl = "";
-			var one_checked = false;
-			files=document.getElementsByName('fileman');
-			var j=0;
-			for (i = 0; i <  files.length; i++)
-				if (files[i].checked){
-					one_checked = true;
-					filesUrl += "&fileman["+j+"]="+files[i].value;
-					j++;
-				}
-			if (!one_checked)
-			{
-				write_msg(get_lang('Please select a file'));
-				return;
-			}
-
-			cExecute('/index.php?menuaction=filemanager.vfs_functions.delete&path='+
-					base64_encode(currentPath)+filesUrl,handlerDelete);
-			break;
-		case 'move_to':
-		case 'copy_to':
-			filesUrl = "";
-			var one_checked = false;
-			files=document.getElementsByName('fileman');
-			var j=0;
-			for (i = 0; i <  files.length; i++)
-				if (files[i].checked){
-					one_checked = true;
-					filesUrl += "&fileman["+j+"]="+files[i].value;
-					j++;
-				}
-			if (!one_checked)
-			{
-				write_msg(get_lang('Please select a file'));
-				return;
-			}
-			var elements = new Array();
-			inputEl = document.getElementById('content_folders');
-			for(i=0; i< inputEl.childNodes.length; i++)
-			{
-				if (inputEl.childNodes[i].nodeName != 'SPAN')
-					continue;
-				elements[i] = new Array();
-				elements[i]['text']=inputEl.childNodes[i].innerHTML;
-				address = document.location.toString();
-				address = address.split("&");
-				elements[i]['url'] = address[0]+
-					"&"+escape(arg)+".x=10"+
-					"&to="+base64_encode(inputEl.childNodes[i].innerHTML)+
-					filesUrl;
-
-			}
-			draw_menu(arg,elements);
-			break;
-		case 'reload':
-			cExecute('/index.php?menuaction=filemanager.uifilemanager.dir_ls&path='+base64_encode(currentPath)+'&criteria='+criteria+'&otype='+order_type,drawFiles);
-			return;
-		case 'tools':
-			elements = new Array();
-                        elements[0] = new Array();
-                        elements[0]['text'] = get_lang('Preferences');
-                        elements[0]['url'] = 'preferences/preferences.php?appname=filemanager';
-			elements[0]['img'] = templatePath+'images/preferences.png';
-                        elements[1] = new Array();
-                        elements[1]['text'] = get_lang('Search');
-                        elements[1]['url'] = 'javascript:\
-						document.getElementById("menu_newFiletools").style.visibility="hidden";\
-						document.getElementById("em_message_search").focus();';
-			elements[1]['img'] = templatePath+'images/search.gif';
-                        /*
-			elements[2] = new Array();
-                        elements[2]['text'] = get_lang('Edit Folders');
-                        elements[2]['url'] = 'javascript:EditFolders()';
-			elements[2]['img'] = 'images/mime16_directory.png';
-			*/
-                        elements[3] = new Array();
-                        elements[3]['text'] = get_lang('Share Folders');
-                        elements[3]['url'] = "index.php?menuaction=preferences.uiaclprefs.index&acl_app=filemanager";
-			elements[3]['img'] = templatePath+'images/mime16_directory.png';
-                        elements[4] = new Array();
-                        elements[4]['text'] = get_lang('Edit Columns');
-                        elements[4]['url'] = "javascript:EditColumns()";
-			elements[4]['img'] = templatePath+'images/editpaste.png';
-                        draw_menu(arg,elements);
-			break;
-		default:
-			return;
-	}
 }
 
@@ -355,4 +203,5 @@
 			}
 		}
+	folderList.drawStripes();
 }
 
@@ -437,4 +286,29 @@
 		return;
 	}
-	cExecute('/index.php?menuaction=filemanager.uifilemanager.search&text='+inputText.value,drawSearch);
-}
+	cExecute('/index.php?menuaction=filemanager.uifilemanager.search&text='+inputText.value,folderList.drawSearch);
+}
+function selectAll(el){
+        checkBoxes = document.getElementsByName('fileman');
+        if (el.checked)
+                for (i=0; i < checkBoxes.length; i++)
+                        checkBoxes[i].checked = true;
+        else
+                for (i=0; i < checkBoxes.length; i++)
+                        checkBoxes[i].checked = false;
+
+}
+function borkb(size){
+                kbyte = 1024;
+                mbyte = kbyte*1024;
+                gbyte = mbyte*1024;
+                if (!size)
+                        size = 0;
+                if (size < kbyte)
+                        return size + 'B';
+                else if (size < mbyte)
+                        return parseInt(size/kbyte) + 'KB';
+                else if (size < gbyte)
+                        return (size/mbyte).toFixed(1) + 'MB';
+                else
+                        return parseInt(size/gbyte).toFixed(1) + 'GB';
+}
