Index: /branches/2.2/mobile/inc/class.ui_home.inc.php
===================================================================
--- /branches/2.2/mobile/inc/class.ui_home.inc.php	(revision 3596)
+++ /branches/2.2/mobile/inc/class.ui_home.inc.php	(revision 3600)
@@ -91,4 +91,5 @@
 			}
 			
+			$GLOBALS['phpgw_info']['mobiletemplate']->set_error_msg($params["error_message"]);
 			$GLOBALS['phpgw_info']['mobiletemplate']->set_success_msg($params["success_message"]);
 			$GLOBALS['phpgw_info']['mobiletemplate']->set_content($this->template->fp('out', 'page'));
@@ -115,5 +116,16 @@
 		}
 		
-    	function search($params) {
+    function search($params) {
+    	if($_SERVER["HTTP_REFERER"] && strpos($_SERVER["HTTP_REFERER"], "ui_home.index")) {
+    		if(!$params["default_folders"] &&
+					 !$params["personal_folders"] &&
+					 !$params["calendar_search"] &&
+					 !$params["contacts_search"]) {
+					 	
+						header('Location: index.php?menuaction=menuaction=mobile.ui_home.index&error_message='.lang("need choose one option"));
+					 }
+    	}
+    		
+				
 			include_once "class.ui_mobilecc.inc.php";
 			$ui_mobilemail = CreateObject("mobile.ui_mobilemail");//Necessário para lista de emails, que é uma função estática
Index: /branches/2.2/mobile/inc/class.ui_mobilemail.inc.php
===================================================================
--- /branches/2.2/mobile/inc/class.ui_mobilemail.inc.php	(revision 3590)
+++ /branches/2.2/mobile/inc/class.ui_mobilemail.inc.php	(revision 3600)
@@ -701,12 +701,9 @@
 			switch($type) {
 				case "clk":
-				case "cc_mob":
+				case "from_mobilecc":
 					$this->template->set_var('action_msg', lang("New message"));
 					break;
 				case "reply_all":
-					$this->template->set_var('action_msg', lang("Reply All"));
-					break;
-				case "user_add":
-					$this->template->set_var('action_msg', lang("Add Recipient"));
+					$this->template->set_var('action_msg', lang("Reply to All"));
 					break;
 				case "forward":
@@ -732,5 +729,4 @@
 			$this->template->set_var('lang_cancel', strtoupper(lang("cancel")));
 			$this->template->set_var('lang_save_draft', strtoupper(lang("save draft")));
-			$this->template->set_var('type', $_GET['type']);
 			$this->template->set_var('lang_to', lang("To"));
 			$this->template->set_var('lang_cc', lang("cc"));
@@ -740,15 +736,9 @@
 			$this->template->set_var('lang_add_history', lang("add history"));
 			
-			
-			$this->template->set_var('type', $_REQUEST['type']);
 			$this->template->parse('add_recipient_box', 'add_recipient_block', true);
-
-			$this->define_action_message($_REQUEST['type']);
 			
 			if(isset($params["error_message"])) {
-				$this->template->set_var('to', $_POST['input_to']);
-				$this->template->set_var('to_mail', $_POST['input_to_mail']);
-				$this->template->set_var('cc', $_POST['input_cc']);
-				$this->template->set_var('cc_mail', $_POST['input_cc_mail']);
+				$this->template->set_var('input_to', $_POST['input_to']);
+				$this->template->set_var('input_cc', $_POST['input_cc']);
 				$this->template->set_var('subject', $_POST['input_subject']);
 				$this->template->set_var('msg_number', $_POST['msg_number']);
@@ -764,44 +754,37 @@
 				$GLOBALS['phpgw_info']['mobiletemplate']->set_error_msg($params["error_message"]);
 			} else {
-				if (isset($_GET['msg_number'])) $msg = $this->imap_functions->get_info_msg(array('msg_number' => $_GET['msg_number'] ) );
+				if (isset($params['msg_number'])) $msg = $this->imap_functions->get_info_msg(array('msg_number' => $params['msg_number'] ) );
 				
-				if($_REQUEST['type']=="clk")
+				if($params['type']=="clk")
 				{
-					$this->template->set_var('to', "");
-					$this->template->set_var('to_mail', "");
-					$this->template->set_var('cc', "");
-					$this->template->set_var('cc_mail', "");
+					$this->template->set_var('input_to', "");
+					$this->template->set_var('input_cc', "");
 					$this->template->set_var('subject', "");
 				}
-				else if($_REQUEST['type']=="cc_mob")
+				else if($params['type']=="from_mobilecc")
 				{
-					$this->template->set_var('to', $_GET['input_to']);
-					$this->template->set_var('to_mail', $_GET['input_to_mail']);
-					$this->template->set_var('cc', $_GET['input_cc']);
-					$this->template->set_var('cc_mail', $_GET['input_cc_mail']);
-					$this->template->set_var('subject', "");
-	
-					$this->template->set_var('msg_number', $_GET['msg_number']);
-					$this->template->set_var('msg_folder', $_GET['msg_folder']);
-	
-					$this->template->set_var('read_only', 'readonly');
-				}
-				else if($_REQUEST['type']=="reply_all"){
-					$reply_to_all = $msg['from']['full'];
-					$reply_to_all = $msg['toaddress2'] ? $reply_to_all.','.$msg['toaddress2']:$reply_to_all;
-					$reply_to_all = $msg['cc'] ? $reply_to_all.','.$msg['cc']:$reply_to_all;
-					$reply_to_all = $msg['bcc'] ? $reply_to_all.','.$msg['bcc']:$reply_to_all;
-					$names = implode(',<br/>',explode(',',$reply_to_all));
+					$this->template->set_var('input_to', $_GET['input_to']);
+					$this->template->set_var('input_cc', $_GET['input_cc']);
+				}
+				else if($params['type']=="reply_all"){
+					$reply_to_all = $msg['from']['email'];
+					if($msg['toaddress2']) $reply_to_all .= ','.$msg['toaddress2'];
+					if($msg['cc']) $reply_to_all .= ','.$msg['cc'];
+					if($msg['bcc']) $reply_to_all .= ','.$msg['bcc'];												
 					
 					$array_emails = explode(',',$reply_to_all);
-					$reply_to_all ='';
-					
-					foreach ($array_emails as $index => $email){
+					$reply_to_all = '';
+					
+					foreach ($array_emails as $index => $email) {
 						$flag = preg_match('/&lt;(.*?)&gt;/',$email,$reply);
-						$reply_to_all .= $flag == 0 ? $email.', ':$reply[1].', ';
+						$email_to_add = $flag == 0 ? $email.',' : $reply[1].',';
+						
+						if( strpos($reply_to_all, $email_to_add) === false)
+							$reply_to_all .= $email_to_add;
 					}
-									
-					$this->template->set_var('to', $reply_to_all);
-					$this->template->set_var('to_mail', $_GET['input_to_mail']);
+					
+					$reply_to_all = substr_replace($reply_to_all, "", strrpos($reply_to_all, ","), strlen($reply_to_all));
+					
+					$this->template->set_var('input_to', $reply_to_all);
 					$this->template->set_var('subject', "Re:" . $msg['subject']);
 	
@@ -809,19 +792,20 @@
 					$this->template->set_var('msg_folder', $_GET['msg_folder']);
 				}
-				else if($_REQUEST['type']=="user_add"){
-					$listMail = implode(',',$_SESSION['mobile_mail']);
-					
-					$this->template->set_var('to', $listMail);
-					$this->template->set_var('to_mail', $listMail);
-					$this->template->set_var('subject', $_SESSION['subject_mail']);
-					$this->template->set_var('body_value', $_SESSION['body_mail']);
+				else if($params['type']=="user_add"){
+					$this->template->set_var('input_to', $params['mobile_add_contact']['mobile_mail']);
+					$this->template->set_var('input_cc', $params['mobile_add_contact']['mobile_mail_cc']);					
+					$this->template->set_var('subject', $params['mobile_add_contact']['subject_mail']);
+					$this->template->set_var('body_value', $params['mobile_add_contact']['body_mail']);
 	
-					$this->template->set_var('msg_number', $_GET['msg_number']);
-					$this->template->set_var('msg_folder', $_GET['msg_folder']);			
-				}
-				else if($_REQUEST['type']=="forward"){
+					$this->template->set_var('check_important', ( ( $params['mobile_add_contact']['check_important'] ) ? "checked" : "" ) );
+					$this->template->set_var('check_read_confirmation', ( ( $params['mobile_add_contact']['check_read_confirmation'] )  ? "checked" : "" ) );
+					$this->template->set_var('check_add_history', ( ( $params['mobile_add_contact']['check_add_history'] )  ? "checked" : "" ) );
+					$this->template->set_var('msg_number', $params['msg_number']);
+					$this->template->set_var('msg_folder', $params['msg_folder']);
+					
+					$params["type"] = $params['mobile_add_contact']['type'];		
+				}
+				else if($params['type']=="forward"){
 					$this->template->set_var('from', $msg['toaddress2']);
-	
-					$mail_to = $msg['from']['full'];
 	
 					$this->template->set_var('subject', "Enc:" . $msg['subject']);
@@ -834,8 +818,5 @@
 				else{
 					$this->template->set_var('from', $msg['toaddress2']);
-	
-					$mail_to = $msg['from']['full'];
-					$this->template->set_var('to', $msg['from']['name']);
-					$this->template->set_var('to_mail', $msg['from']['email']);
+					$this->template->set_var('input_to', $msg['from']['email']);
 	
 					$this->template->set_var('subject', "Re:" . $msg['subject']);
@@ -848,6 +829,9 @@
 			}
 			
-			$_SESSION['mobile_mail'] = array();
-			
+			//tem que ser realizado no final, pois o tipo user_add é modificado para o tipo que o originou
+			$this->template->set_var('type', $params['type']);
+			$this->define_action_message($params['type']);
+			
+			unset($_SESSION['mobile_add_contact']);
 			$GLOBALS['phpgw_info']['mobiletemplate']->set_content($this->template->fp('out', 'page'));
 		}
@@ -881,8 +865,6 @@
 
 			//Recebe os dados do form (passados pelo POST)
-			$userName = $_POST['input_to']; //"User Someone";
-			$userMail = $_POST['input_to_mail']; //"user.someone@mail.com.br";
-			$ccUserName = $_POST['input_cc'];
-			$ccUserMail = $_POST['input_cc_mail'];			
+			$userMail = $_POST['input_to'];
+			$ccUserMail = $_POST['input_cc'];
 			$subject = $_POST['input_subject']; //"Mail Subject";
 			$body = $_POST['body']; //"Mail body. Any text.";
@@ -891,7 +873,4 @@
 			$readConfirmation = $_POST['check_read_confirmation'];
 			$msgNumber = $_POST['reply_msg_number'];
-
-			if($userMail == "") $userMail = $userName;
-			if($ccUserMail == "") $ccUserMail = $ccUserName;
 
 			//Cria objeto
@@ -983,37 +962,41 @@
 			return 0;
 		}
-
-		function retorna()
-		{
-			
-		}
 		
 		function init_schedule() {
-			if($_POST['input_to'] != '' && !is_null($_POST['input_to']))
-				array_push($_SESSION['mobile_mail'],$_POST['input_to']);			
-
-			$_SESSION['subject_mail'] = $_POST['input_subject'];
-			$_SESSION['body_mail'] = $_POST['body'];
-			$this->add_recipients();
-		}
-		
-		
-		function add_recipients() {
-            
+			$_SESSION['mobile_add_contact'] = array();
+			$_SESSION['mobile_add_contact']['mobile_mail']  = $_POST['input_to'];
+			$_SESSION['mobile_add_contact']['mobile_mail_cc'] = $_POST['input_cc'];
+			$_SESSION['mobile_add_contact']['add_to'] = $_POST['add_to'];
+			$_SESSION['mobile_add_contact']['type'] = $_POST['type'];
+			$_SESSION['mobile_add_contact']['msg_number'] = $_POST['reply_msg_number'];
+			$_SESSION['mobile_add_contact']['msg_folder'] = $_POST['folder'];
+			$_SESSION['mobile_add_contact']['subject_mail'] = $_POST['input_subject'];
+			$_SESSION['mobile_add_contact']['body_mail'] = $_POST['body'];
+			$_SESSION['mobile_add_contact']['check_important'] = $_POST['check_important'];
+			$_SESSION['mobile_add_contact']['check_read_confirmation'] = $_POST['check_read_confirmation'];
+			$_SESSION['mobile_add_contact']['check_add_history'] = $_POST['check_add_history'];
+
 			$ui_cc = CreateObject('mobile.ui_mobilecc');
-			$ui_cc->contacts_list('mobilemail');
+			$ui_cc->choose_contact(array("request_from" => "ui_mobilemail.new_msg"));
 		}
 		
 		function add_recipient() {
-			
-			$participants = $_SESSION["mobile_mail"];
-			
-			if(!is_array($participants))
-				$participants = array();
-				
-			$participants[$_GET['cn']] = $_GET['mail'];
-			
-			$_SESSION["mobile_mail"] = $participants;
-			$this->add_recipients();
+			if($_SESSION['mobile_add_contact']['add_to'] == "to")
+				$arr_key_name = "mobile_mail";
+			else
+				$arr_key_name = "mobile_mail_cc";
+			
+			$arr_mobile_add_contact = $_SESSION['mobile_add_contact'];
+			
+			if(strpos($arr_mobile_add_contact[$arr_key_name], $_GET['mail']) === false)
+				$arr_mobile_add_contact[$arr_key_name] .= ( (trim($arr_mobile_add_contact[$arr_key_name]) == "") ? $_GET['mail'] : ",".$_GET['mail']);
+			
+			unset($_SESSION['mobile_add_contact']);
+			
+			$this->new_msg( array( 
+				'mobile_add_contact' => $arr_mobile_add_contact, 
+				'type' => 'user_add', 
+				'msg_number' => $arr_mobile_add_contact['msg_number'], 
+				'msg_folder' => $arr_mobile_add_contact['msg_folder']));
 		}
 		
Index: /branches/2.2/mobile/templates/default/new_msg.tpl
===================================================================
--- /branches/2.2/mobile/templates/default/new_msg.tpl	(revision 3576)
+++ /branches/2.2/mobile/templates/default/new_msg.tpl	(revision 3600)
@@ -1,3 +1,17 @@
 <!-- BEGIN page -->
+
+<script type="text/javascript">
+
+function mobile_add_contact(add_to) {
+	var mail_form = document.getElementById('mail_form');
+	mail_form.action = "index.php?menuaction=mobile.ui_mobilemail.init_schedule";
+	
+	document.getElementById('add_to').value = add_to; 
+	
+	mail_form.submit();
+}
+
+</script>
+
 <div class="menu-contexto">
 	<span><a href="javascript:history.back()">{lang_back}</a></span> <span class="titulo-secao">{action_msg}</span>
@@ -5,15 +19,14 @@
 
 <form method="POST" action="index.php?menuaction=mobile.ui_mobilemail.send_mail" id="mail_form">
-	<input type="hidden" id="input_to_mail" name="input_to_mail" value='{to_mail}' />
-	<input type="hidden" id="input_cc_mail" name="input_cc_mail" value='{cc_mail}' />
 	<input type="hidden" id="reply_from" name="reply_from" value='{from}' />
 	<input type="hidden" id="reply_msg_number" name="reply_msg_number" value='{msg_number}' />
 	<input type="hidden" id="folder" name="folder" value='{msg_folder}' />
 	<input type="hidden" name="type" value='{type}' />
+	<input type="hidden" name="add_to" id="add_to" value='' />
 	
 	<div class="campos-correspondencia">
 		<div class="posiciona-esquerda">
-			<p><strong><label>{lang_to}:</label></strong> <input id="input_to" name="input_to" value='{to}' "{read_only}"></p>
-			<p><strong><label>{lang_cc}:</label></strong> <input id="input_cc" name="input_cc" value='{cc}' "{read_only}"></p>
+			<p><strong><label>{lang_to}:</label></strong> <input id="input_to" name="input_to" value='{input_to}' "{read_only}"></p>
+			<p><strong><label>{lang_cc}:</label></strong> <input id="input_cc" name="input_cc" value='{input_cc}' "{read_only}"></p>
 			<p><strong><label>{lang_subject}:</label></strong> <input id="input_subject" name="input_subject" value='{subject}'></p>
 		</div>
@@ -35,5 +48,5 @@
 		<a href="index.php?menuaction=mobile.ui_home.index"><button id="cancel" class="btn-generico" >{lang_cancel}</button></a>
 		<button id="save_draft" class="btn-generico" onclick="document.getElementById('mail_form').action='index.php?menuaction=mobile.ui_mobilemail.save_draft';document.getElementById('mail_form').submit()" >{lang_save_draft}</button></a>
-		<input type="submit" name="action" id="reply_send" value="{lang_send}" class="btn-generico"/>	
+		<button name="action" id="reply_send" class="btn-generico" onclick="document.getElementById('mail_form').submit()">{lang_send}</button>	
 	</div>
 
@@ -41,5 +54,6 @@
 <!-- END page -->
 <!-- BEGIN add_recipient_block -->
-<p><button name="action" title="Ver agenda" class="btn-contexto">{lang_calendar}</button></p>
+<p><button name="action" title="Ver agenda" class="btn-contexto" onclick="mobile_add_contact('to');">+</button></p>
+<p><button name="action" title="Ver agenda" class="btn-contexto" onclick="mobile_add_contact('cc');">+</button></p>
 <p></p>
 <!-- END add_recipient_block -->
Index: /branches/2.2/mobile/templates/default/home_index.tpl
===================================================================
--- /branches/2.2/mobile/templates/default/home_index.tpl	(revision 3590)
+++ /branches/2.2/mobile/templates/default/home_index.tpl	(revision 3600)
@@ -1,14 +1,14 @@
 <!-- BEGIN page -->
-<form method="post" action="index.php?menuaction=mobile.ui_home.search">
+<form method="post" action="index.php?menuaction=mobile.ui_home.search" id="form_search">
 	<div class="busca"> 
 		<input type="text" name="name" id="name" />
-		<input type="submit" id="buscar" class="btn-generico" value="{lang_search}" />
+		<button id="buscar" class="btn-generico" onclick="document.getElementById('form_search').submit()">{lang_search}</button>
 	</div>
 	
 	<div class="menu-contexto">
 		{lang_new_mail}:
-		<a href="index.php?menuaction=mobile.ui_mobilemail.new_msg&type=clk" style="text-decoration:none;"><button name="email" class="btn-contexto">{lang_context_email}</button></a>
-		<button name="contato" class="btn-contexto">{lang_context_contact}</button>
-		<button name="compromisso" class="btn-contexto">{lang_context_commitment}</button>
+		<button name="email" class="btn-contexto" type="button" onclick='window.location="index.php?menuaction=mobile.ui_mobilemail.new_msg&type=clk"'>{lang_context_email}</button>
+		<button name="contato" class="btn-contexto" type="button" >{lang_context_contact}</button>
+		<button name="compromisso" class="btn-contexto" type="button" >{lang_context_commitment}</button>
 	</div>
 	
@@ -26,5 +26,5 @@
 <!-- END page -->
 <!-- BEGIN folder_block -->
-<dd class="{dd_class}"><div class="nome-item"><a href="index.php?menuaction=mobile.ui_mobilemail.change_folder&folder={folder_id}">{folder_name}</a></div> <span class="contagem">[{folder_unseen}/{folder_total_msg}]</span></dd> 
+<dd class="{dd_class}"><a href="index.php?menuaction=mobile.ui_mobilemail.change_folder&folder={folder_id}"><div class="nome-item">{folder_name}</div></a> <span class="contagem">[{folder_unseen}/{folder_total_msg}]</span></dd> 
 <!-- END folder_block -->
 <!-- BEGIN commitment_block -->
