﻿// JScript 文件
//jquery 字符串处理类

/*
    验证控件是否为空
*/
$.fn.IsNull=function(){
    if($(this).val()==""||$(this).val()==null){
        return true;
    }else{
        return false;
    }
}
/*
    清空下拉列表
*/
$.fn.emptySelect=function(){
    return this.each(function(){
        if(this.tagName=="SELECT")
            this.options.length=0;
    });
}
/*
    验证是否为数字
*/
$.fn.VerNumber=function(){
    var _old=$(this).val();
    $(this).blur(function(){
        if(!(/^[-\+]?\d+(\.\d+)?$/).test($(this).val())){
            $(this).val(_old);
        }
    });
}
/*
    显示、隐藏对象
*/
$.fn.extend({
    block:function(){
        $(this).css("display","block");
    },
    none:function(){
        $(this).css("display","none");
    },
    toshow:function(){
        $(this).show("slow");
    },
    tohide:function(){ 
        $(this).hide("slow");
    }
})
/*
    验证身份证号码
*/
$.fn.VerIdCard=function(){
    var bl=true;
    var _idcard=$(this).val();
    if(!(/(^\d{15}$)|(^\d{17}[0-9Xx]$)/).test(_idcard)){
        bl=false;
    }
    return bl;
}
$.fn.GetBirthdayByIdCard=function(){
    var _birthday="";
    var _idcard=$(this).val();
    if((/(^\d{15}$)|(^\d{17}[0-9Xx]$)/).test(_idcard)){
        _birthday=_idcard.slice(6,10)+"-"+(_idcard.slice(10,12))+"-"+_idcard.slice(12,14); ///(new Date(_idcard.slice(6,10) , _idcard.slice(10,12)-1 , _idcard.slice(12,14))).toLocaleDateString();
    }
    return _birthday;
}
/* 验证Email */
$.fn.VerIsEmail=function(){
    var bl=true;
    var _email=$(this).val();
    if(!(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/).test(_email)){
        bl=false;
    }
    return bl;
}
/* 获取性别 */
$.fn.GetSexByIdCard=function(){
    var sex="";
    var _tempSex=0;
    var _idcard=$(this).val();
    if($(this).VerIdCard()){
        switch(_idcard.length)
        {
            case 15:
                _tempSex=_idcard.substr(14,1);
                break;
            case 18:
                _tempSex=_idcard.substr(16,1);
                break;
        }
    }
    if(_tempSex%2==0){
        sex=1;  //女
    }else{  
        sex=0;  //男
    }
    return sex;
}
/* 设置是否禁用该控件 */
$.fn.SetIsDisabled=function(disabled,datatype,msg){
    if(disabled){
        $(this).addClass("tbxReadOnly").attr('readonly').removeAttr('required').removeAttr('controlname').removeAttr('isvalidator').removeAttr('dataType').unbind();
    }else{
        $(this).removeClass("tbxReadOnly").attr({required:'required',controlname:msg,isvalidator:''}).removeAttr('readonly');
        switch(datatype)
        {
            case "date":
                $(this).attr({isbuilder:'1'}).bind("focus",function(){calendar();});
                break;
        }
    }
}
