Index: /branches/2.2/mobile/inc/class.ui_mobilecalendar.inc.php
===================================================================
--- /branches/2.2/mobile/inc/class.ui_mobilecalendar.inc.php	(revision 3731)
+++ /branches/2.2/mobile/inc/class.ui_mobilecalendar.inc.php	(revision 3829)
@@ -38,4 +38,5 @@
 			$this->template->set_block('home_search_bar','search_bar');
 			$this->template->set_var('lang_back',lang("back"));
+			$this->template->set_var('href_back',$GLOBALS['phpgw_info']['mobiletemplate']->get_back_link());
 			$this->template->set_var('lang_calendar',lang("Calendar"));
 			$this->template->set_var('lang_search',lang("search"));
Index: /branches/2.2/mobile/inc/class.mobiletemplate.inc.php
===================================================================
--- /branches/2.2/mobile/inc/class.mobiletemplate.inc.php	(revision 3734)
+++ /branches/2.2/mobile/inc/class.mobiletemplate.inc.php	(revision 3829)
@@ -4,4 +4,5 @@
 	{
 		private $template;
+		private $href_back;
 		
 		/*
@@ -23,6 +24,4 @@
 				$this->template->set_var('lang_search_error_message',lang("need choose one option"));
 				$this->template->set_var('lang_search_error_message_four_digits',lang("search word need not be empty and has more then four char"));
-				
-				
 			}	else {
 				$this->template->set_file(array('home_t' => 'template.tpl'));
@@ -134,9 +133,42 @@
 			$this->template->set_var('lang_contacts', lang('Contact Center'));
 			$this->template->set_var('lang_calendar', lang('Calendar'));
-			$this->template->set_var('href_back', 'javascript:history.back()');
 			$this->template->set_var('href_cc', 'index.php?menuaction=mobile.ui_mobilecc.init_cc');
 			$this->template->set_var('href_email', "index.php?menuaction=mobile.ui_mobilemail.change_folder&folder=0");
 			$this->template->set_var('href_calendar', "index.php?menuaction=mobile.ui_mobilecalendar.index");
 			$this->template->set_var('href_home', "index.php?menuaction=mobile.ui_home.index");
+		}
+
+		private function process_back_link() {
+			$url = $GLOBALS['phpgw']->session->appsession('mobile.last_url','mobile');
+
+			if($url) {
+				$params = $GLOBALS['phpgw']->session->appsession('mobile.last_request','mobile');
+
+				$query_string = "";
+				unset($params['sessionid']);
+				unset($params['domain']);
+				unset($params['last_loginid']);
+				unset($params['last_domain']);
+				unset($params['kp3']);
+				unset($params['showHeader']);
+				
+				foreach ($params as $key => $value) {
+					$query_string .= "&".$key."=".$value;
+				}
+
+				if($query_string != "")
+					$url .= "?".substr($query_string,1);
+
+				$this->href_back = $url;
+			} else {
+				$this->href_back = 'javascript:history.back()';
+			}
+
+			$GLOBALS['phpgw']->session->appsession('mobile.last_url','mobile',$_SERVER["SCRIPT_URL"]);
+			$GLOBALS['phpgw']->session->appsession('mobile.last_request','mobile',$_REQUEST);
+		}
+
+		function get_back_link(){
+			return $this->href_back;
 		}
 
@@ -150,4 +182,5 @@
 			$var  = Array('title' => lang("expresso mini"));
 			$this->template->set_var($var);
+			$this->process_back_link();
 		}
 
Index: /branches/2.2/mobile/inc/class.ui_home.inc.php
===================================================================
--- /branches/2.2/mobile/inc/class.ui_home.inc.php	(revision 3813)
+++ /branches/2.2/mobile/inc/class.ui_home.inc.php	(revision 3829)
@@ -176,4 +176,5 @@
 			$p->set_var('search_param',$params['name']);
 			$p->set_var('lang_back',lang('back'));
+			$p->set_var('href_back',$GLOBALS['phpgw_info']['mobiletemplate']->get_back_link());
 			$p->set_var('lang_new_message',ucfirst(lang('new message')));
 			$p->set_var('lang_search',lang('search'));
Index: /branches/2.2/mobile/inc/class.ui_mobilemail.inc.php
===================================================================
--- /branches/2.2/mobile/inc/class.ui_mobilemail.inc.php	(revision 3814)
+++ /branches/2.2/mobile/inc/class.ui_mobilemail.inc.php	(revision 3829)
@@ -210,4 +210,5 @@
 			$this->template->set_block('view_msg', 'attachment_alert_block');
 			$this->template->set_var('lang_back', lang("back"));
+			$this->template->set_var('href_back',$GLOBALS['phpgw_info']['mobiletemplate']->get_back_link());
 			$this->template->set_var('lang_reading_message', lang("Reading Message"));
 			$this->template->set_var('theme', $GLOBALS['phpgw_info']['server']['template_set']);
@@ -440,4 +441,5 @@
 			$p->set_var("selected_".$this->current_search_box_type,"selected");
 			$p->set_var("lang_back",lang("back"));
+			$p->set_var('href_back',$GLOBALS['phpgw_info']['mobiletemplate']->get_back_link());
 			$p->set_var("selecteds",ucfirst(lang("Selecteds")));
 			$p->set_var("filter_by",lang("filter by"));
@@ -685,4 +687,5 @@
 			$this->template->set_block('new_msg_t', 'page');
 			$this->template->set_var('lang_back', lang("back"));
+			$this->template->set_var('href_back',$GLOBALS['phpgw_info']['mobiletemplate']->get_back_link());
 			$this->template->set_var('lang_calendar', strtoupper(lang("Calendar")));
 			$this->template->set_var('lang_send', strtoupper(lang("Send")));
Index: /branches/2.2/mobile/inc/class.ui_mobilecc.inc.php
===================================================================
--- /branches/2.2/mobile/inc/class.ui_mobilecc.inc.php	(revision 3825)
+++ /branches/2.2/mobile/inc/class.ui_mobilecc.inc.php	(revision 3829)
@@ -134,4 +134,5 @@
 			//Langs gerais da página
 			$this->template->set_var("lang_back",lang("back"));
+			$this->template->set_var('href_back',$GLOBALS['phpgw_info']['mobiletemplate']->get_back_link());
 			$this->template->set_var("selecteds",ucfirst(lang("selecteds")));
 			$this->template->set_var("lang_more",lang("more"));
@@ -580,4 +581,5 @@
 
 			$this->template->set_var('lang_back',lang("back"));
+			$this->template->set_var('href_back',$GLOBALS['phpgw_info']['mobiletemplate']->get_back_link());
 			$this->template->set_var('lang_use_contact',lang("use contact"));
 			$this->template->set_var('lang_selecteds',lang("selecteds"));
@@ -682,4 +684,5 @@
 			$this->template->set_var('lang_contact_title',lang("context contact"));
 			$this->template->set_var('lang_back',lang("back"));
+			$this->template->set_var('href_back',$GLOBALS['phpgw_info']['mobiletemplate']->get_back_link());
 			$this->template->set_var('lang_cancel',lang("cancel"));
 			$this->template->set_var('lang_confirm', $confirm);
Index: /branches/2.2/mobile/templates/default/contact_view.tpl
===================================================================
--- /branches/2.2/mobile/templates/default/contact_view.tpl	(revision 3700)
+++ /branches/2.2/mobile/templates/default/contact_view.tpl	(revision 3829)
@@ -2,5 +2,5 @@
 
 <div class="menu-contexto">
-	<span><a href="javascript:history.back()">{lang_back}</a></span><span class="titulo-secao">{lang_contact_title}</span>
+	<span><a href="{href_back}">{lang_back}</a></span><span class="titulo-secao">{lang_contact_title}</span>
 </div>
 
Index: /branches/2.2/mobile/templates/default/cc_main.tpl
===================================================================
--- /branches/2.2/mobile/templates/default/cc_main.tpl	(revision 3821)
+++ /branches/2.2/mobile/templates/default/cc_main.tpl	(revision 3829)
@@ -2,5 +2,5 @@
 		<div class="menu-contexto">
 			<form id="form_catalog" action="index.php?menuaction=mobile.ui_mobilecc.change_catalog" method="post">
-				<span><a name="voltar" href="javascript:history.back()">{lang_back}</a></span><span class="titulo-secao">{lang_contacts}</span>
+				<span><a name="voltar" href="{href_back}">{lang_back}</a></span><span class="titulo-secao">{lang_contacts}</span>
 				<select name="catalog" onChange="document.getElementById('form_catalog').submit();">
 					{catalogs}
Index: /branches/2.2/mobile/templates/default/new_msg.tpl
===================================================================
--- /branches/2.2/mobile/templates/default/new_msg.tpl	(revision 3695)
+++ /branches/2.2/mobile/templates/default/new_msg.tpl	(revision 3829)
@@ -21,5 +21,5 @@
 	
 <div class="menu-contexto">
-	<span><a href="javascript:history.back()">{lang_back}</a></span> <span class="titulo-secao">{action_msg}</span>
+	<span><a href="{href_back}">{lang_back}</a></span> <span class="titulo-secao">{action_msg}</span>
 </div>
 
Index: /branches/2.2/mobile/templates/default/contact_add_edit.tpl
===================================================================
--- /branches/2.2/mobile/templates/default/contact_add_edit.tpl	(revision 3701)
+++ /branches/2.2/mobile/templates/default/contact_add_edit.tpl	(revision 3829)
@@ -2,5 +2,5 @@
 
 <div class="menu-contexto">
-	<span><a href="javascript:history.back()">{lang_back}</a></span><span class="titulo-secao">{lang_contact_title}</span>
+	<span><a href="{href_back}">{lang_back}</a></span><span class="titulo-secao">{lang_contact_title}</span>
 </div>
 
Index: /branches/2.2/mobile/templates/default/calendar.tpl
===================================================================
--- /branches/2.2/mobile/templates/default/calendar.tpl	(revision 3731)
+++ /branches/2.2/mobile/templates/default/calendar.tpl	(revision 3829)
@@ -3,5 +3,5 @@
 	<input type="hidden" name="menuaction" value="mobile.ui_mobilecalendar.index" />
 	<div class="menu-contexto">
-		<span><a href="javascript:history.back()">{lang_back}</a></span> <span class="titulo-secao">{lang_calendar}</span>
+		<span><a href="{href_back}">{lang_back}</a></span> <span class="titulo-secao">{lang_calendar}</span>
 			<select name="type" onchange="document.getElementById('form_calendar_type').submit()">
 				{type_option_box}
Index: /branches/2.2/mobile/templates/default/mobilemail.tpl
===================================================================
--- /branches/2.2/mobile/templates/default/mobilemail.tpl	(revision 3731)
+++ /branches/2.2/mobile/templates/default/mobilemail.tpl	(revision 3829)
@@ -1,5 +1,5 @@
 <!-- BEGIN main_emails -->		
 		<div class="menu-contexto">
-			<span><a href="javascript:history.go(-1);">&lt; {lang_back}</a></span>
+			<span><a href="{href_back}">&lt; {lang_back}</a></span>
 			<span class="titulo-secao">{folder}</span>
 			<button class="btn-contexto" onclick="location.href='index.php?menuaction=mobile.ui_mobilemail.new_msg&type=clk'">{lang_new}</button>
Index: /branches/2.2/mobile/templates/default/home_search.tpl
===================================================================
--- /branches/2.2/mobile/templates/default/home_search.tpl	(revision 3731)
+++ /branches/2.2/mobile/templates/default/home_search.tpl	(revision 3829)
@@ -1,5 +1,5 @@
 <!-- BEGIN main -->
 		<div class="menu-contexto">
-			<span><a href="javascript:history.go(-1);">{lang_back}</a></span> <span class="titulo-secao">{lang_search_return}</span>
+			<span><a href="{href_back}">{lang_back}</a></span> <span class="titulo-secao">{lang_search_return}</span>
 		</div>
 			
Index: /branches/2.2/mobile/templates/default/view_msg.tpl
===================================================================
--- /branches/2.2/mobile/templates/default/view_msg.tpl	(revision 3697)
+++ /branches/2.2/mobile/templates/default/view_msg.tpl	(revision 3829)
@@ -1,5 +1,5 @@
 <!-- BEGIN page -->
 <div class="menu-contexto">
-	<span><a href="javascript:history.back()">{lang_back}</a><span class="titulo-secao">{lang_reading_message}</span>
+	<span><a href="{href_back}">{lang_back}</a><span class="titulo-secao">{lang_reading_message}</span>
 </div>
 
