Index: trunk/expressoMail1_2/js/wfolders.js
===================================================================
--- trunk/expressoMail1_2/js/wfolders.js	(revision 1121)
+++ trunk/expressoMail1_2/js/wfolders.js	(revision 5872)
@@ -6,155 +6,122 @@
 	}
 
-	cWFolders.prototype.makeWindowNew = function(border_id, type,from_search)
-	{ //Javascript doesn't seems to have polimorfism
-		_this = this;
+	cWFolders.prototype.load = function( border_id, type )
+	{
+		var folder 		= {};
+		var textButton	= "";
+		
+		switch( type )
+		{
+			case 'save' :
+				textButton = get_lang('Save');
+				break;
+					
+			case 'send_and_file' :
+				textButton = get_lang('Send and file');
+				break;
+					
+			case 'move_to' :
+				textButton = get_lang('Move');	
+				break;
+			
+			case 'change_folder' :
+				textButton = get_lang('Change folder');
+				break;
+				
+			default :
+				textButton = get_lang(type);
+		}
+		
+		var winSaveFile = $("#sendFileMessages");
+			winSaveFile.html( DataLayer.render( BASE_PATH + "modules/mail/templates/sendFileMessages.ejs", {}));
+			winSaveFile.dialog(
+					{
+						height		: 250,
+						width		: 300,
+						resizable	: false,
+						title		: get_lang('Send and file'),
+						modal		: true,
+						buttons		: [
+										 {
+										 	text	: get_lang("Close"), 
+										 	click	: function()
+										 	{
+												winSaveFile.dialog("destroy");
+										 	}
+										 },
+										 {
+										 	text	: textButton, 
+										 	click	: function()
+										 	{
+												if (type == 'save')
+												{
+													save_as_msg(border_id, folder.id, folder.caption,true);
+												}
+												else if (type == 'send_and_file')
+												{
+													send_message( border_id, folder.id, folder.caption);
+													wfolders.alert = true;
+												}
+												else if (type == 'move_to')
+												{
+													var msg_number =  ( border_id ? border_id.replace('_r','') : 'selected');
+													
+													if (border_id.match('search'))
+														move_search_msgs(border_id, folder.id, folder.caption);	
+													else{
+														proxy_mensagens.proxy_move_messages('null',msg_number, border_id, folder.id, folder.caption);
+														wfolders.alert = true;
+													}
+												}
+												else if (type == 'change_folder')
+												{
+													change_folder(folder.id, folder.caption);
+													wfolders.alert = true;
+												}
+
+										 		winSaveFile.dialog("destroy");
+										 	}
+										 }
+									]	 	
+					});	
+			
+		winSaveFile.next().css("background-color", "#E0EEEE");
+			
+		var foldersTree = jQuery("#foldertree-container-sendFileMessage")
+		.removeClass('empty-container')
+		.html(DataLayer.render(BASE_PATH + 'api/templates/foldertree.ejs', {folders: [cp_tree1, cp_tree2, [] ]}))
+		.find("#foldertree").treeview()
+		.click(function(event)
+		{
+			//request new selected folder messages
+			var target = $(event.target);
+
+			if( target.is('.collapsable-hitarea, .expandable-hitarea, .lastCollapsable, .lastExpandable, .treeview') )
+			    return;
+
+			if( !target.attr('id') )
+			    target = target.parent();
+
+	        if (target.attr('id') == "foldertree") return;
+			
+			folder.id 		= target.attr('id');
+			folder.child 	= target.find('.folder');
+			folder.caption	= target.find('span').attr('title');			
+			
+			$('.filetree span.folder.selected').removeClass('selected');
+			if(!target.is('#foldertree > .expandable, #foldertree > .collapsable'))
+				$(target).children('.folder').addClass('selected');
+			
+			selectedFolder = {
+			    id: folder.id, 
+			    name: folder.child.attr('title'),
+			    'class': folder.child.attr('class')
+			};
+		});
+	}
 	
-		var el = document.createElement("DIV");
-		el.style.visibility = "hidden";
-		el.style.position = "absolute";
-		el.style.left = "0px";
-		el.style.top = "0px";
-		el.style.width = "0px";
-		el.style.height = "0px";
-		el.id = 'dJSWin_wfolders';
-		document.body.appendChild(el);
-		
-		el.innerHTML = "<table><tbody><tr><td>&nbsp</td><td>"+
-		"<div id='wfolders_content_tree' style='height:200px; width:250px; overflow:auto; background:#F7F7F7'></div>"+
-		"</td></tr></tbody></table>";
-
-		var space = document.createElement('SPAN');
-		space.innerHTML = "<BR>&nbsp;&nbsp;";
-		el.appendChild(space);
-
-		var butt = Element('dJSWin_wfolders_bok')
-		if (!butt){
-			butt = document.createElement('INPUT');
-			butt.id = 'dJSWin_wfolders_bok';
-			butt.type = 'button';
-			el.appendChild(butt);
-		}
-		if (type == 'save')
-				butt.value = get_lang('Save'); 
-		else if (type == 'send_and_file')
-                butt.value = get_lang('Send and file'); 
-		else if (type == 'move_to')
-			butt.value = get_lang('Move');
-		else if (type == 'change_folder')
-			butt.value = get_lang('Change folder');	
-		else //default value
-			butt.value = get_lang(type);
-
-		butt.onclick = function () {
-			wfolders.arrayWin[el.id].close();
-			if (type == 'save'){
-				save_as_msg(border_id, wfolders_tree._selected.id, wfolders_tree._selected.caption,true);
-			}
-			else if (type == 'send_and_file'){
-				send_message(border_id, wfolders_tree._selected.id, wfolders_tree._selected.caption);
-				wfolders.alert = true;
-			}
-			else if (type == 'move_to')	{
-				var msg_number =  (border_id ? border_id.replace('_r','') : 'selected');
-				if (border_id.match('search'))
-					move_search_msgs(border_id, wfolders_tree._selected.id, wfolders_tree._selected.caption);	
-				else{
-					proxy_mensagens.proxy_move_messages('null',msg_number, border_id, wfolders_tree._selected.id, wfolders_tree._selected.caption);
-					wfolders.alert = true;
-				}
-			}
-			else if (type == 'change_folder'){
-				change_folder(wfolders_tree._selected.id, wfolders_tree._selected.caption);
-				wfolders.alert = true;
-			}
-			else if (type == 'import'){
-				import_msgs(wfolders_tree);
-			}
-		};
-		if (type == 'save')
-			butt.value = get_lang('Save');
-		else if (type == 'send_and_file')
-			butt.value = get_lang('Send and file');
-
-		var space = document.createElement('SPAN');
-		space.innerHTML = "&nbsp;&nbsp;";
-		el.appendChild(space);
-
-		var butt = document.createElement('BUTTON');
-		var buttext = document.createTextNode(get_lang('Close'));
-		butt.appendChild(buttext);
-		butt.onclick = function () {wfolders.arrayWin[el.id].close();};
-		el.appendChild(butt);
-
-		wfolders_tree = new dFTree({name: 'wfolders_tree'});
-		if(!expresso_offline)
-			var n_root = new dNode({id:'root', caption:get_lang("My Folders")});
-		else
-			var n_root = new dNode({id:'local_root', caption:get_lang("local messages")});
-		wfolders_tree.add(n_root,'anything'); //Places the root; second argument can be anything.
-
-		var folders = tree_folders.getNodesList(cyrus_delimiter);
-		for (var i=1; i<folders.length; i++)
-		{
-			if (proxy_mensagens.is_local_folder(folders[i].id) && from_search) {
-				continue;
-			}
-			var nn = new dNode({
-				id: folders[i].id,
-				caption: lang_folder(folders[i].caption),
-				plusSign: folders[i].plusSign
-			});
-			wfolders_tree.add(nn, folders[i].parent);
-			
-		}
-		Element('wfolders_content_tree').innerHTML = ""; //As buscas nÃ£o podem incluir mover entre pastas locais, pelo menos por enquanto
-		wfolders_tree.draw(Element('wfolders_content_tree'));
-		n_root.changeState();
-		if(!expresso_offline)
-			wfolders_tree.getNodeById('INBOX')._select();
-		else
-			wfolders_tree.getNodeById('local_Inbox')._select();
-		_this.showWindow(el, type);
-	}
-
 	cWFolders.prototype.makeWindow = function(border_id, type)
 	{
-		this.makeWindowNew(border_id,type,false);
-	}
-	
-	cWFolders.prototype.showWindow = function (div, type)
-	{
-		if(! div) {
-			alert(get_lang("This list has no participants."));
-			return;
-		}
-		
-		if(! this.arrayWin[div.id]) {
-			div.style.width = "275px";
-			div.style.height = "250px";
-			var title = get_lang('Select a folder')+":";
-			var wHeight = div.offsetHeight + "px";
-			var wWidth =  div.offsetWidth   + "px";
-			div.style.width = div.offsetWidth - 5;
-
-			win = new dJSWin({
-				id: 'win_'+div.id,
-				content_id: div.id,
-				width: wWidth,
-				height: wHeight,
-				title_color: '#3978d6',
-				bg_color: '#eee',
-				title: title,
-				title_text_color: 'white',
-				button_x_img: '../phpgwapi/images/winclose.gif',
-				border: true });
-			
-			this.arrayWin[div.id] = win;
-			win.draw();
-		}
-		else {
-			win = this.arrayWin[div.id];
-		}
-		win.open();
+		this.load( border_id, type, false);
 	}
 	
