<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="areaadd.aspx.cs" Inherits="JuSNS.Web.system.sys.areaadd" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title id="ptitle" runat="server">增加地区</title>
    <link href="../images/css/style.css" rel="stylesheet" type="text/css" />

    <script language="javascript" type="text/javascript" src="../../js/ajax.js"></script>

    <script language="javascript" type="text/javascript" src="../../js/public.js"></script>


</head>
<body>
    <table width="99%" border="0" align="center" cellpadding="5" cellspacing="1">
        <tr>
            <td width="120" align="center" valign="top">
                <div class="menu">
                    <ul>
                        <%=this.GetSystemMenu(sort)%>
                    </ul>
                </div>
            </td>
            <td valign="top">
                <div class="navip">
                    <span class="Blue">
                    <a href="index.aspx">空间管理</a> 
                    <a href="Email.aspx">电子邮件设置</a> 
                    <a href="EmailSend.aspx">邮件通知</a> 
                    <a href="EmailSys.aspx">发送邮件内容编辑</a> 
                    <a href="SysKey.aspx">关键字过滤</a> 
                    <a href="gbook.aspx">留言管理</a> 
                    <a href="EmailSTMP.aspx">邮件服务器设置</a> 
                    <a href="Area.aspx">地区管理</a> 
                        </span>
                </div>
               <div style="padding:6px 8px 0px 8px;">
               <div><a href="area.aspx">地区管理</a> <a href="vo.aspx">行业管理</a></div>
                <form id="form1" runat="server">
                    <input type="hidden" id="txtID" runat="server"/> 
                    <div class="user"><a href="AreaAdd.aspx?r=0">添加一级地区</a> <a href="AreaAdd.aspx?r=1">添加二级地区</a> <a href="AreaAdd.aspx?r=2">添加三级地区</a></div>
                        <table width="100%" border="0" cellpadding="3" cellspacing="1" class="maintable">
                            <tr class="maintablelist" id="Tr_Area0">
                                <td align="right" style="width: 200px;">
                                    一级地区</td>
                                <td align="left" style="width: 678px">
                                    <select name="ParentID" id="selArea0" runat="server" onchange="ShowC(this.value);"></select>
                                </td>
                            </tr>
                             <tr class="maintablelist" id="Tr_Area1" style="display:none;">
                                <td align="right" style="width: 200px;">
                                    二级地区</td>
                                <td align="left" style="width: 678px">
                                    <select name="ParentID" id="selArea1" runat="server"></select>
                                </td>
                            </tr>
                            <tr class="maintablelist">
                                <td align="right" style="width: 200px;">
                                    地区名称</td>
                                <td align="left" style="width: 678px">
                                   <input type="text" id="txtAreaName" runat="server"/>
                                </td>
                            </tr>
                            <tr class="maintablelist">
                                <td align="right" style="width: 200px">
                                </td>
                                <td align="left" colspan="2">
                                   <input type="button" class="f-button" value="保存" onclick="AddArea();" />
                                </td>
                            </tr>
                        </table>
                    
                </form>
                </div> 
                
            </td>
        </tr>
    </table>
</body>
</html>
<script language="JavaScript" type="text/javascript">
//function $(o){return document.getElementById(o);}

//初始化
function Load()
{
    var r=$("txtID").value;
    
    if(r==0)//添加一级
    {
        $("Tr_Area0").style.display="none";
        $("Tr_Area1").style.display="none";
    }
    else if(r==1)//添加二级
    {
        if($("selArea0").length>0)
        {
            $("Tr_Area0").style.display="";
        }
        else
        {
            $("Tr_Area0").style.display="none";
        }
        $("Tr_Area1").style.display="none";
    }
    else if(r==2)//添加三级
    {
         if($("selArea0").length>0)
        {
            $("Tr_Area0").style.display="";
        }
        else
        {
            $("Tr_Area0").style.display="none";
        }
        if($("selArea1").length>0)
        {
            $("Tr_Area1").style.display="";
        }
        else
        {
            $("Tr_Area1").style.display="none";
        }
    }
}Load();

//根据省加载市
function ShowC(id)
{
    if($("txtID").value!=2)return;
     var  options={  
				   method:'post',  
				   parameters:"id="+id+"&r="+$("txtID").value+"&Type=City",  
				   onComplete:function(transport)
					{ 
					    var v=transport.responseText;
					    if (v.indexOf("??")>-1)
					    {
					        alert('对不起，该地区还没有二级地区，不能添添加三级地区！');
					        window.history.go();
                        }
					    else
					    {
                           var array=v.split('|');
                           var len=array.length;
                           if(len>0)
                           {  
                               $("Tr_Area1").style.display="";
                               $("selArea1").length=0;
                               for(var i=0;i<array.length-1;i++)
                               { 
                                  var s=array[i].split(',');
                                  if(s.length>0)
                                  {
                                    $("selArea1").options.add(new Option(s[1],s[0]));
                                  }
                               }
                           } 
                           else
                           {
                                $("Tr_Area1").style.display="none";
                           }
                        }
					}  
				  }; 
       new Ajax.Request('AreaAdd.aspx',options);
}

//添加地区
function AddArea()
{
    var r=$("txtID").value;
    var name=escape($("txtAreaName").value);
    if(name=="")
    {
        alert("地区名字不能为空");
        return;
    }
    if(r==0)//加一级地区
    {
        self.location="?Type=Add&ParentID=0&name="+escape($("txtAreaName").value);
    }
    else if(r==1)//加二级地区
    {
        self.location="?Type=Add&ParentID="+$("selArea0").value+"&name="+escape($("txtAreaName").value);
    }
    else if(r==2)//加三级地区
    {
        self.location="?Type=Add&ParentID="+$("selArea1").value+"&name="+escape($("txtAreaName").value);
    }
}
</script>