Index: trunk/jabberit_messenger/java_source/src/nu/fw/jeti/applet/Jeti.java
===================================================================
--- trunk/jabberit_messenger/java_source/src/nu/fw/jeti/applet/Jeti.java	(revision 1164)
+++ trunk/jabberit_messenger/java_source/src/nu/fw/jeti/applet/Jeti.java	(revision 1423)
@@ -14,5 +14,4 @@
 import javax.swing.JPanel;
 import javax.swing.SwingUtilities;
-
 import nu.fw.jeti.backend.LoginInfo;
 import nu.fw.jeti.backend.Start;
@@ -29,10 +28,10 @@
 import nu.fw.jeti.ui.AddContact;
 import nu.fw.jeti.ui.JIDInput;
-
 import nu.fw.jeti.ui.StatusButton;
-
 import nu.fw.jeti.util.I18N;
+import nu.fw.jeti.util.JavaScriptServerExpresso;
 import nu.fw.jeti.util.Popups;
 import nu.fw.jeti.util.Preferences;
+import nu.fw.jeti.util.ProxyIM;
 
 import netscape.javascript.JSObject;
@@ -73,4 +72,5 @@
 	private boolean started = false;
 	private SecureMethodRunner secureMethodInvoker;
+	private Thread initIM;
 	public static JLabel from;
 	public static LoginInfo loginInfo;
@@ -80,5 +80,4 @@
 	public static String USEHTTPS;
 	public static String CNNAME;
-	public static JSObject WINDOWAPPLET;
 	public static List GROUPSUSER;
 	public static String SERVERJABBER;
@@ -87,4 +86,6 @@
 	public static String JAVAPLUGINS;
 	
+	public static JSObject WINDOWAPPLET = null;	
+
 	/**
 	 * @Author	: Alexandre Correia - alexandrecorreia@celepar.pr.gov.br
@@ -93,146 +94,124 @@
 	 */
 	public static boolean DEBUG_APPLET_VIEWER = false;
-	
+
 	public void init()
 	{
+		splash();
+		loadApplet();
+	}
+	
+	public void loadApplet()
+	{
 		applet = this;
-
-		Thread t = new Thread()
-		{
-			public void run()
+		
+		String server = new String(applet.getParameter("SERVER"));
+		String portText = new String(applet.getParameter("PORT"));
+		boolean ssl = Boolean.valueOf(applet.getParameter("SSL")).booleanValue();
+		String user = new String(applet.getParameter("USER"));
+		String password = new String(applet.getParameter("PASSWORD"));
+		String resource = new String(applet.getParameter("RESOURCE"));
+		String host = new String(applet.getParameter("HOST"));
+		String serverExpresso = new String(applet.getParameter("EXPRESSO"));
+		String useHttps = new String(applet.getParameter("USEHTTPS"));
+		String nameCompany = new String(applet.getParameter("NAMECOMPANY"));
+		String cnName = new String(applet.getParameter("CNNAME"));
+		String country = new String(applet.getParameter("COUNTRY"));
+		String language = new String(applet.getParameter("LANGUAGE"));
+		String javaPlugins = new String(applet.getParameter("JAVAPLUGINS"));
+		
+		/**
+		 * @Author : Alexandre Correia - alexandrecorreia@celepar.pr.gov.br
+		 * @Date : 20/10/2008
+		 * @Description : - Nome Servidor IM-Jabber para Constant SERVERJABBER
+		 * 				  - Nome da Maquina Expresso para Constant SERVEREXPRESSO
+		 * 				  - Nome da Empresa para Constant NAMECOMPANY
+		 * 				  - Informa qual o tipo de protocolo a ser usado http ou https.
+		 * 				  - Passa ao java o cn do ldap do servidor expresso.
+		 * 				  - Carrega plugins para o Java.
+		 * 				  - uid expresso;		 					  
+		 */
+		
+		SERVERJABBER	= server;	
+		SERVEREXPRESSO	= serverExpresso;
+		NAMECOMPANY		= nameCompany;
+		USEHTTPS		= useHttps;
+		CNNAME			= cnName;
+		LANGUAGE		= language;
+		COUNTRY			= country;
+		JAVAPLUGINS		= javaPlugins;
+		USERID			= user;
+
+		// Reinit languages incase they changed
+		I18N.init(language, country);
+		
+		groupchatRoom = getParameter("GROUPCHATROOM");
+		groupchatServer = getParameter("GROUPCHATSERVER");
+		
+		Start.programURL = getCodeBase();
+		Start.applet = true;
+		final JPanel panel = new JPanel(new BorderLayout());
+		start = new Start( getCodeBase().toString(), panel );
+		
+		backend = start.getBackend();
+		backend.getMain().translate();
+
+		if( server !=null || resource != null || portText !=null )
+		{
+			int port = Integer.parseInt(portText);
+			
+			ProxyIM.setProxy("http://" + server);
+			String proxyServer = ProxyIM.getProxyServer();
+			String proxyPort   = String.valueOf(ProxyIM.getProxyPort());
+
+			loginInfo = new LoginInfo(server, host.trim(), user, password, resource, port, ssl, proxyServer, proxyPort);
+			backend.autoLogin(loginInfo, 2);
+
+			if( loginInfo != null )
 			{
-	
-				String server = new String(applet.getParameter("SERVER"));
-				String portText = new String(applet.getParameter("PORT"));
-				boolean ssl = Boolean.valueOf(applet.getParameter("SSL")).booleanValue();
-				String user = new String(applet.getParameter("USER"));
-				String password = new String(applet.getParameter("PASSWORD"));
-				String resource = new String(applet.getParameter("RESOURCE"));
-				String host = new String(applet.getParameter("HOST"));
-				String useJavaProxy = new String(applet.getParameter("USEPROXY").toUpperCase());
-				String serverExpresso = new String(applet.getParameter("EXPRESSO"));
-				String useHttps = new String(applet.getParameter("USEHTTPS"));
-				String nameCompany = new String(applet.getParameter("NAMECOMPANY"));
-				String cnName = new String(applet.getParameter("CNNAME"));
-				String country = new String(applet.getParameter("COUNTRY"));
-				String language = new String(applet.getParameter("LANGUAGE"));
-				String javaPlugins = new String(applet.getParameter("JAVAPLUGINS"));
-				
-				/**
-				 * @Author : Alexandre Correia - alexandrecorreia@celepar.pr.gov.br
-				 * @Date : 20/10/2008
-				 * @Description : - Nome Servidor IM-Jabber para Constant SERVERJABBER
-				 * 				  - Nome da Maquina Expresso para Constant SERVEREXPRESSO
-				 * 				  - Nome da Empresa para Constant NAMECOMPANY
-				 * 				  - Informa qual o tipo de protocolo a ser usado http ou https.
-				 * 				  - Passa ao java o cn do ldap do servidor expresso.
-				 * 				  - Carrega plugins para o Java.
-				 * 				  - uid expresso;		 					  
-				 */
-				
-				SERVERJABBER = server;	
-				SERVEREXPRESSO = serverExpresso;
-				NAMECOMPANY = nameCompany;
-				USEHTTPS = useHttps;
-				CNNAME = cnName;
-				LANGUAGE = language;
-				COUNTRY = country;
-				JAVAPLUGINS = javaPlugins;
-				USERID = user;
-
-				// Reinit languages incase they changed
-				I18N.init(language, country);
-				
-				groupchatRoom = getParameter("GROUPCHATROOM");
-				groupchatServer = getParameter("GROUPCHATSERVER");
-				
+				secureMethodInvoker = new SecureMethodRunner(backend);
+				secureMethodInvoker.start();
+
+				backend.addExtensionHandler("jeti:prefs",new PreferencesHandler());
 				try
 				{
-                     exitURL = new URL(getDocumentBase(),getParameter("EXITPAGE"));
-				} 
-				catch (MalformedURLException e){}
+					backend.addListener(StatusChangeListener.class,new StatusChangeListener()
+					{
+						public void connectionChanged(boolean online)
+						{
+							if( online )
+							{	
+								backend.send(new InfoQuery("get",new IQPrivate(new JetiPrivatePreferencesExtension())));
+								
+								if( !nu.fw.jeti.applet.Jeti.DEBUG_APPLET_VIEWER )
+									WINDOWAPPLET = JSObject.getWindow(applet);
+							}
+						}
+						public void ownPresenceChanged(int show, String status)	{}
+						public void exit(){}
+					});
+				}
+				catch(NoClassDefFoundError e)
+				{	
+					e.printStackTrace();
+				}
 				
-				if( server !=null || resource != null || portText !=null )
+				new Popups(Jeti.this);
+				SwingUtilities.invokeLater(new Runnable()
 				{
-					int port = Integer.parseInt(portText);
-					
-					if( useJavaProxy.equals("TRUE"))
-						loginInfo = new LoginInfo(server,host,user,password,resource,port,ssl,0);
-					else
-						loginInfo = new LoginInfo(server,host,user,password,resource,port,ssl,0,false);
-				}
-
-				Start.programURL = getCodeBase();
-				Start.applet = true;
-				final JPanel panel = new JPanel(new BorderLayout());
-				start = new Start( getCodeBase().toString(), panel );
-				
-				backend = start.getBackend();
-				backend.getMain().translate();
-				
-				if( loginInfo != null && loginInfo.getPassword() != null)
-				{
-					backend.autoLogin(loginInfo,10);
-
-					secureMethodInvoker = new SecureMethodRunner(backend);
-					secureMethodInvoker.start();
-					
-					backend.addExtensionHandler("jeti:prefs",new PreferencesHandler());
-					try
+					public void run()
 					{
-						backend.addListener(StatusChangeListener.class,new StatusChangeListener()
-						{
-							public void connectionChanged(boolean online)
-							{
-								if( online)
-								{
-									backend.send(new InfoQuery("get",new IQPrivate(new JetiPrivatePreferencesExtension())));
-									String chatTO = getParameter("CHATTO");
-									if(chatTO!=null && chatTO.length()>0)
-						    		{
-						    			if(Boolean.valueOf(getParameter("SHOWCHATTOASMAIN")).booleanValue())
-						    			{
-						    				setContentPane(backend.getMain().createChatPanel(new UnknownJIDStatus(JID.jidFromString(chatTO))));
-						    				validate();
-						    			}
-						    			else backend.getMain().startChat(JID.jidFromString(chatTO));
-									}
-								}
-							}
-							public void ownPresenceChanged(int show, String status)	{}
-							public void exit(){}
-						});
+						setContentPane(panel);
+						validate();
 					}
-					catch(NoClassDefFoundError e)
-					{	
-						e.printStackTrace();
-					}
-					
-					new Popups(Jeti.this);
-					SwingUtilities.invokeLater(new Runnable()
-					{
-						public void run()
-						{
-							setContentPane(panel);
-							validate();
-						}
-					});
-					
-					started = true;
-				}else
-					started = false;
+				});
+				started = true;
 			}
-		};
-		
-		t.start();
-		splash();
-		
-		if ( !DEBUG_APPLET_VIEWER )
-		{	
-			JSObject winApplet = JSObject.getWindow(this);	
-			WINDOWAPPLET = winApplet;
-		}
-	}
-			
+			else
+			{
+				started = false;
+			}
+		}
+	}
+	
 	private void splash()
 	{ 
@@ -261,4 +240,10 @@
 	}
 	
+	public String getStatusMessages(int status)
+	{
+        List messages = Preferences.getStatusMessages(status);
+		return messages.toString();
+	}
+	
 	public String getGroupsToExpresso()
 	{
@@ -319,5 +304,4 @@
 		catch (Exception e) 
 		{
-			//catch all exceptions else jvm hangs
 			e.printStackTrace();
 		} 
