

function active_merge_shape_point(button) {
    disable_edit_tools();
    select_menu_button(button);
    active_func.merge = true;
}

function disable_merge_shape_point() {
    disable_edit_tools();
}

function active_move_point(button) {
    if (active_func.move) {
        disable_edit_tools();
        canvas_redraw();
    } else {
        disable_edit_tools();
        select_menu_button(button);
        $('.point_div').show(500);
        active_func.move = true;
    }
}

function active_split_point(button) {
    if (active_func.split) {
        disable_edit_tools();
        canvas_redraw();
    } else {
        disable_edit_tools();
        select_menu_button(button);
        active_func.split = true;
    }
}

function active_remove_shape_point(button) {
    disable_edit_tools();
    $('.point_div').show(500);
    select_menu_button(button);
    active_func.remove = true;
}

function disable_remove_shape_point() {
    disable_edit_tools()
}

function active_draw_shape(button) {
    if (active_func.draw) {
        canvas_redraw();
    } else {
        disable_edit_tools();
        select_menu_button(button);
        active_func.draw = true;
    }
}

function disable_draw_shape() {
    disable_edit_tools()
}




function active_create_block(button) {
    if (active_func.create_new_block) {
        disable_create_block();
    } else {
        disable_edit_tools();
        select_menu_button(button);
        active_func.create_new_block = true;
    }

}

function disable_create_block() {
    disable_edit_tools()
}

function active_create_block_part(button) {
    button_highlight(button);
    add_new_block_before_selected();
}


function disable_create_block_part() {
    disable_edit_tools()
}

function active_change_block_part_style(button) {
    if (active_func.change_style) {

        disable_change_block_part_style();
    } else {
        disable_edit_tools();
        select_menu_button(button);
        active_func.change_style = true;
    }
}

function disable_change_block_part_style() {
    disable_edit_tools()
}

function active_remove_block_part(button) {
    if (active_func.remove_block_part) {
        disable_edit_tools();

    } else {
        disable_edit_tools();
        select_menu_button(button);
        active_func.remove_block_part = true;
    }
}

function disable_remove_block_part() {
    disable_edit_tools();
}

function active_merge_block_parts(button) {
    if (active_func.merge_block_parts) {
        disable_merge_block_parts();
    } else {
        disable_edit_tools();
        select_menu_button(button);
        active_func.merge_block_parts = true;
    }
}

function disable_merge_block_parts() {
    disable_edit_tools()
}

function active_split_block_parts(button) {
    if (active_func.split_block_parts) {
        disable_split_block_parts();
    } else {
        disable_edit_tools();
        select_menu_button(button);
        active_func.split_block_parts = true;
    }
}

function disable_split_block_parts() {
    disable_edit_tools();
}

function toggle_layers(button) {
    if (button != "") {
        button_highlight(button);
    }
    if (active_block_view) {
        show_layer_tools(false);
        active_block_view = false;
    } else {
        show_layer_tools(true);
        active_block_view = true;
    }
    change_block_view();
}

function end_record_edit(button) {
    button_highlight(button);
    prepare_dialog_unlock_report();

}



var tester;

function test_fnc(button) {
    validate_html();




    if (tester != undefined) {
        clearInterval(tester);
    } else {
        tester = setInterval(function() {
            button_highlight(button);
            wave_menu();
        }, 1100);
    }
}



function show_index_select() {
    var div = $('<div id="block_index"><i class="material-icons" style="" >playlist_add</i></div>');
    var select = $(render_index_select());
    select.change(function() {
        var el = $(pageparts).children().find('.selected_span');
        change_el_index(el, $(this).find('option:selected').val());
    });
    div.append(select);
    $('toptoolbar').append(div);
}



function down_trans_steps(button) {
    button_highlight(button);
    html_part(1);
    html_part(2);
    html_part(3);
    html_part("html");

}

function menu_load_xml_vers(button) {
    button_highlight(button);
    get_xml_vers_from_json();
}



function split_records(button) {
    button_highlight(button);
    wave_menu();
    var rec = prompt(" Zadejte prosím ID pro přidání ", "");
    if (rec != null && isNaN(parseInt(rec)) == false) {
        merge_load_record(rec);
        start_full_loader(true);
    }
}

function send_final_xml(button) {
    button_highlight(button);
    wave_menu();
    if (save_block_status()) {
        prepare_select_block_status_dialog(true);
    }

}

function send_html_report(button) {
    button_highlight(button);
    prepare_dialog_send_report();

}


function send_report(button) {

}

function send_blocks_to_control(button) {
    button_highlight(button);

    var o = $('pageparts div')[0];
    $.post(xml_xsl, {
        req: "html",
        file1: html_xsl1,
        file2: html_xsl2,
        file3: html_xsl3,
        html: nodeToString(o).replace(/\r?\n|\r/g, ''),
    }).done(function(data) {
        recognize(data)
    });

}

function clone_record(button) {
    $(pageparts_div).click();
    disable_edit_tools();
    button_highlight(button);
    set_confirm_dialog(clone_record_accept_text, clone_record_accept, 400, 170, 'Zrušit', 'Naklonovat');
}

function clone_record_accept() {
    load_delete_block_parts
    wave_menu();
    start_transform_from_html_clone();
}



function check_before_save(button) {
    var o = nodeToString($('pageparts div')[0]).replace(/\r?\n|\r/g, '');
    save_backup(o);
    button_highlight(button);
    wave_menu();
}

function menu_toggle() {
    $('sidemenu').toggleClass('open_menu');
    $('footermenu').toggleClass('open_menu_footer');
    $('toptoolbar').toggleClass('open_menu_toptoolbar');
    if (menu_open) {
        $('.menu_item_label').fadeOut(1000);
        menu_open = false;
    } else {
        $('.menu_item_label').fadeIn(500);
        menu_open = true;
    }
}

function wave_menu() {
    $('.menu_item').each(function(i, el) {
        setTimeout(function() {
            button_highlight($(el))
        }, 50 * i);
    });
}

function show_source_page(button) {
    button_highlight(button);
    switch (get_url_params().dict) {
        case "SJS":
            break;
        case "MS":
            break;
        case "RSI":
            show_source();
            break;
        default:
            if (source_show) {
                $('sourcepage').fadeOut(1000);
                source_show = false;
                disable_edit_tools();
            } else {
                show_source();
                disable_edit_tools();
                select_menu_button(button);
                $('sourcepage').fadeIn(500);
                source_show = true;
            }
            break;
    }
}

function show_prev(args) {}

function disable_key_active() {
    for (var i in key_active) {
        key_active[i] = false;
    }
}

function disable_edit_tools() {
    for (var i in active_func) {
        active_func[i] = false;
    }
    $('sourcepage').fadeOut(1000);
    $('.menu_item').css({
        'background-color': 'transparent'
    });
    source_show = false;
    first_merge_block_part = undefined;
    second_merge_block_part = undefined;
}

function show_layer_tools(e) {
    if (e) {
        $('#new_block_create').show(500);
    } else {
        $('#new_block_create').hide(500);
    }
}
