<div class="hint"><h3>修改密码</h3></div>
<form method="post" name="frmedit" id="frmedit">
<input type="hidden" name="action" id="action" value="update" />
<div class="m-sec">
	<div class="sub">旧密码:</div>
	<div class="main main-2">
		<div class="inner">
			<input type="password" name="oldpass" id="oldpass" class="inptxt" />
			<label class="tips" id="oldpass_info">如未设置旧密码请留空</label>
		</div>
	</div>
</div>
<div class="m-sec">
	<div class="sub">新密码:</div>
	<div class="main main-2">
		<div class="inner">
			<input type="password" name="newpass" id="newpass" class="inptxt" onfocus="showTip(this,'newpass')" onblur="showTips(this,'newpass')" />
			<label class="tips" id="newpass_info"></label>
		</div>
	</div>
</div>
<div class="m-sec">
	<div class="sub">确认密码:</div>
	<div class="main main-2">
		<div class="inner">
			<input type="password" name="repass" id="repass" class="inptxt" onfocus="showTip(this,'repass')" onblur="showTips(this,'repass')" />
			<label class="tips" id="repass_info"></label>
		</div>
	</div>
</div>
<div class="m-sec">
	<div class="sub"></div>
	<div class="main">
		<div class="inner">
			<input type="submit" value="提交修改" class="post_submit">
		</div>
	</div>
</div>
</form>
<script language="javascript" type="text/javascript">
var regminpwd 	= parseInt('{?$config.regminpwd?}');
var regmaxpwd 	= parseInt('{?$config.regmaxpwd?}');
var regnpdifferf= parseInt('{?$config.regnpdifferf?}');
var pwdcomplex	= '{?$config.regchrpwd?}';
var oldpassInfo = new Array(
		" ",
		"原密码不能为空。",
		"请输入原密码");
var newpassInfo = new Array(
		" ",
		"密码设置错误，密码中必须包含小写字母",
		"密码设置错误，密码中必须包含大写字母",
		"密码设置错误，密码中必须包含数字",
		"密码设置错误，密码中必须包含符号",
		"密码设置错误，密码长度太短",
		"密码设置错误，密码太长",
		"密码设置错误，密码不允许和用户名相同",
		"密码设置错误，密码不允以下字符:\ & ' \" ! / * , < > % # ?。",
        getPwdRule());
var repassInfo = new Array(
		" ",
		"两次输入的密码不一致。",
		"请再输入一遍您上面填写的密码");
function getObj(id) {
	return document.getElementById(id);
}
function showTips(obj,type) {
	var key;
	if( type == 'newpass' ) {
		key = checkPwd(obj);
	} else if( type == 'oldpass' ) {
		key = checkPwdOld(obj);
	} else {
		key = checkPwdRepeat(obj);
	}
	if( parseInt(key) == 0 ) {
		getObj(obj.id + '_info').innerHTML = '<img src="{?$saxue_skin_url?}/images/icon/right.png" align="absmiddle">';
	} else {
		getObj(obj.id + '_info').innerHTML = '<img src="{?$saxue_skin_url?}/images/icon/error.png" align="absmiddle">&nbsp;'+eval(obj.id + 'Info')[key];
	}
	return key;		
}
function showTip(obj,type) {
	var lastid = eval(obj.id + 'Info').length - 1;		
	if(eval(obj.id + 'Info')[lastid] != '') {
		getObj(obj.id + '_info').innerHTML = eval(obj.id + 'Info')[lastid];
	}	
}
function checkAll() {
	//ispwdold = showTips(getObj('oldpass'), 'oldpass');
	ispwd = showTips(getObj('newpass'), 'newpass');
	ispwdrepeat = showTips(getObj('repass'), 'repass');
	if (ispwd == 0 && ispwdrepeat == 0) return true;
	return false; 
}
function checkPwdOld(obj){
	if (obj.value.length > 0) {
		return 0;
	} else {
		return 1;
	}
}
function checkPwd(obj) {
	var pwd = obj.value;
	if(pwd.length<regminpwd){
		return 5;
	}else if(regmaxpwd>0 && pwd.length>regmaxpwd) {
		return 6;
	}else if(regnpdifferf>0 && '{?$uname?}'==pwd) {
		return 7;
	}
	if(/[\\/\&\'\"\*\,<>#\?% ]/.test(pwd)){
		return 8;
	}
	if (pwdcomplex!=''){
		var rule = pwdcomplex.split(',');
		var pwdReg;
		for(var i=0;i<rule.length;i++){
			switch(Number(rule[i])){
				case 1:
					pwdReg = /[a-z]/;
					if(!pwdReg.test(pwd)) return 1;
					break;
				case 2:
					pwdReg = /[A-Z]/;
					if(!pwdReg.test(pwd)) return 2;
					break;
				case 3:
					pwdReg = /[0-9]/;
					if(!pwdReg.test(pwd)) return 3;
					break;
				case 4:
					pwdReg = /[^a-zA-Z0-9]/;
					if(!pwdReg.test(pwd)) return 4;
					break;
				default:
					break;
			}
		}
	}
	var pwdRepeat = getObj('repass');
	if(pwdRepeat.value && checkPwdRepeat(pwdRepeat)){
	    getObj('repass_info').innerHTML = '<img src="{?$saxue_skin_url?}/images/icon/error.png" align="absmiddle"> '+repassInfo[1];
	}
	return 0;
}
function checkPwdRepeat(obj){
	if (obj.value==getObj('newpass').value && obj.value.length > 0) {
		return 0;
	} else {
		return 1;
	}
}
function getPwdRule(){
	var intiString 	= "";
	if(regminpwd){
		intiString 	+= "最小长度:"+regminpwd+" ";
	}
	if(regmaxpwd){
		intiString 	+= "最大长度:"+regmaxpwd+" ";
	}
	if(!pwdcomplex){
		return intiString;
	}
	var addString 	= " 必须包含:";
	var rule = pwdcomplex.split(',');
	for(var i=0;i<rule.length;i++){
		switch(Number(rule[i])){
			case 1:
				addString += "小写字母 ";
				break;
			case 2:
				addString += "大写字母 ";
				break;
			case 3:
				addString += "数字 ";
				break;
			case 4:
				addString += "符号 ";
				break;
			default:
				break;
		}
	}
	return intiString + addString;
}
$(function(){
	$("#frmedit").ajaxForm({
		beforeSubmit : function(){
			var check = checkAll();
			if (!check){
				return false;
			}
		},
        dataType: "json",
        success : function(data){
			if(data.flag == 0){
				alert(data.msg);
			}else{
				alert('密码修改成功，请牢记您的新密码');
				location.href='/member/';
			}
        }
    });
})
</script>