///------------------------------------------
///弹出层添加类型
///------------------------------------------

var strDivP060601 = "divP060601";
var strTableP060601 = "TKjkm";
var strOpratP060601;

/// <summary>弹出层</summary>
function showDialogP060601(strType,control) {

    control.combobox("hidePanel", control.attr("id"));

    strOpratP060601 = strType;
    creatDiv_ShowDialog(strDivP060601, "添加科目", false, true, strTableP060601);

    if (strOpratP060601 == "1") {
        addPopContentP060601();
    }
    control.combobox("setValue","");
}

/// <summary>添加内容</summary>
function addPopContentP060601() {

    var strForm = "";
    strForm = "<ul>";
    strForm += "<li><font color='red'>*</font>科目代码：<input type='text'  value=''  name='bh' id='bh' /></li>";
    strForm += "<li><font color='red'>*</font>科目名称：<input type='text'  value=''  name='kmmc' id='kmmc' maxlength='50' onkeypress='return checkValidate(event)' onpaste='return validatePaste()'/></li>";
    strForm += "</ul>";

    $("#" + strDivP060601 + "_divform").append(strForm);

    var obJBh = ParseData(window.external.DoOptions(strTableP060601, 'MakeBH', "{'ParentBH':'3003'}"));
    $("#bh", "#" + strDivP060601).val(obJBh.BH);
    $("#bh", "#" + strDivP060601).attr("disabled", true);
    $("#kmmc", "#" + strDivP060601).focus();
}

/// <summary>验证表单</summary>
function checkFormP060601(strDialog, strType) {

    var strBh = trim($("#bh", "#" + strDivP060601).val());
    var strMc = trim($("#kmmc", "#" + strDivP060601).val());
    if (!strMc) {
        window.parent.cihoAlert(msg.sz.kjkm.NoEmp, null, function () {
            $("#kmmc", "#" + strDivP060601).focus();
        });
        return false;
    }
    var objResult = ParseData(window.external.DoOptions(strTableP060601, 'DoOthers', "{'bh':'" + strBh + "','kmmc':'" + strMc + "'}"));
    if (objResult == true) {
        window.parent.cihoAlert(msg.sz.kjkm.nameQqual, null, function () {
            $("#kmmc", "#" + strDivP060601).focus();
        });
        return false;
    }
}

/// <summary>保存到数据库</summary>
function saveToDbP060601(strDialog, strType) {
    var strData = "{";
    strData += "\"bh\":\"" + trim($("#bh", "#" + strDivP060601).val()) + "\"";
    strData += ",\"a3\":\"" + trim($("#kmmc", "#" + strDivP060601).val()) + "\"";
    strData += ",\"parent\":\"3003\"";
    strData += ",\"level\":\"2\"";
    strData += "}";

    var objResult = ParseData(window.external.DoOptions(strTableP060601, 'Add', strData));
    if (objResult.ReturnCode != 0) {
        window.parent.cihoAlert(objResult.MSG);
        return false;
    }
    if (strType == "2") {
         $(":input", "#" + strDivP060601).val("");
        var strBh = ParseData(window.external.DoOptions(strTableP060601, 'MakeBH', '{"ParentBH":"3003"}')).BH;
        $("#bh", "#" + strDivP060601).val(strBh);
        strOpratP060601 = "1";
        $("#" + strDialog + "_divform").data("change", false);
        $("#kmmc", $("#" + strDialog + "_divform")).focus();
    } else {
        cihoDlgClose(strDialog);
    }
    var objFykm = ParseData(window.external.DoOptions(strTableP050601, "GetTreeList", "{}")).Records;
    objFykm.push({ dm: "-1", mc: "<font color='red'>添加科目</font>" });
    $("#fykmdm", "#" + strDivP050601).combobox("loadData", objFykm);
    $("#fykmdm", "#" + strDivP050601).combobox('setValue', objResult.kmdm);
}

/// <summary>保存</summary>
function saveMyDataTp060601(strDialog, strType) {
    if (checkFormP060601(strDialog, strType) == false) {
        return;
    }
    saveToDbP060601(strDialog, strType);
}