Index: trunk/expressoMail1_2/js/draw_api.js
===================================================================
--- trunk/expressoMail1_2/js/draw_api.js	(revision 1108)
+++ trunk/expressoMail1_2/js/draw_api.js	(revision 1121)
@@ -22,67 +22,68 @@
 	// Check if the tree folders alredy exist.
 	if (Element('dftree_tree_folders')){
-		var update_tree_folders = function(data){
-			build_quota(data);
-			var unseen_in_mailbox = 0;
-			var unseen_in_shared_folders = 0;
-			for (var i=0; i<data.length; i++){
-				if ( data[i].folder_unseen > 0 )
+		if (!expresso_offline) {
+			var update_tree_folders = function(data){
+				build_quota(data);
+				var unseen_in_mailbox = 0;
+				var unseen_in_shared_folders = 0;
+				for (var i=0; i<data.length; i++){
+					if ( data[i].folder_unseen > 0 )
+					{
+						unseen_in_mailbox = parseInt( unseen_in_mailbox + data[ i ].folder_unseen );
+						if ( data[i].folder_id.indexOf( 'INBOX' ) !== 0 )
+							unseen_in_shared_folders = parseInt( unseen_in_shared_folders + data[ i ].folder_unseen );
+					}
+	
+					var folder_unseen = Element('dftree_'+data[i].folder_id+'_unseen');
+					
+					if ((folder_unseen) && (data[i].folder_unseen > 0))
+					{
+						folder_unseen.innerHTML = data[i].folder_unseen;
+					}
+					else if (data[i].folder_unseen > 0)
+					{
+						tree_folders.getNodeById(data[i].folder_id).alter({caption:lang_folder(data[i].folder_name) + '<font style=color:red>&nbsp(</font><span id="dftree_'+data[i].folder_id+'_unseen" style=color:red>'+data[i].folder_unseen+'</span><font style=color:red>)</font>'});
+						tree_folders.getNodeById(data[i].folder_id)._refresh();
+					}
+					else if (data[i].folder_unseen <= 0)
+					{
+						tree_folders.getNodeById(data[i].folder_id).alter({caption:lang_folder(data[i].folder_name)});
+						tree_folders.getNodeById(data[i].folder_id)._refresh();
+					}
+
+					if(data[i].folder_id == current_folder){					
+						var old_new_m = isNaN(parseInt(Element('new_m').innerHTML)) ? parseInt(Element('new_m').firstChild.innerHTML) : parseInt(Element('new_m').innerHTML);
+	//					if(!isNaN(old_new_m) && old_new_m < data[i].folder_unseen){
+	//						Element('tot_m').innerHTML = parseInt(Element('tot_m').innerHTML) + (parseInt(data[i].folder_unseen)-old_new_m);
+	//					}
+						Element('new_m').innerHTML = data[i].folder_unseen ? '<font color="RED">'+data[i].folder_unseen+'</font>' : 0;
+						draw_paging(Element('tot_m').innerHTML);
+					}
+				}
+
+				var display_unseen_in_mailbox = tree_folders.getNodeById( 'root' );
+				//if ( unseen_in_mailbox )
+				//	display_unseen_in_mailbox.alter({caption:'<font style=color:red>[</font><span id="dftree_root_unseen" style="color:red">' + unseen_in_mailbox +'</span><font style=color:red>]</font> ' + get_lang("My Folders")});
+				//else
+					display_unseen_in_mailbox.alter({caption:get_lang("My Folders")});
+				display_unseen_in_mailbox._refresh();
+	
+				var display_unseen_in_shared_folders = tree_folders.getNodeById( 'user' );
+				if ( display_unseen_in_shared_folders )
 				{
-					unseen_in_mailbox = parseInt( unseen_in_mailbox + data[ i ].folder_unseen );
-					if ( data[i].folder_id.indexOf( 'INBOX' ) !== 0 )
-						unseen_in_shared_folders = parseInt( unseen_in_shared_folders + data[ i ].folder_unseen );
+					if ( unseen_in_shared_folders )
+						display_unseen_in_shared_folders.alter({caption:'<font style=color:red>[</font><span id="dftree_user_unseen" style="color:red">' + unseen_in_shared_folders +'</span><font style=color:red>]</font> ' + get_lang("Shared folders")});
+					else
+						display_unseen_in_shared_folders.alter({caption:get_lang("Shared folders")});
+					display_unseen_in_shared_folders._refresh();
 				}
-
-				var folder_unseen = Element('dftree_'+data[i].folder_id+'_unseen');
-				
-				if ((folder_unseen) && (data[i].folder_unseen > 0))
-				{
-					folder_unseen.innerHTML = data[i].folder_unseen;
-				}
-				else if (data[i].folder_unseen > 0)
-				{
-					tree_folders.getNodeById(data[i].folder_id).alter({caption:lang_folder(data[i].folder_name) + '<font style=color:red>&nbsp(</font><span id="dftree_'+data[i].folder_id+'_unseen" style=color:red>'+data[i].folder_unseen+'</span><font style=color:red>)</font>'});
-					tree_folders.getNodeById(data[i].folder_id)._refresh();
-				}
-				else if (data[i].folder_unseen <= 0)
-				{
-					tree_folders.getNodeById(data[i].folder_id).alter({caption:lang_folder(data[i].folder_name)});
-					tree_folders.getNodeById(data[i].folder_id)._refresh();
-				}
-
-				if(data[i].folder_id == current_folder){					
-					var old_new_m = isNaN(parseInt(Element('new_m').innerHTML)) ? parseInt(Element('new_m').firstChild.innerHTML) : parseInt(Element('new_m').innerHTML);
-//					if(!isNaN(old_new_m) && old_new_m < data[i].folder_unseen){
-//						Element('tot_m').innerHTML = parseInt(Element('tot_m').innerHTML) + (parseInt(data[i].folder_unseen)-old_new_m);
-//					}
-					Element('new_m').innerHTML = data[i].folder_unseen ? '<font color="RED">'+data[i].folder_unseen+'</font>' : 0;
-					draw_paging(Element('tot_m').innerHTML);
-				}
-			}
-
-			var display_unseen_in_mailbox = tree_folders.getNodeById( 'root' );
-			//if ( unseen_in_mailbox )
-			//	display_unseen_in_mailbox.alter({caption:'<font style=color:red>[</font><span id="dftree_root_unseen" style="color:red">' + unseen_in_mailbox +'</span><font style=color:red>]</font> ' + get_lang("My Folders")});
-			//else
-				display_unseen_in_mailbox.alter({caption:get_lang("My Folders")});
-			display_unseen_in_mailbox._refresh();
-
-			var display_unseen_in_shared_folders = tree_folders.getNodeById( 'user' );
-			if ( display_unseen_in_shared_folders )
-			{
-				if ( unseen_in_shared_folders )
-					display_unseen_in_shared_folders.alter({caption:'<font style=color:red>[</font><span id="dftree_user_unseen" style="color:red">' + unseen_in_shared_folders +'</span><font style=color:red>]</font> ' + get_lang("Shared folders")});
-				else
-					display_unseen_in_shared_folders.alter({caption:get_lang("Shared folders")});
-				display_unseen_in_shared_folders._refresh();
-			}
-		}
-		cExecute ("$this.imap_functions.get_folders_list&folder="+current_folder, update_tree_folders);
-
+			}
+			cExecute ("$this.imap_functions.get_folders_list&folder="+current_folder, update_tree_folders);
+		}
 
 		/**
 		 * Pastas locais
 		 */
-		if(preferences.use_local_messages==1) {
+		if(preferences.use_local_messages==1 || expresso_offline) {
 			var local_folders = expresso_local_messages.list_local_folders();
 			var has_changes = false;
@@ -126,35 +127,37 @@
 	}
 	else{
-		tree_folders = new dFTree({name: 'tree_folders'});
-
-		var n_root = new dNode({id:'root', caption: get_lang("My Folders")});
-		tree_folders.add(n_root,'anything'); //Places the root; second argument can be anything.
-	
-		var unseen_in_mailbox = 0;
-		var unseen_in_shared_folders = 0;
-		for (var i=0; i<folders.length; i++){
-			if (folders[i].folder_unseen > 0)
-			{
-				unseen_in_mailbox = parseInt( unseen_in_mailbox + folders[ i ].folder_unseen );
-				if ( folders[i].folder_id.indexOf( 'INBOX' ) !== 0 )
-					unseen_in_shared_folders = parseInt( unseen_in_shared_folders + folders[ i ].folder_unseen );
-
-				var nn = new dNode({id:folders[i].folder_id, caption:lang_folder(folders[i].folder_name) + '<font style=color:red>&nbsp(</font><span id="dftree_'+folders[i].folder_id+'_unseen" style=color:red>'+folders[i].folder_unseen+'</span><font style=color:red>)</font>', onClick:"change_folder('"+folders[i].folder_id+"','"+folders[i].folder_name+"')", plusSign:folders[i].folder_hasChildren}); 
+		if (!expresso_offline) {
+			tree_folders = new dFTree({name: 'tree_folders'});
+	
+			var n_root = new dNode({id:'root', caption: get_lang("My Folders")});
+			tree_folders.add(n_root,'anything'); //Places the root; second argument can be anything.
+	
+			var unseen_in_mailbox = 0;
+			var unseen_in_shared_folders = 0;
+			for (var i=0; i<folders.length; i++){
+				if (folders[i].folder_unseen > 0)
+				{
+					unseen_in_mailbox = parseInt( unseen_in_mailbox + folders[ i ].folder_unseen );
+					if ( folders[i].folder_id.indexOf( 'INBOX' ) !== 0 )
+						unseen_in_shared_folders = parseInt( unseen_in_shared_folders + folders[ i ].folder_unseen );
+
+					var nn = new dNode({id:folders[i].folder_id, caption:lang_folder(folders[i].folder_name) + '<font style=color:red>&nbsp(</font><span id="dftree_'+folders[i].folder_id+'_unseen" style=color:red>'+folders[i].folder_unseen+'</span><font style=color:red>)</font>', onClick:"change_folder('"+folders[i].folder_id+"','"+folders[i].folder_name+"')", plusSign:folders[i].folder_hasChildren}); 
 				
-				if( folders[i].folder_name.toLowerCase() == 'inbox' )
-					Element('new_m').innerHTML = '<font style="color:red">' + folders[i].folder_unseen + '</font>';
-			}
-			else
-				var nn = new dNode({id:folders[i].folder_id, caption:lang_folder(folders[i].folder_name), onClick:"change_folder('"+folders[i].folder_id+"','"+folders[i].folder_name+"')", plusSign:folders[i].folder_hasChildren}); 
-			
-			if (folders[i].folder_parent == '')
-				folders[i].folder_parent = 'root';
-			else if (folders[i].folder_parent == 'user'){
-				if (!tree_folders.getNodeById('user')){
-					var n_root_shared_folders = new dNode({id:'user', caption:get_lang("Shared folders"), plusSign:true}); 
-					tree_folders.add(n_root_shared_folders,'root');
+					if( folders[i].folder_name.toLowerCase() == 'inbox' )
+						Element('new_m').innerHTML = '<font style="color:red">' + folders[i].folder_unseen + '</font>';
 				}
-			}
-			tree_folders.add(nn,folders[i].folder_parent);
+				else
+					var nn = new dNode({id:folders[i].folder_id, caption:lang_folder(folders[i].folder_name), onClick:"change_folder('"+folders[i].folder_id+"','"+folders[i].folder_name+"')", plusSign:folders[i].folder_hasChildren}); 
+				
+				if (folders[i].folder_parent == '')
+					folders[i].folder_parent = 'root';
+				else if (folders[i].folder_parent == 'user'){
+					if (!tree_folders.getNodeById('user')){
+						var n_root_shared_folders = new dNode({id:'user', caption:get_lang("Shared folders"), plusSign:true}); 
+						tree_folders.add(n_root_shared_folders,'root');
+					}
+				}
+				tree_folders.add(nn,folders[i].folder_parent);
+			}
 		}
 		//tree_local_folders = new dFTree({name: 'tree_local_folders'});
@@ -162,5 +165,5 @@
 		 * Pastas locais
 		 */
-		if (preferences.use_local_messages==1) {
+		if (preferences.use_local_messages==1 || expresso_offline) {
 			if (!window.google || !google.gears) {
 				temp = confirm(get_lang("To use local messages you have to install google gears. Would you like to be redirected to gears installation page?"));
@@ -174,4 +177,6 @@
 			}
 			else{
+				if (expresso_offline) 
+					tree_folders = new dFTree({name: 'tree_folders'});
 				var root_local = new dNode({
 					id: "local_root",
@@ -201,5 +206,12 @@
 
 		tree_folders.draw(Element('content_folders'));
-		n_root.changeState();
+		if (!expresso_offline) {
+			n_root.changeState();
+			tree_folders.getNodeById('INBOX')._select();
+		}
+		else {
+			root_local.changeState();
+			tree_folders.getNodeById('local_Inbox')._select();
+		}
 
 		var trash_span=document.getElementById('lINBOX/'+trashfolder+'tree_folders');
@@ -220,5 +232,5 @@
 			spam_span.style.backgroundImage="url(../phpgwapi/templates/"+template+"/images/foldertree_spam.png)";
 
-		tree_folders.getNodeById('INBOX')._select();
+
 		draw_paging(Element('tot_m').innerHTML);
 		// Draw right menu folders.
@@ -229,5 +241,8 @@
 		*/
 
-		var display_unseen_in_mailbox = tree_folders.getNodeById( 'root' );
+		if(!expresso_offline)
+			var display_unseen_in_mailbox = tree_folders.getNodeById( 'root' );
+		else
+			var display_unseen_in_mailbox = tree_folders.getNodeById( 'local_root' );
 		//if ( unseen_in_mailbox )
 		//	display_unseen_in_mailbox.alter({caption:'<font style=color:red>[</font><span id="dftree_root_unseen" style="color:red">' + unseen_in_mailbox +'</span><font style=color:red>]</font> ' + get_lang("My Folders")});
@@ -247,31 +262,33 @@
 	}
 
-	var folder_create = "";
-	var nm1 = "";
-	if(tree_folders._folderPr.length > 0){
-		var nm_folder = "";
-		for(var i=0; i < tree_folders._folderPr.length; i++){
-			nm_folder = tree_folders._folderPr[i].split(cyrus_delimiter);
-			if(nm_folder[0] == "INBOX"){
-				if(nm1 == ""){
-					nm1 = nm_folder[1];
-					folder_create = "INBOX" + cyrus_delimiter + nm_folder[1] + ";";
-				}else{
-					if( nm1 != nm_folder[1]){
-						folder_create += "INBOX" + cyrus_delimiter + nm_folder[1] + ";";
+	if (!expresso_offline) {
+		var folder_create = "";
+		var nm1 = "";
+		if(tree_folders._folderPr.length > 0){
+			var nm_folder = "";
+			for(var i=0; i < tree_folders._folderPr.length; i++){
+				nm_folder = tree_folders._folderPr[i].split(cyrus_delimiter);
+				if(nm_folder[0] == "INBOX"){
+					if(nm1 == ""){
 						nm1 = nm_folder[1];
+						folder_create = "INBOX" + cyrus_delimiter + nm_folder[1] + ";";
+					}else{
+						if( nm1 != nm_folder[1]){
+							folder_create += "INBOX" + cyrus_delimiter + nm_folder[1] + ";";
+							nm1 = nm_folder[1];
+						}
 					}
 				}
 			}
 		}
-	}
-	if(folder_create != ""){
-		if(confirm(get_lang("There are folders with invalid format. Do you want to fix them?"))){
-			var handler_correct_folders = function(data){
-				//Timeout to release HTTPRequest , loadScript and update tree folders.
-				if(data)
-					setTimeout("connector.loadScript('TreeShow');ttreeBox.update_folder();",500);
-			}
-			cExecute("$this.imap_functions.create_extra_mailbox",handler_correct_folders,"nw_folders="+folder_create);
+		if(folder_create != ""){
+			if(confirm(get_lang("There are folders with invalid format. Do you want to fix them?"))){
+				var handler_correct_folders = function(data){
+					//Timeout to release HTTPRequest , loadScript and update tree folders.
+					if(data)
+						setTimeout("connector.loadScript('TreeShow');ttreeBox.update_folder();",500);
+				}
+				cExecute("$this.imap_functions.create_extra_mailbox",handler_correct_folders,"nw_folders="+folder_create);
+			}
 		}
 	}
@@ -1851,5 +1868,8 @@
 		//var option_send = '<span class="message_options" onclick=send_message("'+ID+'","null","null");>'+get_lang("Send")+'</span> | ';
 		var option_send   = '<input type="button" id="send_button_'+ID+'" class="em_button_like_span" tabindex="1" value="'+get_lang("Send")+'" onclick=send_message("'+ID+'","null","null");>' + ' | ';
-		var option_send_and_file= '<span class="message_options" onclick=wfolders.makeWindow("'+ID+'","send_and_file");>'+get_lang("Send and file")+'</span> | ';
+		if(!expresso_offline)
+			var option_send_and_file= '<span class="message_options" onclick=wfolders.makeWindow("'+ID+'","send_and_file");>'+get_lang("Send and file")+'</span> | ';
+		else
+			var option_send_and_file='';
 	}
 	else{
@@ -1860,6 +1880,12 @@
 	}
 //	var option_save_as		= '<span class="message_options" onclick=wfolders.makeWindow("'+ID+'","save");>'+get_lang("Save as")+'</span> | ';
-	var option_save			= '<span id="save_message_options_'+ID+'" class="message_options" onclick="openTab.toPreserve['+ID+'] = true; save_msg('+ID+');">'+get_lang("Save")+'</span> | ';
-	var option_search		= '<span class="message_options" onclick=openListUsers("'+ID+'");>'+get_lang("Search")+'</span>';
+	if (!expresso_offline) {
+		var option_save = '<span id="save_message_options_'+ID+'" class="message_options" onclick="openTab.toPreserve['+ID+'] = true; save_msg('+ID+');">'+get_lang("Save")+'</span> | ';
+		var option_search = '<span class="message_options" onclick=openListUsers("'+ID+'");>'+get_lang("Search")+'</span>';
+	}
+	else {
+		var option_save = '<input type="hidden" id="save_message_options_'+ID+'">';
+		var option_search = '';
+	}
 	td_menu_new_message.innerHTML = option_send + option_send_and_file + option_save + option_search;
 	
@@ -1961,8 +1987,14 @@
 	td_to.appendChild(forwarded_local_message);
 	
-	var img_search = document.createElement("IMG");
-	img_search.src = "./templates/"+template+"/images/search.gif";
-	img_search.title = get_lang('Search') + " | " + get_lang('Use F9 Key as shortcut.');
-	img_search.onclick = function () {emQuickSearch(document.getElementById('to_'+ID).value, 'to', ID);};
+	if (!expresso_offline) {
+		var img_search = document.createElement("IMG");
+		img_search.src = "./templates/"+template+"/images/search.gif";
+		img_search.title = get_lang('Search') + " | " + get_lang('Use F9 Key as shortcut.');
+		img_search.onclick = function () {emQuickSearch(document.getElementById('to_'+ID).value, 'to', ID);};
+	}
+	else {
+		var img_search = document.createElement("SPAN");
+	}
+	
 	var span_search = document.createElement("SPAN");
 	span_search.innerHTML = get_lang('Search');
@@ -2336,5 +2368,6 @@
 	RichTextEditor.loadEditor(ID);
 //////////////////////////////////////////////////////////////////////////////////////////////////////
-	draw_from_field(sel_from,tr1_1);
+	if(!expresso_offline)
+		draw_from_field(sel_from,tr1_1);
 	return ID;
 }
@@ -2798,8 +2831,9 @@
 		'<span class="message_options_trash"><span ' + change_font_color + ' title="'+get_lang("Delete")+'" class="message_options" onclick=proxy_mensagens.delete_msgs(\'null\',\'selected\',\'null\')>'+get_lang("Delete")+'</span></span>'+
 		'<span class="message_options_move"><span ' + change_font_color + ' title="'+get_lang("Move")+'" class="message_options" onclick=wfolders.makeWindow(\"\",\"move_to\")>'+get_lang("Move")+'</span></span>'+
-   		'<span class="message_options_print"><span ' + change_font_color + ' title="'+get_lang("Print")+'" class="message_options" onclick=print_all()>'+get_lang("Print")+'</span></span>'+
+   		(expresso_offline)?" ":' | <span class="message_options_print"><span ' + change_font_color + ' title="'+get_lang("Print")+'" class="message_options" onclick=print_all()>'+get_lang("Print")+'</span></span>'+
+//		'<span class="message_options_print"><span ' + change_font_color + ' title="'+get_lang("Print")+'" class="message_options" onclick=print_all()>'+get_lang("Print")+'</span></span>'+
         '<span class="message_options_export"><span ' + change_font_color + ' title="'+get_lang("Export")+'" class="message_options" onclick="proxy_mensagens.export_all_messages()">'+get_lang("Export")+'</span></span>' +
 		'<span class="message_options_import"><span ' + change_font_color + ' title="'+get_lang("Import")+'" class="message_options" onclick="import_window()">'+get_lang("Import")+'</span></span>';
-    if(preferences.use_local_messages==1)
+    if(preferences.use_local_messages==1 && !expresso_offline)
 		if(proxy_mensagens.is_local_folder(current_folder))
 			span_options.innerHTML += '&nbsp; <span title="'+get_lang("Unarchive")+'" class="message_options" onclick="expresso_local_messages.unarchive_msgs(\''+folder+'\',null)">'+get_lang("Unarchive")+'</span>';
