$(function(){

	$("#savePwdBtn").click(function(){
		var uname = localStorage.uname; // 用户名
		var utype = localStorage.utype; // 管理员 1
		if(uname==''||utype==''||uname==undefined||utype==undefined){
			layer.msg('您当前还未登录，退出登录后操作',{icon: 5});
			return false;
		}
		if(utype!=1){
			layer.msg('非管理员禁止操作',{icon: 5});
			return false;
		}

		var pwd=$.trim($("#pwd").val());
		var newpassword=$.trim($("#newpassword").val());
		var confirmpassword=$.trim($("#confirmpassword").val());
		if(pwd==''){
			layer.msg('请填写当前密码！',{icon: 5});
			return false;
		}
		if(newpassword==''||confirmpassword==''){
			layer.msg('新密码不能为空',{icon: 5});
			return false;
		}

		if(newpassword!=confirmpassword){
			layer.msg('两次密码不相等，请检查',{icon: 5});
			return false;
		}
		var secpwd=$.md5(pwd);
		var npwd = $.md5(newpassword);

		var params = {
				uname:uname,
				pwd:secpwd,
				npwd:npwd
		};
		var _URL = HttpRest+'user/pwd.shtml';
		$.ajax({
			url:_URL,
			type:"post",
			data:$.toJSON(params),   
			dataType: "json",
			async:true,
			contentType:"application/json",
			success:function(data){
				if(data.code=='01'){
					layer.confirm('修改密码成功!需重新登录', function(index) {
						/*layer.close(index);
						 *var index = parent.layer.getFrameIndex(window.name);
						 *parent.layer.close(index); //再执行关闭   
						 */					
						localStorage.hostId = '';
						localStorage.utype = '';
						localStorage.uname = '';
						localStorage.pwd = '';
						window.location.href = HttpRest+'system/login.shtml';
					});
				}else{
					layer.msg(data.msg,{icon: 5});
				}
			}
		});

	});

});