/* look for the rate in te account file for the time in the login string */
  public RateEntry getRate(String login) {
    int logday = 0, rateday = 0;
    //    System.out.println("getRate: login='******'");
    String day, time, rate = null;
    StringTokenizer st = new StringTokenizer(login);
    // frits     pts/21       flash            Fri Mar 18 13:46 - 14:30 (6+00:44)
    //                                        ^              ^
    day = st.nextToken();
    time = st.nextToken();
    time = st.nextToken();
    time = st.nextToken().substring(0, 5);
    // System.out.println(login+" "+day+" "+time);
    // Get the international names of the days and which day is (1,2,3...
    // Then find day of each rate entry, (1,2,3,4
    // Now we can compare, independent of the language used for the days
    // Finally use the time to compare as well
    DateFormatSymbols dfs = new DateFormatSymbols();
    String[] days = dfs.getShortWeekdays();
    for (int j = 1; j < days.length; j++) {
      if (day.compareTo(days[j]) == 0) {
        logday = j;
        break;
      }
    }
    // logday -> the day given in the gorecords.xml file (the log)

    int n = rates.size();
    // the last rate applies if before the first entry
    // Init to last rate given in the account
    RateEntry tmpRE, saveRE = rates(n - 1);
    //    System.out.println("n="+n);
    for (int i = 0; i < n; i++) {
      tmpRE = rates(i);
      for (int j = 1; j < days.length; j++) {
        if (tmpRE.day.compareTo(days[j]) == 0) {
          rateday = j;
          break;
        }
      }
      //    System.out.println("j="+jday+" k="+kday+" "+tmpRE.time+" "+tmpRE.loginhr);
      // the last rate applies if before the first entry
      if (logday > rateday) {
        saveRE = tmpRE;
      }
      if ((logday == rateday) && (time.compareTo(tmpRE.time) >= 0)) {
        saveRE = tmpRE;
      }
    }
    return saveRE;
  }
 public JPanel getGuiPanel() {
   JPanel panel = new JPanel();
   JButton button = new JButton();
   button.addActionListener(new DoItListener());
   outputLabel = new JLabel("date appears here");
   DateFormatSymbols dateStuff = new DateFormatSymbols();
   month = new JComboBox(dateStuff.getMonths());
   day = new JTextField(8);
   year = new JTextField(8);
   JPanel inputPanel = new JPanel(new GridLayout(3, 2));
   inputPanel.add(new JLabel("Month"));
   inputPanel.add(month);
   inputPanel.add(new JLabel("Day"));
   inputPanel.add(day);
   inputPanel.add(new JLabel("Year"));
   inputPanel.add(button);
   inputPanel.add(outputLabel);
   return panel;
 }
 public LogDateChooser(String label) {
   thisDialog = this;
   border = new EtchedBorder();
   setBorder(border);
   Font f = new Font("Helvetica", Font.PLAIN, 10);
   title = new JLabel(label);
   add(title);
   setLayout(new DateLayout());
   dfs = new DateFormatSymbols();
   months = dfs.getMonths();
   weekdays = dfs.getShortWeekdays();
   for (int i = 0; i < 7; i++) {
     days[i] = new JLabel(weekdays[i + 1]);
     days[i].setFont(f);
     add(days[i]);
   }
   gc = new GregorianCalendar();
   mDown = new JButton("<");
   mDown.setMargin(new Insets(0, 0, 0, 0));
   mDown.addActionListener(new MDownEar());
   mDown.setBorderPainted(false);
   mDown.setFont(f);
   mDown.setForeground(Color.BLUE);
   add(mDown);
   mUp = new JButton(">");
   mUp.setMargin(new Insets(0, 0, 0, 0));
   mUp.addActionListener(new MUpEar());
   mUp.setBorderPainted(false);
   mUp.setFont(f);
   mUp.setForeground(Color.BLUE);
   add(mUp);
   month = new JLabel(months[gc.get(Calendar.MONTH)]);
   month.setHorizontalAlignment(SwingConstants.CENTER);
   month.setFont(f);
   add(month);
   year = new JLabel(new Integer(gc.get(Calendar.YEAR)).toString());
   year.setFont(f);
   add(year);
   yDown = new JButton("<");
   yDown.setMargin(new Insets(0, 0, 0, 0));
   yDown.addActionListener(new YDownEar());
   yDown.setBorderPainted(false);
   yDown.setFont(f);
   yDown.setForeground(Color.BLUE);
   add(yDown);
   yUp = new JButton(">");
   yUp.setMargin(new Insets(0, 0, 0, 0));
   yUp.addActionListener(new YUpEar());
   yUp.setBorderPainted(false);
   yUp.setFont(f);
   yUp.setForeground(Color.BLUE);
   add(yUp);
   //    System.out.println(year.getText());
   NumberEar numberEar = new NumberEar();
   for (int i = 0; i < 31; i++) {
     number[i] = new JButton(new Integer(i + 1).toString());
     number[i].setMargin(new Insets(0, 0, 0, 0));
     number[i].addActionListener(numberEar);
     number[i].setBorderPainted(false);
     number[i].setContentAreaFilled(false);
     number[i].setFont(f);
     number[i].setForeground(Color.BLUE);
     add(number[i]);
   }
   number[0].setForeground(Color.CYAN);
 }
  Double getCharge(String date, double howLong) {
    int jday = 0;
    Double nMins;
    String day, time, rate = null;
    double remain = howLong;
    StringTokenizer st = new StringTokenizer(date);
    day = st.nextToken();
    time = st.nextToken();
    time = st.nextToken();
    time = st.nextToken().substring(0, 5);
    nMins = AProps.getInstance().toMinutes(time);
    DateFormatSymbols dfs = new DateFormatSymbols();
    String[] days = dfs.getShortWeekdays();
    for (int j = 1; j < days.length; j++) {
      if (day.compareTo(days[j]) == 0) {
        jday = j;
        break;
      }
    }
    int n = rates.size(), tableNMin;
    // One Rate for the entire Login session
    if (n == 1) { // only one flat rate
      // Get time in hours
      Double howLongHr = howLong / 60.0;
      // Calc cost of logon time
      Double cost = new Double(rates(0).loginhr).doubleValue() * howLongHr;
      // Cost of each login
      Double login = new Double(rates(0).login).doubleValue();
      cost = cost + login;
      return (cost);
    }
    // Multiple Rates for this login session
    // Default to last rate in list so that if last rate is eg., Fri and
    // the current day is Sun, it will still use Friday.
    iRE = n - 1;
    RateEntry tmpRE, saveRE = rates(n - 1);
    for (int i = 0; i < n; i++) {
      tmpRE = rates(i);
      if (tmpRE.dayOfWeek() < jday) {
        saveRE = tmpRE;
        iRE = i;
      }
      tableNMin = (AProps.getInstance().toMinutes(tmpRE.time())).intValue();
      if ((tmpRE.dayOfWeek() == jday) && (nMins.intValue() > tableNMin)) {
        saveRE = tmpRE;
        iRE = i;
      }
    }
    tRE = iRE + 1; // iRE set rate, tRE set time until
    if (tRE >= n) tRE = 0;
    Double charge;
    int ndays;
    double diffMins;
    if (tRE == 0) {
      ndays = rates(0).dayOfWeek() + (7 - jday);
    } else {
      ndays = rates(tRE).dayOfWeek() - jday;
    }
    if (ndays > 7) ndays = ndays - 7;
    int nmin = AProps.getInstance().toMinutes(rates(tRE).time()).intValue() - nMins.intValue();
    diffMins = ndays * 24 * 60 + nmin;
    if (remain < diffMins) {
      diffMins = remain;
    }
    // Calc charge for the first period of time up to the next rate change
    Double hours = new Double(diffMins / 60.0);
    charge = new Double(hours * new Double(rates(iRE).loginhr()));
    // Add in the per session login rate
    charge += new Double(rates(iRE).login());
    remain -= diffMins;

    // now we have the charge for the first increment including the login,
    // calculate changes for remaining periods using their rates
    while (remain > 0.0) {

      if ((remain - rates(tRE).nMinutes()) >= 0) {

        charge += rates(tRE).nMinutes() * new Double(rates(tRE).loginhr()) / 60.0;
      } else {

        charge += remain * new Double(rates(tRE).loginhr()) / 60.0;
      }
      remain -= rates(tRE).nMinutes();
      iRE++;
      if (iRE >= n) iRE = 0;
      tRE++;
      if (tRE >= n) tRE = 0;
    }

    return (charge);
  }