anchor.diff:          navig_links([{"javascript: history.back();", "Back"}]) ++
           footer([]).
   
  +%% ----------------------------------------------------------------------
  +%% Internal functions
  +%% ----------------------------------------------------------------------
  +
  +header(Title, _Options) ->
  +    "<html>\n\n"
  +        "<head>\n"
  +        "<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>\n"
  +        "<meta http-equiv='Content-Style-Type' content='text/css'>\n"
  +        "<meta http-equiv='Content-Script-Type' content='text/javascript'>\n"
  +        "<title>" ++ Title ++ "</title>\n"
  +        "<link rel='stylesheet' href='res/styles.css'>\n"
  +        "</head>\n\n"
  +        "<body>\n\n".
  +
  +footer(_Options) ->
  +    "\n\n</body>\n"
  +        "</html>\n".
  +
  +h1(String) ->
  +    "<h1>" ++ String ++ "</h1>".
  +
  +b(String) ->
  +    "<b>" ++ String ++ "</b>".
  +
  +table(Game) ->
  +    "<table cellpadding=0 cellspacing=0>\n"
  +        "<tr>\n"
  +        "<td>\n"
  +        "<td class=crd_t><tt>a</tt>\n"
  +        "<td class=crd_t><tt>b</tt>\n"
  +        "<td class=crd_t><tt>c</tt>\n"
  +        "<td class=crd_t><tt>d</tt>\n"
  +        "<td class=crd_t><tt>e</tt>\n"
  +        "<td class=crd_t><tt>f</tt>\n"
  +        "<td class=crd_t><tt>g</tt>\n"
  +        "<td class=crd_t><tt>h</tt>\n"
  +        "<td>\n"
  +        ++ table_rows(Game) ++
  +        "<tr>\n"
  +        "<td>\n"
  +        "<td class=crd_b><tt>a</tt>\n"
  +        "<td class=crd_b><tt>b</tt>\n"
  +        "<td class=crd_b><tt>c</tt>\n"
  +        "<td class=crd_b><tt>d</tt>\n"
  +        "<td class=crd_b><tt>e</tt>\n"
  +        "<td class=crd_b><tt>f</tt>\n"
  +        "<td class=crd_b><tt>g</tt>\n"
  +        "<td class=crd_b><tt>h</tt>\n"
  +        "<td>\n"
  +        "</table>\n".
  +
  +table_rows(Game) ->
  +    table_rows(tuple_to_list(Game), 8, []).
  +table_rows([Row | Tail], N, Result) ->
  +    StrRow =
  +        "<tr>\n"
  +        "<td class=crd_l><tt>" ++ integer_to_list(N) ++ "</tt>\n"
  +        ++ table_row(Row, N) ++
  +        "<td class=crd_r><tt>" ++ integer_to_list(N) ++ "</tt>\n",
  +    table_rows(Tail, N - 1, [StrRow | Result]);
  +table_rows(_, _, Result) ->
  +    lists:reverse(Result).
  +
  +table_row(Row, N) when is_tuple(Row) ->
  +    table_row(
  +      tuple_to_list(Row),
  +      if N rem 2 == 0 -> "wc";
  +         true -> "bc"
  +      end);
  +table_row([Figure | Tail], CellClass) ->
  +    NewCellClass =
  +        case CellClass of
  +            "bc" -> "wc";
  +            "wc" -> "bc"
  +        end,
  +    "<td class=" ++ CellClass ++ ">" ++ figure(Figure) ++ "\n" ++
  +        table_row(Tail, NewCellClass);
  +table_row(_, _) -> "".
  +
  +figure(?empty) -> "&nbsp;";
  +figure(Fig) ->
  +    "&#" ++ integer_to_list(figure_(Fig)) ++ ";".
  +figure_(?w_king  ) -> 9812;
  +figure_(?w_queen ) -> 9813;
  +figure_(?w_rook  ) -> 9814;
  +figure_(?w_bishop) -> 9815;
  +figure_(?w_knight) -> 9816;
  +figure_(?w_pawn  ) -> 9817;
  +figure_(?b_king  ) -> 9818;
  +figure_(?b_queen ) -> 9819;
  +figure_(?b_rook  ) -> 9820;
  +figure_(?b_bishop) -> 9821;
  +figure_(?b_knight) -> 9822;
  +figure_(?b_pawn  ) -> 9823.
  +
  +navig_links(List) -> navig_links(List, undefined).
  +navig_links([], _Current) -> "";
  +navig_links(List, Current) ->
  +    "<div class=navig>[&nbsp;" ++
  +        string:join(
  +          lists:map(
  +            fun({URL, Caption}) ->
  +                    "<a href='" ++ URL ++ "'>" ++
  +                        if Caption == Current ->
  +                                b(Caption);
  +                           true -> Caption
  +                        end ++ "</a>"
  +            end, List), "&nbsp;|&nbsp;") ++
  +        "&nbsp;]</div>".
  +
  +section_caption(?SECTION_HOME) -> "Home";
  +section_caption(?SECTION_USERS) -> "Users";
  +section_caption(Other) -> Other.
  +
  +navigation() ->
  +    navig_links(
  +      [{"?goto=" ++ S, section_caption(S)} ||
  +          S <- [?SECTION_HOME, ?SECTION_USERS,
  +                ?SECTION_TEST]] ++
  +          [{"?action=exit", "Logout"}],
  +      section_caption(echessd_session:get_val(section))).
  +
  
positive.code: 
  -include("echessd.hrl").
  
  header(Title, _Options) ->
      "<html>\n\n"
          "<head>\n"
          "<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>\n"
          "<meta http-equiv='Content-Style-Type' content='text/css'>\n"
          "<meta http-equiv='Content-Script-Type' content='text/javascript'>\n"
          "<title>" ++ Title ++ "</title>\n"
          "<link rel='stylesheet' href='res/styles.css'>\n"
          "</head>\n\n"
          "<body>\n\n".
  
  footer(_Options) ->
      "\n\n</body>\n"
          "</html>\n".
  
  h1(String) ->
      "<h1>" ++ String ++ "</h1>".
  
  b(String) ->
      "<b>" ++ String ++ "</b>".
  
  table(Game) ->
      "<table cellpadding=0 cellspacing=0>\n"
          "<tr>\n"
          "<td>\n"
          "<td class=crd_t><tt>a</tt>\n"
          "<td class=crd_t><tt>b</tt>\n"
          "<td class=crd_t><tt>c</tt>\n"
          "<td class=crd_t><tt>d</tt>\n"
          "<td class=crd_t><tt>e</tt>\n"
          "<td class=crd_t><tt>f</tt>\n"
          "<td class=crd_t><tt>g</tt>\n"
          "<td class=crd_t><tt>h</tt>\n"
          "<td>\n"
          ++ table_rows(Game) ++
          "<tr>\n"
          "<td>\n"
          "<td class=crd_b><tt>a</tt>\n"
          "<td class=crd_b><tt>b</tt>\n"
          "<td class=crd_b><tt>c</tt>\n"
          "<td class=crd_b><tt>d</tt>\n"
          "<td class=crd_b><tt>e</tt>\n"
          "<td class=crd_b><tt>f</tt>\n"
          "<td class=crd_b><tt>g</tt>\n"
          "<td class=crd_b><tt>h</tt>\n"
          "<td>\n"
          "</table>\n".
  
  table_rows(Game) ->
      table_rows(tuple_to_list(Game), 8, []).
  table_rows([Row | Tail], N, Result) ->
      StrRow =
          "<tr>\n"
          "<td class=crd_l><tt>" ++ integer_to_list(N) ++ "</tt>\n"
          ++ table_row(Row, N) ++
          "<td class=crd_r><tt>" ++ integer_to_list(N) ++ "</tt>\n",
      table_rows(Tail, N - 1, [StrRow | Result]);
  table_rows(_, _, Result) ->
      lists:reverse(Result).
  
  table_row(Row, N) when is_tuple(Row) ->
      table_row(
        tuple_to_list(Row),
        if N rem 2 == 0 -> "wc";
           true -> "bc"
        end);
  table_row([Figure | Tail], CellClass) ->
      NewCellClass =
          case CellClass of
              "bc" -> "wc";
              "wc" -> "bc"
          end,
      "<td class=" ++ CellClass ++ ">" ++ figure(Figure) ++ "\n" ++
          table_row(Tail, NewCellClass);
  table_row(_, _) -> "".
  
  figure(?empty) -> "&nbsp;";
  figure(Fig) ->
      "&#" ++ integer_to_list(figure_(Fig)) ++ ";".
  figure_(?w_king  ) -> 9812;
  figure_(?w_queen ) -> 9813;
  figure_(?w_rook  ) -> 9814;
  figure_(?w_bishop) -> 9815;
  figure_(?w_knight) -> 9816;
  figure_(?w_pawn  ) -> 9817;
  figure_(?b_king  ) -> 9818;
  figure_(?b_queen ) -> 9819;
  figure_(?b_rook  ) -> 9820;
  figure_(?b_bishop) -> 9821;
  figure_(?b_knight) -> 9822;
  figure_(?b_pawn  ) -> 9823.
  
  navig_links(List) -> navig_links(List, undefined).
  navig_links([], _Current) -> "";
  navig_links(List, Current) ->
      "<div class=navig>[&nbsp;" ++
          string:join(
            lists:map(
              fun({URL, Caption}) ->
                      "<a href='" ++ URL ++ "'>" ++
                          if Caption == Current ->
                                  b(Caption);
                             true -> Caption
                          end ++ "</a>"
              end, List), "&nbsp;|&nbsp;") ++
          "&nbsp;]</div>".
  
  section_caption(?SECTION_HOME) -> "Home";
  section_caption(?SECTION_USERS) -> "Users";
  section_caption(Other) -> Other.
  
  navigation() ->
      navig_links(
        [{"?goto=" ++ S, section_caption(S)} ||
            S <- [?SECTION_HOME, ?SECTION_USERS,
                  ?SECTION_TEST]] ++
            [{"?action=exit", "Logout"}],
        section_caption(echessd_session:get_val(section))).
  
  login() ->
      header("echessd - Login", []) ++
  
negative.code: -module(echessd_html).
  
  -export([login/0,
           register/0,
           error/1,
           eaccess/0,
  