<!--#include file="conn.asp"-->
<%
page_title=Eval("about_title"&Language)
page_keywords=Eval("about_keywords"&Language)
page_description=Eval("about_description"&Language)
if page_title="" then
page_title=city_title
page_keywords=city_keywords
page_description=city_description
end if
%>
<!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>
<meta http-equiv="Content-Language" content="zh-CN">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title><%=page_title%></title>
<meta name="keywords" content="<%=page_keywords%>" />
<meta name="description" content="<%=page_description%>" />
<!--#include file="top.asp"-->
<!--#include file="header.asp"-->
<%
if session("user_xxx_name")="" then
response.Redirect("login.asp")
end if
%>
<link href="<%=filepath%>inc/mycenter.css" type="text/css" rel="stylesheet">
<link href="<%=filepath%>inc/style.css" type="text/css" rel="stylesheet">
<link href="<%=filepath%>inc/user.css" type="text/css" rel="stylesheet">

    <div id="wrap">
        <!--container-->
        <div class="main">
            
<!--sidebar-->
<!--#include file="Mb_left.asp"-->

<script type="text/javascript">
                try
                {
                    document.getElementById("User_BaseConfig").className = "current"; //控制CSS
                }
                catch(e){}
</script>

<!--sidebar end-->
<%dim action,username
action=request.QueryString("action")
username=session("user_xxx_name")
select case action
'//用户资料
case "add"
set rs=server.CreateObject("adodb.recordset")
rs.open "select * from [com_Uadd]",conn,1,3
rs.addnew
rs("UserID")=session("UserID")
rs("receiverName")=request("receiverName")
rs("provinceId")=request("provinceId")
rs("cityId")=request("cityId")
rs("countyId")=request("countyId")
rs("address")=request("address")
rs("postCode")=request("postCode")
rs("splitPhone1")=request("splitPhone1")
rs("splitPhone2")=request("splitPhone2")
rs("splitPhone3")=request("splitPhone3")
rs("mobile")=request("mobile")
if request("isDefault")=1 then
 set rsis=server.CreateObject("adodb.recordset")
 sql="select isDefault from com_Uadd where UserID="&session("UserID")&" order by isDefault desc"
 rsis.open sql,conn,1,3
 if not rsis.bof or not rsis.eof then
 rsis("isDefault")=0
 rsis.update
 end if
 rsis.close
 set rsis=nothing
rs("isDefault")=1
else
rs("isDefault")=0
end if

rs.update
rs.close
set rs=nothing
response.Write "<script language=javascript>alert('添加成功！');window.location.href='address.asp';</script>"
response.end

case "edit"
set rs=server.CreateObject("adodb.recordset")
rs.open "select * from [com_Uadd] where id="&request("id")&"",conn,1,3
rs("receiverName")=request("receiverName")
rs("provinceId")=request("provinceId")
rs("cityId")=request("cityId")
rs("countyId")=request("countyId")
rs("address")=request("address")
rs("postCode")=request("postCode")
rs("splitPhone1")=request("splitPhone1")
rs("splitPhone2")=request("splitPhone2")
rs("splitPhone3")=request("splitPhone3")
rs("mobile")=request("mobile")
rs("isDefault")=request("isDefault")

rs.update
rs.close
set rs=nothing
response.Write "<script language=javascript>alert('修改成功！');window.location.href='address.asp';</script>"
response.end



case "setis"

set rsis=server.CreateObject("adodb.recordset")
sql="select isDefault from com_Uadd where UserID="&session("UserID")&" order by isDefault desc"
rsis.open sql,conn,1,3
rsis("isDefault")=0
rsis.update
rsis.close
set rsis=nothing

set rs=server.CreateObject("adodb.recordset")
rs.open "select * from [com_Uadd] where id="&request("id")&"",conn,1,3
rs("isDefault")=1
rs.update
rs.close
set rs=nothing

response.Write "<script language=javascript>alert('设置成功！');window.location.href='address.asp';</script>"
response.end

case "del"
conn.execute("delete from com_Uadd where id="&request("id"))
response.Write "<script language=javascript>alert('删除成功！');window.location.href='address.asp';</script>"
end select
%>

            <!--main-->
<div class="mainBox">
			<div class="mainContent">

				<!------>
				<h3 class="mainContent_title" style="margin-bottom: 15px">
					<span>我的收货地址簿</span>
				</h3>
				<!--内容-->

				<table cellspacing="0" cellpadding="0" align="center" border="1" class="listtable margin_bottom10">
					<thead>
						<tr>
							<th width="10%">收货人</th>
							<th width="22%">所在地区</th>
							<th width="23%">详细地址</th>
							<th width="8%">邮编</th>
							<th width="14%">电话/手机</th>
							<th width="10%">是否默认</th>
							<th width="13%">操作</th>
						</tr>
					</thead>

					<tbody>

<%
set rs=server.CreateObject("adodb.recordset")
rs.open "select * from com_Uadd where UserID="&session("UserID")&"  order by isDefault desc",conn,1,1
i=1 
if rs.eof or rs.bof then
else
while not rs.eof
%>
						<tr>
							<td><%=rs("receiverName")%></td>
							<td><%call showAddName(rs("provinceId"))%>&nbsp;<%call showAddName(rs("cityId"))%>&nbsp;<%call showAddName(rs("countyId"))%></td>
							<td><%=rs("address")%></td>
							<td><%=rs("postCode")%></td>
							<td><%=rs("splitPhone1")%>-<%=rs("splitPhone2")%><%if rs("splitPhone3")<>"" then%>-<%=rs("splitPhone3")%><%end if%>/<%=rs("mobile")%></td>
							<td><%if rs("isDefault")=1 then%><span style="color:red">默认</span><%else%><a href="?action=setis&id=<%=rs("id")%>">设为默认</a><%end if%></td>
							<td><a id="rpt_DataBind_ctl01_lbn_edit" href="?edit=yes&id=<%=rs("id")%>">修改</a> |<a id="rpt_DataBind_ctl01_lbn_delete" href="?action=del&id=<%=rs("id")%>">删除</a></td>
						</tr>
<%
i=i+1
rs.movenext
Wend 
end if
rs.close
set rs=nothing
%>
</tbody></table>
				<div style="clear:both">
				</div>
<%
if request("edit")="yes" then
set rs=server.CreateObject("adodb.recordset")
rs.open "select * from [com_Uadd] where id="&request("id")&"",conn,1,3
%>
<form id="myform" name="myform" action="?action=edit" method="post">
<input type="hidden" id="id" name="id" value="<%=request("id")%>">
<input type="hidden" id="telephone" name="telephone" value=""> <input type="hidden" id="isDefault" name="isDefault" value="0">
<br />
<h3><span style="color: #C00000; font-weight: bold;">修改收货地址</span></h3>
<div class="Smsg-list">
<ul>
<li><span>收货人姓名：</span><input name="receiverName" type="text" id="receiverName" value="<%=rs("receiverName")%>" class="input" style="height: 21px; width: 120px;"><font style="color: Red">*</font></li>
<li style="margin-top: 8px;"><span>所在地区：</span>	
<SELECT style="WIDTH: 80px; HEIGHT: 21px" id=provinceId class=input name=provinceId> 
<%
set rsClass1=server.createobject("adodb.recordset")
sqlClass1="select * from com_china where parentid=0 and LevelID=0 order by id asc"
rsClass1.open sqlClass1,conn,1,1
count1=0
do while not rsClass1.eof
if rs("provinceId")=rsClass1("id") then
selectOK="selected=''"
else
selectOK=""
end if
response.write "<OPTION value="&rsClass1("id")&" "&selectOK&">"&rsClass1("name")&"</OPTION>"
count1=count1 + 1
rsClass1.movenext
loop
rsClass1.close
%></SELECT> &nbsp;省&nbsp;
<SELECT style="WIDTH: 120px" id=cityId name=cityId>
<%
set rsClass1=server.createobject("adodb.recordset")
sqlClass1="select * from com_china where parentid="&rs("provinceId")&" and LevelID=1 order by id asc"
rsClass1.open sqlClass1,conn,1,1
count1=0
do while not rsClass1.eof
if rs("cityId")=rsClass1("id") then
selectOK="selected=''"
else
selectOK=""
end if
response.write "<OPTION value="&rsClass1("id")&" "&selectOK&">"&rsClass1("name")&"</OPTION>"
count1=count1 + 1
rsClass1.movenext
loop
rsClass1.close
%>
</SELECT> 市 
<SELECT style="WIDTH: 100px" id=countyId name=countyId>
<%
set rsClass1=server.createobject("adodb.recordset")
sqlClass1="select * from com_china where parentid="&rs("cityId")&" and LevelID=2 order by id asc"
rsClass1.open sqlClass1,conn,1,1
count1=0
do while not rsClass1.eof
if rs("countyId")=rsClass1("id") then
selectOK="selected=''"
else
selectOK=""
end if
response.write "<OPTION value="&rsClass1("id")&" "&selectOK&">"&rsClass1("name")&"</OPTION>"
count1=count1 + 1
rsClass1.movenext
loop
rsClass1.close
%>
</SELECT> 区
<font style="color: Red">*</font></li>
<li style="margin-top: 8px;"><span>街道地址：</span><textarea name="address" rows="2" cols="20" id="address" class="input" style="height: 50px; width: 300px;"><%=rs("address")%></textarea>
<font style="color: Red">*</font><font style="font-size: 12px">不需要重复填写省/市/区</font></li>

<li style="margin-top: 8px;"><span>邮编编码：</span><input value="<%=rs("postCode")%>" name="postCode" type="text" maxlength="6" id="postCode" class="input" style="height: 21px; width: 100px;"> <font style="color: Red">*</font></li>
<li style="margin-top: 8px;"><span>固定电话：</span><input value="<%=rs("splitPhone1")%>" name="splitPhone1" type="text" maxlength="4" id="splitPhone1" class="input" style="height: 21px; width: 60px;"> -<input value="<%=rs("splitPhone2")%>" name="splitPhone2" type="text" maxlength="8" id="splitPhone2" class="input" style="height: 21px; width: 100px;"> -<input value="<%=rs("splitPhone3")%>" name="splitPhone3" type="text" maxlength="4" id="splitPhone3" class="input" style="height: 21px; width: 60px;"> <font style="color: Red">*</font><font style="font-size: 12px">区号-电话号码-分机</font></li>
<li style="margin-top: 8px;"><span>手机号码：</span><input value="<%=rs("mobile")%>" name="mobile" type="text" id="mobile" class="input" style="height: 21px; width: 120px;"> <font style="color: Red">*</font><font style="font-size: 12px">手机号码和固定电话至少有一项必填!</font></li>
<li style="margin-top: 8px;"><span>设为默认：</span><input id="isDefaultCheckbox" type="checkbox" name="isDefaultCheckbox" <%if rs("isDefault")=1 then%>checked="checked"<%end if%>></li>
<li style="margin-top: 8px;"><span></span><input type="submit" id="btnSave" value=" 保 存 " class="btn"></li>
</ul>
</div>
</form>
<%
rs.close
set rs=nothing

else
%>
<form id="myform" name="myform" action="?action=add" method="post">
<input type="hidden" id="telephone" name="telephone" value=""> <input type="hidden" id="isDefault" name="isDefault" value="0">
<br />
<h3><span style="color: #C00000; font-weight: bold;">新增收货地址</span></h3>
<div class="Smsg-list">
<ul>
<li><span>收货人姓名：</span><input name="receiverName" type="text" id="receiverName" value="" class="input" style="height: 21px; width: 120px;"><font style="color: Red">*</font></li>
<LI style="MARGIN-TOP: 8px"><SPAN>所在地区：</SPAN>
<SELECT style="WIDTH: 80px; HEIGHT: 21px" id=provinceId class=input name=provinceId> 
    <OPTION selected value=0>请选择</OPTION>
<%
set rsClass1=server.createobject("adodb.recordset")
sqlClass1="select * from com_china where parentid=0 and LevelID=0 order by id asc"
rsClass1.open sqlClass1,conn,1,1
count1=0
do while not rsClass1.eof
response.write "<OPTION value="&rsClass1("id")&">"&rsClass1("name")&"</OPTION>"
count1=count1 + 1
rsClass1.movenext
loop
rsClass1.close
%></SELECT> &nbsp;省&nbsp;
	
	
	<SELECT style="WIDTH: 120px" id=cityId name=cityId> <OPTION selected value=0>选择地区</OPTION></SELECT> 市 
	<SELECT style="WIDTH: 100px" id=countyId name=countyId> <OPTION selected value=0>选择地区</OPTION></SELECT> 区
	
	<FONT  style="COLOR: red">*</FONT> 
  
<li style="margin-top: 8px;"><span>街道地址：</span><textarea name="address" rows="2" cols="20" id="address" class="input" style="height: 50px; width: 300px;"></textarea>
<font style="color: Red">*</font><font style="font-size: 12px">不需要重复填写省/市/区</font></li>

<li style="margin-top: 8px;"><span>邮编编码：</span><input value="" name="postCode" type="text" maxlength="6" id="postCode" class="input" style="height: 21px; width: 100px;"> <font style="color: Red">*</font></li>
<li style="margin-top: 8px;"><span>固定电话：</span><input value="" name="splitPhone1" type="text" maxlength="4" id="splitPhone1" class="input" style="height: 21px; width: 60px;"> -<input value="" name="splitPhone2" type="text" maxlength="8" id="splitPhone2" class="input" style="height: 21px; width: 100px;"> -<input value="" name="splitPhone3" type="text" maxlength="4" id="splitPhone3" class="input" style="height: 21px; width: 60px;"> <font style="color: Red">*</font><font style="font-size: 12px">区号-电话号码-分机</font></li>
<li style="margin-top: 8px;"><span>手机号码：</span><input value="" name="mobile" type="text" id="mobile" class="input" style="height: 21px; width: 120px;"> <font style="color: Red">*</font><font style="font-size: 12px">手机号码和固定电话至少有一项必填!</font></li>
<li style="margin-top: 8px;"><span>设为默认：</span><input id="isDefaultCheckbox" type="checkbox" name="isDefaultCheckbox"></li>
<li style="margin-top: 8px;"><span></span><input type="submit" id="btnSave" value=" 保 存 " class="btn"></li>
</ul>
</div>
</form>
<%
end if
%>		
</div>
<script type="text/javascript">
function dataValidator() {

}

dataValidator.isEmail = function(str) {
    var re = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
    return re.test(str);
}


dataValidator.isNumber = function(str) {
    var re = /^\d+$/;
    return re.test(str);
}


dataValidator.isChinese = function(str) {
    var re = /^[\u4e00-\u9fa5]+$/;
    return re.test(str);
}

dataValidator.isMobile = function(str) {
    var re = /^(13|15|16|18)[0-9]{9}$/;
    return re.test(str);
}
dataValidator.isPhone = function(str) {
    var re = /^(([0\+]\d{2,3}-)?(0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/;
    return re.test(str);
}
dataValidator.isPostcode = function(str) {
    var re = /^\d{6}$/;
    return re.test(str);
}

dataValidator.isTime = function(str) {
    var re = /^\d{4}(\-|\/|\.)\d{1,2}\1\d{1,2}$/;
    return re.test(str);
}


$(document).ready(function(){
	$("#provinceId").change(function(){
		var id=$(this).val();
		var dataString = 'provinceId='+ id;
		
		$.ajax({
			type: "POST",
			url: "address-select.asp",
			data: dataString,
			cache: false,
			success: function(html){
				$("#cityId").html(html);
			} 
		});
		$("#countyId").html("<option value='0'>请选择</option>");
	});
	$("#cityId").change(function(){
		var id=$(this).val();
		var dataString = 'cityId='+ id;
		
		$.ajax({
			type: "POST",
			url: "address-select.asp",
			data: dataString,
			cache: false,
			success: function(html){
				$("#countyId").html(html);
			} 
		});
	});
});
function format_phone(p1,p2,p3){
	var result ="";
	if(p1!=''){
		result=p1+"-"
	}
	result=result+p2;
	if(p3!=''){
		result=result+' '+p3;
	}
	return result;
}
$("#myform").submit(function() {
		var p1 = $('#splitPhone1').val();
		var p2 = $('#splitPhone2').val();
		var p3 = $('#splitPhone3').val();
		$('#telephone').val(format_phone(p1,p2,p3));
		var telephone = $('#telephone').val();
		var mobile = $('#mobile').val();

		var receiverName = $('#receiverName').val();
		if (receiverName == '') {
			alert('请输入收件人');
			return false;
		}
		if($('#provinceId').val()=='0'){
			alert('请选择省份');
			return false;
		}
		if($('#cityId').val()=='0'){
			alert('请选择城市');
			return false;
		}		
		if($('#countyId').val()=='0'){
			alert('请选择区');
			return false;
		}				
		var address = $('#address').val();
		if (address == '') {
			alert('请输入地址');
			return false;
		}
		var postcode = $('#postCode').val();
		if (postcode == '') {
			alert('请输入邮编');
			return false;
		}else{
		    if(!dataValidator.isPostcode(postcode)){
		       alert('请输入6位邮编');
		       return false;
		    }
		}
		if (mobile == '' && p2 == '') {
			alert('请输入电话或手机');
			return false;
		}
		if(mobile!=''){
			if(!dataValidator.isMobile(mobile)){
			   alert('请输入合法手机号');
			   return false;
			}
		}
		if ($('#isDefaultCheckbox').is(':checked')) {
			$('#isDefault').val('1');
		}

		return true;
});

	//alert('设置成功');
</script>

		</div>
            <!--main end-->
        </div>
        <!--container end-->
        <div class="clr">
        </div>
        

  
<!--#include file="foot.asp"--> 