//获取请求参数。
function __mt_Request(name) {
    var Value = null;
    var Url = location.href;
    var Str = Url.split('?');
    Str = Str[1];
    if (Str != null) {
        Str = Str.split('&');
        for (i = 0; i < Str.length; i++) {
            var str = Str[i];
            str = str.split('=');
            if (str[0] != null && str[0] != "") {

                if (str[0].toLowerCase() == name.toLowerCase()) {
                    if (str[1] != null) {
                        Value = str[1];
                    }
                    break;
                }
            }
        }
    }
    return Value;
}

//菜单定位。
function __mt_getTop(sender) {
    var t = sender.offsetTop
    while (sender = sender.offsetParent) t += sender.offsetTop;
    return t;
}

function __mt_getLeft(sender) {
    var l = sender.offsetLeft
    while (sender = sender.offsetParent) l += sender.offsetLeft;
    return l;
}

//去除字符串左右空字符。
function __mt_Trim(str) {
    return str.replace(/(^\s*)|(\s*$)/g, "");
}

//在对象的子对象集合0索引处添加子对象。
function __mt_prependChild(parent, newChild) {
    if (parent.firstChild) {
        parent.insertBefore(newChild, parent.firstChild);
    } else {
        parent.appendChild(newChild);
    }

    //if (parent.firstChild) {
    //    parent.insertBefore(newChild, parent.childNodes[parent.childNodes.length - 2]);
    //} else {
    //    parent.appendChild(newChild);
    //}
    return parent;
}

//鼠标效果。
function __mt_NavMouseover(sender, className) {
    _l_currentClass = sender.className;
    if (_l_currentClass == className) sender.className = className + ' ' + className + '_selected';//'navbutton navbutton_selected';
}

function __mt_NavMouseout(sender) {
    sender.className = _l_currentClass;
}

function back(sender) {
    if (__mt_js_geturl != "") {
        __mt_location(__mt_js_geturl);
    } else
        window.history.back();
}

function __mt_location(_url) {
    var a = document.getElementById("__mt_agoto");
    if (a == null) {
        window.open(_url, "_self");
    }
    else {
        a.href = _url;
        a.click();
    }
}

function __mt_open(_url, target) {

    window.open(_url, target);
}

function __mt_iframes(name, url)
{
    var _iframes = document.getElementsByTagName("iframe");
    _iframes[name].contentWindow.location = url;
}

function __stopDefault(e) {
    if (e && e.preventDefault)
        e.preventDefault();
    else
        window.event.returnValue = false;

    return false;
}

function __addEvent() {
    var as = document.getElementsByTagName("a");
    for (i = 0; i < as.length; i++) {
        if (as[i].id != "" && as[i].href != "" && as[i].href.indexOf("javascript:") == -1) {
            var link = document.getElementById(as[i].id);
            if (link != null) {
                link.onclick = function (e) {
                    parent.onClickLink(this, this.href);
                    __stopDefault(e);
                }

            }

        }
    }
}

function __mt_addTableLeftCss() {
    __mt_addTableLeftCss("tb");
}

function __mt_addTableLeftCss(name) {
    var _tb = document.getElementById(name);
    for (i = 0; i < _tb.rows.length; i++) {

        if (_tb.rows[i].cells[0].tagName == "TD")
            _tb.rows[i].cells[0].className = "table_left_width";
    }
}


//function __mt_addTableLeftCss(name,cellIndex) {
//    var _tb = document.getElementById(name);
//    for (i = 0; i < _tb.rows.length; i++) {

//        if (_tb.rows[i].cells[0].tagName == "TD")
//            _tb.rows[i].cells[0].className = "table_left_width";
//    }
//}


function __mt_CreateSubMenu(tb, divimg, index, rowspan_num, cellIndex) {
    try {
        for (i = 0; i < tb.rows.length; i++) {
            if (tb.rows[i].cells[0].tagName == "TD")
                if (cellIndex < tb.rows[i].cells.length) {
                    var cell = tb.rows[i].cells[cellIndex];
                    cell.setAttribute("colspan", 2);
                }
        }
    } catch (e) {
        alert(e.message);
    }

    for (i = index; i < (rowspan_num + index) ; i++) {
        if (cellIndex < tb.rows[i].cells.length) {
            tb.rows[i].cells[cellIndex].attributes["colspan"].value = 1;
        }
    }

    var _divImage = divimg;
    if (_divImage != null) {
        cell = document.createElement("td");
        text = __mt_CreateHtmlNode("div", _divImage.innerHTML);
        cell.appendChild(text);
        cell.setAttribute("rowspan", rowspan_num);
        tb.rows[index].appendChild(cell);

    }
}

function __mt_CreateHtmlNode(tag, text) {

    var n = document.createElement(tag);
    if (text) n.innerHTML = text;
    return n;
}