// Generated by CoffeeScript 1.8.0
(function() {
  $(function() {
    $(".toast").hide();
    $("#text").html("用户注册");
    $("button.am-button").click(function() {
//      if(!$("#checked").is(":checked")){
//    	  wrongMsg("请阅读并同意《财富管理合伙人协议》！");
//    	  toast.hide();
//    	  return;
//      }
      if (!isMobile($("#phone")[0], "手机号")) {
        return;
      }
      if (!isNotNull($("#verifyCode")[0], "校验码")) {
        return;
      } else if (!verifyPassword($("#pwd")[0],"密码")) {
        return;
      }
      return Ajax({
        url: baseUrl + '/api/user/register.do',
        data: $("#userRegist").serialize(),
        success: function(obj) {
          if (obj.status === 200) {
        	  return Ajax({
        	        url: baseUrl + '/api/user/login.do',
        	        data:{mobile:$("#phone").val(),password:$("#pwd").val()},
        	        success: function(data) {
        	          if (data.status === 200) {
        	        	  toast.success({msg:"恭喜您，注册成功！"});
        	        	  setTimeout(function(){
        	        		  return location.href = "../product/index.html";
        	        		  
        	        	  },1000);
        	          }
        	        }
        	     });
          }else if(obj.status==301){
        	  return location.href = "./login.html";
          }else{
        	  wrongMsg(obj.message);
          }
        }
      });
    });
    $("#verCode").on("tap", function() {
    	if(!$("#verCode")[0].disabled){
    	        if (!isMobile($("#phone")[0], "手机号")) {
    	          return;
    	        }
    	        return $.ajax({
    	          url: baseUrl + '/api/user/send_sms.do',
    	          data: {
    	            mobile: $("#phone").val(),
    	            smsType:1
    	          },
    	          beforeSend: function() {
    	              toast.innerHTML = tipTpl.loading;
    	              return toast.show();
    	          },
    	          success: function(data) {
    	        	  if(data.status==200){
    	        		  toast.success({msg:"短信已发送，请稍候!"});
    	        		  setTimeout(function(){
    	        			  toast.hide();
    	        		  }, 3000);
    	        		  return settime($("#verCode"));
    	        	  }else{
    	        		  wrongMsg(data.message);
    	        	  }
    	          }
    	        });
    	}
    });
  });

}).call(this);
