$(document).ready(function () {
	old_btn_getpassword_question = '';
	if (document.body.scrollHeight < window.screen.height) height = window.screen.height;
	else height = document.body.scrollHeight;
	$('#Warting').css('height', height);
	var insertHtmlToPasswordAnswerForm = function(html_data) {
		$('#PasswordAnswerForm').html(html_data);
		$('#FormSubmit').click(resetUserPassword);
		$('#FormReset').click(resetPasswordQuestion);
		$('#BackWhenError').click(function () {
			$('#PasswordAnswerResult').hide();
			$('#PasswordAnswerForm').hide();
			resetPasswordQuestion();
		});
		$('#formGetPasswordBack input').keypress(function (e) {
			if (e.keyCode == 13) resetUserPassword();
		});
		$('#PasswordAnswerForm').show();
		$('#WaitingImage').hide();
		$('#Warting').hide();closeWindow();
	};
	var insertHtmlToPasswordAnswerResult = function(html_data) {
		$('#PasswordAnswerForm').hide();
		$('#PasswordAnswerResult').html(html_data);
		$('#BackWhenError').click(function () {
//			resetPasswordQuestion();
			$('#PasswordAnswerResult').hide();
			$('#PasswordAnswerForm').show();
		});
		$('#PasswordAnswerResult').show();
		$('#WaitingImage').hide();
		$('#Warting').hide();closeWindow();
	};
	var fetchPasswordQuestion = function () {
		old_btn_getpassword_question = $('#btnGetPasswordQuestion').val();
		if ($('#login_name').val())
		{
			$('#Warting').css('display', 'block');showWindow();
			$('#WaitingImage').css('display', 'block');
			$.post('/index.php/memberpanel/printGetPasswordQuestion', {login_name : $('#login_name').val()}, insertHtmlToPasswordAnswerForm);
			$('#login_name').attr('disabled', 'disabled');
			$('#login_name').attr('readonly', 'readonly');
			$('#btnGetPasswordQuestion').val('重新输入登录账号');
		}
		else alert('请输入您的登录账号');
	};
	var resetPasswordQuestion = function () {
		$('#PasswordAnswerForm').hide();
		$('#PasswordAnswerResult').hide();
		$('#btnGetPasswordQuestion').val(old_btn_getpassword_question);
		$('#login_name').removeAttr('disabled');
		$('#login_name').removeAttr('readonly');
	};
	var resetUserPassword = function () {
		$('#Warting').show();showWindow();
		$('#WaitingImage').show();
		$.post('/index.php/memberpanel/getPasswordQuestion', $('#formGetPasswordBack').formToArray(), insertHtmlToPasswordAnswerResult);
		return false;
	};

	$('#btnGetPasswordQuestion').toggle(fetchPasswordQuestion, resetPasswordQuestion);
	$('#login_name').keypress(function (e) {
		if (e.keyCode == 13) fetchPasswordQuestion();
	});
	$('#formGetPasswordBack').submit(function () {
		resetUserPassword();
		return false;
	});
});
