Index: sandbox/filemanager/js/common_functions.js
===================================================================
--- sandbox/filemanager/js/common_functions.js	(revision 1575)
+++ sandbox/filemanager/js/common_functions.js	(revision 1627)
@@ -1,24 +1,48 @@
+var menuTimeout;
+/* draw_menu(id of menu, left position, top position, menu elements) */
+function draw_menu(id,left_pos,top_pos,elements){
+	var menu = document.getElementById('menu_newFile'+id);
+	if (menu == null){
+		menu = document.createElement('DIV');
+		menu.id = "menu_newFile"+id;
+		menu.style.left = left_pos+"px";
+		menu.style.top = top_pos+"px";
+		for(j in elements)
+			menu.innerHTML += "<a href="+elements[j]['url']+">"+elements[j]['text']+"</a><br>";
+
+		menu.onmouseout = function () { menuTimeout = setTimeout("document.getElementById('menu_newFile"+id+"').style.visibility = 'hidden'",50);}
+		menu.onmouseover = function () { clearTimeout(menuTimeout); };
+		menu.className = "menu_box";
+		document.getElementById('tableDivAppbox').appendChild(menu);
+	}
+	menu.style.visibility = '';
+
+}
 function formfmValidate(arg)
 {
+	var button = document.getElementsByName(arg);
+	button = button[0];
 	switch (arg) {
 		case 'newdir':
-		case 'newfile':
-			var name = prompt(get_lang('Enter with the name of new file/directory'), '');
-			var input_text = document.getElementById('newfile_or_dir');
-			if (name == null || ! validateFileExtension(name))
-			{
-				return false;
-			}
-			else
-			{
-				var fileExtension = name.split(".");
-			        fileExtension = fileExtension[1];
-				if (typeof(fileExtension) == 'undefined')
-					input_text.value = name+".html";
-				else
-					input_text.value = name;
-				return true;
-			}
-			break
+			break;
+		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(document.getElementById('cdtodir').value);
+
+			draw_menu(arg,button.parentNode.offsetLeft+50,190,elements);
+			return false;
+			break;
 		case 'edit_comments':
 		case 'rename':
@@ -34,7 +58,38 @@
 			else
 			{
-				alert(get_lang('Please select a file'));
+				write_msg(get_lang('Please select a file'));
 				return false;
 			}
+			break;
+		case 'move_to':
+		case 'copy_to':
+			filesUrl = "";
+			var one_checked = false;
+			files=document.getElementsByClassName('checkbox');
+			for (i = 0; i <  files.length; i++)
+				if (files[i].checked){
+					one_checked = true;
+					filesUrl += "&"+files[i].name+"="+files[i].value;
+				}
+			if (!one_checked)
+			{
+				write_msg(get_lang('Please select a file'));
+				return false;
+			}
+			var elements = new Array();
+			inputEl = document.getElementsByName('todir');
+			for(i=0; i< inputEl[0].childNodes.length; i++)
+			{
+				elements[i] = new Array();
+				elements[i]['text'] =inputEl[0].childNodes[i].innerHTML;
+				address = document.location.toString();
+				address = address.split("&");
+				elements[i]['url'] = address[0]+
+					"&todir="+inputEl[0].childNodes[i].innerHTML+
+					"&"+arg+".x=10"+filesUrl;
+			}
+			draw_menu(arg,button.parentNode.offsetLeft+50,190,elements);
+			return false;
+			break;
 		default:
 			return true;
@@ -62,5 +117,5 @@
 	if ( error_flag == true )
 	{
-		alert(get_lang('File extension forbidden or invalid file') + '.');
+		write_error(get_lang('File extension forbidden or invalid file') + '.');
 		return false;
 	}
@@ -81,2 +136,98 @@
 
 }
+
+
+function newEmptyFile(){
+	var name = prompt(get_lang('Enter with the name of new file/directory'), '');
+	var input_text = document.getElementById('newfile_or_dir');
+	if (name != null && name != '' && validateFileExtension(name))
+	{
+		var fileExtension = name.split(".");
+		fileExtension = fileExtension[1];
+		if (typeof(fileExtension) == 'undefined')
+			input_text.value = name+".html";
+		else
+			input_text.value = name;
+		address = document.location.toString();
+		address = address.split("&");
+		document.location = address[0]+"&newfile.x=clicked&newfile_or_dir="+input_text.value;
+
+	}
+
+}
+
+
+/*
+ * base64.js - Base64 encoding and decoding functions
+ *
+ * Copyright (c) 2007, David Lindquist <david.lindquist@gmail.com>
+ * Released under the MIT license
+ */
+
+function base64_encode(str) {
+	var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
+	var encoded = [];
+	var c = 0;
+	while (c < str.length) {
+		var b0 = str.charCodeAt(c++);
+		var b1 = str.charCodeAt(c++);
+		var b2 = str.charCodeAt(c++);
+		var buf = (b0 << 16) + ((b1 || 0) << 8) + (b2 || 0);
+		var i0 = (buf & (63 << 18)) >> 18;
+		var i1 = (buf & (63 << 12)) >> 12;
+		var i2 = isNaN(b1) ? 64 : (buf & (63 << 6)) >> 6;
+		var i3 = isNaN(b2) ? 64 : (buf & 63);
+		encoded[encoded.length] = chars.charAt(i0);
+		encoded[encoded.length] = chars.charAt(i1);
+		encoded[encoded.length] = chars.charAt(i2);
+		encoded[encoded.length] = chars.charAt(i3);
+	}
+	return encoded.join('');
+}
+
+function base64_decode(str) {
+	var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
+	var invalid = {
+strlen: (str.length % 4 != 0),
+	chars:  new RegExp('[^' + chars + ']').test(str),
+	equals: (/=/.test(str) && (/=[^=]/.test(str) || /={3}/.test(str)))
+	};
+	if (invalid.strlen || invalid.chars || invalid.equals)
+		throw new Error('Invalid base64 data');
+	var decoded = [];
+	var c = 0;
+	while (c < str.length) {
+		var i0 = chars.indexOf(str.charAt(c++));
+		var i1 = chars.indexOf(str.charAt(c++));
+		var i2 = chars.indexOf(str.charAt(c++));
+		var i3 = chars.indexOf(str.charAt(c++));
+		var buf = (i0 << 18) + (i1 << 12) + ((i2 & 63) << 6) + (i3 & 63);
+		var b0 = (buf & (255 << 16)) >> 16;
+		var b1 = (i2 == 64) ? -1 : (buf & (255 << 8)) >> 8;
+		var b2 = (i3 == 64) ? -1 : (buf & 255);
+		decoded[decoded.length] = String.fromCharCode(b0);
+		if (b1 >= 0) decoded[decoded.length] = String.fromCharCode(b1);
+		if (b2 >= 0) decoded[decoded.length] = String.fromCharCode(b2);
+	}
+	return decoded.join('');
+}
+
+
+function setRestricted(data){
+	if (data.indexOf("True") == 0){
+		returnVal = data.split(':');
+		var img_lock = document.getElementById('restrict_'+returnVal[1]);
+		if (img_lock.src.indexOf('button_unlock') > 0)
+		{
+			img_lock.src = img_lock.src.replace(/button_unlock/g,'button_lock');
+			write_msg(get_lang('%1 marked as restricted',returnVal[1]));
+		}
+		else
+		{
+			img_lock.src = img_lock.src.replace(/button_lock/g,'button_unlock');
+			write_msg(get_lang('%1 unmarked as restricted',returnVal[1]));
+		}
+	}
+	else
+		write_error("Could not mark as restricted");
+}
