//获取请求参数。
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)
{
    try
    {
        var _iframes = document.getElementsByTagName("iframe");
        _iframes[name].contentWindow.location = url;
    }catch(e)
    {
        alert(e.message);
    }
}

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;
}


function __mt__GetCookieVal(offset)
    //获得Cookie解码后的值
{
    var endstr = document.cookie.indexOf(";", offset);
    if (endstr == -1)
        endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
}


function __mt__SetCookie(name, value)
    //设定Cookie值
{
    __mt__DelCookie(name);

    var argv = __mt__SetCookie.arguments;
    var argc = __mt__SetCookie.arguments.length;
    var expires = (argc > 2) ? argv[2] : null; //expires，在这里表示过期时间。
    var path = (argc > 3) ? argv[3] : null;
    var domain = (argc > 4) ? argv[4] : null;
    var secure = (argc > 5) ? argv[5] : false;
    document.cookie = name + "=" + escape(value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString()))
+ ((path == null) ? "" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain))
+ ((secure == true) ? "; secure" : "");
}


function __mt__DelCookie(name)
    //删除Cookie
{
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = __mt__GetCookie(name);
    document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}


function __mt__GetCookie(name)
    //获得Cookie的原始值
{
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg)
            return __mt__GetCookieVal(j);
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break;
    }
    return null;
}




function __mt__setSearchCookie(value) {
    var expdate = new Date();
    expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000 * 365));
    __mt__SetCookie("__mt__Search", value, expdate, "/", null, false);
}

function __mt__getSearchCookie() {
    var cookie = __mt__GetCookie("__mt__Search");
    if (cookie == null)
        return 0;
    else
        return parseInt(cookie);
}


function __mt__setClassCookie(value) {
    var expdate = new Date();
    expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000 * 365));
    __mt__SetCookie("__mt__Class", value, expdate, "/", null, false);
}

function __mt__getClassCookie() {
    var cookie = __mt__GetCookie("__mt__Class");
    if (cookie == null)
        return 0;
    else
        return parseInt(cookie);
}


function __mt__setModeCookie(value) {
    var expdate = new Date();
    expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000 * 365));
    __mt__SetCookie("__mt__MobileorPC", value, expdate, "/", null, false);
}

function __mt__getModeCookie() {
    var cookie = __mt__GetCookie("__mt__MobileorPC");
    if (cookie == null)
        return 1;
    else
        return parseInt(cookie);
}