var divHeight = ""; // 查询面板高度
var dataGridWidth = ""; // 查询面板宽度
var dataGridHeight = "";
var bodyWidth = 0;
var bodyHeight = 0;
var operation = "";
var addWinWidth = 0; // 新增窗口宽度
var addWinHeight = 0; // 新增窗口高度
var bodyWidth = 0;
var bodyHeight = 0;
var operation = "";
var userEmailId = "";

$(function() {
	openPwd();

	$("#sendMailWinId").window('close');
	
	divHeight = $("#queryDiv").height();
	dataGridWidth = $("#queryDiv").width();
	dataGridHeight = divHeight + 28;

	bodyWidth = document.body.clientWidth;
	bodyHeight = document.documentElement.clientHeight;
	addWinWidth = (bodyWidth / 100) * 80
	addWinHeight = (addWinWidth / 16) * 9

	
	
	$('#editpass').click(function() {
		$('#w').window('open');
	});

	$('#btnEp').click(function() {
		serverLogin();
	})

	$('#btnCancel').click(function() {
		closePwd();
	})

	$('#loginOut').click(function() {
		$.messager.confirm('系统提示', '您确定要退出本次登录吗?', function(r) {
			if (r) {
				location.href = '/admin/logout';
			}
		});
	})
});

var _menus = {
	"menus" : [ {
		"menuid" : "1",
		"icon" : "icon-sys",
		"menuname" : "系统管理",
		"menus" : [ {
			"menuid" : "11",
			"menuname" : "部门管理",
			"icon" : "icon-set",
			"url" : "/admin/org/goinOrgListPage"
		}, {
			"menuid" : "12",
			"menuname" : "用户管理",
			"icon" : "icon-users",
			"url" : "/admin/user/queryAllUser"
		}, {
			"menuid" : "13",
			"menuname" : "角色管理",
			"icon" : "icon-role",
			"url" : "/admin/role/goinRoleListPage"
		}, {
			"menuid" : "14",
			"menuname" : "权限管理",
			"icon" : "icon-role",
			"url" : "/admin/privilegeManage/goinPriListPage"
		}, {
			"menuid" : "15",
			"menuname" : "角色权限分配",
			"icon" : "icon-role",
			"url" : "/admin/privilegeManage/goRolePriListPage"
		}, {
			"menuid" : "16",
			"menuname" : "数据字典管理",
			"icon" : "icon-database",
			"url" : "/admin/metadataManage/goinMetadataListPage"
		} ]
	}, {
		"menuid" : "2",
		"icon" : "icon-sys",
		"menuname" : "业务管理",
		"menus" : [ {
			"menuid" : "21",
			"icon" : "icon-nav",
			"menuname" : "会员管理",
			"url" : "/business/memberBaseInfoManage/goinMemberBaseInfoListPage"
		}, {
			"menuid" : "22",
			"icon" : "icon-nav",
			"menuname" : "活动管理",
			"url" : "/admin/newsManage/goinNewsListPage_en"
		}, {
			"menuid" : "23",
			"icon" : "icon-nav",
			"menuname" : "邮件管理",
			"menus" : [ {
				"menuid" : "231",
				"icon" : "icon-nav",
				"menuname" : "已发送邮件",
				"url" : "/admin/logManage/goinLogInfoListPage"
			}, {
				"menuid" : "232",
				"icon" : "icon-nav",
				"menuname" : "草稿箱",
				"url" : "/admin/logManage/goinLogInfoListPage"
			} ]
		}, {
			"menuid" : "24",
			"icon" : "icon-nav",
			"menuname" : "客户服务",
			"menus" : [ {
				"menuid" : "231",
				"icon" : "icon-nav",
				"menuname" : "待处理事项",
				"url" : "/admin/logManage/goinLogInfoListPage"
			}, {
				"menuid" : "232",
				"icon" : "icon-nav",
				"menuname" : "已处理事项",
				"url" : "/admin/logManage/goinLogInfoListPage"
			} ]
		} ]
	}, {
		"menuid" : "56",
		"icon" : "icon-sys",
		"menuname" : "日志管理",
		"menus" : [ {
			"menuid" : "31",
			"icon" : "icon-nav",
			"menuname" : "统计日志",
			"url" : "/admin/logManage/goinLogInfoListPage"
		} ]
	} ]
};
// 设置登录窗口
function openPwd() {
	$('#w').window({
		title : '修改密码',
		width : 400,
		height : 200,
		modal : true,
		shadow : true,
		closed : true,
		collapsible : false, // 是否显示折叠按钮
		minimizable : false, // 是否显示最小化按钮
		maximizable : false, // 是否显示最大化按钮
		resizable : false
	});
}
// 关闭登录窗口
function closePwd() {
	$('#w').window('close');
}

// 修改密码
function serverLogin() {
	var $newpass = $('#txtNewPass');
	var $rePass = $('#txtRePass');

	if ($newpass.val() == '') {
		msgShow('系统提示', '请输入密码！', 'warning');
		return false;
	}
	if ($rePass.val() == '') {
		msgShow('系统提示', '请在一次输入密码！', 'warning');
		return false;
	}

	if ($newpass.val() != $rePass.val()) {
		msgShow('系统提示', '两次密码不一至！请重新输入', 'warning');
		return false;
	}

	$.post('/admin/user/changePass/' + $newpass.val(), function(msg) {
		msgShow('系统提示', '恭喜，密码修改成功！<br>您的新密码为：' + $newpass.val(), 'info');
		$newpass.val('');
		$rePass.val('');
		$("#w").window('close');
	})

}

function initInput_emilWin(){
	$("#serverHostId").attr("style","width:"+ smallWinInputShort()+"px");
	$("#serverPortId").attr("style","width:"+ smallWinInputShort()+"px");
	$("#emailCountId").attr("style","width:"+ smallWinInputShort()+"px");
	$("#emailPasswordId").attr("style","width:"+ smallWinInputShort()+"px");
	$("#serverProtocolId").combobox({
		width:smallWinInputShort()+4 
	});
	
}


/**
 * 打开修改窗口
 */  
function setEmail(){
	initInput_emilWin();
	$.getJSON("/admin/user/queryUserEmailById" , function(data) {
		if(null == data){
			operation = "add";
		}else {
			userEmailId = data.id;
			operation = "edit";
		}
		$("#emailCountForm").form('load', data); 
	});    
	$("#sendMailWinId").window({  
		title : '设置邮箱信息',  
		width : 600,
		height : 300, 
		left : (bodyWidth - 660)/2,
		top : (bodyHeight - 300)/2, 
		closable : true, // 否显示关闭按钮
		collapsible : false, // 是否显示折叠按钮
		minimizable : false, // 是否显示最小化按钮
		maximizable : false, // 是否显示最大化按钮
		close : true, // 初始是否关闭
		modal : true 
	}); 
	$("#sendMailWinId").window('open');
}

//保存数据
function saveMail(){
	var url = "";
	if('add' == operation){
		url = "/admin/user/addOrUpdateUserEmail?operation="+operation;
		$('#emailCountForm').form('submit',{
			url: url,
			onSubmit: function(){
				return $(this).form('validate');
			},
			success: function(data){
				var data = eval("("+data+")");
				if (data.flag){
					$.messager.alert('提示', data.info, 'ok');
					closeWindow();
				} else {
					$.messager.alert("提示",data.info,'error');
				}
			}
		});    
	}
	if('edit' == operation){ 
		url = "/admin/user/addOrUpdateUserEmail?userEmailId="+userEmailId+"&operation="+operation;
		$('#emailCountForm').form('submit',{
			url: url,
			onSubmit: function(){
				return $(this).form('validate');
			},
			success: function(data){
				var data = eval("("+data+")")
				if (data.flag){
					$.messager.alert('提示',data.info, 'ok');
					closeWindow();
				} else {
					$.messager.alert("提示",data.info,'error');
				}
			}
		}); 
	}
}

function closeWindow(){
	$("#sendMailWinId").window('close');
}

/**
 * 弹出窗口输入项少的，长输入框和小输入框统一确定长度标准
 * 小窗口长输入框长度
 */
function smallWinInputLong(){
	var borwserType = judgeBrowser();
	if(borwserType == "IE"){
		return 660*0.841;
	}else if(borwserType == "Firefox"){
		return 660*0.841;      
	}else if(borwserType == "Safari"){
		return 660*0.841;   
	}else if(borwserType == "Opera"){
		return 660*0.841;   
	}else {
		return 660*0.841;            
	}
}
/**
 * 小窗口短输入框长度
 */
function smallWinInputShort(){
	var borwserType = judgeBrowser();
	if(borwserType == "IE"){
		return 660*0.841;
	}else if(borwserType == "Firefox"){
		return 660*0.841;     
	}else if(borwserType == "Safari"){
		return 660*0.841;
	}else if(borwserType == "Opera"){
		return 660*0.841;    
	}else {
		return 660*0.336;            
	}
}

/**
 * 判断浏览器类型
 */
function judgeBrowser(){
	var bro=$.browser;
    var browserType = "";
    if(bro.msie) {
    	browserType = "IE"; 
    }
    if(bro.mozilla) {
    	browserType = "Firefox";
    } 
    if(bro.safari) {
    	browserType = "Safari";
    }
    if(bro.opera) {
    	browserType = "Opera";
    }
    return browserType;
}
