/**
 * Created by Administrator on 2016/7/26.
 */
(function() {
    var my_balance=$('#my_balance').html();
    var total=$('#total').html();
    var progress_bar=parseFloat( $('#progress_bar').css('width') );
    $('#progress_bar i').css('width', my_balance/ total *progress_bar+'px');

   $('#userName').keyup(function(){
       valiUsername(this);
   });
    $('#userTel').keyup(function(){
        valiTel(this);
    });
    $('#submit').click(function(){
        var userName=$('#userName')[0];
        var userTel=$('#userTel')[0];
        var valiU=valiUsername(userName);
        var valiT=valiTel(userTel);
        if( !valiU ){
            $(userName).focus();
        }else {
            if( !valiT ){
                $(userTel).focus();
            }else{
                $('#form')[0].submit;
            }
        }
    });
    function valiUsername(obj){
        var uText=obj.value.trim();
        if(!uText){
            $('#errorName').html('用户名不能为空，请重新输入！');
            return false;
        }else {
            $('#errorName').html('');
            return true;
        }
    }
    function valiTel(obj){
        var telText=obj.value.trim();
        var reg=/^[0-9]{11}$/;
        if( !reg.test(telText) ){
            $('#errorTel').html('手机号有误，请重新输入！');
            return false;
        }else{
            $('#errorTel').html('');
            return true;
        }
    }
})();
