#use(ui_lang.js)

function test_deliver_enter() {
    var rp = RecordPosition(Position_ELEMENT_POS, ui_trans('msgSelectPosition') );


    var script = 
        "function fire_submit(e, w) {" + 
        "    try {\n" +
        "        e.value = 'SU01'; \n" + 
        "        var clicked = false; \n" + 
        "        for (var i = 0; i < e.form.length; i++) { \n" + 
        "            if(e.form[i].type == 'submit') { \n" + 
        "                clicked = true; \n" + 
        "                e.form[i].click(); \n" + 
        "                break; \n" + 
        "            }\n" + 
        "        } \n" + 
        "        if(!clicked) { \n" + 
        "            e.form.submit(); \n" + 
        "        }\n" + 
        "    } catch (e) {\n" +
        "       alert(e.message)\n" +
        "    }\n" +
        "}";

    var res = rp.ExecScript(script, true);

}

function activation_test() {
    var rp = RecordPosition(Position_ELEMENT_POS, ui_trans('msgSelectPosition') );

    var on_mousedown = rp.ExecScript("onmousedown");
    if (on_mousedown != "null") {
        rp.ExecScript("fireEvent('onmousedown')");
        page_changed = true;
    }

    var on_click = rp.ExecScript("onclick");
    if (on_click != "null") {
        rp.ExecScript("fireEvent('onclick')");
        page_changed = true;
    } else {
        rp.ExecScript("$click()");
    }
}

function update_window_id(mac, old_window_id, new_window_id) {
    for (var i = 0; i < mac.NumParams(); i++) {
        var par = mac.GetParam(i);

        if (typeof(par.WindowID) != undefined) {
            if (par.WindowID == old_window_id) {
                par.WindowID = new_window_id;
                mac.SetParam(i, par);

            }
        }
    }
}


function change_window_id_test() {
    for (i = 0; i < NumTourstops(); i++) {
        var ts_changed = false;
        var ts = GetTourstop(i);

        var mac = ts.NextMacro();

        while (mac != null) {
            var temp_name = mac.Template();

            if (temp_name == "new_window") {
                var ps = mac.GetParam("dump_win_relpos");
                log(typeof(ps));

                var id = ps.WindowID;

                log("ID: " + id);
                if (id == 1 && mac.GetParam("new_step") != "Value Help Selection") {
                    ps.WindowID = 0;
                    mac.SetParam("dump_win_relpos", ps);
                    ts_changed = true;
                }
            } if (ts_changed) {
                update_window_id(mac, 1, 0);
            }

            mac = ts.NextMacro(mac.TourPosition());
        }
    }
}


function test() {
    var mac = NextMacro();

    var new_mac = CreateMacro("explanation_long");

    while (mac) {
        ReplaceEvent(mac.TourPosition(), new_mac);
        log(mac.TourPosition());
        mac = NextMacro(mac.TourPosition());
    }

    var new_mac = CreateMacro("goto_tourstop");

    var mac = NextMacro();
    while (mac) {
        ReplaceEvent(mac.TourPosition(), new_mac);
        log(mac.TourPosition());
        mac = NextMacro(mac.TourPosition());
    }

    var new_mac = CreateMacro("explanation");

    var mac = NextMacro();
    while (mac) {
        ReplaceEvent(mac.TourPosition(), new_mac);
        log(mac.TourPosition());
        mac = NextMacro(mac.TourPosition());
    }
}
