$(function(){	

	$('.tabPanel ul li').click(function(){

		$(this).addClass('hit').siblings().removeClass('hit');

		$('.panes>div:eq('+$(this).index()+')').show().siblings().hide();	

	});

 $("#signupForm").validate({

   onfocusout:function(element) {$(element).valid()},

    rules:{

    user_login:{

    	required: true,

    	rangelength:[6,22],

    	remote: {

	    url: "/user/register/checkName",     //后台处理程序

	    type: "post",               //数据发送方式

	    dataType: "json",           //接受数据格式   

	    data: {                     //要传递的数据

	        user_login: function() {

	            return $("#user_login").val();

	        }

	      }

		   }

    },

    user_email:{

      required: true,

      remote: {

      url: "/user/register/checkEmail",     //后台处理程序

      type: "post",               //数据发送方式

      dataType: "json",           //接受数据格式   

      data: {                     //要传递的数据

          user_email: function() {

              return $("#user_email").val();

          }

        }

       }

    },



        password:{   

           required: true,

           rangelength: [6,22]

        },

        repassword: {

          required: true,

          equalTo: "#password"

        },

        realname:"required",

        id_card:{   

          required: true,

          idcard: true

        },

        checkboxname:"required"    

    },

   

    messages:{

    	    username:{

    	       required: "用户名是必填项！",   

               rangelength: $.format("用户名要在{0}-{1}个字符之间！")   

            },

            user_email:{

               required: "邮箱是必需的！",   

               email:"邮箱格式错误"   

            },

    	    password:{

    	       required: "密码是必需的！",   

               rangelength: $.format("密码要在{0}-{1}个字符之间！")   

            },

            repassword:{

                required: "请输入确认密码",

                equalTo: "两次输入密码不一致不一致"

               },

            id_card:{

               required: "身份证是必需的！",   

               idcard: '身份证格式错误！'

            },

            realname:{

               required: "姓名是必需的！"

            },

            checkboxname: "请阅读注册服务协议"

    },

    errorClass: "reg_false",

	validClass: "reg_true",

	errorElement: "aside",

    errorPlacement: function(error, element) {

    if ( element.is(":radio") )

        error.appendTo( element.parent().next().next() );

    else if ( element.is(":checkbox") )

       error.appendTo( element.parent().next());// error.appendTo ( element.next() );

    else

        error.appendTo( element.parent().next() );

	},





    });



$("#signupForm1").validate({

   onfocusout:function(element) {$(element).valid()},

    rules:{

    user_login:{

        required: true,

        tel:true,

        remote: {

        url: "/user/register/checkTel",//后台处理程序

        type: "post",//数据发送方式

        dataType: "json",//接受数据格式   

        data: {//要传递的数据

            user_login: function() {

                return $("#tel").val();

            },

            tel: function() {

                return $("#tel").val();

            }

          }

        }

    },

    user_email:{

      required: true,

      remote: {

      url: "/user/register/checkEmail",     //后台处理程序

      type: "post",               //数据发送方式

      dataType: "json",           //接受数据格式   

      data: {                     //要传递的数据

          user_email: function() {

              return $("#user_email1").val();

          }

        }

       }

    },

        password:{   

           required: true,

           rangelength: [6,22]

        },

        repassword: {

          required: true,

          equalTo: "#password1"

        },

        realname:"required",

        code:"required",

        id_card:{   

          required: true,

          idcard: true

        },

        checkboxname:"required"       

    },

   

    messages:{

            username:{

               required: "手机号是必填项！",   

               tel: "手机号格式错误"  

            },

            user_email:{

               required: "邮箱是必需的！",   

               email:"邮箱格式错误"   

            },

            password:{

               required: "密码是必需的！",   

               rangelength: $.format("密码要在{0}-{1}个字符之间！")   

            },

            repassword:{

                required: "请输入确认密码",

                equalTo: "两次输入密码不一致不一致"

               },

            id_card:{

               required: "身份证是必需的！",   

               idcard: '身份证格式错误！'

            },

            realname:{

               required: "姓名是必需的！"

            },

            code:{

               required: "验证码是必需的！"

            },

            checkboxname: "请阅读注册服务协议"

    },

    errorClass: "reg_false",

    validClass: "reg_true",

    errorElement: "aside",

    errorPlacement: function(error, element) {

    if ( element.is(":radio") )

        error.appendTo( element.parent().next().next() );

    else if ( element.is(":checkbox") )

        error.appendTo( element.parent().next());//error.appendTo ( element.next() );

    else

        error.appendTo( element.parent().next() );

    },





    });



$("#bangtel").validate({

   onfocusout:function(element) {$(element).valid()},

    rules:{

    tel:{

        required: true,

        tel:true,

        remote: {

        url: "/user/register/checkTel",//后台处理程序

        type: "post",//数据发送方式

        dataType: "json",//接受数据格式   

        data: {//要传递的数据

            user_login: function() {

                return $("#tel").val();

            },

            tel: function() {

                return $("#tel").val();

            }

          }

        }

    }  

    },

    messages:{

            tel:{

               required: "手机号是必填项！",   

               tel: "手机号格式错误"  

            }

    },

    errorClass: "reg_false",

    validClass: "reg_true",

    errorElement: "aside",

    errorPlacement: function(error, element) {

    if ( element.is(":radio") )

        error.appendTo( element.parent().next().next() );

    else if ( element.is(":checkbox") )

        error.appendTo( element.parent().next());//error.appendTo ( element.next() );

    else

        error.appendTo( element.parent().next() );

    },





    });



$('#btncode').click(function () {

    var tel = $("#tel").val();

    if(tel){

      var count = 30;

      var countdown = setInterval(CountDown, 1000);

        function CountDown() {

          $("#btncode").attr("disabled", true);

          $("#btncode").val("在" + count + " 秒后再次获取");

           if (count == 0) {

               $("#btncode").val("重新获取验证码").removeAttr("disabled");

                clearInterval(countdown);

            }

          count--;

        }

        $.ajax({

            type: 'POST',

            url: '/user/register/sendTel' ,

            data: {                     //要传递的数据

            tel: function() {

                return $("#tel").val();

            }

          },

        success:function(data){    

            if(data.state !="success"){ 

              $("#btncode").val("发送失败").removeAttr("disabled");

              clearInterval(countdown);

            }    

        },

        cache:false,

        error:function(){ 

          alert("异常！");    

        },

        dataType:'json'

        });

    }else{

      $("#btncode").val("手机号为空");

    }

    

                

    })

/*防沉迷*/

$("#f1").validate({

   onfocusout:function(element) {$(element).valid()},

    rules:{

        realname:"required",

        id_card:{   

          required: true,

          idcard: true

        },

        checkboxname:"required"       

    },

   

    messages:{

            id_card:{

               required: "身份证是必需的！",   

               idcard: '身份证格式错误！'

            },

            realname:{

               required: "姓名是必需的！"

            },

    },

    errorClass: "reg_false",

    validClass: "reg_true",

    errorElement: "span",

    errorPlacement: function(error, element) {

        error.appendTo( element.parent().next() );

    },





    });

/*修改密码*/

$("#editpwd").validate({



   onfocusout:function(element) {$(element).valid()},

    rules:{

      old_password:"required",

      password:{   

           required: true,

           rangelength: [6,22]

      },

      repassword: {

        required: true,

        equalTo: "#password1"

      },     

    },

   

    messages:{

          password:{

               required: "新密码是必需的！",   

               rangelength: $.format("密码要在{0}-{1}个字符之间！")   

            },

            repassword:{

                required: "请输入确认密码",

                equalTo: "两次输入密码不一致不一致"

          },

          old_password:{

               required: "原密码是必需的！"

            },

    },

    errorClass: "reg_false",

    validClass: "reg_true",

    errorElement: "span",

    errorPlacement: function(error, element) {

        error.appendTo(element.parent().next());

    },





    });

})