function jsCommonLogic(){

};

/*判断存在或取某字段的字*/
jsCommonLogic.selColumnData=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" && result[0].table!=undefined)
            {
               returnResult=result[0].table[0].DataValue; 
            }
        }
        strSql=null;
        return returnResult;
}

/*时间格式差*/
jsCommonLogic.TimeFormatSpace=function(currentTime,timeWay,timeSize,operateWay)
{
//    var now = new Date();
//    alert(new Date(now.getTime() - 1000 * 60 * 60 * 24 * 7));
    
    var arys=new Array();
    arys=currentTime.split("-");
    
      /* var nowTime=new Date(arys[0]-1,arys[1],arys[2]);
    var nowTime=new Date(Date.parse(currentTime.replace(/-/g,"/")));*/
    var nowYear=arys[0];//nowTime.getYear();
    var nowMonth=arys[1];//nowTime.getMonth();
    var nowDate=arys[2];//nowTime.getDate();


    if(nowMonth.toString().indexOf("0")==0)
    {
        nowMonth=nowMonth.toString().substring(1);
    }
    if(nowDate.toString().indexOf("0")==0)
    {
        nowDate=nowDate.toString().substring(1);
    }
    var currentYear=parseInt(nowYear);
    var currentMonth=parseInt(nowMonth);
    var currentDate=parseInt(nowDate);
    switch(timeWay)
    {
            case "year":
            {
                if(operateWay=="minus")
                {
                    currentYear=currentYear-timeSize;
                }
                else if(operateWay=="add")
                {
                    currentYear=currentYear+timeSize;
                }
            }
            break;
            case "month":
                var daysInMonth = new Array([0],[31],[28],[31],[30],[31],[30],[31],[31],[30],[31],[30],[31]);   
                if(currentYear%4==0 && currentYear%100!=0){
                    daysInMonth[2]=29;
                }
                if(operateWay=="minus")
                {
                    if(currentMonth-timeSize<=0){
                        currentYear-=1;
                        if(currentMonth-timeSize==0){
                            currentMonth=1;
                        }else{
                            currentMonth=12-( Math.abs(currentMonth-timeSize));
                        }                        
                    }
                    else{
                        currentMonth=currentMonth-timeSize;
                    }
                }
                else if(operateWay=="add")
                {
                     currentMonth=currentMonth+timeSize;
                }
                currentDate=daysInMonth[currentMonth]>=currentDate?currentDate:daysInMonth[currentMonth];
            break;
            case "day":
                var daysInMonth = new Array([0],[31],[28],[31],[30],[31],[30],[31],[31],[30],[31],[30],[31]);   
                if(currentYear%4==0 && currentYear%100!=0){
                    daysInMonth[2]=29;
                }
                if(operateWay=="minus")
                {
                    currentDate=currentDate-timeSize;               
                    if(currentMonth-1==0 && currentDate<0 ){
                         currentYear-=1;
                         currentMonth=12;                      
                    } else if(currentDate==0){
                         currentMonth-=1;
                         currentDate=daysInMonth[currentMonth];                         
                    }            
                }
                else if(operateWay=="add")
                {
                    if(currentDate==daysInMonth[currentMonth]){
                        if(currentMonth==12){
                            currentYear+=1;
                            currentMonth=1;                            
                        }else{
                            currentMonth+=1;                            
                        }
                        currentDate=1+(timeSize-1);
                    }else{
                       currentDate=currentDate+timeSize;
                    }
                }
                currentDate=daysInMonth[currentMonth]>=currentDate?currentDate:daysInMonth[currentMonth];
            break;
            default:
            break;
    }
    
    if(currentDate.toString().indexOf("-")!=-1)
    {
       var a=(currentDate>0)?currentDate:currentDate*(-1);
       currentDate=30-a;
       currentMonth=currentMonth-1;
    }
    if(currentMonth.toString().indexOf("-")!=-1)
    {
       var b=(currentMonth>0)?currentMonth:currentMonth*(-1);
       currentMonth=12-b;
    }
    
    if(currentMonth.toString().length==1)
    {
        currentMonth="0"+currentMonth;
    }
    if(currentDate.toString().length==1)
    {
        currentDate="0"+currentDate;
    }
    
    arys.length=0;
    arys=null;
    nowDate=null;
    nowMonth=null;
    nowYear=null;
    CollectGarbage();
    return currentYear+"-"+currentMonth+"-"+currentDate;
}

/*验证输入框输入的值*/
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{6}|\d{5}|\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{6}|\d{5}|\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();
};

/*临时表操作*/
jsCommonLogic.rcTemporary_Update=function(entity)
{
    var result;
    var txtSql="select top 1 ID from T_TemporaryTable ";
    var obj=DBReader.selectSql(txtSql,"T_TemporaryTable");
    if(obj==null || obj==undefined)
    {
        result=false;
    }
    else
    {
        var rowCount=obj.RecordCount;
        DBReader.Dispose(obj);  
        if(parseInt(rowCount)==0)/*数量为0时插入数据*/
        {
            result=entity.Insert(entity);
        }
        if(parseInt(rowCount)>0)
        {
            result=entity.Update(entity);
        }
    }
    return result;
}

//过滤特殊字符
jsCommonLogic.stripscript=function(s) 
{
    var pattern = new RegExp("[`~!@#$_%^&*()+\\\\\/=|{}':;',\\[\\].<>?~！@#￥……&*（）——|｛｝》《【】\"’‘；：”“'。，、？]") 
    var rs = ""; 
    for (var i = 0; i < s.length; i++) { 
         rs = rs+s.substr(i, 1).replace(pattern, ''); 
    }
    return rs; 
}