function jsCommonLogic(){

};

/*判断标识是否已存在*/
jsCommonLogic.chkLableIsExist=function(strBillLable,strOldBillLable){
            var strSql="select count(*) as [count] from eOA_fip_CallInputSheet where Lable='"+strBillLable+"' and Lable<>'"+ strOldBillLable+"'";
            var obj=DBReader.selectSql(strSql,"SelLableExist");
            if(DBReader.DObjectIsNull(obj)==false)
            {
                  if(parseInt(obj.RecordCount)>0)
                  {
                            if(obj.Fields("count").Value>0)
                             {
                                var count=obj.Fields("count").Value;
                                DBReader.Dispose(obj);   
                                obj=null;
                                CollectGarbage();
                                return count;
                              }
                             else
                              {
                                DBReader.Dispose(obj);   
                                return 0;
                              }
                    }
                   else
                   {
                              DBReader.Dispose(obj);   
                              return 0;
                    }   
            }
            else
            {
                    return 0;
            }
           strSql=null;
};

 //根据ID获取JS文件的服务器名和路径
jsCommonLogic.GetJSFileInfo=function(id)
{
    var txtSql = "select Lable,JSFileName,JSFilePath from eOA_fip_CallInputSheet where ID=" + id ;
    var obj=DBReader.selectSql(txtSql,"eOA_fip_CallInputSheet");
    if(!DBReader.DObjectIsNull(obj))
    {
        var rowCount=parseInt(obj.RecordCount);
        if(rowCount==0){
            DBReader.Dispose(obj);
            return null;
        }
        else
        {
            obj.MoveFirst();
            var FileEntity=
            {
                Lable:obj.Fields("Lable").Value,
                FileName:obj.Fields("JSFileName").Value,
                Path:obj.Fields("JSFilePath").Value
            }
            DBReader.DisposeEntity(obj);
            return FileEntity;
        }
    }
    else
    {
        return null;
    }
}

/*判断存在或取某字段的字*/
jsCommonLogic.selExistData = function(selColumn, selTable, strWhere) {
    var returnResult = 0;
    var strSql = "select " + selColumn + " as DataValue from " + selTable + "  ";
    if (strWhere != "" && strWhere != undefined) {
        strSql += strWhere;
    }
    var obj = DBReader.selectSqlForJson(strSql);
    if (obj != null) {
        var result = eval("[{" + obj + "}]");
        if (result[0].result == "1") {
            returnResult = result[0].table[0].DataValue;
        }
    }
    strSql = null;
    return returnResult;
}

//判断是否存在表
jsCommonLogic.selColumnData = function(selTable) {
    try {
        var strSql = "select * from " + selTable + " where 1=1";
        var strObj = DBReader.selectSqlForJson(strSql, "SelColumnData");
        var obj = eval("[{" + strObj + "}]");
        strSql = null;
        if (DBReader.DObjectIsNull(obj) == false) {
            if (obj[0].col != undefined) {
                return strObj;
            }
            else {
                return "";
            }

        }
        else {
            return "";

        }
    } catch (e) {
        alert(e.message);
    }
}
/*************************************************** ▌页面通用类型枚举 ▌************************************************/
var PageTypeEnum = 
{
   CommonArchiveTypeEditPage: "CommonArchiveTypeEditPage",   //通用类型档案编辑页面
   CommonArchiveEditPage: "CommonArchiveEditPage"            //通用单个档案编辑页面
}
/*************************************************** ▌根据状态加载控件的可见性 ▌****************************************/
//(参数1)：controlStringsObj [控件状态数组，声明格式:var arr=new Array();arr["New"]="btnSave,visible,disabled|btnModify,unvisible,enabled";]
//(参数1)：pageTypeEnum [页面类型枚举]
//创建：Charles [2010/10/23]
jsCommonLogic.LoadStateControls=function(controlArray,pageTypeEnum)
{ 
    switch(pageTypeEnum)
    {
        case PageTypeEnum.CommonArchiveTypeEditPage.toString():
            if(pageState=="New")
            {
                $("#Editbtn,#Addbtn,#Deletebtn,#UserInfomation").hide();
                $("#Savebtn,#Cancelbtn,#serachType").show();
                $("#frScheduleType").resetForm();
                $("#frScheduleType input").attr("disabled","");
                $("#htxtDescription").attr("disabled","");
            }
            else if(pageState=="Update")
            {  
                $("#Editbtn,#Addbtn").hide();
                $("#Savebtn,#Cancelbtn,#serachType").show();
                $("#frScheduleType input").attr("disabled","");
                $("#htxtDescription").attr("disabled","");
            }
            else if(pageState=="View")
            {
                $("#Deletebtn,#Editbtn,#Addbtn").show();
                $("#Savebtn,#Cancelbtn,#serachType").hide();
                $("#frScheduleType input").attr("disabled","disabled");
                $("#htxtDescription").attr("disabled","disabled");
            }
            break
        case PageTypeEnum.CommonArchiveTypeEditPage:
            if(pageState=="New")
            {
                $("#Editbtn,#Addbtn,#Deletebtn,#UserInfomation").hide();
                $("#Savebtn,#Cancelbtn,#serachType").show();
                $("#frScheduleType").resetForm();
                $("#frScheduleType input").attr("disabled","");
                $("#htxtDescription").attr("disabled","");
            }
            else if(pageState=="Update")
            {
                $("#Editbtn,#Addbtn").hide();
                $("#Savebtn,#Cancelbtn,#serachType").show();
                $("#frScheduleType input").attr("disabled","");
                $("#htxtDescription").attr("disabled","");
            }
            else if(pageState=="View")
            {
                $("#Deletebtn,#Editbtn,#Addbtn").show();
                $("#Savebtn,#Cancelbtn,#serachType").hide();
                $("#frScheduleType input").attr("disabled","disabled");
                $("#htxtDescription").attr("disabled","disabled");
            }
            break
        default:
            if (pageState == "New") {
                SetControlsState(controlArray["New"]);
            }
            else if (pageState == "Update") {
               
                SetControlsState(controlArray["Update"]);
            }
            else if (pageState == "View") {
                SetControlsState(controlArray["View"]);
            }
            else if (pageState == "Customer") {
                SetControlsState(controlArray["Customer"]);
            }
    }
}
//解释控件串的状态
//参数格式：btnSave,visible,disabled|btnModify,unvisible,enabled
function SetControlsState(controlStrings)
{
    var controlState = controlStrings.split('|');
    for(var i=0;i<controlState.length;i++)
    {
        if(controlState[i].split(',')[1]=="visible") {
           
          $("#" + controlState[i].split(',')[0]).show();
          $("#s_" + controlState[i].split(',')[0]).show();
        }
        else
        {
            $("#"+controlState[i].split(',')[0]).hide();
            $("#s_"+controlState[i].split(',')[0]).hide();
        }
        if(controlState[i].split(',')[2]=="disabled")
        {
            $("#"+controlState[i].split(',')[0]).attr("disabled","disabled");
        }
        else
        {
            $("#"+controlState[i].split(',')[0]).attr("disabled","");
        }
        if(controlState[i].split(',')[1]=="hideClass")
        {
            $(controlState[i].split(',')[0]).hide();
        }
        else
        {
            $(controlState[i].split(',')[0]).show();
        }
    }
}


/*验证输入框输入的值*/
jsCommonLogic.dataValidate = function(validate, obj) {
    if ($.trim(obj.value) != "") {
        var _reTimeReg = "";
        var _val = obj.value;
        var alertTxt = "";
        if (validate == 3 || validate == 20) {
            _reTimeReg = /^$|^[]{0,1}[0-9]{1,}$/;
            alertTxt = "错误的格式，请重新输入正整数格式如：1或27";
        } else if (validate == 5 || validate == 6 || validate == 131) {
            _reTimeReg = /^[1-9]d*.d*|0.d*[1-9]d*$/;
            alertTxt = "错误的格式，请重新输入小数格式如：1.14或27.95";
        } else if (validate == 135) {
            _reTimeReg = /^(?:19|20)[0-9][0-9]-(?:(?:0[1-9])|(?:1[0-2]))-(?:(?:[0-2][1-9])|(?:[1-3][0-1])) (?:(?:[0-2][0-3])|(?:[0-1][0-9])):[0-5][0-9]:[0-5][0-9]$/;
            alertTxt = "错误的格式，请重新输入日期格式如：2010-01-20 09:24:30";
        } else if (validate == 136) {
            _reTimeReg = /^$|^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$/;
            alertTxt = "错误的格式，请重新输入日期格式如：2010-01-20";
        } else if (validate == 1) {
            _reTimeReg = /^((\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)/;
            alertTxt = "错误的格式，请重新输入格式如下：\r\n手机号码如：13612456789\r\n电话号码如：020-12345678\r\n带分机号格式如：020-12345678-9999";
//            if (_val.indexOf("-") != -1) {
//                alertTxt = "错误的格式，请重新输入电话格式如：0757-82378457或0757-82378457-8012或82378457";
//            }
        }
        if (_reTimeReg != "" && (_val != null || $.trim(_val) != "")) {
            if (!(_reTimeReg.test(_val))) {
                alert(alertTxt);
                //                obj.value = "";
                obj.focus();
            } else if (validate == 1 && _val.indexOf("-") != -1) {
                if (_val.indexOf("-") == _val.lastIndexOf("-")) {
                    if (_val.length > 13) {
                        alert(alertTxt);
                        obj.focus();
                    }
                }
            } else if (validate == 1 && _val.indexOf("-") == -1) {
                if (_val.length > 11) {
                    alert(alertTxt);
                    obj.focus();
                }
            }
        }
        _reTimeReg = null;
        _val = null;
        alertTxt = null;
        validate = null;
    }
    obj = null
    CollectGarbage();
};