<%@ Page CodeBehind="regedit.aspx.cs" Language="c#" AutoEventWireup="True" Inherits="Webdisk.regedit" %>

<%@ Import Namespace="Webdisk" %>
<link href="<%=xml.GetStyle()%>" type="text/css" rel="stylesheet">
<style type="text/css">
    .style5
    {
        color: #ff0000;
    }
</style>
<form id="Form1" runat="server">
<div class="menuBlock" id="show1" runat="server" style="background:#fff;">
<input type="hidden" id="hiddenOldEmail" runat="server" />
    <div class="menuHead" style="overflow: hidden; border-bottom: 1px dashed #cfcfcf;">
        <h2 style="font-size: 18px; color: #1EA7DF;">
            <img src="pics/contacts.gif" align="absMiddle">
            修改注册资料</h2>
    </div>
    <table class="form-table">
        <tbody>
        <tr>
            <td class="label">
                用 户 名：
            </td>
            <td>
                <span id="username"><%=vusername%></span><a data-href="regedit.aspx?pass=1" data-id="show2" class="show_html" href="javascript:void(0);" style='margin-left: 20px;
                    color: #1EA7DE;'>点此修改密码</a>
            </td>
        </tr>
        <tr id="tdDept" runat="server">
            <td class="label">
                所在部门：
            </td>
            <td>
                <select name="dept" id="dept" class="input4" onchange="javascript:setValue()" runat="server">
                    <option selected></option>
                </select>
                <input type="hidden" id="hidDept" runat="server"/>
                &nbsp;<span id="adddept2" runat="server"><a style='margin-left: 20px; color: #1EA7DE;'
                    href="javascript:void(0)" class="getOtherDept" data-other="2">指定另外部门</a></span>
            </td>
        </tr>
        <tr style="display: none" id="tdshow2" runat="server">
            <td class="label">
                所在部门2：
            </td>
            <td>
                <select name="dept2" class="input4" id="dept2" runat="server">
                    <option selected></option>
                </select>
                &nbsp;<span id="adddept3" runat="server"><a style='margin-left: 20px; color: #1EA7DE;'
                    href="javascript:void(0)" class="getOtherDept" data-other="3">指定另外部门</a></span>
            </td>
        </tr>
        <tr style="display: none" id="tdshow3" runat="server">
            <td class="label">
                所在部门3：
            </td>
            <td>
                <select name="dept3" id="dept3" class="input4" runat="server" >
                    <option selected></option>
                </select>
                &nbsp;<span id="adddept4" runat="server"><a style='margin-left: 20px; color: #1EA7DE;'
                    href="javascript:void(0)" class="getOtherDept" data-other="4">指定另外部门</a></span>
            </td>
        </tr>
        <tr style="display: none" id="tdshow4" runat="server">
            <td class="label">
                所在部门4：
            </td>
            <td>
                <select name="dept4" id="dept4" class="input4" runat="server">
                    <option selected></option>
                </select>
                &nbsp;<span id="adddept5" runat="server"><a style='margin-left: 20px; color: #1EA7DE;'
                    href="javascript:void(0)" class="getOtherDept" data-other="5">指定另外部门</a></span>
            </td>
        </tr>
        <tr style="display: none" id="tdshow5" runat="server">
            <td class="label">
                所在部门5：
            </td>
            <td>
                <select name="dept5" id="dept5" class="input4" runat="server">
                    <option selected></option>
                </select>
            </td>
        </tr>
        <tr>
            <td class="label">
                所属角色：
            </td>
            <td>
                <label runat="server" id="role" name="role"/>
                <%--<select id="role" class="input4" name="role" runat="server"   disabled="disabled">
                    <option value="0">请选择</option>
                    <option value="3">管理</option>
                    <option value="1">教师</option>
                    <option value="2">学生</option>
                </select>--%>
                <input id="hidrole" type="hidden" runat="server" />
            </td>
        </tr>
        <tr>
            <td class="label">
                电子邮箱：
            </td>
            <td>
                <input class="input3" id="email" name="email" runat="server" >
                <span class="style5">*
				<span id="emailError"></span>
                    <asp:requiredfieldvalidator id="RequiredFieldValidator3" runat="server" display="Dynamic"
                        errormessage="请输入邮件地址" controltovalidate="email"></asp:requiredfieldvalidator>
                    <asp:regularexpressionvalidator id="RegularExpressionValidator3" runat="server" display="Dynamic"
                        errormessage="错误的电子邮件地址" controltovalidate="email" validationexpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:regularexpressionvalidator>
                </span>
            </td>
        </tr>
        <tr>
            <td class="label">
                性 别：
            </td>
            <td>
                <asp:radiobuttonlist id="sex" runat="server" repeatlayout="Flow" width="80px" repeatdirection="Horizontal"
                   >
								<asp:ListItem Value="男" Selected="True">男</asp:ListItem>
								<asp:ListItem Value="女">女</asp:ListItem>
							</asp:radiobuttonlist>
            </td>
        </tr>
        <tr>
            <td class="label">
                真实姓名：
            </td>
            <td>
                <input class="input3" id="realname" name="realname" runat="server">
            </td>
        </tr>
        <tr>
            <td class="label">
                联系电话：
            </td>
            <td>
                <input class="input3" id="phone" name="phone" runat="server">
				<span class="style5">*<span id="telError"></span></span>
            </td>
        </tr>
        <tr>
            <td class="label">
            </td>
            <td>
                <input class="but1" id="Submit1" type="button" value="保存"  name="Button1" runat="server">
                <span style="margin-left: 30px;" class="style5" id="okError"></span> 
            </td>
        </tr></tbody>
    </table>
    <br>
    <br>
</div>
<div class="menuBlock" id="show2" runat="server"  style="background:#fff;">
    <div class="menuHead" style="overflow: hidden; border-bottom: 1px dashed #cfcfcf;">
        <h2 style="font-size: 18px; color: #1EA7DF;">
            <img src="pics/contacts.gif" align="absMiddle">
            修改用户密码</h2>
    </div>
    <table class="form-table">
        <tbody>
            <tr>
                <td class="label" style="width:150px;">
                    用 户 名：
                </td>
                <td>
                    <%=vusername%>
					<a data-href="regedit.aspx" data-id="show1" class="show_html" href="javascript:void(0);" style='margin-left: 20px;
                        color: #1EA7DE;'>点此修改用户资料</a>
                </td>
            </tr>
            <tr id="hidepass" runat="server">
                <td class="label">
                    旧 密 码：
                </td>
                <td>
                    <input class="input3" id="Password" type="password" name="Password" runat="server">
					<span class="style5">*
						<span id="opError"></span>
						</span>
                </td>
            </tr>
            <tr>
                <td class="label">
                    新&nbsp;密&nbsp;码：
                </td>
                <td>
                    <input class="input3" id="Password1" type="password" name="Password1" runat="server">
					<span class="style5">*<span id="pError"></span></span>
                </td>
            </tr>
            <tr>
                <td class="label">
                    重复新密码：
                </td>
                <td>
                    <input class="input3" id="Password2" type="password" name="Password2" runat="server">
					<span class="style5">*<span id="rpError"></span></span>
                </td>
            </tr>
            <tr>
                <td class="label">
                </td>
                <td>
                    <input class="but1" id="Submit2" type="button" value="确认修改" name="Submit2" runat="server">
					<span  class="style5" id="okpError" style="margin-left: 30px;"></span> 
                </td>
            </tr>
        </tbody>
    </table>
    <br>
    <br>
    <br>
</div>
</form>

<script language="javascript">
	var Regedit = {};
	Regedit.init = function(){
		this.addEvent();
	}
	Regedit.addEvent = function(){
		
		var that = this ;
		//切换页面
		$(".show_html").click(function(){
			$("#"+$(this).data("id")).show().siblings().hide();
		});
		//获取另外部门
		$(".getOtherDept").click(function(){
			var id = "tdshow"+$(this).data("other");
			$(this).hide();
			$("#"+id).show();
			$("#dept"+$(this).data("other")).html($("#dept").html()).val("0");
		});
		//保存更改个人信息
		$("#Submit1").click(function(){
			if(!$(this).hasClass("disabled")){
				that.submitInfo();
			}
		});
		//修改密码
		$("#Submit2").click(function(){
			that.submitPass();
		});
	}
	/**
	*修改密码
	*/
	Regedit.submitPass = function(){
		var that = this ;
		var _user = $.trim($("#username").text());
		var _oldPass = $.trim($("#Password").val());
		var _pass = $.trim($("#Password1").val());
		var _pass1 = $.trim($("#Password2").val());
		var error = $("#opError").html("");
		if(_oldPass == ""){
			error.html("旧密码不能为空");
			return false ;
		}
		error = $("#pError").html("");
		if(_pass == ""){
			error.html("新密码不能为空");
			return false ;
		}
		error = $("#rpError").html("");
		if(_pass1 == ""){
			error.html("确认密码不能为空");
			return false ;
		}
		if(_pass != _pass1){
			error.html("两次输入密码不一致");
			return false ;
		}
		error = $("#okpError").html("");
		var d = dialog();
		d.showModal();
		$.ajax({
			url :"OtherHandler.ashx?cmd=UpdatePassWord",
			cache:false,
			data : {password:_oldPass,password1:_pass,user:_user},
			type :"POST",
			dataType : "json",
			success : function(data){
				console.log(data);
				if(data.code == 100){
					location.href="/login.aspx";
				}else if(data.code == 0 ){
				d.content(data.msg);
				
				setTimeout(function(){
					d.close().remove();
				},2000);
				}else{
					d.close().remove();
					error.html(data.msg);
				}
			}
		});
	}
	/**
	*修改个人资料
	*/
	Regedit.submitInfo = function(){
		var that = this ;
		var error ;
		var _user = $.trim($("#username").text());
		
		var _dept = $("#dept").val();
		var _dept2 = $("#dept2").val();
		var _dept3 = $("#dept3").val();
		var _dept4 = $("#dept4").val();
		var _dept5 = $("#dept5").val();
		var _role = $("#role").val();
		
		var _email = $.trim($("#email").val());
		var _oldEmail = $("#hiddenOldEmail").val();
		
		var _sex = $('input[name="sex"]:checked').val();
		var _realname = $.trim($("#realname").val());
		var _phone = $.trim($("#phone").val());
		
		error = $("#emailError").html("");
		if(_email == ""){
			error.html("电子邮箱不能为空");
			return false;
		}
		if(!/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/.test(_email)){
			error.html("电子邮箱格式不对");
			return false ;
		}
		error = $("#telError").html("");
		if(_phone !="" && !/(^(\d{3,4}-)?\d{7,8})$|(1[3,4,5,8][0-9]{9})/.test(_phone)){
			error.html("电话号码格式不对，应该为常用电话号码格式或手机号码格式!");
			return false ;
		}
		
		error = $("#okError").html("")
		var _data = {email:encodeURI(_email),realname:encodeURI(_realname),phone:encodeURI(_phone),dept:encodeURI(_dept),dept2:encodeURI(_dept2),
				dept3:encodeURI(_dept3),dept4:encodeURI(_dept4),dept5:encodeURI(_dept5),role:encodeURI(_role),oldemail:encodeURI(_oldEmail),user:encodeURI(_user),sex:encodeURI(_sex)};
		
		var d = dialog();
		d.showModal();
		$.ajax({
			url : "OtherHandler.ashx?cmd=SaveRegedit",
			cache:false,
			type :"POST",
			data : _data,
			dataType : "json",
			success : function(data){
				if(data.code == "100"){
					location.href="/login.aspx";
				}else if(data.code == 0 ){
					d.content(data.msg);
					setTimeout(function(){
						d.close().remove();
                        if(_dept!=$("#hidDept").val()){
                            window.location="exit.aspx";
                        }
					},2000);
				}else{
					d.close().remove();
					error.html(data.msg);
				}
			}
		});
	}
	
	Regedit.init();
        function editpass() {
            if (document.getElementById("hidepass").style.display != "none") {
                var strTemp = document.Form1.Password.value;
                if (strTemp.length == 0) {
                    alert("请输入旧密码！");
                    document.Form1.Password.focus();
                    return false;
                }
            }
            var strTemp = document.Form1.Password1.value;
            if (strTemp.length == 0) {
                alert("请输入新密码！");
                document.Form1.Password1.focus();
                return false;
            }
            var strTemp = document.Form1.Password1.value;
            var strTemp1 = document.Form1.Password2.value;
            if (strTemp != strTemp1) {
                alert("两次填写密码不一致！");
                document.Form1.Password2.focus();
                return false;
            }
            return true;
        }
        function setValue() { 
            var html = "<%=xml.GetStr(@"regedit/deptchang") %>";
			var d = dialog({
				content : html ,
				title : "温馨提示",
				okValue: '确定',
				ok: function () {
				}
			});
           d.showModal();
        }
</script>