var isIE = (navigator.userAgent.indexOf("MSIE") != -1) ? true : false;
var isIE2 = (/msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent));
var isHideFlash = (navigator.userAgent.indexOf("Win") != -1 || navigator.userAgent.indexOf("Mac") != -1) ? false : true;
var hint = new Array();
var mn_clevel = null;
var mn_mnodes = new Array();
var mn_menucookie = "";
var mn_smnodes = {};
var mn_menupane_y = 0;
var mn_menu_lastid = {all: null, favorite: null, popular: null};
var mn_menu_previd = {all: null, favorite: null, popular: null};
var mn_hint_obj = null;
var mn_hint_timer = null;
var mn_ka_timer = null;
var mn_isready = false;
var mn_isform = false;
var mn_currlist = "";
var mn_successlist = "";
var mn_cmbimg = "";
var mn_form_move = null;
var mn_form_size = null;
var mn_text_id = "";
mn_help_type = 0;
mn_help_form_type = 0;

function mn_load_loc(begin_loc, loc, type) {
    if (begin_loc == "binary") {
        loc = top.binary + loc;
    } else {
        loc = begin_loc + loc;
    }
    if (type == "form") {
        top.formframe.location = loc;
    } else if (type == "list") {
        top.workarea.location = loc;
    } else if (type == "tmp") {
        top.tmp.location = loc;
    }
}

function mn_cancel_form(refresh) {
    mn_form_hide();
    if (refresh || formframe.fr_cancelrefresh) workarea.location = (mn_successlist) ? mn_successlist : mn_currlist;
}

function mn_do_action(action, startpage) {
    if (action == "ready") {
        mn_isready = true;
        return;
    } else if (action == "top") {
        top.location = (startpage != '') ? String(top.location).replace(/\?.*/, "") + "?startpage=" + startpage : String(top.location).replace(/\?.*/, "");
        return;
    } else if (action == "restart" || action == "reboot" || action == "mgrrestart") {
        mn_get_obj("formlayer").style.visibility = "hidden";
        mn_fetch_action(action);
        return;
    }
    if (mn_isform) {
        mn_cancel_form(1);
    } else {
        workarea.location = (mn_successlist) ? mn_successlist : mn_currlist;
        ;
    }
}

function mn_error_show(obj, val, code, msg, content) {
    var errorstr = [];
    errorstr.push(content);
    alert(errorstr.join(' '));
    workarea.location = (mn_successlist) ? mn_successlist : mn_currlist;
}

function mn_switch_menu(type) {
    var menus = ["all", "favorite", "popular"];
    var flag = false;
    for (var i = 0; i < menus.length; i++) if (type == menus[i]) flag = true;
    if (!flag) type = "all";
    var bname = String(binary).replace(/(.*\/)/g, "");
    var cookienew = "";
    var cookieold = String(document.cookie);
    if (cookieold.match(/mbar=([^;]+);?/)) {
        cookienew = RegExp.$1;
        var re = new RegExp(bname + "-" + mn_clevel + "-\\w+:?", "g");
        cookienew = cookienew.replace(re, "");
        cookienew = cookienew.replace(/:$/g, "");
    }
    if (cookienew != "") cookienew += ":";
    cookienew += bname + "-" + mn_clevel + "-" + type;
    document.cookie = "mbar=" + cookienew + "; expires=Fri Jul 26 13:00:00 2020;";
    for (var i = 0; i < menus.length; i++) {
        if (menus[i] == type) {
            document.getElementById("menu-" + menus[i]).style.display = "block";
            mn_add_class(document.getElementById("mbarimgtd-" + menus[i]), "mbaron");
        } else {
            document.getElementById("menu-" + menus[i]).style.display = "none";
            mn_remove_class(document.getElementById("mbarimgtd-" + menus[i]), "mbaron");
        }
    }
}

function mn_expandall_menu(dvalue) {
    for (var i = 0; i < mn_mnodes.length; i++) mn_expand_menu(mn_mnodes[i], dvalue);
}

function mn_expand_menu(id, dvalue) {
    if (id == null) return;
    var elem = mn_get_obj(id + "-all");
    if (elem == null) return;
    var displayvalue = (dvalue) ? dvalue : (elem.style.display != "none") ? "none" : "block";
    elem.style.display = displayvalue;
    var felem = mn_get_obj(id + "-favorite");
    if (felem) felem.style.display = displayvalue;
    var pelem = mn_get_obj(id + "-popular");
    if (pelem) pelem.style.display = displayvalue;
    var str = "";
    for (var i = 0; i < mn_mnodes.length; i++) {
        var re = new RegExp(mn_clevel + "_" + mn_mnodes[i] + "-[01]:?", "g");
        mn_menucookie = mn_menucookie.replace(re, "");
        var telem = mn_get_obj(mn_mnodes[i] + "-all");
        if (telem == null) {
            continue;
        }
        str += mn_clevel + "_" + mn_mnodes[i] + "-";
        str += (telem.style.display == "none") ? "0" : "1";
        if (i != mn_mnodes.length - 1) {
            str += ":";
        }
    }
    if (mn_menucookie.length > 0 && mn_menucookie.substr(-1) != ":") mn_menucookie += ":";
    mn_menucookie += str;
    document.cookie = "menupane=" + mn_menucookie + "; expires=Fri Jul 26 13:00:00 2020;";
}

function mn_export_excel() {
    var eurl = String(workarea.location);
    if (eurl.match(/(\?.*)/)) {
        var mgrname = top.binary;
        location = "/mancgi/xml2csv" + RegExp.$1 + "&mgrname=" + mgrname.replace(/(.*\/)/g, "");
    }
}

function mn_fetch_action(action) {
    mn_isready = false;
    if (action == "reboot") mn_form_hide();
    var wlmsg = mn_get_obj("waitlayer-msg");
    if (wlmsg != null) wlmsg.innerHTML = "<span>" + eval("msg_" + action) + "</span>";
    var wl = mn_get_obj("waitlayer");
    if (wl != null) wl.style.visibility = "visible";
    top.fka.location = binary + "?func=" + action;
    setTimeout("mn_wakeup()", 5000);
}

function mn_form_hide() {
    mn_hintout();
    var elem = document.getElementById("formlayer");
    if (elem == null) return;
    if (isHideFlash) {
        var diagram = workarea.tb_get_obj("diagramdiv");
        if (diagram) {
            diagram.style.display = "block";
            workarea.tb_resize();
        }
    }
    mn_form_normalize();
    elem.style.visibility = "hidden";
    if (formframe.document.body) formframe.document.body.innerHTML = "";
    document.getElementById("ftitle").innerHTML = "";
    mn_isform = false;
    mn_set_active_select(mn_menu_lastid["all"], 0);
    mn_set_active_select(mn_menu_previd["all"], 1);
    mn_menu_lastid["all"] = mn_menu_previd["all"];
    mn_set_active_select(mn_menu_lastid["favorite"], 0);
    mn_set_active_select(mn_menu_previd["favorite"], 1);
    mn_menu_lastid["favorite"] = mn_menu_previd["favorite"];
    mn_set_active_select(mn_menu_lastid["popular"], 0);
    mn_set_active_select(mn_menu_previd["popular"], 1);
    mn_menu_lastid["popular"] = mn_menu_previd["popular"];
}

function mn_form_maxmin() {
    mn_hintout();
    if (formframe.fr_maxwidth) {
        mn_get_obj("formframe").width = 440;
        mn_form_normalize(true);
        mn_form_maxmin_icon("max");
    } else {
        var ww = (window.innerWidth) ? window.innerWidth : document.body.clientWidth;
        mn_get_obj("formframe").width = ww * 0.8;
        mn_form_normalize(true);
        mn_form_maxmin_icon("min");
    }
    formframe.fr_inputfile();
}

function mn_form_maxmin_icon(icon) {
    var maxmin = document.getElementById("maxmin");
    if (!maxmin) return;
    if (icon == "max") {
        maxmin.src = localdir + "fi-max.png";
        formframe.fr_maxwidth = false;
    } else {
        maxmin.src = localdir + "fi-min.png";
        formframe.fr_maxwidth = true;
    }
}

function mn_form_normalize(withoutsize) {
    var felem = document.getElementById("formelem");
    if (!felem) return;
    var frameelem = document.getElementById("formframe");
    if (!frameelem) return;
    if (!withoutsize) frameelem.width = 440;
    if (isIE) {
        if (felem.style.position == "relative") {
            var wh = (window.innerHeight) ? window.innerHeight : document.body.clientHeight;
            var ww = (window.innerWidth) ? window.innerWidth : document.body.clientWidth;
            formelem.style.left = ((ww - formelem.offsetWidth) / 2) + "px";
            formelem.style.top = ((wh - formelem.offsetHeight) / 2) + "px";
        }
    } else {
        felem.style.position = "static";
        felem.parentNode.align = "center";
        felem.parentNode.vAlign = "middle";
        felem.parentNode.style.verticalAlign = "middle";
    }
}

function mn_form_reset() {
    function getElements(parent, tagName) {
        var elements = parent.getElementsByTagName(tagName);
        return Array.prototype.splice.call(elements, 0, elements.length);
    }

    var f = window.formframe.document.getElementsByTagName('form')[0];
    var inputs = getElements(f, 'input');
    var textareas = getElements(f, 'textarea');
    var selects = getElements(f, 'select');
    var elems = inputs.concat(textareas);
    f.reset();
    if ('cleartoempty' in f.attributes) {
        for (var i = 0, len = elems.length; i < len; i++) try {
            var elem = elems[i];
            if ('readonly' in elem.attributes) continue;
            switch (elem.type) {
                case 'button':
                case 'submit':
                case 'reset':
                case 'hidden':
                    continue;
                case 'radio':
                case 'checkbox':
                    elem.checked = false;
                    elem.onchange();
                    break;
                default:
                    elem.value = '';
                    break;
            }
        } catch (e) {
        }
        for (var i = 0, len = selects.length; i < len; i++) try {
            var select = selects[i];
            if ('readonly' in select.attributes) continue;
            select.selectedIndex = 0;
            select.onchange();
        } catch (e) {
        }
    } else {
        elems = elems.concat(selects);
        for (var i = 0, len = elems.length; i < len; i += 1) try {
            var elem = elems[i];
            if ('readonly' in elem.attributes) continue;
            elem.onchange();
        } catch (e) {
        }
    }
}

function mn_form_show(src, frommenu) {
    mn_currlist = workarea.location;
    mn_hintout();
    mn_get_obj("waitlayer-msg").innerHTML = "";
    mn_get_obj("waitlayer").style.visibility = "visible";
    if (isHideFlash) {
        var diagram = workarea.tb_get_obj("diagramdiv");
        if (diagram) {
            diagram.style.display = "none";
            workarea.tb_resize();
        }
    }
    document.getElementById("formframe").src = src + "&operafake=" + Math.round(Math.random() * 1000) + ((frommenu) ? "&clickstat=yes" : "");
    mn_isform = true;
}

function mn_get_frame_class(obj) {
    while (obj.nodeName.toLowerCase() != "body") obj = obj.parentNode;
    return obj.className;
}

function mn_get_menu_state() {
    var cookiestr = document.cookie;
    var posA = cookiestr.indexOf("menupane=");
    if (posA != -1) {
        var posB = cookiestr.indexOf(";", posA);
        posA += 9;
        mn_menucookie = (posB != -1) ? cookiestr.substring(posA, posB) : cookiestr.substr(posA);
        var cook = mn_menucookie.split(":");
        for (var i = 0; i < cook.length; i++) {
            var el = cook[i].split("-");
            var ell = el[0].split("_");
            if (ell[0] == mn_clevel) mn_smnodes[ell[1]] = el[1];
        }
    }
}

function mn_get_obj(id) {
    if (document.getElementById) return document.getElementById(id); else if (document.all) return document.all[id]; else return null;
}

function mn_get_obj_pos(obj) {
    x = 0;
    y = 0;
    while (obj.offsetParent) {
        x += obj.offsetLeft;
        y += obj.offsetTop;
        obj = obj.offsetParent;
    }
    return [x, y];
}

function mn_hnt(e, txt) {
    if (!e) var e = window.event;
    var obj = (e.target) ? e.target : e.srcElement;
    if (!obj) return;
    var msg = txt;
    if (!msg) {
        while (obj.parentNode) {
            if (obj.getAttribute("hint")) break;
            obj = obj.parentNode;
        }
        try {
            msg = obj.getAttribute("hint");
        } catch (ce) {
            return;
        }
        if (msg.substr(0, 3) == "js:") {
            try {
                msg = eval(msg.substr(3));
            } catch (ce) {
                return;
            }
        }
    }
    if (!msg || msg == "") return;
    var x = e.clientX;
    var y = e.clientY;
    var owin = (obj.ownerDocument.defaultView) ? obj.ownerDocument.defaultView : (obj.ownerDocument.parentWindow) ? obj.ownerDocument.parentWindow : window;
    if (owin != window) {
        var pos = mn_get_obj_pos(mn_get_obj(owin.name));
        x += pos[0];
        y += pos[1];
        x -= (owin.scrollX != null) ? owin.scrollX : owin.document.body.scrollLeft;
        y -= (owin.scrollY != null) ? owin.scrollY : owin.document.body.scrollTop;
    }
    mn_hint_obj = {obj: obj, msg: msg, x: x, y: y};
    mn_hint_timer = setTimeout('mn_hnt_show()', 500);
}

function mn_hnt_show() {
    var hlayer = mn_get_obj("hintpane");
    var hlayerframe = mn_get_obj("hintframe");
    var ww = (window.innerWidth) ? top.window.innerWidth : top.document.body.clientWidth;
    if (hlayer && mn_hint_obj) {
        if (hlayer.style.visibility == 'visible') mn_hintout();
        var xpos = (mn_hint_obj.x + hlayer.offsetWidth > ww) ? mn_hint_obj.x - hlayer.offsetWidth + 10 : mn_hint_obj.x;
        var ypos = mn_hint_obj.y + 22;
        hlayer.innerHTML = mn_hint_obj.msg;
        hlayer.style.left = xpos;
        hlayer.style.top = ypos;
        hlayer.style.visibility = 'visible';
        hlayerframe.style.left = xpos;
        hlayerframe.style.top = ypos;
        hlayerframe.style.width = hlayer.offsetWidth;
        hlayerframe.style.height = hlayer.offsetHeight;
        hlayerframe.style.display = 'block';
        mn_hint_obj = null;
        clearTimeout(mn_hint_timer);
    }
}

function mn_hint(hid, e) {
    if (!e) var e = window.event;
    if (hid == "") return;
    if (e == null) return;
    var x = e.clientX;
    var y = e.clientY;
    var obj = (e.target) ? e.target : e.srcElement;
    if (obj == null) return;
    var fcl = mn_get_frame_class(obj);
    if (fcl == "form-body") {
        opos = mn_get_obj_pos(mn_get_obj('formframe'));
        x += opos[0];
        y += opos[1];
        y -= (formframe.scrollY != null) ? formframe.scrollY : formframe.document.body.scrollTop;
        try {
            hid = eval("formframe." + hid);
        } catch (ce) {
            return;
        }
    } else if (fcl == "content-body") {
        opos = mn_get_obj_pos(mn_get_obj('workarea'));
        x += opos[0];
        y += opos[1];
        y -= (workarea.scrollY != null) ? workarea.scrollY : workarea.document.body.scrollTop;
        try {
            hid = eval("workarea." + hid);
        } catch (ce) {
            return;
        }
    } else {
        try {
            hid = eval(hid);
        } catch (ce) {
            return;
        }
    }
    if (!hid) return;
    mn_hint_timer = setTimeout('mn_hint_show("' + hid + '","' + fcl + '",' + x + ',' + y + ')', 500);
}

function mn_xhint(hid, e) {
    if (!e) var e = window.event;
    if (hid == "") return;
    if (e == null) return;
    var x = e.clientX;
    var y = e.clientY;
    var obj = (e.target) ? e.target : e.srcElement;
    if (obj == null) return;
    var fcl = mn_get_frame_class(obj);
    mn_hint_timer = setTimeout('mn_hint_show("' + hid + '","' + fcl + '",' + x + ',' + y + ')', 500);
}

function mn_hintout() {
    hlayer = mn_get_obj("hintpane");
    hlayerframe = mn_get_obj("hintframe");
    if (hlayer != null) {
        hlayerframe.style.display = 'none';
        hlayer.style.visibility = 'hidden';
        hlayer.style.top = 0;
        hlayer.style.left = 0;
    }
    mn_hint_obj = null;
    clearTimeout(mn_hint_timer);
}

function mn_hint_show(hid, fcl, x, y) {
    hlayer = mn_get_obj("hintpane");
    hlayerframe = mn_get_obj("hintframe");
    ww = (window.innerWidth) ? top.window.innerWidth : top.document.body.clientWidth;
    if (hlayer) {
        if (hlayer.style.visibility == 'visible') mn_hintout();
        var xpos = (x + hlayer.offsetWidth > ww) ? x - hlayer.offsetWidth + 10 : x;
        var ypos = y + 22;
        hlayer.innerHTML = hid;
        hlayer.style.left = xpos;
        hlayer.style.top = ypos;
        hlayer.style.visibility = 'visible';
        hlayerframe.style.left = xpos;
        hlayerframe.style.top = ypos;
        hlayerframe.style.width = hlayer.offsetWidth;
        hlayerframe.style.height = hlayer.offsetHeight;
        hlayerframe.style.display = 'block';
        clearTimeout(mn_hint_timer);
    }
}

function mn_init() {
    mn_ka_timer = setTimeout(mn_keepalive, 3000000);
    mn_menupane_y = mn_get_obj_pos(mn_get_obj("menupane"))[1];
    if (String(workarea.location).match(/javascript/)) {
        workarea.location = document.getElementById("workarea").src;
    }
    mn_resize_window();
    if (startform != "") mn_form_show(binary + "?func=" + startform);
    if (typeof touchScroll == 'function') {
        touchScroll('menupane');
    }
}

function mn_keepalive() {
    fka.location = binary + "?func=keepalive";
    clearTimeout(mn_ka_timer);
    mn_ka_timer = setTimeout(mn_keepalive, 3000000);
}

function mn_load_list(lnk, frommenu) {
    workarea.location = top.binary + '?func=' + lnk + ((frommenu) ? "&clickstat=yes" : "");
}

function mn_resize_window() {
    var wh = (window.innerHeight) ? window.innerHeight : document.body.clientHeight;
    var ww = (window.innerWidth) ? window.innerWidth : document.body.clientWidth;
    if (navigator.userAgent.match(/opera/i)) mn_get_obj("workarea").style.height = "99%";
    mn_get_obj("rTbl").style.height = wh + "px";
    mn_get_obj("lTbl").style.height = wh + "px";
    mn_get_obj("workarea").style.height = "100%";
    mn_get_obj("menupane").style.height = wh - mn_menupane_y + "px";
    if (workarea.tb_resize) {
        var interval = setTimeout("workarea.tb_resize()", 1);
    }
    if (mn_isform && formframe.fr_maxwidth) {
        mn_get_obj("formframe").width = ww * 0.8;
    }
}

function mn_set_active(qs) {
    var func = null;
    if (qs.match(/func=([\w\.]+)/)) func = RegExp.$1; else return;
    var re = new RegExp("[^\\w\\.]" + func + "[^\\w\\.]");
    var menus = ["all", "favorite", "popular"];
    for (var i = 0; i < menus.length; i++) {
        var menudiv = document.getElementById("menu-" + menus[i]);
        if (!menudiv) continue;
        var links = menudiv.getElementsByTagName("a");
        var flag = false;
        if (func == "dashboard") {
            mn_set_active_select(mn_menu_lastid[menus[i]], 0);
        } else {
            for (var j = 0; j < links.length; j++) {
                if (String(links[j].getAttribute("onclick")).match(re)) {
                    mn_menu_previd[menus[i]] = mn_menu_lastid[menus[i]];
                    mn_menu_lastid[menus[i]] = links[j].id;
                    mn_set_active_select(mn_menu_previd[menus[i]], 0);
                    mn_set_active_select(links[j].id, 1);
                    flag = true;
                    break;
                }
            }
            if (!flag) mn_menu_previd[menus[i]] = mn_menu_lastid[menus[i]];
        }
    }
}

function mn_set_active_select(id, sel) {
    if (!id) return;
    var link = document.getElementById(id);
    if (!link) return;
    linktd = link;
    while (linktd.parentNode && linktd.tagName.toLowerCase() != "td") {
        linktd = linktd.parentNode;
    }
    if (!linktd) return;
    linktd.className = (sel == 0) ? "m1" : "m1-active";
}

function mn_show_help(type, func) {
    var suffix = '';
    if (helplevel) {
        suffix = '&level=' + hlevel;
    }
    ;
    if (type == 2) {
        window.open(binary + "?func=help&topic=" + func);
        return;
    }
    if (mn_isform) {
        if (mn_help_form_external) {
            window.open(mn_help_form_external);
            return;
        }
        if (mn_help_form_type != 0) {
            window.open(mn_help_form_value);
            return;
        }
    } else {
        if (mn_help_type != 0) {
            window.open(mn_help_value);
            return;
        }
    }
    var hfunc = "";
    var curloc = (type == 0) ? String(workarea.location) : (type == 1) ? String(formframe.location) : "";
    if (curloc.match(/func=([\w\.]+)/)) {
        hfunc = RegExp.$1;
    } else {
        return;
    }
    window.open(binary + "?func=help&topic=" + hfunc + suffix);
}

function mn_md_fsize(e) {
    if (!e) var e = window.event;
    var felem = mn_get_obj("formelem");
    if (!felem) return;
    var frameelem = mn_get_obj("formframe");
    if (!frameelem) return;
    var pos = mn_get_obj_pos(felem);
    if (felem.style.position != "relative") {
        felem.parentNode.align = "left";
        felem.parentNode.vAlign = "top";
        felem.parentNode.style.verticalAlign = "top";
        felem.style.position = "relative";
        felem.style.left = pos[0];
        felem.style.top = pos[1];
    }
    document.body.style.cursor = "e-resize";
    mn_form_size = {
        frobj: frameelem,
        fobj: felem,
        x: e.clientX,
        y: e.clientY,
        w: parseInt(frameelem.width),
        h: parseInt(frameelem.height)
    };
    document.onmouseup = mn_mu_doc;
    if (document.captureEvents) document.captureEvents(Event.MOUSEUP);
    document.onmousemove = mn_mm_doc;
    if (document.captureEvents) document.captureEvents(Event.MOUSEMOVE);
    formframe.fr_reg_mm("e-resize");
    mn_stop_event(e);
}

function mn_md_ftitle(e) {
    if (!e) var e = window.event;
    var felem = mn_get_obj("formelem");
    if (!felem) return;
    var pos = mn_get_obj_pos(felem);
    if (felem.style.position != "relative") {
        felem.parentNode.align = "left";
        felem.parentNode.vAlign = "top";
        felem.parentNode.style.verticalAlign = "top";
        felem.style.position = "relative";
        felem.style.left = pos[0];
        felem.style.top = pos[1];
    }
    document.body.style.cursor = "move";
    mn_form_move = {
        obj: felem,
        x: (e.clientX - pos[0]),
        y: (e.clientY - pos[1]),
        w: felem.offsetWidth,
        h: felem.offsetHeight
    };
    document.onmouseup = mn_mu_doc;
    if (document.captureEvents) document.captureEvents(Event.MOUSEUP);
    document.onmousemove = mn_mm_doc;
    if (document.captureEvents) document.captureEvents(Event.MOUSEMOVE);
    try {
        formframe.fr_reg_mm("move");
    } catch (e) {
    }
    mn_stop_event(e);
}

function mn_mu_doc() {
    function fr_unreg_mm() {
        try {
            formframe.fr_unreg_mm();
        } catch (e) {
        }
    }

    if (mn_form_move) {
        document.body.style.cursor = "default";
        mn_form_move = null;
        document.onmouseup = null;
        document.onmousemove = null;
        fr_unreg_mm();
    }
    if (mn_form_size) {
        document.body.style.cursor = "default";
        mn_form_size = null;
        document.onmouseup = null;
        document.onmousemove = null;
        mn_form_maxmin_icon("max");
        fr_unreg_mm();
    }
}

function mn_mm_doc(e) {
    if (!e) var e = window.event;
    if (mn_form_move) {
        var cx = e.clientX;
        var cy = e.clientY;
        if (e.isFormFrame) {
            var pos = mn_get_obj_pos(mn_get_obj("formframe"));
            cx += pos[0];
            cy += pos[1];
        }
        var x = cx - mn_form_move.x;
        var y = cy - mn_form_move.y;
        var ww = (window.innerWidth) ? window.innerWidth : document.body.clientWidth;
        var wh = (window.innerHeight) ? window.innerHeight : document.body.clientHeight;
        if (x < 10) x = 10;
        if (y < 10) y = 10;
        if (ww - x - mn_form_move.w < 10) x = ww - mn_form_move.w - 10;
        if (wh - y - mn_form_move.h < 10) y = wh - mn_form_move.h - 10;
        mn_form_move.obj.style.left = x;
        mn_form_move.obj.style.top = y;
    }
    if (mn_form_size) {
        var ww = (window.innerWidth) ? window.innerWidth : document.body.clientWidth;
        var cx = e.clientX;
        if (e.isFormFrame) {
            var pos = mn_get_obj_pos(mn_get_obj("formframe"));
            cx += pos[0];
        }
        if (ww - cx < 20) cx = ww - 20;
        var w = cx - mn_form_size.x + mn_form_size.w;
        if (w < 440) w = 440;
        mn_form_size.frobj.width = w;
        formframe.fr_inputfile();
    }
}

function mn_wakeup() {
    if (mn_isready) {
        var wl = mn_get_obj("waitlayer");
        if (wl) wl.style.visibility = "hidden";
        mn_do_action();
    } else {
        top.fka.location = binary + "?func=isready";
        setTimeout("mn_wakeup()", 2000);
    }
}

function mn_stop_event(e) {
    e || (e = window.event);
    if (isIE2) {
        e.cancelBubble = true;
        e.returnValue = false;
    } else {
        e.preventDefault();
        e.stopPropagation();
    }
    return false;
}

function mn_remove_class(el, name) {
    if (!(el && el.className)) return;
    var cls = el.className.split(" ");
    var ar = new Array();
    for (var i = cls.length; i > 0;) if (cls[--i] != name) ar[ar.length] = cls[i];
    el.className = ar.join(" ");
}

function mn_add_class(el, name) {
    mn_remove_class(el, name);
    el.className += " " + name;
}

function mn_reg_dbmm() {
    document.onmousemove = mn_db_mm;
    if (document.captureEvents) document.captureEvents(Event.MOUSEMOVE);
}

function mn_unreg_dbmm() {
    document.onmousemove = null;
}

function mn_db_mm() {
    workarea.db_block_mu();
}

function mn_dbborder(w) {
    var menubar = document.getElementById("menubar");
    if (menubar) menubar.style.borderRightWidth = w;
    var menudashboard = document.getElementById("menudashboard");
    if (menudashboard) menudashboard.style.borderRightWidth = w;
}

function mn_add_option_element(sel, text, value) {
    alert("add");
    var option = document.createElement("option");
    var optionText = document.createTextNode(text);
    option.appendChild(optionText);
    option.setAttribute("value", value);
    sel.appendChild(option);
}

function mn_remove_opt(sel, col) {
    sel.options.length = col;
}

function mn_select_len(sel, col) {
    sel.options.length = col;
}

function mn_remove_sel(sel, col) {
    sel.options.length = col;
}

function mn_change_select(sel, mas, sel2, n, idx, pid, m, beginfor) {
    sel.options.length = mas.length;
    for (var i = beginfor; i < mas.length; i++) {
        if (mas[i][3] == sel2.options[sel2.selectedIndex].value) {
            sel.options[n].value = mas[i][1];
            sel.options[n].text = mas[i][0];
            if (mas[i][m] == pid) {
                idx = n;
            }
            n++;
        }
    }
    sel.options.length = n;
    sel.selectedIndex = idx;
    return n;
}

function mn_change_select2(sel, mas, cu, n, idx, pid, m) {
    sel.options.length = mas.length;
    for (var j = 0; j < mas.length; j++) {
        if (!mas[j][3] || mas[j][3] == cu) {
            sel.options[n].value = mas[j][1];
            sel.options[n].text = mas[j][0];
            if (mas[j][m] == pid) idx = n;
            n++;
        }
    }
    sel.options.length = n;
    sel.selectedIndex = idx;
    return n;
}

function mn_change_select3(sel, mas, sel2, n, m) {
    sel.options.length = mas.length;
    for (var i = 1; i < mas.length; i++) {
        if (mas[i][m] == sel2.options[sel2.selectedIndex].value) {
            sel.options[n].value = mas[i][1];
            sel.options[n].text = mas[i][0];
            n++;
        }
    }
    sel.options.length = n;
    return n;
}