$(document).ready(function(){ 
	$("#stp1").show();
	$("#stp2").hide();
	$("#stp3").hide();
	$("#gonext").click( function() { 
		if($.trim($("#user").val())=="")
		{
			alert('用名不能為空');
		}
		else
		{
			$.ajax({
				beforeSend:function(){$("#msg").html("正在加載");},
				type: "post",
				url:"user.php?act=check",
				data:"username="+$("#user").val(),
				success: function(comm){
					if(comm=="用名不存在")
					{
						$("#msg").html(comm);
						alert(comm);
					}
					else
					{
						$("#msg").html("輸入正確");
						alert("進入一下步，密碼提示問題");
						$("#msg").html("填寫答案");
						$("#wenti").html(comm);
							$("#stp2").show();
							$("#stp1").hide();
							$("#stp3").hide();
					}
					
				},
			error:function(err){
				$("#msg").html("鏈接出錯");
			}
		});
		}
	
	 } ); 
	 
	 
	 
	 $("#gonext2").click( function() { 
		if($.trim($("#huida").val())=="")
		{
			alert('答案不能為空');
		}
		else
		{
			$.ajax({
				beforeSend:function(){$("#msg").html("正在傳送");},
				type: "post",
				url:"user.php?act=wenti",
				data:"huida="+$("#huida").val(),
				success: function(comm){
					if(comm=="答案錯誤")
					{
						$("#msg").html(comm);
						alert(comm);
					}
					else
					{
						
						$("#msg").html("輸入正確");
						alert("進入一下步:修改密碼");
						$("#msg").html("填寫新密碼");
						$("#wenti").html(comm);
							$("#stp3").show();
							$("#stp2").hide();
							$("#stp1").hide();
					}
					
				},
			error:function(err){
				$("#msg").html("鏈接出錯");
			}
		});
		}
	
	 } ); 
	 
	 
	 	 
	 $("#goend").click( function() { 
		if($.trim($("#passwd1").val())=="" || $.trim($("#passwd2").val())=="")
		{
			alert('密碼不能空');
		}
		else if($.trim($("#passwd1").val())!=$.trim($("#passwd2").val()))
		{
			alert("輸入的密碼不相等")
		}
		else
		{
			$.ajax({
				beforeSend:function(){$("#msg").html("正在傳送");},
				type: "post",
				url:"user.php?act=pwd",
				data:"pwd="+$("#passwd1").val(),
				success: function(comm){
					if(comm=="修改失敗")
					{
						$("#msg").html(comm);
						alert(comm);
					}
					else
					{
						$("#stp3").html(comm)
						$("#msg").html("修改成功");
							
					}
					
				},
			error:function(err){
				$("#msg").html("鏈接出錯");
			}
		});
		}
	
	 } ); 



 }); 


