(function($){
//允许输入包括0的数字(没改)
  $.fn.checkNum=function(){
     var numstr = $(this).val();  
     var num =numstr.replace(/,| /g,"");
        
     if(num.length>1)
     {
         num = num.replace(/\b[0*]/g,"");
     }          
     if(!num.match(/[^0-9]/g))
     { 
        $(this).val(num.replace(/,/g,""));
     }
     else
     {
         alert("Enter integer");
	     $(this).val('');
     }
  }
  
$.fn.checkDouble=function(){
   var test_value=$(this).val();
   if(test_value.match(/^\d+((\.?\d+)|(\d*))$/)){
        return true;
   }else{
        return false;
   }
 }
 
  $.fn.checkEmail=function(){
      if($(this).val()!=""){
         if(!$(this).val().match(/^([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/g)){
            return true;
         }else{
            return false;
         }
      }
  }
  
  $.fn.checkConfirm=function(obj){
    if(obj.checkNotNull()&&$(this).checkNotNull()){
        if(obj.val().trim()!=$(this).val().trim()){
            return true;
        }else{
            return false;
        }
    }else{
        return true;
    }
  }
  $.fn.checkNull=function(){
    if($(this).val().trim()==""||$(this)==null){
        return true;
    }else{
        return false;
    }
  }
  $.fn.checkNotNull=function(){
    if($(this).val()==""||$(this)==null){
        return false;
    }else{
        return true;
    }
  }
  $.fn.showMsg=function(showobj,msg,obj_focus){
    if(obj_focus!=null){
        showobj.html(msg);
        obj_focus.val('');
        obj_focus[0].focus();
        obj_focus.css({border:'1px solid red'});
        obj_focus.blur(function(){
            obj_focus.css({border:'1px solid #d6a455'});
            obj_focus.unbind('blur');
        })
    }
  }
  $.fn.showMsg_In=function(obj_focus,msg){
    if(obj_focus!=null){
        obj_focus.val(msg);
        obj_focus[0].focus();
        obj_focus.select();
        obj_focus.css({border:'1px solid red'});
        obj_focus.blur(function(){
            obj_focus.css({border:'1px solid #d6a455'});
            obj_focus.unbind('blur');
        })
    }
  }
  
  $.fn.disUsPhone=function(objs){
    var _rePhone='';
    objs=objs.children('input');
    objs.each(function(){
        if($(this).checkNotNull())
        {
            _rePhone+='-'+$(this).val();
        }else{
            _rePhone='';
            return false;
        }
    })
    if(_rePhone!='')
        return _rePhone.substring(1);
    else
        return _rePhone;
  }
  $.fn.checkTime=function(){
    if($(this).val()!=""){
         if(!$(this).val().match(/\d{2}-\d{2}\s\d{2}:\d{2}/g)){
            return true;
         }else{
            return false;
         }
    }
  }
    
})(jQuery)

String.prototype.trim=function(){return   this.replace(/(^\s*)|(\s*$)/g,"");}

function submit_check(check_objs){
    if(check_objs.fullname.checkNull()){
        $(this).showMsg_In(check_objs.fullname,'please input fullname');
        return false;
    }
    if(check_objs.email.checkNull()||check_objs.email.checkEmail()){
        $(this).showMsg_In(check_objs.email,'please input email');
        return false;
    }
    if(check_objs.notusphone.checkNull()&&$(this).disUsPhone(check_objs.usphone)==''){
        $(this).showMsg(check_objs.error,'please input us phone or non_us phone',check_objs.usphone.children('input:eq(0)'));
        return false;
    }
    check_objs.error.html('');
    showimg();
}


function checkAct(){
   return submit_check({
        fullname:$('#ctl00_ContentPlaceHolder1_txtfullname'),
        email:$('#ctl00_ContentPlaceHolder1_txtemail'),
        usphone:$('#actusphone'),
        notusphone:$('#ctl00_ContentPlaceHolder1_txtNphone'),
        error:$('acterror')
    })
}

function checkCdk(){
   return submit_check({
        fullname:$('#ctl00_ContentPlaceHolder1_txtfullname'),
        email:$('#ctl00_ContentPlaceHolder1_txtemail'),
        usphone:$('#cdkusphone'),
        notusphone:$('#ctl00_ContentPlaceHolder1_txtNphone'),
        error:$('cdkerror')
    })
}

function checkPl(){
        if($('#ctl00_ContentPlaceHolder1_Powerlevelingorder1_txtStartingTime').checkTime()||$('#ctl00_ContentPlaceHolder1_Powerlevelingorder1_txtStartingTime').checkNull()){
            $(this).showMsg_In($('#ctl00_ContentPlaceHolder1_Powerlevelingorder1_txtStartingTime'),'please input starting time');
            return false;
        }
        if($('#ctl00_ContentPlaceHolder1_Powerlevelingorder1_ddlServerId').val()=='0'){
            $(this).showMsg($('#plerror'),'please select server name',$('#ctl00_ContentPlaceHolder1_Powerlevelingorder1_ddlServerId'));
            return false;
        }
        if($('#ctl00_ContentPlaceHolder1_Powerlevelingorder1_txtAccountName').checkNull()){
            $(this).showMsg_In($('#ctl00_ContentPlaceHolder1_Powerlevelingorder1_txtAccountName'),'please input account name');
            return false;
        }
        if($('#ctl00_ContentPlaceHolder1_Powerlevelingorder1_txtPassword').checkNull()){
            $(this).showMsg($('#plerror'),'please input account password',$('#ctl00_ContentPlaceHolder1_Powerlevelingorder1_txtPassword'));
            return false;
        }
        
        if($('#ctl00_ContentPlaceHolder1_Powerlevelingorder1_txtCharacterName').checkNull()){
            $(this).showMsg_In($('#ctl00_ContentPlaceHolder1_Powerlevelingorder1_txtCharacterName'),'please input charactername ');
            return false;
        }
        if($('#ctl00_ContentPlaceHolder1_Powerlevelingorder1_DDLCharClass').val()=='0'){
            $(this).showMsg($('#plerror'),'please select server name',$('#ctl00_ContentPlaceHolder1_Powerlevelingorder1_DDLCharClass'));
            return false;
        }
        if($('#plusphone input').length!=0){
            return submit_check({
                fullname:$('#ctl00_ContentPlaceHolder1_Powerlevelingorder1_txtFullName'),
                email:$('#ctl00_ContentPlaceHolder1_Powerlevelingorder1_txtEmail'),
                usphone:$('#plusphone'),
                notusphone:$('#ctl00_ContentPlaceHolder1_Powerlevelingorder1_txtNon_US_Phone'),
                error:$('#plerror')
            })
        }else{
            showimg();
        }
}

function checkRegister(){
        if($('#ctl00_ContentPlaceHolder1_Register1_txtpwd').checkConfirm($('#ctl00_ContentPlaceHolder1_Register1_txtrepwd'))){
           $(this).showMsg($('#reerror'),'please input confirm password',$('#ctl00_ContentPlaceHolder1_Register1_txtrepwd'));
           return false;
        }
        if($('#reusphone input').length!=0){
            return submit_check({
                fullname:$('#ctl00_ContentPlaceHolder1_Register1_txtfullname'),
                email:$('#ctl00_ContentPlaceHolder1_Register1_txtmail'),
                usphone:$('#reusphone'),
                notusphone:$('#ctl00_ContentPlaceHolder1_Register1_txtnon'),
                error:$('#reerror')
            })
        }else{
            showimg();
        }
        
}