var userId;
var obj;
var dataGridWidth = ""; //查询面板宽度
var h = "";
$(function() {
	
	dataGridWidth = document.documentElement.clientWidth;
	h = document.documentElement.clientHeight;
	
	var userName = getParamter("userName");
	userId = getParamter("userId");
	userName = decodeURIComponent(userName);
	$("#userNameId").text(userName);
	$("#changePassId").window('close');
	initPrivilege();
});

function initPrivilege() {
	
	
	
	$.post("login/getUserPrivilege.do", {
	}, function(result) {
		obj = eval("(" + result + ")");
		getMenu(obj);
	});

}
// 获取左侧权限菜单
function getMenu(obj) {
	BUI.use('common/main', function() {
		var j = "";
		var objArray = new Array();
		for ( var i = 0; i < obj.pri.length; i++) {
			j = {id : obj.pri[i].id,text : obj.pri[i].text,href : obj.pri[i].href}, 
			objArray.push(j);
		}
		var config = [ {
			id : '1',
			menu : [ {
				text : '系统模块',
				items : objArray
			} ]
		} ];
		new PageUtil.MainPage({
			modulesConfig : config
		});
	});
}

// 退出
function logout() {
	$.messager.confirm("退出", "确定退出系统？", function(r) {
		if (r) {
			$.ajax({
				url : 'login/logout.do',
				dataType : "json",
				type : 'post',
				async : false,
				success : function(result) {
					if (result.success) {
						window.location = 'login/login.html';
					} else {
						window.location = 'login/login.html';
					}
				}
			});
		}
	});

}

function showLocale(objD) {
	var str, colorhead, colorfoot;
	var yy = objD.getYear();
	if (yy < 1900)
		yy = yy + 1900;
	var MM = objD.getMonth() + 1;
	if (MM < 10)
		MM = '0' + MM;
	var dd = objD.getDate();
	if (dd < 10)
		dd = '0' + dd;
	var hh = objD.getHours();
	if (hh < 10)
		hh = '0' + hh;
	var mm = objD.getMinutes();
	if (mm < 10)
		mm = '0' + mm;
	var ss = objD.getSeconds();
	if (ss < 10)
		ss = '0' + ss;
	var ww = objD.getDay();
	if (ww == 0)
		colorhead = "";
	if (ww > 0 && ww < 6)
		colorhead = "";
	if (ww == 6)
		colorhead = "";
	if (ww == 0)
		ww = "星期日";
	if (ww == 1)
		ww = "星期一";
	if (ww == 2)
		ww = "星期二";
	if (ww == 3)
		ww = "星期三";
	if (ww == 4)
		ww = "星期四";
	if (ww == 5)
		ww = "星期五";
	if (ww == 6)
		ww = "星期六";
	colorfoot = "";
	str = yy + "年" + MM + "月" + dd + "日" + hh + ":" + mm + ":" + ss + " " + ww;
	return (str);
}
function tick() {
	var today;
	today = new Date();
	$("#localtime").text(showLocale(today));
	window.setTimeout("tick()", 1000);
}
tick();
// 修改密码
function changePass() {
	$("#changePassId").window({
		title : '修改密码',
		width : 400,
		height : 230,
		left : (dataGridWidth - 400)/2,
		top : (h - 230)/2,
		closable : false, // 否显示关闭按钮
		collapsible : false, // 是否显示折叠按钮
		minimizable : false, // 是否显示最小化按钮
		maximizable : false, // 是否显示最大化按钮
		close : true, // 初始是否关闭
		modal : true
	});
	$("#changePassId").window('open');
}

function savePass() {
	var pass = $("#passwordId").val();
	var pass1 = $("#password1Id").val();
	var pass2 = $("#password2Id").val();
	$.getJSON("userManage/verifyPass.do?pass=" + pass + "&userId=" + userId,
	function(check) {
		if (!check.flag) {
			$.messager.alert('提示', '旧密码输入错误，请重新输入！', 'error');
		} else {
			if (pass1 != pass2) {
				$.messager.alert('提示', '密码两次输入不一致，请重新输入！', 'error');
			} else {
				// 如果不重复则添加用户
				url = "userManage/changePass.do?pass1=" + pass1	+ "&userId=" + userId;
				$('#passForm').form('submit',{
					url : url,
					onSubmit : function() {
						return $(this).form('validate');
					},
					success : function(result) {
						var result = eval("(" + result + ")");
						if (result.success != '-1') {
							showAlert("提示", result.info,'info', function() {
								// 关闭弹出框
								closeWindow();
							});
						}
					}
				});
			}
		}
	});
}

// 关闭新增或修改窗口
function closeWindow() {
	$("#passForm").form('clear');
	$("#changePassId").window('close');
}
