<%@ Page Language="C#" AutoEventWireup="true" debug="true" Inherits="WinLibClass.Form.UserInfo.Address.UI_List" CodePage="65001" GameType="1" PageFileFlag="UserAddress" PageFileTitle="收货地址-会员中心" DataBindingType="1" PageFlagId="1"  %>

<%@ Register TagPrefix="Site" TagName="Menu" Src="~/WUC/Common/Site_Menu.ascx" %>
<%@ Register TagPrefix="Site" TagName="UserPicNote" Src="~/WUC/Common/Site_UserPicNote.ascx" %>
<%@ Register TagPrefix="Site" TagName="Game1" Src="~/WUC/Common/Site_Game1.ascx" %>

<%@ Register TagPrefix="Site" TagName="Side_UserPicNote" Src="~/WUC/Common/Site_Side_UserPicNote.ascx" %>
<%@ Register TagPrefix="Site" TagName="Side_Future" Src="~/WUC/Common/Site_Side_Future.ascx" %>
<%@ Register TagPrefix="Site" TagName="Side_Main" Src="~/WUC/Common/Site_Side_Menu.ascx" %>


<!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>
<Site:Menu id="menu_headtitle" runat="server" Flag="HeadTitle" CurrentPageTitle = "会员中心 - 收货地址" />
<Site:Menu id="menu_headjs" runat="server" Flag="HeadJs"  />

<link href="/css/common.css" type="text/css" rel="stylesheet" />
<link href="/css/common_3.css" type="text/css" rel="stylesheet" />
<link href="/css/article.css" type="text/css" rel="stylesheet" />

</head>
<script>
<!--
/*第一种形式 第二种形式 更换显示样式*/
function setTab(name,cursel,n){
    for(i=1;i<=n;i++){
    var menu=document.getElementById(name+i);
    //var con=document.getElementById("con_"+name+"_"+i);
    menu.className=i==cursel?"hover":"";
    con.style.display=i==cursel?"block":"none";
    }
}
//-->
</script>
<body>

<Site:Menu id="menu_topmenu" runat="server" Flag="TopMenu"  CurrentPageFlag="User" />

<div class="clear"></div>
<!--start 内容-->
<div class="ArtContent PageWidth">
	<!-- 左侧菜单 -->
<Site:Side_Main id="Side_Main_art1" runat="server" PageFlagId="100"  CurrentPageFlag="User" DataBindingType="1" />
	<!-- 左侧菜单结束 -->
	<!-- 右侧正文或列表 -->
<!--start 主体内容-->
<script type="text/javascript" language="javascript">


function SetTab(mids,focus,blur,cids,curid)
{
	var mid = jQuery(mids);
	var cid = jQuery(cids);
	var curObj = jQuery(curid);
	
	mid.removeClass(focus).addClass(blur);
	curObj.removeClass(blur).addClass(focus);
	cid.addClass("hide");
	jQuery(cids + '[flag="' + curObj.attr("id") + '"]' ).removeClass("hide");

}

jQuery(function(){

	//保存
	$("#btnSubmit").click(function(){if(CheckAll())UpdateInfo();});	

	
	$("a[id^='trtd_']").click(function(){
		//$("tr[class='hasline']").css("background-color","#ffffff");
		//SetActive($(this)).id.substr("tr_".length);
		$(this).parent().parent().css("");
		SetActiveForAddress($(this).parent().parent(),1);
	});
	
});



function SetActiveForAddress(o,flag)
{
	if(!flag)flag = 0;
	var x = 1;
	//菜单处理
	if(flag==0) x = o.attr("value");
	else SetCurrentItemToEidt(o);//EDIT
	
	if(x==1)
	{
		if($("#AddId").val()==""||$("#AddId").val()==0 ) x=2;
	}
	SetActive(o.attr("id").substr("tr_".length));

	jQuery("#medit").click();
	

	if(x==2){$("#aspnetForm")[0].reset();$("#AddId").val("0");x=1;};
	$("div[id^='div_AddressItem_']").hide();
	$("#div_AddressItem_"+x).show();
}

function SetCurrentItemToEidt(obj)
{

	var inputList = $("#aspnetForm input,#aspnetForm textarea");//,#aspnetForm submit
	obj.find("td").each(function(i,o){
		if(i<inputList.length-1) inputList[i].value = $(o).attr("value");
	});

	

}

function CheckAll()
{

	var t = true;
	if(t) t = CheckIsEmpty("Receiver",1,"收货人姓名不能为空.",50,"收货人名字太长(50字以内)");//收货人
	if(t) t = CheckIsEmpty("Address",1,"收货人地址不能为空.",50,"收货人地址太长(50字以内)");//地址
	if(t) t = CheckIsEmpty("PostCode",6,"收货人邮编无效(6位数字).",6,"收货人邮编无效(6位数字)");//邮编
	if(t) t = CheckPostCode("PostCode","收货人邮编无效(6位数字)");
	if(t) t = CheckIsEmpty("PhoneNo",1,"收货人电话不能为空.",50,"收货人电话太长(50字以内)");//手机
	if(t) t = CheckIsEmpty("Remark",0,"备注不能为空.",50,"备注太长(100字以内)");//备濂
	return t;
}

function UpdateInfo()
{
	var queryString = $("#aspnetForm").serialize();
	AjaxSubmit(null,
		"/index.aspx?s=/UserInfo/UserAddressUpdate/",
		queryString,
		function(msg){ 
			if(msg==1)
			{
				//alert(msg);
				Common.ShowTipSuccess(false,"您的收货地址信息已保存.");
				window.location.replace(window.location.href);
			} 
			else 
			{
				Common.ShowTipError(false,"数据保存有误（错误代码："+msg+")。");
				
			}
		},
		function(msg){Common.ShowTipError(false,"数据保存有误:"+(msg.responseText?msg.responseText:"") +"。");}
	);
}

function CheckIsEmpty(id,Min,msgMin,Max,msgMax)
{
	var o = $("#"+id);
	var ospan = $("#"+id+"_label");
	var oimg = o.parent().find("img");
	//alert(oimg);
	//是否为空
	if(o.val().trim().length<Min)
	{
		oimg.hide();
		ospan.html(msgMin).show();
		return false;
	}

	//最大值
	else if(o.val().trim().length>Max)
	{
		oimg.hide();
		ospan.html(msgMax).show();
		return false;
	}
	else
	{
		ospan.html("").hide();
		oimg.show();
		return true;
	}
	return false;
	
}

function CheckPostCode(id,msgMin)
{
	var o = $("#"+id);
	var ospan = $("#"+id+"_label");
	var oimg = o.parent().find("img");

	var type = /\d{6}$/;  

	var code = o.val();
	if(!code.match(type))
	{
		oimg.hide();
		ospan.html(msgMin).show();
		return false;
	}
	else
	{
		ospan.html("").hide();
		oimg.show();
		return true;
	}
	
}

</script>



<div class="Grid-Base PageWidth_Right2">

	<div class="help-box padding0 " >
 		<div class="tit2 H60 LH55">
				收货地址
		</div>
		<div class="tab">
			<div id="mlist" class="tab-0 ML20 color1" onclick='SetTab(".tab-0","color1","color2",".help-box .editexp","#mlist");'>
				<div class="tab-0-left"></div>
				<div class="yjcont "><div class="tabtit">地址列表</div></div>
                <div class="tab-0-right"></div>
				
			</div>

			<div id="medit" class="tab-0 ML5 color2" onclick='SetTab(".tab-0","color1","color2",".help-box .editexp","#medit");'>
                 <div class="tab-1-left"></div>     			
				 <div class="yjcont"><div class="tabtit">添加新地址</div></div>
				 <div class="tab-1-right"></div>
			</div>

		</div>

	</div>

	<div class="help-box H485" style="border-bottom:0px;" value="Content" >
 
		<div class="editexp hide" id="div-Edit" flag="medit">
        <form name="aspnetForm" id="aspnetForm" onsubmit="return false;checkAll();">		
			<li><div class="info-name">收货人姓名：</div><div class="info-input inputbg W298">
			<input type="hidden" name="AddId" id="AddId" value="0" />
				<input type="text" class="inputbox W235" id="Receiver" name="Receiver">
				</div></li>
			<li><div class="info-name">手机/电话号码：</div><div class="info-input inputbg W298">
				<input type="text" class="inputbox W235" id="PhoneNo" name="PhoneNo" >
				</div></li>
			<li><div class="info-name">收货地址：</div><div class="info-input inputbg W298">
				<input type="text"  class="inputbox W235"  id="Address" name="Address" >
				</div></li>
			<li><div class="info-name">邮编：</div><div class="info-input inputbg W298">
				<input type="text"  class="inputbox W235"  id="PostCode" name="PostCode" >
				</div></li>
			<li style="height:100px;"><div class="info-name">备注：</div><div class="info-input textareabg W298">
			<textarea class="textareabox W235 H90" id="Remark" name="Remark" ></textarea>
			
			</div></li>
			<li><input type="image" src="/images/btnsubmit.gif" id="btnSubmit" > </li>
		</form>	
		</div>
		
		<div class="editexp " id="div-List" flag="mlist">
			<table>
				<tr class="list-th">
					<th CLASS="hide">ID</th>
					<th>收货人</th>
					<th>手机/电话</th>
					<th >地址</th>
					<th >邮编</th>
					<th CLASS="hide">添加时间</th>
					<th CLASS="hide">备注</th>
					<th>最后更新</th>
					<th>操作</th>
				</tr>
<asp:Repeater id="rpList" runat="server"> 
<ItemTemplate>					

				<tr class="list-td" id="tr_<%#Eval("id")%>">

                        	<td CLASS="hide" value="<%#Eval("id")%>" ><%#Eval("id")%></td>
                            <td value="<%#Eval("Receiver")%>"><%#Eval("Receiver")%></td>
                            <td value="<%#Eval("Phone")%>"><%#Eval("Phone")%></td>
                            <td title ="<%#Eval("PostalAddress")%>" value="<%#Eval("PostalAddress")%>"><%#DV.Eval(Eval("PostalAddress").ToString(),20,"...")%></td>
                            <td value="<%#Eval("PostalCode")%>"><%#Eval("PostalCode")%></td>
                            <td value="<%#Eval("Remark")%>"><%#Eval("UpdateTime","{0:yyyy-MM-dd HH:mm}")%></td>
							<td><a id="trtd_<%#Eval("id")%>" href="javascript:;">编辑</a> </td>				
				
				
				</tr>
		
</ItemTemplate>		
</asp:Repeater>						
				
			</table>
			<div class="Page Pnv">
<%=strPageInfo%>			
			</div>
		</div>
	</div>

</div>
<!--end 主体内容结束-->
	<!-- 右侧正文或列表结束 -->

  <div class="clear"></div>

</div>
<!--end 内容-->
<div class=" clear"></div>
<Site:Menu id="menu_foothelper" runat="server" Flag="FootHelper"  />
<div class=" clear"></div>
<Site:Menu id="menu_links" runat="server" Flag="Links"  />
<div class=" clear"></div>
<Site:Menu id="menu_foot" runat="server" Flag="Foot"   />


</body>
</html>
