function address(flag){
   var id =GetQueryString("id");
    
    if(  id!="null" &&id!="" &&id!=undefined){
    	 $("#img").attr("onclick","location.href='../product/appointmentDetail.html?id="+id+"'");
    	if(flag){
    		 $("#btn").html("确定");
    		 $("#addAddress")[0].setAttribute("style","display:block");
    		 $("#addAddress").on("click",function() {
     	    	localStorage.setItem("orderId", GetQueryString("id"));
     	    	return location.href="./emailAdd.html"
     	      });
     	 
    	$(document).on("tap", ".item", function() {
 	      $(this).parents(".am-flexbox").addClass("active").siblings().removeClass("active");
 	    });
     	
     	 $("#btn").on("tap", function() {
     		 var addressId=$(".active").children()[1].getAttribute("data-id");
     		 if(addressId!=undefined&&addressId!="null"){
     	  	     return  Ajax({
     	  	            url: baseUrl + '/api/order/add_order_address.do',
     	  	            data:{orderId:id,addressId:addressId,
     	  	        	      majorStatus:1071,
     	  	        	      minorStatus:1077
     	  	            },
     	  	            callback: function(data) {
     	  	            	toast.success({msg:"索取合同成功"});
     	  	            	setTimeout(function(){
     	  	            		return location.href = "../product/appointmentDetail.html" + (id ? "?id="+id  : "");
     	  	            	},1000);
     	  	            }
     	  	      });
     	  	 }else{
     	  		 wrongMsg("请选择邮寄地址");
     	  		 toast.hide(2000);
     	  	 }
     	    });
    	}else{
    		$("#btn").on("click", function() {
    			localStorage.setItem("orderId", GetQueryString("id"));
     	    	return location.href="./emailAdd.html"
    		});
    	}
    	 
    }else{
    	 $("#img").attr("onclick","location.href='../user/userInfo.html'");
    	$(document).on("tap", ".item,.icon-duigou", function() {
  	      var addressId;
  	      addressId=$(this).data("id");
  	      $("#sure").val(addressId);
  	      return $("#mask").show();
  	    });
    	 $(".am-message-main").html("设为我的首选地址");
    	 $("#sure").on("click", function() {
 	        var addressId=$("#sure").val();
 	  	 return  Ajax({
 	  	        url: baseUrl + '/api/user/default_address.do',
 	  	        data:{
 	  	        	addressId:addressId
 	  	        },
 	  	        callback: function(data) {
 	  	          $("#mask").hide();
 	  	          return location.href = "./email.html" ;
 	  	        }
 	  	      });
 	    });
    	 
    	$("#btn").on("click",function(){
    		return location.href = "./emailAdd.html" ;
    	}); 
       }
 }