<?php
$group = Mage::getModel('customer/group');
$group->load(Mage::getModel('customer/session')->getCustomerGroupId());
?>
<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>

<form action="<?php echo $this->getUrl('customer/account/editPost') ?>" method="post" id="form-validate">
	<div class="fieldset"> <?php echo $this->getBlockHtml('formkey')?>
		<h2 class="legend"><?php echo $this->__('Account Information') ?></h2>
		<ul class="form_list">
			<li class="fields"><span class="label-like">会员等级</span><strong><?php echo $group->getCode(); ?></strong></li>
			<li class="fields"> <?php echo $this->getLayout()->createBlock('customer/widget_name')->setObject($this->getCustomer())->toHtml() ?> </li>
			
			<li class="fields"> <!-- 邮箱地址是必须的 -->
				<span class="label-like"><?php echo $this->__('Email Address') ?><span class="required">*</span></span>
				<div class="input-box">
					<input type="text" name="email" id="email" value="<?php echo $this->htmlEscape($this->getCustomer()->getEmail()) ?>" class="input-text" validata="required:true,email:true"/>
					<span class="prompt-msg" message="<?php echo $this->__('Please enter email');?>"></span>
				</div>
			</li>
			
			<li class="fields">
				<span class="label-like"><?php echo $this->__('User Name') ?><?php if($this->isRegisterRequireLoginAttribute('username')):?><span class="required">*</span><?php endif;?></span>
				<div class="input-box">
					<input type="text" name="username" id="username" value="<?php echo $this->htmlEscape($this->getCustomer()->getUsername()) ?>" class="input-text" validata="username:true<?php if($this->isRegisterRequireLoginAttribute('username')){echo ',required:true';}?>"/>
				</div>
			</li>
			
			<li class="fields"><span class="label-like"><?php echo $this->__('Telephone') ?><?php if($this->isRegisterRequireLoginAttribute('telephone')):?><span class="required">*</span><?php endif;?></span>
				<div class="input-box">
					<input type="text" name="telephone" id="telephone" value="<?php echo $this->htmlEscape($this->getCustomer()->getTelephone()) ?>" class="input-text" validata="<?php if($this->isRegisterRequireLoginAttribute('telephone')){echo 'required:true';}?>"/>
					<span class="prompt-msg" message="<?php echo $this->__('Please enter telephone.');?>"></span>
				</div>
			</li>
			<li class="fields"><span class="label-like"><?php echo $this->__('Mobile') ?><?php if($this->isRegisterRequireLoginAttribute('mobile')):?><span class="required">*</span><?php endif;?></span>
				<div class="input-box">
					<input type="text" name="mobile" id="mobile" value="<?php echo $this->htmlEscape($this->getCustomer()->getMobile()) ?>" class="input-text" validata="number:11<?php if($this->isRegisterRequireLoginAttribute('mobile')){echo ',required:true';}?>"/>
					<span class="prompt-msg" message="<?php echo $this->__('Please enter mobile.');?>"></span>
				</div>
			</li>
			
			<?php $_dob = $this->getLayout()->createBlock('customer/widget_dob') ?>
			<?php if ($_dob->isEnabled()): ?>
			<li class="fields"><?php echo $_dob->setDate($this->getCustomer()->getDob())->toHtml() ?></li>
			<?php endif ?>
			<?php $_gender = $this->getLayout()->createBlock('customer/widget_gender') ?>
			<?php if ($_gender->isEnabled()): ?>
			<li class="fields"><?php echo $_gender->setGender($this->getCustomer()->getGender())->toHtml() ?></li>
			<?php endif ?>
			<li class="fields">
				<div class="input-box">
					<input type="checkbox" class="checkbox" title="Change Password" id="change_password" name="change_password">
					<span><label for="change_password"><?php echo $this->__('Change Password');?></label></span>
				</div>
			</li>
		</ul>
		<ul class="form_list changePassword" style="display:none;">
			<?php if (!$this->getCustomer()->getNotVerifyCurrentPassword()):?>
			<li class="fields"> <span class="label-like"><?php echo $this->__('Current Password') ?>:</span>
				<div class="input-box">
					<input type="password" class="input-text current_password" name="current_password" id="current_password"/>
					<span class="prompt-msg" message="<?php echo $this->__('Please enter password');?>"></span>
				</div>
			</li>
			<?php endif;?>
			<li class="fields"> <span class="label-like"><?php echo $this->__('New Password') ?>:</span>
				<div class="input-box">
					<input type="password" class="input-text password" name="password" id="password"/>
					<span class="prompt-msg" message="<?php echo $this->__('Please enter new password');?>"></span>
				</div>
			</li>
			<li class="fields"><span class="label-like"><?php echo $this->__('Confirm New Password') ?>:</span>
				<div class="input-box">
					<input type="password" class="input-text conpassword" name="confirmation" id="confirmation"/>
					<span class="prompt-msg" message="<?php echo $this->__('Please enter confirm password');?>"></span>
				</div>
			</li>
		</ul>
		<div style="padding-left: 9.5em;">
			<button type="submit" class="button"><span><span><?php echo $this->__('Save') ?></span></span></button>
		</div>
	</div>
</form>
<script type="text/javascript">
//<![CDATA[
var checkPassword = function(){
	if($('#password').val()!=$('#confirmation').val()){
		return {fail:true, msg:"<?php echo $this->__('Two input password does not agree.');?>"};
	}
	return true;
};
$(function() {
	var accountForm = makingware.form.getInstance('#form-validate', {
    	 error: {
    		 required: '<?php echo Mage::helper('core')->__('Required Fields');?>',
             minLength: '<?php echo Mage::helper('core')->__('At least %s characters');?>',
             number1: '<?php echo Mage::helper('core')->__('Must be a number');?>',
 			 number2: '<?php echo Mage::helper('core')->__('Must be %s digits');?>',
             email: '<?php echo Mage::helper('core')->__('Invalid %s address');?>',
             username: '<?php echo Mage::helper('core')->__('Invalid user name');?>'
         }
	 });
	accountForm.submit(function(){
		 return $(this).data('this').isValidata();
	 });

	$("#change_password").change(function(){
		if ($(this).attr('checked')) {
			$('.form_list.changePassword').show();
			<?php if (!$this->getCustomer()->getNotVerifyCurrentPassword()):?>
			$('#current_password').attr('validata','required:true');
			<?php endif;?>
			$('#password').attr('validata','required:true');
			$('#confirmation').attr('validata','required:true,method:checkPassword');
		}else {
			$('.form_list.changePassword').hide();
			accountForm.unvalidata('.changePassword');
		}
	});
	 
	 <?php if ($this->getCustomer()->getChangePassword()):?>
	 	$("#change_password").attr('checked', true).trigger('change');
	 <?php endif;?>
});
//]]>
</script>