<?xml version="1.0"?>
<labeltemplate>
   <label>
    <![CDATA[
	<script type="text/javascript">
	 function loadCity(){
	   var pid=jQuery("#provinceid option:selected").val();
	   if (pid!=''){
	     jQuery.get("{$GetInstallDir}plus/ajaxs.ashx", { a: "loadcityoption", pid:pid},
			 function(data){
					if (data!=null&&data!=''){
					  jQuery("#showcity").show();
					  jQuery("#cityid").empty();
					  jQuery("#cityid").append("<option value=''>请选择...</option>");
					  jQuery("#cityid").append(data);
					}else{
					  jQuery("#showcity").hide();
					  jQuery("#cityid").empty();
					  jQuery("#cityid").append("<option value=''>请选择...</option>");
					}
					jQuery("#showcounty").hide();
					jQuery("#countyid").empty();
					jQuery("#countyid").append("<option value=''>请选择...</option>");
			  });
	  }
	  jQuery("#showselectarea").html(jQuery("#provinceid option:selected").get(0).text);
	 }
	 function loadCounty(){
	   var cid=jQuery("#cityid option:selected").val();
	   if (cid!=''){
	   
	  	   
	     jQuery.get("{$GetInstallDir}plus/ajaxs.ashx", { a: "loadcountyoption", cid:cid},
			 function(data){
					if (data!=null&&data!=''){
					jQuery("#showcounty").show();
					jQuery("#countyid").empty();
					jQuery("#countyid").append("<option value=''>请选择...</option>");
					jQuery("#countyid").append(data);
					}else{
					jQuery("#showcounty").hide();
					jQuery("#countyid").empty();
					jQuery("#countyid").append("<option value=''>请选择...</option>");
					}
			  });
		}
	  loadSelect();
	 }
	 function loadSelect(){
	   var str=jQuery("#provinceid option:selected").get(0).text;
	   try{
	   if (jQuery("#cityid option:selected").val()!='') str+=jQuery("#cityid>option:selected").get(0).text;
	   if (jQuery("#countyid option:selected").val()!='') str+=jQuery("#countyid>option:selected").get(0).text;
	   }catch(e){
	   }
	   jQuery("#showselectarea").html(str);
	 }
	 var provinceid=0;
	 var cityid=0;
	 function saveAddress(obj){
	    provinceid=jQuery("#provinceid option:selected").val();
		 if (provinceid==''){
		  alert('请选择收货地区!');
		  return false;
		 }
		 cityid=jQuery("#cityid option:selected").val();
		 if (cityid==''){
		  alert('请选择收货城市!');
		  return false;
		 }
		 
	   try{
	    if ($("input[name=addressId][checked=true]").val()!='0'){
	  $("#city_"+$("input[name=addressId][checked=true]").val()).val(cityid);
	  $("#provinceid_"+$("input[name=addressId][checked=true]").val()).val(provinceid);
	   }
	  }catch(e){}
		 
		 var countyid=0;
		 if (jQuery("#countyid")[0]){
		  countyid=jQuery("#countyid option:selected").val();
		 }
		 var address=jQuery("#address").val();
		 if (address==''){
		  alert('请输入收货地址!','jQuery("#address").focus();');
		  return false;
		 }
		 var zipcode=jQuery("#zipcode").val();
		 if (zipcode==''){
		  alert('请输入邮政编码!','jQuery("#zipcode").focus();');
		  return false;
		 }
		 var realname=jQuery("#realname").val();
		 if(realname==''){
		  alert('请输入收货人姓名!','jQuery("#realname").focus();');
		  return false;
		 }
		 var mobile=jQuery("#mobile").val();
		 if (mobile==''){
		   alert('请输入手机号码!');
		   return false;
		 }
		 if (mobile!=''){
		   if (ismobile(mobile)==false){
		   alert('手机号码不正确，请重新输入!');
		   jQuery("#mobile").focus();
		   return false;
		   }
		 }
		 
		 var email=jQuery("#email").val();
		 showWaitInfo("请稍候,正在保存收货地址!",obj);
	     jQuery.get("{$GetInstallDir}plus/ajaxs.ashx", { a: "saveproaddress", addrid:jQuery("#addrid").val(),provinceid:provinceid,cityid:cityid,countyid:countyid,address:address,zipcode:zipcode,realname:realname,mobile:mobile,email:email},
			 function(data){
					if (parseInt(data)!=0){
					   jQuery.get("{$GetInstallDir}plus/ajaxs.ashx",{a:"loaddefaultaddress",sid:data,fromMobile:1},function(data1){
					     jQuery("#myaddress").html(data1);
						 selectAddress(data);
					   });
					  jQuery("#addmyaddress").fadeOut("fast");
					  
					  if (parseInt(jQuery("#addrid").val())==0){
					    
					    alert('恭喜,添加成功!');
					  //location.reload();
					  }
					  else
					  alert('恭喜,修改成功!');
					  //加载配送方式列表
					  if (document.getElementsByName("addressId").length==0){
					   location.reload();
					  }else{
					  showDeliveryList();
					  }
					}
					clearWaitInfo();
			  });
	 }
	 
function addAddress(obj){
   
	jQuery("#addrid").val(0);
    showWaitInfo("请稍候,正加载添加收货地址表单!",obj);
	jQuery('#addmyaddress').fadeIn('slow');
	jQuery("#ShowDeliveryList").html("<div style='padding:10px;background:#ffffee;margin:5px 2px;border:1px #f9c943 solid;font-weight:bold'>请完善并保存您的收货信息。</div>");
	clearWaitInfo();

}
function loadModifyAddress(id,obj){
 jQuery("#addrid").val(id);
 showWaitInfo("请稍候,正加载收货地址表单!",obj);
 jQuery.getScript('{$GetInstallDir}plus/ajaxs.ashx?a=modifyproaddress&addrid='+id,function(){
			if (address.issuccess=='true'){
			 jQuery("#provinceid>option[value="+address.provinceid+"]").attr("selected",true);
			 if (parseInt(address.cityid)!=0){
			   jQuery.get("{$GetInstallDir}plus/ajaxs.ashx", { a: "loadcityoption", pid:address.provinceid},
				 function(data){
				    if (data!=null && data!=''){
					jQuery("#showcity").show();
					jQuery("#cityid").empty();
					jQuery("#cityid").append("<option value=''>请选择---</option>");
					jQuery("#cityid").append(data);
					jQuery("#cityid").val(address.cityid);
					loadSelect();
					}else{
					jQuery("#showcity").hide();
					jQuery("#cityid").empty();
					jQuery("#cityid").append("<option value=''>请选择---</option>");
					}
				  });
			 }else{
					jQuery("#showcity").hide();
					jQuery("#cityid").empty();
					jQuery("#cityid").append("<option value=''>请选择---</option>");
			 }
			 if (parseInt(address.countyid)!=0){
			 jQuery.get("{$GetInstallDir}plus/ajaxs.ashx", { a: "loadcountyoption", cid:address.cityid},
			 function(data){
					if (data!=null&&data!=''){
					jQuery("#showcounty").show();
					jQuery("#countyid").empty();
					jQuery("#countyid").append("<option value=''>请选择...</option>");
					jQuery("#countyid").append(data);
					jQuery("#countyid").val(address.countyid);
					loadSelect();
					}else{
					jQuery("#showcounty").hide();
					jQuery("#countyid").empty();
					jQuery("#countyid").append("<option value=''>请选择...</option>");
					}
			  });
			 
			 }else{
					jQuery("#showcounty").hide();
					jQuery("#countyid").empty();
					jQuery("#countyid").append("<option value=''>请选择...</option>");
			 }
			 jQuery("#addmyaddress").fadeIn('slow');
			 jQuery("#address").val(address.address);
			 jQuery("#zipcode").val(address.zipcode);
			 jQuery("#realname").val(address.realname);
			 jQuery("#email").val(address.email);
			 jQuery("#tel").val(address.tel);
			 jQuery("#mobile").val(address.mobile);
			}else{
			 alert('对不起,找不到记录,加载收货地址表单出错!');
			}
			clearWaitInfo();
	 });
	 
}

//删除地址
function loadDelAddress(id,obj){
   if (confirm("确认删除该收货地址吗？")){
		$.get("{$GetInstallDir}plus/ajaxs.ashx", { a: "deletemyaddress",addressId:id},
			 function(data){
			  if (data=="success"){
			     if ($("input[name=addressId][value='"+id+"']").attr("checked")!=undefined){
				  selectAddress(0);
				 }
			     $("#tr"+id).remove();
				//location.reload();
			  }else{
			   alert('对不起，操作失败！');
			  }
	 });
 };
 
}

	</script>
<div id="addmyaddress" style="{$DisplayOrNone}">
	
	<input type="hidden" name="addrid" id="addrid" value="0" />
	<table class="ctable table table-border table-bordered">
		<tr>
		 <td>{$ShowArea}
		  <span id="showcity" style="display:none"><select name="cityid" id="cityid" onchange="loadCounty();"></select></span>
		  <span id="showcounty" style="display:none"><select name="countyid" onchange="loadSelect();" id="countyid"></select></span>
		 <font color=red>*</font>
		 </td>
		</tr>
		<tr>
		 <td><div id="showselectarea"></div><input type="text" placeholder="收货地址" name="address" id="address" maxlength="100" /><font color=red>*</font> </td>
		</tr>
		<tr>
		<td><input placeholder="邮　　编" maxlength="6" type="text" name="zipcode" id="zipcode" /><font color=red>*</font> </td>
		</tr>
		<tr>
		<td><input  placeholder="收货人姓名" type="text" name="realname" id="realname" maxlength="15" />
		<font color=red>*</font></td>
		</tr>
		<tr>
		<td><input placeholder="手机号码" type="text" maxlength="12" name="mobile" id="mobile" /><font color=red>*</font></td>
		</tr>
		<tr>
		<td><input placeholder="电子邮件" type="text" maxlength="50" name="email" id="email" /></td>
		</tr>
	</table>
    <input type="button" value="保存收货人信息" class="btn btn-addr button" onclick="saveAddress(this)"/>
</div>
	]]>
   </label>
</labeltemplate>