
	$(function() {
	
		$("#log-btn").click(function() {
			var my_account = $("#log-account");
			var my_password = $("#log-password");
			
			var account = my_account.val();//.replace(/ /g, '').replace(/'/g, '');
			var password = my_password.val();//.replace(/ /g, '').replace(/'/g, '');
			
			if(account == "") {
				alert("用户名不能为空！");
				my_password.val("").focus();
			} else if(password == "") {
				alert("密码不能为空！");
				my_password.val("").focus();
			} else {
				$.post(root + "?m=login.check", { account:account, password:password }, function(data) {
					
					
				
					if(data[0] == "success") {

									window.location.href = root + "?m=ktv.ktvMmember";
					
					
					} else {
						alert(data[1]);
						if(data[2] == "account is null") {
							account.val("").focus();
						} else if(data[2] == "password is null") {
							my_password.val("").focus();
						} else if(data[2] == "member is not exists") {
							account.focus();
						} else if(data[2] == "member is stopped") {
							account.focus();
						} else if(data[2] == "password error") {
							my_password.val("").focus();
						}
					}
				}, "json");
			}
		});
		
		
		function isEmail(str){
			var reg1 = /([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)/;
 			return reg1.test( str );
		}

		
		
		
		$("#reg-btn").click(function() {
		
		});
		
		
		$('#send_code').click(function(){
			
			var my_account = $("#mobile");
			var my_password = $("#reg-password");
			
			
			var account = my_account.val();
			var password = my_password.val();
			
			$.post(root + "?m=login.checkAccount", { account:account}, function(data) {
																							 
						var ary = eval("(" + data + ")");											
						
						if(ary[0] == 'error')
						{
							alert('该账号已经存在,请从左侧进行登录');	
						}
						else
						{
						
							var data = $("#formSend").serialize();
		
							$.ajax({
								type:'POST',
								url:root + 'msg/send_action.php?type=code',
								data:data,
								success: function (data) {	
									alert(data);
								},
								cache: false
							});
							
							$("#send_code").attr("disabled",true);
							$("#send_code").attr('value','输入验证码');
							$("#send_code").attr('title','验证码有效期为1分钟');
							
							setTimeout('$("#send_code").attr("disabled",false)' , 60000);
							setTimeout('$("#send_code").attr("value","发送验证码")' , 60000);
	
						}
			});			
									   
		
			
		});
		
		$('#find-btn').click(function(){
				
			var my_account = $("#find-mobile");
			var account = my_account.val();
			
			if(account == '')
			{
				alert('请输入手机号');
				my_account.focus();
				return;
			}
			
				$.post(root + "?m=login.checkAccount", { account:account}, function(data) {
																						 
					var ary = eval("(" + data + ")");											
					
					if(ary[0] == 'error')
					{
						//var data = $("#formSend").serialize();
						
						$.ajax({
							type:'POST',
							url:root + 'msg/send_action.php?type=find&mobile='+account,
							success: function (data) {	
							
							},
							cache: false
						});
						$('.phone').hide();
						$('.find_code').show();
						
					}else{
						alert('该手机号码不存在！');	
						return;
					}
					
					
					
				
				});	
					
				
		});
		
		$('#find-code-btn').click(function(){
										   

			
			var data = $("#formSend").serialize();
		
			$.ajax({
				type:'POST',
				url:root + 'msg/send_action.php?type=find',
				data:data,
				success: function (data) {
					if(data == 1)
					{
						alert('手机验证码错误，请重新输入！');
						return;
					}else
					{
						$('#find-code-btn').hide();
						$('#chk_find-code-btn').show();
						find_code.focus();	
					}
				
					
				},
				cache: false
			});
			
			
			/*$('.find_code').hide();
			$('.new_pwd').show();*/
					
				
		});
		
		
		$('#chk_find-code-btn').click(function(){
			var find_code = $("#find_code");
			var findCode = find_code.val();
			
			var data = $("#formSend").serialize();
		
			$.ajax({
				type:'POST',
				url:root + 'msg/send_action.php?type=find&find_code='+findCode,
				data:data,
				success: function (data) {	
					if(data == '2')				
					{
						$('.find_code').hide();
						$('.new_pwd').show();
						find_code.focus();
					}else{
						alert('手机验证码错误！');	
					}
				
					
				},
				cache: false
			});

		});
		
		
		$('#new-pwd-btn').click(function(){
			
			var new_pwd = $('#new_pwd').attr('value');
			var new_pwd_checked = $('#chk_pwd').attr('value');
			
			var my_account = $("#find-mobile");
			var account = my_account.val();
		
			
			
			if(new_pwd != new_pwd_checked)
			{
				alert('两次密码不一致');
				return;
			}
		
			$.post("?m=member.editpwdByAccount", {account:account ,  new_pwd:new_pwd , new_pwd_checked:new_pwd_checked, ktvFindCode:1 }, function(data) {
				alert('修改成功');
				parent.location.reload();   

			});
		});
		
		
		

		
	});