


var canvas;
var ctx;
var rect;
var second_select = true;
var in_xsl,
    in_xml,
    in_xsd,
    html_xsl1,
    html_xsl2,
    html_xsl3,
    html_test,
    prev_xsl;
var block_editor, dictionary_author, text_styling, type_spec, word_type;
var file_prefix = "xml/";
var report_email = ['pavel.svejda@aipberoun.cz', 'olga.ciperova@aipberoun.cz'];
var scrolled = 0;
var save_iter = 0;
var check_iter = 0;
var saved_interval = "";
var check_interval = "";
var style_result = true;
var first_click = true;
var first_click_pos = {};
var menu_open = false;
var fill_color = "rgba(255, 0, 0, .3)";
var stroke_color = "red";
var points = [];
var shapes = [];
var point = 0;
var shape = 0;
var source_show = false;
var resized = false;
var ask_xml = false;
var active_map_view = true;
var max_font_id = 0;
var xml_xsl = "/js/gorazd_editor/xml_xsl.php";
var aip_block_template = "1-1-0-0";
var cache = {};
cache.select_font = "";
cache.select_type = "";
cache.select_block_part = "";
cache.select_block_type = "";
cache.input_span_replace = "";
cache.select_block_select = "";
cache.select_block_index = "";
cache.select_font_style = "";
cache.select_first;
cache.select_e;
cache.select_block_for_rec = "";
cache.select_block_status = "";
cache.img_prev_width = 0;
cache.img_prev_height = 0;
cache.img_ratio = [];
cache.load_xsl = "";
cache.load_xml = "";
cache.imgs = [];
cache.imgs_offset = [];
cache.img_temp_store = [];
cache.load_record_id;
cache.height_reserve = 40;
cache.side_reserve = 15;
cache.input_key_pos = 0;
cache.aip_block_store = {};
cache.input_length_const = 15;
var active_layer = 1;
var page_zoom_edit = 0;
var active_block_view = false;
var edit_history = [];
var edit_history_stat = -1;
var selected_block;
var selected_block_clone;
var prev_marc;
var colors = [];
var block_types = [];
var marc_div;
var marc;
var type_index_array = [];
var not_all_chars = [{
    ch: '<',
    val: '&lt;'
}, {
    ch: '>',
    val: '&gt;'
}];
var colors = JSON.parse('{"Neurčeno":"#CDB3DC","Záhlaví_hesla":"#CDC8DC","Gramatické_zařazení záhlaví":"#907009","Určení_slovního druhu":"#6BAD1D","Památka_1":"#307A41","Památka_2":"#8E3764","Památka_3":"#97D7A8","Památka_4":"#F1835F","Památka_5":"#887D1F","Památka_6":"#CEAA9E","Památka_7":"#3DAF40","Památka_8":"#0B5185","Památka_9":"#65AADE","Památka_10":"#3E91A7","Památka_11":"#48A93C","Text_odstavce 1":"#E34980","Text_odstavce 2":"#9CBC12","Text_odstavce 3":"#4ECB5D","Text_odstavce 4":"#10D08F"}')
var aip_type_colors;
var block_colors = ['#2196F3', '#3F51B5', '#009688', '#673AB7', '#4CAF50', '#8BC34A', '#CDDC39', '#3db8ff', '#FF9800', '#FF5722', '#795548'];
var active_func = {};
active_func.remove = false;
active_func.draw = false;
active_func.merge = false;
active_func.split = false;
active_func.move = false;
active_func.change_style = false;
active_func.remove_block_part = false;
active_func.merge_block_parts = false;
active_func.split_block_parts = false;
active_func.create_new_part = false;
active_func.create_new_block = false;
var first_merge;
var second_merge;
var first_merge_block_part;
var second_merge_block_part;
var dialog_change_style;
var dialog_remove_block_part;
var dialog_remove_block_parts;
var dialog_virtual_keyboard;
var dialog_select_block_status;
var dialog_clone_block;
var dialog_send_report;
var dialog_unlock_block;
var dialog_uni;
var dialogs = {};
dialogs.open_delete_blocks = false;
dialogs.open_delete_block = false;
dialogs.open_keyboard = false;
dialogs.change_style = false;
dialogs.select_block_type = false;
dialogs.rescan_block = false;
dialogs.uni = false;
dialogs.block_status = false;
dialogs.block_clone_success = false;
dialogs.send_report = false;
dialogs.block_unlock = false;

var mouse_click_active = false;
var key_active = [];
var key_bind_global = [];


key_bind_global[18] = function(e) {
    delete_block_part(e.target);

key_bind_global[33] = function(e) {
    select_prev_block_part_style(e)

key_bind_global[34] = function(e) {
    select_next_block_part_style(e)

key_bind_global[27] = function(e) {
    remove_select_block_parts(e);
    block_input_edit($(pageparts).children().find(input));

key_bind_global[38] = function(e) {
    select_up_block_part(e)

key_bind_global[40] = function(e) {
    select_down_block_part(e)

key_bind_global[37] = function(e) {
    select_prev_block_part(e);

key_bind_global[39] = function(e) {
    select_next_block_part(e);

key_bind_global[46] = function(e) {
    load_delete_block_parts(e);

key_bind_global[74] = function(e) {
    merge_selected_block_parts(e);

var key_bind_input = [];
key_bind_input[46] = function(e, input) {
    merge_block_parts_delete(e, input);

key_bind_input[8] = function(e, input) {
    merge_block_parts_delete_prev(e, input);

key_bind_input[32] = function(e, input) {
    split_block_parts_space(e, input);

var span_create_temp = function() {
    cache.i++;
    return $('<span aip-type="" fontsize="normal" aip-style="" content="" page_id="" lang="" list_num="' + cache.i + '" style="" class="text_seg">Vložte_text</span>');
}
var input_edit_temp = $('<input style="display:inline-block;height:38px;" type="text" value="">');
var loading_image_ = $('<img src="/js/gorazd_editor/img/loader_large.gif">');
var end_block = function(num) {
    return $('<end class="end_block" block="' + num + '" ></end>')
};
var start_block = function(num) {
    return $('<start class="start_block" block="' + num + '" ></start>')
};
var dialog_send_report_text = $('<span id="dialog_send_report_text">Chcete odeslat hlášení o chybě s uloženou zálohou ?</span>')
var dialog_remove_parts_text = $('<span id="dialog_remove_block_part_text">Opravdu chcete dané části smazat ?</span>');
var dialog_remove_part_text = $('<span id="dialog_remove_block_part_text">Opravdu chcete danou část smazat ?</span>');
var dialog_change_block_type_text = $('<span id="dialog_change_block_type_text">Typ bloku:</span>');
var select_block_to_rec_text = $('<span id="dialog_change_block_type_text">Odstavec:</span>');
var select_xml_vers_text = $('<p>Vyberte verzi pro načtení</p>');
var clone_record_accept_text = $('<span>Naklonovat heslo  ? </span>');
var error_when_loading_record = $('<span>Nepodařilo se načíst záznam</span> <i class="material-icons">sentiment_neutral</i>');
var error_record_taken = function(user) {
    return '<span>Záznam je obsazen (uživatel ' + user + ')</span><i class="material-icons">person</i>';
}
var error_record_saving = '<span>Záznam se nyní ukládá</span><i class="material-icons">mood</i>';
var error_record_long_saving = '<span>Záznam se ukládá docela dlouho</span><i class="material-icons">sentiment_neutral</i>';
var error_record_not_saving = '<span>Záznam se nejspíše nepovedlo uložit</span><i class="material-icons">sentiment_dissatisfied</i>';
var error_record_locked = '<span>Záznam je uzamčen</span><i class="material-icons">sentiment_dissatisfied</i>';
var error_record_not_exists = '<span>Záznam neexistuje</span><i class="material-icons">sentiment_very_dissatisfied</i>';
var error_record_open_multiple = '<span>Heslo je otevřeno na více místech</span><i class="material-icons">sentiment_very_dissatisfied</i>';
var error_record_close_error = '<span>Heslo se nepodařilo uzavřít</span><i class="material-icons">sentiment_very_dissatisfied</i>';
var error_record_backup_found = '<span>Byla nalezena vaše záloha</span><i class="material-icons">sentiment_very_satisfied</i>';
var error_record_save_error = '<span>Nepovedlo se uložit předešlou práci</span><i class="material-icons">sentiment_very_dissatisfied</i>';
var error_record_corrupted = '<span>Záznam není kompletní</span><i class="material-icons">widgets</i>';
var error_record_clone = '<span>Nepovedlo se naklonovat</span><i class="material-icons">error_outline</i>';
var error_record_backup_save = '<span>Nepovedlo se uložit zálohu</span><i class="material-icons">error_outline</i>';
var error_record_backup_remove = '<span>Nepovedlo se odebrat zálohu záznamu</span><i class="material-icons">error_outline</i>';
var error_record_backup_load = '<span>Nepovedlo se načíst zálohu záznamu</span><i class="material-icons">error_outline</i>';
var error_record_backup_status = '<span>Nepovedlo se změnit stav zálohy</span><i class="material-icons">error_outline</i>';
var error_transformation = '<span>Nepovedlo se uskutečnit transformaci</span><i class="material-icons">error_outline</i>';
var error_transformation_false = '<span>Dokončete editaci hesla</span><i class="material-icons">error_outline</i>';
var error_loading_timeout = '<span>Záznam se nedaří načíst ResCode:101 <br />Stiskněte prosím F5</span><i class="material-icons">error_outline</i>';
var error_loading_xml_vers = '<span>Nepodařilo se načíst verze záznamu</span><i class="material-icons">error_outline</i>';

function get_url_params() {
    var returnArr = [];
    var url = window.location.href.split('?');
    if (url.length > 1) {
        var temp = url[1].split('&');
        for (var i in temp) {
            returnArr[temp[i].split('=')[0]] = temp[i].split('=')[1];
        }
        returnArr['count'] = i;
        if (returnArr.dict == undefined) {
            returnArr.dict = cache.loaded_dict;
        }
          if (returnArr.dict != undefined) {
            returnArr.dict = (returnArr.dict.search('SNSP')>-1?'MS':returnArr.dict);
          }
        return returnArr;
    }
    return "-1";
}

function assign_xml_() {
    switch (get_url_params().dict) {
        case "MS":
            in_xsl = "xsl/gorazd_MS.xsl";
            in_xml = "xml/vzorek_160008.xml";
            in_xsd = "xsd/gXML_MS.xsd";
            html_xsl1 = "xsl/dzarog-part1.xsl";
            html_xsl2 = "xsl/dzarog-part2.xsl";
            html_xsl3 = "xsl/dzarog-part3_MS.xsl";
            html_test = "xsl/test.xsl";
            prev_xsl = "xsl/gxmlpreview2.xsl";
            break;
        case "RSI":
            in_xsl = "xsl/gorazd_RSI.xsl";
            in_xml = "xml/vzorek_160008.xml";
            in_xsd = "xsd/gXML.xsd";
            html_xsl1 = "xsl/dzarog-part1.xsl";
            html_xsl2 = "xsl/dzarog-part2_RSI.xsl";
            html_xsl3 = "xsl/dzarog-part3_RSI.xsl";
            html_test = "xsl/test.xsl";
            prev_xsl = "xsl/gxmlpreview2.xsl";
            second_select = false;
            break;
        default:
            in_xsl = "xsl/gorazd.xsl";
            in_xml = "xml/vzorek_160008.xml";
            in_xsd = "xsd/gXML.xsd";
            html_xsl1 = "xsl/dzarog-part1.xsl";
            html_xsl2 = "xsl/dzarog-part2.xsl";
            html_xsl3 = "xsl/dzarog-part3.xsl";
            html_test = "xsl/test.xsl";
            prev_xsl = "xsl/gxmlpreview2.xsl";
            break;
    }
}
