// Decompiled by DJ v2.9.9.61 Copyright 2000 Atanas Neshkov  Date: 24/12/2002 11:23:18
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   LoginBox.java

import java.applet.Applet;
import java.applet.AppletContext;
import java.awt.*;
import java.io.PrintStream;
import java.net.MalformedURLException;
import java.net.URL;

public class LoginBox extends Applet
{

    public Color getColor(String s)
    {
        String s1 = getParameter(s);
        if(s1 != null)
        {
            if(s1.substring(0, 1).equals("#"))
            {
                s1 = s1.substring(1);
                int i = Integer.parseInt(s1, 16);
                return new Color(i);
            } else
            {
                return null;
            }
        } else
        {
            return null;
        }
    }

    public LoginBox()
    {
        title = "Login...";
        frameWidth = 250;
        frameHeight = 150;
        loginText = "Login";
        passwordText = "Password";
    }

    public String getAppletInfo()
    {
        return "Name: LoginBox\r\n" + "Author: Taiji Software\r\n";
    }

    public URL giveURL(String s)
    {
        try
        {
            if(s.toUpperCase().startsWith("HTTP"))
                return new URL(s);
            else
                return new URL(getCodeBase(), s);
        }
        catch(MalformedURLException malformedurlexception)
        {
            System.out.println(malformedurlexception);
        }
        return null;
    }

    public void register()
    {
        try
        {
            URL url1 = new URL("http://www.taijisoftware.com");
            getAppletContext().showDocument(url1, "_blank");
            stop();
            return;
        }
        catch(Exception exception)
        {
            System.out.println(exception);
        }
        stop();
    }

    public void putComponents()
    {
        LoginFrame loginframe = new LoginFrame(title, this);
        loginframe.reshape(200, 200, frameWidth, frameHeight);
        loginframe.setLayout(new FlowLayout());
        Panel panel = new Panel();
        panel.setLayout(new GridLayout(2, 2));
        panel.add(new Label(loginText));
        t1 = new TextField(10);
        panel.add(t1);
        panel.add(new Label(passwordText));
        t2 = new TextField(10);
        panel.add(t2);
        Panel panel1 = new Panel();
        panel1.setLayout(new FlowLayout());
        Button button = new Button("Ok");
        panel1.add(button);
        Button button1 = new Button("Cancel");
        panel1.add(button1);
        loginframe.add(panel);
        loginframe.add(panel1);
        loginframe.setBackground(getColor("background_color"));
        loginframe.show(true);
    }

    public void getParameters()
    {
        String s = getParameter("WIDTH");
        wi = Integer.parseInt(s);
        s = getParameter("HEIGHT");
        he = Integer.parseInt(s);
        s = getParameter("title");
        if(s != null)
            title = s;
        s = getParameter("frame_width");
        if(s != null)
            frameWidth = Integer.parseInt(s);
        s = getParameter("frame_height");
        if(s != null)
            frameHeight = Integer.parseInt(s);
        s = getParameter("login_text");
        if(s != null)
            loginText = s;
        s = getParameter("password_text");
        if(s != null)
            passwordText = s;
    }

    public void init()
    {
        String s = null;
        try
        {
            s = (new URL(getCodeBase().toString())).getHost().toUpperCase();
        }
        catch(Exception _ex) { }
        if(!getCodeBase().toString().toUpperCase().startsWith("FILE"))
        {
            char ac[] = new char[s.length()];
            s.getChars(0, s.length(), ac, 0);
            String s1 = new String("haricot");
            char ac1[] = new char[s1.length()];
            s1.getChars(0, s1.length(), ac1, 0);
            for(int j = 0; j < s.length(); j++)
            {
                int i;
                if(j >= s1.length())
                    i = j - s1.length() * (j / s1.length());
                else
                    i = j;
                ac[j] = (char)(ac[j] + ac1[i]);
                ac[j] = (char)((ac[j] - (ac[j] / 26) * 26) + 97);
            }

            String s2 = new String(ac);
            String s3 = getParameter("registration_code");
            if(s3 == null)
                s3 = "aa";
            if(!s2.equalsIgnoreCase(s3))
                register();
        }
        getParameters();
        putComponents();
    }

    public String url;
    private String title;
    private int wi;
    private int he;
    private int frameWidth;
    private int frameHeight;
    public TextField t1;
    public TextField t2;
    private String loginText;
    private String passwordText;
}