<%@ Page Language="C#" MasterPageFile="~/User/Main.Master" EnableViewState="true"
    AutoEventWireup="true" CodeBehind="UserEdit.aspx.cs" Inherits="OAWeb.User.UserEdit" %>

<%@ Register Src="/UserControls/UserLeft.ascx" TagName="TaskNav" TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlace" runat="server">
    <style>
        .TdRight
        {
            text-align: right;
            padding-right: 10px;
            width: 40%;
        }
    </style>

    <script language="javascript" type="text/javascript">
        var xmlHttp = false;
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            try {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e2) {
                xmlHttp = false;
            }
        }
        var type = "", IsSucceed = false;
        function CallCity(objID) {
            var url = "";
            if (objID == "ddlProvinceID") {
                url = "/crm/City.aspx?ID=0"; //省
                type = "First";
            }
            else if (objID == "ddlCityID") {
                url = "/crm/City.aspx?ID=" + document.getElementById("<%=ddlProvinceID.ClientID %>").value; //市
                type = "Second";
            } else if (objID == "txtTelephone") {
                if (document.getElementById(objID).value == "") {
                    IsSucceed = false;
                    return false;
                }
                url = "/crm/City.aspx?state=1&tel=" + document.getElementById(objID).value;

            } else if (objID == "txtMobilePhone" && !IsSucceed) {
                url = "/crm/City.aspx?state=2&mobile=" + document.getElementById(objID).value;
            }

            if (objID == "txtTelephone" || (objID == "txtMobilePhone" && !IsSucceed)) {
                xmlHttp.open("GET", url, false);
                xmlHttp.onreadystatechange = SetProvinceCity;
                xmlHttp.send(null);
                if (objID == "txtMobilePhone") {
                    IsSucceed = false;
                }
            }
            else if (objID == "ddlProvinceID" || objID == "ddlCityID") {
                xmlHttp.open("GET", url, false);
                xmlHttp.onreadystatechange = SetRespond;
                xmlHttp.send(null);
            }

        }

        function SetRespond() {
            if (xmlHttp.readyState == 4) {
                var response = xmlHttp.responseText;
                var _List = response.split(",");
                var obj = null;
                if (type == "First") {
                    obj = document.getElementById("<%=ddlProvinceID.ClientID %>");
                }
                else if (type == "Second") {
                    obj = document.getElementById("<%=ddlCityID.ClientID %>");
                }

                for (var i = obj.options.length - 1; i >= 0; --i)   //撤消原来的列表项
                {
                    obj.options.remove(i)
                }
                for (var i = 0; i < _List.length; i++) {
                    var TypeID_Value = _List[i].split("#");
                    var oOption = document.createElement('OPTION');
                    oOption.text = TypeID_Value[1];
                    oOption.value = TypeID_Value[0];
                    obj.options.add(oOption);
                }
            }
        }

        function SetProvinceCity() {
            if (xmlHttp.readyState == 4) {
                var response = xmlHttp.responseText;
                var _List = response.split(",");
                var obj = document.getElementById("<%=ddlProvinceID.ClientID %>");
                if (_List.length > 1) {
                    bindOptions(obj, _List[0]);
                }

                obj = document.getElementById("<%=ddlCityID.ClientID %>");
                if (_List.length >= 2 && obj.value != _List[1]) {
                    CallCity("ddlCityID");
                    bindOptions(obj, _List[1]);
                }
                if (obj.value == _List[1])
                    IsSucceed = true;
                else
                    IsSucceed = false;
            }
        }

        function bindOptions(obj, value) {
            for (var i = 0; i < obj.options.length; i++) {
                if (obj.options[i].value == value)
                { obj.options.selectedIndex = i; break; }
            }
        }
    </script>

    <div class="w main">
        <div class="right">
            <table class="data_title" cellspacing="3" style="">
                <tr>
                    <td class="data_caption">
                        基本设置
                    </td>
                </tr>
                <tr>
                    <td class="data_field">
                        <table cellpadding="0" cellspacing="0" border="0" class="" style="width: 50%">
                            <tr>
                                <td class="TdRight">
                                    公司名称：
                                </td>
                                <td>
                                    <asp:TextBox ID="txtCustomerName" runat="server" CssClass="text width200">
                                    </asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td class="TdRight">
                                    姓名：
                                </td>
                                <td>
                                    <asp:TextBox ID="txtName" runat="server" CssClass="text width200">
                                    </asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td class="TdRight">
                                    性别：
                                </td>
                                <td>
                                    <asp:DropDownList ID="ddlSex" runat="server">
                                        <asp:ListItem Selected="True" Value="0">未指定</asp:ListItem>
                                        <asp:ListItem Value="1">男</asp:ListItem>
                                        <asp:ListItem Value="2">女</asp:ListItem>
                                    </asp:DropDownList>
                                </td>
                            </tr>
                            <tr>
                                <td class="TdRight">
                                    QQ：
                                </td>
                                <td>
                                    <asp:TextBox ID="txtQQ" runat="server" CssClass="text width200">
                                    </asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td class="TdRight">
                                    手机：
                                </td>
                                <td>
                                    <asp:TextBox ID="txtMobilePhone" runat="server" CssClass="text width200">
                                    </asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td class="TdRight">
                                    电话：
                                </td>
                                <td>
                                    <asp:TextBox ID="txtTelephone" runat="server" CssClass="text width200">
                                    </asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td class="TdRight">
                                    传真：
                                </td>
                                <td>
                                    <asp:TextBox ID="txtFax" runat="server" CssClass="text width200">
                                    </asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td class="TdRight">
                                    电子邮件：
                                </td>
                                <td>
                                    <asp:TextBox ID="txtEmail" runat="server" CssClass="text width200">
                                    </asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td class="TdRight">
                                    网址：
                                </td>
                                <td>
                                    <asp:TextBox ID="txtWeb" runat="server" CssClass="text width200">
                                    </asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td class="TdRight">
                                    邮编：
                                </td>
                                <td>
                                    <asp:TextBox ID="txtPostCode" runat="server" CssClass="text width200">
                                    </asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td class="TdRight">
                                    省份：
                                </td>
                                <td>
                                    <asp:DropDownList ID="ddlProvinceID" runat="server">
                                    </asp:DropDownList>
                                    城市：<asp:DropDownList ID="ddlCityID" runat="server">
                                    </asp:DropDownList>
                                </td>
                            </tr>
                            <tr>
                                <tr>
                                    <td class="TdRight">
                                        地址：
                                    </td>
                                    <td>
                                        <asp:TextBox ID="txtAddress" runat="server" CssClass="text width200">
                                        </asp:TextBox>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                    </td>
                                    <td>
                                        <asp:Button ID="btnChange" runat="server" Text="提 交" OnClick="btnChange_Click" CssClass="btn_77px" />
                                    </td>
                                </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </div>
        <div class="left">
            <uc1:TaskNav ID="TaskNav1" runat="server" />
        </div>
    </div>
</asp:Content>
