///声明常用的变量
var PageIndex = 1;
var PageSize = 10;
var orderfile = "CONVERT(int ,CoursewareType_SortCode)";
var ordertype = "asc";
var sqlwhere = "";
var parentid = ""; //父级id
var childid = "";

$(function () {
    var typeid = QueryString("typeid");
    var typechildId = QueryString("typechildId");
    var teacherid = QueryString("teacherid");
    if (typeid.length > 0 && typechildId) {
        GetChildren(typeid, teacherid);
        GetCss(typechildId);
    }
});


function GetChildren(id, teachid) {
    var parm = "typeid=" + id;
    getAjax("GetCS_Type.ashx", parm, function (rs) {
        if (rs != "0" && rs != "1") {
            GetHtml(rs, id, teachid);
        }
    });
}

function GetHtml(jsonstr, id, teachid) {
    var listmodel = eval('(' + jsonstr + ')');
    var html = "";
    if (listmodel.length > 0) {
        html += "<li class=\"current\"><a title=\"全部\" href='/Mall/Mall_List.aspx?typeid=" + id + "&&typechildId=&&teacherid=" + teachid + "'><strong>全部</strong></a></li>";
    }
    for (var i = 0; i < listmodel.length; i++) {
        html += "<li><a id=\"" + listmodel[i].CoursewareType_CtId + "\" title=\"" + listmodel[i].CoursewareType_CtName + "\" href=\"/Mall/Mall_List.aspx?typeid=" + id + "&&typechildId=" + listmodel[i].CoursewareType_CtId + "&&teacherid=" + teachid + "\">" + listmodel[i].CoursewareType_CtName + "</a></li>";
    }
    $("#childtype_ul").html(html);
    if (html.length > 0) {
        $("#childtype").css("display", "block");
    } else {
        window.location.href = "/Mall/Mall_List.aspx?typeid=" + id + "&&teacherid=" + teachid;
    }

}
//给二级菜单赋样式
function GetCss(typechildId) {
    $("#childtype_ul li:first").removeClass("current");
    $("#childtype_ul li:first").find("a").html($("#childtype_ul li:first").find("a").text());
    $("#childtype_ul").find("#" + typechildId).parent().addClass("current");
    $("#childtype_ul").find("#" + typechildId).html("<strong>" + $("#childtype_ul").find("#" + typechildId).text() + "</strong>");
}

function getAjax(url, parm, callBack) {
    $.ajax({
        type: 'post',
        dataType: "text",
        url: url,
        data: parm,
        cache: false,
        async: false,
        success: function (msg) {
            callBack(msg);
        }
    });
}