
/*加载数据在内容里*/
function CreateTree() {
    var data = null;
    if (_source != null && _source != undefined) {
        var obj = null;
        switch (_source.format) {
            case "text": 
                {
                    obj = document.getElementById('dataText');
                } break;
            case "dateTime":
                {
                    obj = document.getElementById('dataTime');
                    if (_source.isEndTime) {
                        var isEndTime = document.getElementById("isEndTime");
                        isEndTime.checked = true;
                        isEndTime = null;
                    }
                } break;
            case "decimal": 
                {
                    obj = document.getElementById('dataNumeric');
                } break;
        }
        if (obj != null) {
            obj.value = _source.type;
            showEditModule(obj);
            obj = null;
        }
        var sel = document.getElementById("treeSel");
        sel.identity = _source.identity;
        sel.datasource = _source.datasource;
        var _title = document.getElementById('txtTitle');
        var _identity = document.getElementById('txtIdentity');
        sel.title = _source.title;
        if (_source.title != "") {
            _title.value = sel.title;
        } else {
            _title.value = Request["showText"];
        }
        _identity.value = sel.identity;
        _title = null;
        _identity = null;
        if (_source.type == "select") {
            var sp = document.getElementById('showControl');
            sp.innerText = "下拉框";
            sp = null;
        }
        else if (_source.type == "radio") {
            var sp = document.getElementById('showControl');
            sp.innerText = "单选按钮";
            sp = null;
        }
        else if (_source.type == "checkbox") {
            var sp = document.getElementById('showControl');
            sp.innerText = "复选按钮";
            sp = null;
        }
        else if (_source.type == "text") {
            var sp = document.getElementById('showControl');
            sp.innerText = "文本框";
            sp = null;
        }
        else if (_source.type == "textarea") {
            var sp = document.getElementById('showControl');
            sp.innerText = "多行文本框";
            sp = null;
        }
        if (_source.dataType == "sql") {
            if (_source.type == "select" || _source.type == "radio" || _source.type == "checkbox") {
                var _length = _source.selSource.length;
                for (var i= 0; i <_length; i++) {
                    var newItem = new Option(_source.selSource[i].name, _source.selSource[i].value);
                    sel.options.add(newItem);
                    newItem = null;
                }
            }
        }
    }
    CollectGarbage();
}

function getHtmlBySql(id) {

    var resultValue = null;
    var _name = null;
    var sqlTxt = "exec eOA_Sys_Select 'eOA_cmbDataSource','SQLContent,Name','AND ID=" + id + "'";
    var obj = DBReader.selectSql(sqlTxt);
    if (obj == null || obj == undefined) {
        resultValue = null;
    }
    else {
        var rowCount = parseInt(obj.RecordCount);
        if (rowCount == 0 || rowCount == NaN) {
            resultValue = null;
        }
        else if (typeof (obj) == "object" && rowCount > 0) {
            obj.MoveFirst();
            resultValue = obj.Fields("SQLContent").Value;
            _name = obj.Fields('Name').Value;
            var _sql = document.getElementById('txtSql');
            _sql.value = unescape(resultValue);
            var txtName = document.getElementById('txtSqlDataSource');
            txtName.value = _name;
            _sql = null;
            txtName = null;
            CollectGarbage();
        }
        else {
            resultValue = null;
        }
    }
    DBReader.Dispose(obj);
}

/*关闭窗口*/
function windowClose() {
    ShowWindow.close();
}

/*当选择下拉框、单选、复选时显示修改模块*/
function showEditModule(obj) {
    var _val = obj.value;
    var divSRC = document.getElementById('divSRC');
        if (_val == "select" || _val == "radio" || _val == "checkbox") {
            divSRC.style.display = "block";
            var contorlFont = document.getElementById("showControl");
            contorlFont.innerText = obj[obj.selectedIndex].text;
            contorlFont = null;
            if (_source.dataType == "sql") {
                jseOA_EditInputOrModifyControl.showControlModule("1");
            }
            else {
                jseOA_EditInputOrModifyControl.showControlModule("2");
            }
        } else {
            divSRC.style.display = "none";
        }
    
    obj = null;
    divSRC = null;
    CollectGarbage();
}

/*选择格式*/
function changeFormat(_val) {
    var control = document.getElementById('divSRC');
    control.style.display = "none";
    document.getElementById("SpanEndTime").style.display = "none";
    document.getElementById("isEndTime").style.display = "none";
    document.getElementById("timePara").style.display = "none";
    switch (_val) {
        case "0":
            {
                var _dom = document.getElementById("liDataText");
                _dom.style.display = "none";
                _dom = null;
                _dom = document.getElementById("liDataTime");
                _dom.style.display = "none";
                _dom = null;
                _dom = document.getElementById("liDataNumeric");
                _dom.style.display = "none";
                _dom = null;
                _dom = document.getElementById("liDataAttachment");
                _dom.style.display = "none";
                _dom = null;
                _dom = document.getElementById("liDataTable");
                _dom.style.display = "none";
                _dom = null;
            }
            break;
        case "1":
            {
                var _dom = document.getElementById("liDataText");
                var dataText = document.getElementById('dataText');
                if (dataText.value == "select" || dataText.value == "radio" || dataText.value == "checkbox") {
                    control.style.display = "";
                } else if (dataText.value == "") {
                    dataText.value = "text";
                }
                _dom.style.display = "inline";
                _dom = null;
                _dom = document.getElementById("liDataTime");
                _dom.style.display = "none";
                _dom = null;
                _dom = document.getElementById("liDataNumeric");
                _dom.style.display = "none";
                _dom = null;
                _dom = document.getElementById("liDataAttachment");
                _dom.style.display = "none";
                _dom = null;
                _dom = document.getElementById("liDataTable");
                _dom.style.display = "none";
                _dom = null;
            } break;
        case "2":
            {
                var _dom = document.getElementById("liDataText");
                _dom.style.display = "none";
                _dom = null;
                _dom = document.getElementById("liDataTime");
                _dom.style.display = "inline";
                document.getElementById("SpanEndTime").style.display = "";
                document.getElementById("isEndTime").style.display = "";
                _dom = null;
                _dom = document.getElementById("liDataNumeric");
                _dom.style.display = "none";
                _dom = null;
                _dom = document.getElementById("liDataAttachment");
                _dom.style.display = "none";
                _dom = null;
                _dom = document.getElementById("liDataTable");
                _dom.style.display = "none";
                _dom = null;
            }
            break;
        case "3":
            {
                var _dom = document.getElementById("liDataText");
                _dom.style.display = "none";
                _dom = null;
                _dom = document.getElementById("liDataTime");
                _dom.style.display = "none";
                _dom = null;
                _dom = document.getElementById("liDataNumeric");
                _dom.style.display = "inline";
                _dom = null;
                _dom = document.getElementById("liDataAttachment");
                _dom.style.display = "none";
                _dom = null;
                _dom = document.getElementById("liDataTable");
                _dom.style.display = "none";
                _dom = null;
            }
            break;
        case "4":
            {
                var _dom = document.getElementById("liDataText");
                _dom.style.display = "none";
                _dom = null;
                _dom = document.getElementById("liDataTime");
                _dom.style.display = "none";
                _dom = null;
                _dom = document.getElementById("liDataNumeric");
                _dom.style.display = "none";
                _dom = null;
                _dom = document.getElementById("liDataAttachment");
                _dom.style.display = "none";
                _dom = null;
                _dom = document.getElementById("liDataTable");
                _dom.style.display = "none";
                _dom = null;
            }
            break;
        case "5":
            {
                var _dom = document.getElementById("liDataText");
                _dom.style.display = "none";
                _dom = null;
                _dom = document.getElementById("liDataTime");
                _dom.style.display = "none";
                _dom = null;
                _dom = document.getElementById("liDataNumeric");
                _dom.style.display = "none";
                _dom = null;
                _dom = document.getElementById("liDataAttachment");
                _dom.style.display = "none";
                _dom = null;
                _dom = document.getElementById("liDataTable");
                _dom.style.display = "none";
                _dom = null;
            }
            break;

    }
    CollectGarbage();
}