function DocEngineTable() {};

DocEngineTable.prototype = new DocEngine;
DocEngineTable.superClass = DocEngine.prototype;

DocEngineTable.prototype.transaction_info = function(macro, ts) {
    this.close_table();
    DocEngineTable.superClass.transaction_info.call(this, macro, ts);
}

DocEngineTable.prototype.draw_hinweis_table = function(text, icon_path) {
    this.close_table();
    DocEngineTable.superClass.draw_hinweis_table.call(this, text, icon_path);
}

DocEngineTable.prototype.open_table = function() {
    if (!this._table_open) {
        Document.BeginParagraph(word_trans('para_bubble_text'));

        Document.BeginTable("standard_table");
            Document.BeginRow();
                Document.BeginCell();
                    this.add_html_paragraph(word_trans('para_bubble_text_center'),
                                            "<b>" + prj_trans('docTableHeaderStep') + "</b>");
                Document.EndCell();
                Document.BeginCell();
                    this.add_html_paragraph(word_trans('para_bubble_text'),
                                            "<b>" + prj_trans('docTableHeaderAction') + "</b>");
                Document.EndCell();
            Document.EndRow();

        this._table_open = true;
    }
}

DocEngineTable.prototype.close_table = function() {
    if (this._table_open) {
        Document.EndTable();
        Document.EndParagraph();

        this._table_open = false;
    }
}

DocEngineTable.prototype.add_bubble_text = function(macro, index) {
    if (!cfg.standard.doc.show_bubble_text) return;
    var text = this.get_macro_text(macro);
    var doc_index = ((index != -1 && cfg.standard.doc.rects_with_index) ? index + "." : "");
    if (text.length == 0) return false;

    if (index > 0) {
        this.open_table();

        Document.BeginRow();
            Document.BeginCell();
                this.add_html_paragraph(word_trans('para_bubble_text_center'), doc_index);
            Document.EndCell();
            Document.BeginCell();
                this.add_html_paragraph(word_trans('para_bubble_text'), text);
            Document.EndCell();
        Document.EndRow();
    } else {
        Document.LineBreak();
        this.add_html_paragraph(word_trans('para_bubble_text'), text);
        Document.LineBreak();
    }

    return true;
};

DocEngineTable.prototype.reset = function() {
    DocEngineTable.superClass.reset.call(this);

    this._table_open = false;
};


DocEngineTable.prototype.define_styles = function() {
    DocEngineTable.superClass.define_styles.call(this);

    // STANDARD TABLE
    Document.SetCurrCellStyle("standard_cell_left");
    Document.CellWidth = 50;
    Document.CellLeftPad = 3.5;
    Document.CellRightPad = 3.5;
    Document.CellTopPad = 3.5;
    Document.CellBottomPad = 3.5;
    Document.CellBgColor = 0xffffff;

    Document.SetCurrCellStyle("standard_cell_right");
    Document.CellWidth = 360;
    Document.CellLeftPad = 3.5;
    Document.CellRightPad = 3.5;
    Document.CellTopPad = 3.5;
    Document.CellBottomPad = 3.5;
    Document.CellBgColor = 0xffffff;

    Document.SetCurrRowStyle("standard_row");
    Document.RowHeight = 12.0;
    Document.SetRowCellStyles("standard_cell_left", "standard_cell_right");

    Document.SetCurrTableStyle("standard_table");
    Document.TableBorder = 2;
    //Document.TablePreferredWidth = 432.3;
    Document.TableRowStyle = "standard_row";

};

DocEngineTable.prototype.new_page = function(macro, ts) {
    this.close_table();
    DocEngineTable.superClass.new_page.call(this, macro, ts);

};


DocEngineTable.prototype.handle_tourstop = function(ts) {
    log("DocEngineTable::handle_tourstop");

    if (this.more_details) {
        this.add_text_paragraph(word_trans('para_heading') + (cfg.standard.doc.singledoc_headinglevel + 1),
                                Translate("IDS_TOURSTOP") + " " + ts.Index + ": " + ts.Caption);

    } else if (cfg.standard.doc.heading_from_tourstop) {

        var text = ts.Caption;

        if (text != "") {

            this.close_table();

            var parastyle = word_trans('para_heading') + (cfg.standard.doc.singledoc_headinglevel + 1);
            this.add_text_paragraph(parastyle, text);
        }
    }
};

DocEngineTable.prototype.handle_tour_stops = function() {
    log("DocEngineTable::handle_tour_stops");
    DocEngineTable.superClass.handle_tour_stops.call(this);
    this.close_table();
}
