Index: /branches/2.2/phpgwapi/inc/class.sessions.inc.php
===================================================================
--- /branches/2.2/phpgwapi/inc/class.sessions.inc.php	(revision 3430)
+++ /branches/2.2/phpgwapi/inc/class.sessions.inc.php	(revision 3486)
@@ -405,5 +405,7 @@
 		{
 			// Use HTTP_X_FORWARDED_HOST if set, which is the case behind a none-transparent proxy
-			$this->cookie_domain = isset($_SERVER['HTTP_X_FORWARDED_HOST']) ?  $_SERVER['HTTP_X_FORWARDED_HOST'] : $_SERVER['HTTP_HOST'];
+			//$this->cookie_domain = isset($_SERVER['HTTP_X_FORWARDED_HOST']) ?  $_SERVER['HTTP_X_FORWARDED_HOST'] : $_SERVER['HTTP_HOST'];
+			//Modificacao feita para que o Expresso redirecione para o primeiro proxy caso haja um encadeamento de mais de um proxy.
+			$this->cookie_domain = nearest_to_me();
 
 			// remove port from HTTP_HOST
Index: /branches/2.2/phpgwapi/inc/common_functions.inc.php
===================================================================
--- /branches/2.2/phpgwapi/inc/common_functions.inc.php	(revision 3437)
+++ /branches/2.2/phpgwapi/inc/common_functions.inc.php	(revision 3486)
@@ -706,4 +706,15 @@
         }
 
+        /*!
+	 @function nearest_to_me
+	 @abstract return host nearest to client
+	 @Include by Serpro ( Antonio Carlos da Silva).
+         */
+        function nearest_to_me()
+        {
+                $proxies=explode(',',$_SERVER['HTTP_X_FORWARDED_HOST']);
+                return isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $proxies[0] : $_SERVER['HTTP_HOST'];
+        }
+
 	/*!
 	 @function session_convert
Index: /branches/2.2/phpgwapi/templates/default/login_default.php
===================================================================
--- /branches/2.2/phpgwapi/templates/default/login_default.php	(revision 3480)
+++ /branches/2.2/phpgwapi/templates/default/login_default.php	(revision 3486)
@@ -198,12 +198,14 @@
 				list($forward,$extra_vars) = explode('?',$forward,2);
 			}
-			if ($GLOBALS['phpgw_info']['server']['use_https'] != 2)
-			{
-				$forward = 'http://'.$_SERVER['HTTP_HOST'].($GLOBALS['phpgw']->link($forward.'?cd=yes'));
-				echo "<script language='Javascript1.3'>location.href='".$forward."'</script>";
-			}
-			else
-			{
-				$GLOBALS['phpgw']->redirect_link($forward,$extra_vars);
+		if ($GLOBALS['phpgw_info']['server']['use_https'] != 2)
+			{
+			//Modificacao feita para que o Expresso redirecione para o primeiro proxy caso haja um encadeamento de mais de um proxy.
+			//$forward = 'http://'.$_SERVER['HTTP_HOST'].($GLOBALS['phpgw']->link($forward.'?cd=yes'));
+			$forward = 'http://' . nearest_to_me() . $GLOBALS['phpgw']->link($forward.'?cd=yes');
+			echo "<script language='Javascript1.3'>location.href='".$forward."'</script>";
+			}
+		else
+			{
+			$GLOBALS['phpgw']->redirect_link($forward,$extra_vars);
 			}
 		}
@@ -363,7 +365,4 @@
 	$tmpl->set_var('website_title', $GLOBALS['phpgw_info']['server']['site_title']);
 	$tmpl->set_var('template_set',$GLOBALS['phpgw_info']['login_template_set']);
-
-        include_once(dirname( __FILE__ ) . '/../../../infodist/ultima-revisao-svn.php');
-        if(isset($ultima_revisao)) $tmpl->set_var('ultima_rev','<br>' . $ultima_revisao);
 
 	$GLOBALS['phpgw']->translation->add_app('loginhelp',$_GET['lang']);
@@ -539,4 +538,7 @@
 		
 
+        $tmpl->set_var('dir_root', 'http://' . nearest_to_me() . '/');
+        include_once(dirname( __FILE__ ) . '/../../../infodist/ultima-revisao-svn.php');
+        if(isset($ultima_revisao)) $tmpl->set_var('ultima_rev','<br>' . $ultima_revisao);
 	$tmpl->pfp('loginout','login_form');
 ?>
Index: /branches/2.2/phpgwapi/templates/default/login.tpl
===================================================================
--- /branches/2.2/phpgwapi/templates/default/login.tpl	(revision 3480)
+++ /branches/2.2/phpgwapi/templates/default/login.tpl	(revision 3486)
@@ -40,5 +40,5 @@
 		newScreenX  = screen.width - newWidth;	
 		newScreenY  = 0;		
-		Window1=window.open(link,'',"width="+newWidth+",height="+newHeight+",screenX="+newScreenX+",left="+newScreenX+",screenY="+newScreenY+",top="+newScreenY+",toolbar=no,scrollbars=yes,resizable=no");				
+		Window1=window.open('{dir_root}'+link,'',"width="+newWidth+",height="+newHeight+",screenX="+newScreenX+",left="+newScreenX+",screenY="+newScreenY+",top="+newScreenY+",toolbar=no,scrollbars=yes,resizable=no");
 	}
         var opened = false, vkb = null, text = null; 
Index: /branches/2.2/phpgwapi/templates/default/navbar.inc.php
===================================================================
--- /branches/2.2/phpgwapi/templates/default/navbar.inc.php	(revision 3338)
+++ /branches/2.2/phpgwapi/templates/default/navbar.inc.php	(revision 3486)
@@ -278,6 +278,6 @@
                                 $GLOBALS['phpgw_info']['user']['lastpasswd_change'] < $aux)
 			{
-				$changepasswd_url = $_SERVER['HTTP_HOST'] . $GLOBALS['phpgw_info']['server']['webserver_url'] . '/preferences/changepassword.php?cd=1';
-				
+				//$changepasswd_url = $_SERVER['HTTP_HOST'] . $GLOBALS['phpgw_info']['server']['webserver_url'] . '/preferences/changepassword.php?cd=1';
+                                $changepasswd_url = nearest_to_me() . '/preferences/changepassword.php?cd=1';
 				if ($GLOBALS['phpgw_info']['server']['use_https'] > 0)
 					$changepasswd_url = 'https://' . $changepasswd_url;
