function MenuClick(classid) {
    $.get("/Menu.gdr?ClassID=" + classid + "&tmp=" + (new Date()).getTime(), { "resultType": "html" }, function(data, textStatus) {
        $("#sysMenu").html(data);
    }); 
}
function ChangeModel() {
    $("#SetModel").html("正在启动...");
    $.getJSON("/ChangeModel.gdr?tmp=" + (new Date()).getTime(), { "resultType": "json" }, function(data, textStatus) {
        if (data == 0) {
            $("#SetModel").html("验证模式");
            $("#navConfig").css("display", "none");
            var divList = $("div");
            for (var i = 0; i < divList.length; i++) {
                if (divList[i].className == "navMenu") {
                    MenuClick(divList[i].id); break;
                }
            }
        } else {
            $("#SetModel").html("配置模式");
            $("#navConfig").css("display", "block");
            $("#dplPlugClass").empty();
            $("#dplPlugClass").append("<option value='0'>选择分类</option>");
            for (var i = 0; i < data.length; i++) {
                $("#dplPlugClass").append("<option value='" + data[i].ClassID + "'>" + data[i].ClassName + "</option>");
            }
        }
    }); 
}

function gotoNavigateUrl() {
    var strNav =$("#txtNav").attr("value");
    var strClassID = $("#dplPlugClass").val();
    var strPlugName = $("#txtName").attr("value");
    if (strClassID == "0") { alert("请选择分类！");return;}
    if (strNav.length > 0) {
        $.getJSON("/OpenModel.gdr?PageName=" + strNav + "&PlugName=" + encodeURI(strPlugName) + "&ClassID=" + strClassID + "&tmp=" + (new Date()).getTime(), { "resultType": "json" }, function(data, textStatus) {
            if (data.length==0) {
                alert("发生错误，无法加载！");
            } else {
                AddNewFrameTab("/" + data.URL);
                GetParameter(data.PlugID);
            }
        }); 
    } else {alert("请输入页面名称！");}
}

function dyniframesize(down) {
    var pTar = null;
    if (document.getElementById) {
        pTar = document.getElementById(down);
    } else {
        eval('pTar = ' + down + ';');
    }
    var pHeight = document.documentElement.clientHeight - 100;
    if (pTar && !window.opera) {
        pTar.style.display = "block"
        if (pTar.contentDocument && pTar.contentDocument.body.offsetHeight) {
            pTar.height = pTar.contentDocument.body.offsetHeight -10;
        }
        else if (pTar.Document && pTar.Document.body.scrollHeight) {
            pTar.height = pTar.Document.body.scrollHeight-30;
        }
        if (pTar.height < pHeight) { pTar.height = pHeight-30; }
    }
}

function GetParameter(PlugID) {
    $.get("/GetParameter.gdr?PlugID=" + PlugID + "&tmp=" + (new Date()).getTime(), { "resultType": "html" }, function(data, textStatus) {
        if (data == "0") {
            $("#sysMenu").html("系统错误，未能获取插件信息！");
        } else {
            $("#sysMenu").html(data);
        }
    }); 
}
function SaveParameter(parID, txtParNoteID) {
    var txtParNote = $("#" + txtParNoteID).attr("value");

    $.get("/ChangeParNote.gdr?ParID=" + parID + "&Note=" + encodeURI(txtParNote) + "&tmp=" + (new Date()).getTime(), { "resultType": "html" }, function(data, textStatus) {
        if (data == "0") {
            alert("系统错误，未能获取参数信息！");
        } else {
            alert("修改成功！");
        }
    }); 
}
function DeleteParameter(parID, PlugID) {

    $.get("/DeletePar.gdr?ParID=" + parID + "&PlugID=" + PlugID + "&tmp=" + (new Date()).getTime(), { "resultType": "html" }, function(data, textStatus) {
        if (data == "0") {
            alert("系统错误，未能获取参数信息！");
        } else {
            GetParameter(PlugID);
        }
    }); 
}

function GetModel() {
    $.get("/GetModel.gdr?tmp=" + (new Date()).getTime(), { "resultType": "html" }, function(data, textStatus) {
        ChangeModel();
    });
}
function AdminIndexInit() {
    var strMenu = '';
    $.get("/SecurityModel.gdr?tmp=" + (new Date()).getTime(), { "resultType": "html" }, function(data, textStatus) {
        if (data != "0") {
            $('"<div class="titleMenu"><span onclick="ChangeModel();" style="cursor:hand;" id="SetModel">验证模式</span></div><div class="menuQkLine"></div>"').appendTo($("#TopMenu"));
        }
    });

    $.getJSON("/LoadPlugClass.gdr?tmp=" + (new Date()).getTime(), { "resultType": "json" }, function(data, textStatus) {
        if (data.length > 0) {
            for (var i = 0; i < data.length; i++) {
                strMenu += '<div id="' + data[i].ClassID + '" class="navMenu" >' + data[i].ClassName + '</div><div class="navMenuLine"></div>';
            }
            $('#PlugClass').append(strMenu);
            $('.navMenu', '#PlugClass').each(function() {
                $(this).bind('click', function() { MenuClick(this.id); });
            });
            MenuClick(data[0].ClassID);
        } else {
            alert("用户组权限错误！");
            window.location = "/Login.aspx";
        }
    });
}
function ClearCache() {
    $.get("/ClearCache.gdr?tmp=" + (new Date()).getTime(), { "resultType": "html" }, function(data, textStatus) {
        $.dialog({
            lock: true,
            title: '提示',
            icon: 'success.gif',
            content: '缓存清除完毕！',
            width: '320',
            height: '150',
            max: false,
            min: false
        });
    });
}
$(document).ready(function() { AdminIndexInit(); });