<!--#include file="conn.asp"-->
<%
page_title=Eval("order_title"&Language)
page_keywords=Eval("order_keywords"&Language)
page_description=Eval("order_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"-->
<link href="<%=filepath%>inc/cart.css" rel="stylesheet" type="text/css">
<script src="../inc/jquery-1.8.3.min.js" type="text/javascript"></script>
<script src="../inc/jquery.placeholder.min.js" type="text/javascript"></script>
<script src="../inc/jzoshow.js" type="text/javascript"></script>
<script src="../inc/bo.js" type="text/javascript"></script>
<%
if session("user_xxx_name")<>"" then
username=trim(session("user_xxx_name"))
else
	if request.Cookies("shopxp")("dingdanusername")="" then
	username=now()
	username=replace(trim(username),"-","")
	username=replace(username,"/","")
	username=replace(username,":","")
	username=replace(username," ","")
	username=username
	response.Cookies("shopxp")("dingdanusername")=username

	set rs=server.CreateObject("adodb.recordset")
	rs.open "select * from [com_user] ",conn,1,3
	rs.addnew
	rs("username")=username
	rs("niming")=1
	rs.update
	rs.close
	set rs=nothing
	
	else
	username=request.Cookies("shopxp")("dingdanusername")
	end if
end if
%>
<%
set rs=server.CreateObject("adodb.recordset")
rs.open "select shopxp_action.pro_color_id,shopxp_action.pro_size_id,shopxp_action.shopxpptid,com_books.id,com_books.cid from com_books inner join  shopxp_action on com_books.id=shopxp_action.shopxpptid where shopxp_action.username='"&username&"' and shopxp_action.zhuangtai=9",conn,1,1 
shuliang=rs.recordcount
if shuliang<>0 then
booklist=""""&rs("shopxpptid")&"-"&rs("pro_color_id")&"-"&rs("pro_size_id")&""""
rs.movenext 
do while not rs.eof
booklist=booklist&","""&rs("shopxpptid")&"-"&rs("pro_color_id")&"-"&rs("pro_size_id")&""""
rs.movenext
loop
end if
rs.close
set rs=nothing
%>
<script type="text/javascript">
//<![CDATA[
var shoppingCartItemIdList = [<%=booklist%>];
$(function(){
   initDisplayShoppingCartListEvent();
   
});

var showShoppingCartPriceAndInventoryChangeDialog = function() {
	var html = '<div class="dgcontent">\
		            <strong>友请提醒：</strong>\
		            <p>购物车的商品价格或者库存有发生变化！<br>请刷新购物车，显示最新的商品价格与库存。</p>\
		            <div class="btncon">\
		                <a class="btn-gouwu" href="javascript:refreshShoppingCart();"><span>确定</span></a>\
		            </div>\
		        </div>';
		        
	app.dialog.show(html);
};

var refreshShoppingCart = function() {
	var refreshShoppingCartForm = $('<form action="/modifyCart" method="post"></form>');
    refreshShoppingCartForm.appendTo(document.body).submit();
};

var initDisplayShoppingCartListEvent = function() {
	
	if (shoppingCartItemIdList && shoppingCartItemIdList.length > 0) {
		$.each(shoppingCartItemIdList, function(n, valObj){
			quantityValidator(valObj);
		});
	}
	
};

var quantityValidator = function(itemId) {
		var quantityObj = $("#quantity_"+itemId);
		$("#reduceBtn_"+itemId).click(function(){
			var num = parseInt(quantityObj.val());
			num = (!num || num < 1) ? 1 : (num - 1);
			updateShoppingCartByItemId(itemId, num);
		});
		
		$("#addBtn_"+itemId).click(function(){
			var num = parseInt(quantityObj.val());
			num = !num ? 1 : num + 1;
			updateShoppingCartByItemId(itemId, num);
		});
		
		//限制用户输入除1-9的其他字符
		quantityObj.keydown(function(e){
			 return ($.browser.msie) ? ((e.keyCode > 47) && (e.keyCode < 58)  || e.keyCode == 8) : ((e.which > 47) && (e.which < 58)  || e.which == 8);
		}).focus(function() {
         	this.style.imeMode='disabled';   // 禁用输入法,禁止输入中文字符
		});
};

var recalculatePrice = function(itemId){
	var num = parseInt($("#quantity_" + itemId).val());
	var totalPrice =  parseFloat($("#price_" + itemId).html().replace(/,/g, "")) * num;
	$("#totalPrice_" + itemId).html(app.helper.formatCurrency(totalPrice));
	recalculateTotalPriceAndQuantity();
};

var recalculateTotalPriceAndQuantity = function(){
	var totalQuantity = 0;
	var totalPrice = 0;
	$("tr[id^=item_]").each(function(){
		var itemId = this.id;
		itemId = itemId.split("_")[1];
		totalQuantity += parseInt($("#quantity_" + itemId).val().replace(/,/g, ""));
		totalPrice += parseFloat($("#totalPrice_" + itemId).html().replace(/,/g, ""));
	});
	
	$("#totalQuantity").html(totalQuantity);
	$("#totalPrice").html(app.helper.formatCurrency(totalPrice));
	
	$("#userShoppingCartQuantity").html(totalQuantity);
};

var changeQuantity = function(itemId) {
		var num = parseInt($("#quantity_"+itemId).val());
		num = (!num || num < 1) ? 0 : num;
		updateShoppingCartByItemId(itemId, num);
};

var recoverUserShoppingCartQuantity = function(itemId) {
	var originalNum = parseInt($("#original_quantity_" + itemId).val());
	originalNum = !originalNum ? 1 : originalNum;
	$("#quantity_"+itemId).val(originalNum);
};

var updateShoppingCartByItemId = function(itemId, num) {

	if (num < 1) {
		app.alertTips.show("quantity_" + itemId, ("请填写正确的商品数量"));
		recoverUserShoppingCartQuantity(itemId);
		return;
	}

	var array = itemId.split("-");
	app.ajaxHelper.submitRequest({
    	data: {productId:array[0], colorId:array[1], sizeId:array[2], quantity:num},
    	url: "ajax_cart_list_add.asp",
    	success: function(data, textStatus, jqXHR){
    		if(app.handlerServiceResponse(data)){
    			if (data.data.isEnough) {
    				$("#quantityErrorTip_" + itemId).html("");
    				$("#quantityErrorTip_" + itemId).css("display", "none");
    				
    				$("#quantity_"+itemId).val(num);
    				$("#original_quantity_"+itemId).val(num);
    				
    				$("#totalPrice_"+itemId).html(data.data.actualSalePrice);
    				/*$("#promoRuleDescription_"+itemId).html(data.data.promoRuleDescription);*/
    				
					recalculatePrice(itemId);
					app.alertTips.show("quantity_" + itemId, "数量修改成功");
    			} else {
    				recoverUserShoppingCartQuantity(itemId);
    				$("#quantityErrorTip_" + itemId).html("最多只能购买"+data.data.inventory+"件");
					$("#quantity_"+itemId).val(data.data.inventory);
					updateShoppingCartByItemId(itemId, data.data.inventory);
    				$("#quantityErrorTip_" + itemId).css("display", "block");
    				
    				//app.alertTips.show("quantity_" + itemId, "购买的数量超出库存量");
    			}
			}
		}
    }); 
};

var deleteAllShoppingCart = function() {
	app.ajaxHelper.submitRequest({
		url: "ajax_cart_list_del.asp",
    	success: function(data, textStatus, jqXHR){
    		if(app.handlerServiceResponse(data)){
    			$("tr[id^=item_]").each(function(){
					$(this).remove();
				});
				initShoppingCartListTableHtml();
				recalculateTotalPriceAndQuantity();
				show_num_goods();
				jQuery.confirm.close();
			}
		}
    });
};

var deleteAllItem = function(obj) {
	if ($("tr[id^=item_]").length > 0) {
		jQuery.confirm.show(obj, 160, 'javascript:deleteAllShoppingCart(); void(0);', '您确定要清空购物车吗？');
	} else {
		app.alertTips.show("deleteAllItem", "购物车无商品");
	}
};

var deleteSelectedItem = function(obj, productId, colorId, sizeId) {
	if (productId && colorId && sizeId) {
		jQuery.confirm.show(obj, 160, "javascript:deleteSelectedItemFromShoppingCart('"+productId+"','"+colorId+"','"+sizeId+"'); void(0);", "您确定不购买该商品吗？");
	}
};

var deleteSelectedItemFromShoppingCart = function(productId, colorId, sizeId) {
	app.ajaxHelper.submitRequest({
		data: {productId:productId, colorId:colorId, sizeId:sizeId},
    	url: "ajax_cart_list_del.asp",
    	success: function(data, textStatus, jqXHR){
    		if(app.handlerServiceResponse(data)){
    			$("#item_"+productId +"-"+colorId+"-"+sizeId).remove();
				initShoppingCartListTableHtml();
				recalculateTotalPriceAndQuantity();
				show_num_goods();
				jQuery.confirm.close();
			}
		}
    }); 
};


var initShoppingCartListTableHtml = function() {
	if ($("tr[id^=item_]").length <= 0){
		var html = '<tr><td valign="middle" height="80" bgcolor="#FFFFFF" colspan="6">您还没有挑选商品，现在就去挑选自己心爱的商品。</td></tr>';
		$("#shoppingCartListTable").html(html); 
	}
};


//移动到收藏夹
function addFavorites(productId, colorId, sizeId,colorA,sizeA, itemId) {
	app.ajaxHelper.submitRequest({
    	data: {productId:productId, colorId:colorId, sizeId:sizeId, colorA:colorA, sizeA:sizeA},
    	url: "ajax_cart_list_fav.asp",
    	success: function(data, textStatus, jqXHR){
    		if(app.handlerServiceResponse(data)){
					if (data.data.isLogin) {
						var msg = data.data.isExist ? "您已经收藏过该商品" : "成功收藏";
						//app.showAlertTip({messages:msg});
						app.alertTips.show("addFavorites_" + itemId, msg);
					} else {
						location.href = 'Login.asp?backurl=cart.asp';
					}
			}
		}
    });
};

var forwardToNextStep = function(url) {
	app.helper.showLoadingTip();
	location.href = url;
};

//]]>
</script>

<!-- start middle -->
<div class="headnav">
	<div class="cart-steps">
		<ul>
			<li class="current"><span>1.我的购物车<%=request("data")%></span></li>
			<li><span>2.填写核对订单</span></li>
			<li><span>3.成功提交订单</span></li>
			<li class="clear"></li>
		</ul>
	</div>
</div>

<div id="content" class="w990">
	<form id="form1" action="cart" method="post" name="form1">
	<div class="div-nav">
		<span>我挑选的商品</span>
	</div>
	<div class="gouwu-list">
		<div class="tb-head">
			<table cellspacing="0" cellpadding="0" border="0">
				<tbody>
					<tr>
						<td>商品</td>
						<td width="77">原价</td>
						<td width="77">促销价</td>
						<td width="87">数量</td>
						
						<td width="77">小计</td>
						<td width="67">操作</td>
					</tr>
				</tbody>
			</table>
		</div>
		<div class="tb-body">
<table cellpadding="0" cellspacing="0" border="0" id="shoppingCartListTable">
							<tbody>
<%
set rs=server.CreateObject("adodb.recordset")
	rs.open "select shopxp_action.shopxpacid,shopxp_action.pro_color,shopxp_action.pro_size,shopxp_action.pro_color_id,shopxp_action.pro_size_id,shopxp_action.shopxpptid,shopxp_action.productcount,shopxp_action.zonger,com_books.id,com_books.cid,com_books.titlecn,com_books.bookpicm,com_books.titlecn,com_books.shichangjia,com_books.shopxphyjia,com_books.jifeng,com_books.shopxpvjia from com_books inner join  shopxp_action on com_books.id=shopxp_action.shopxpptid where shopxp_action.username='"&username&"' and shopxp_action.zhuangtai=9",conn,1,1 
	shuliang=rs.recordcount
	jianshu=0
	zongji=0
if shuliang<>0 then

do while not rs.eof
	bookiid=rs("shopxpptid")
	jianshu=jianshu+rs("productcount")
	zongji=zongji+rs("zonger")
	subtitle=rs("titlecn")
	subid=rs("id")
	subcid=rs("cid")
	subbookpicm=rs("bookpicm")
	subjifeng=rs("jifeng")
	shichangjia=rs("shichangjia")
	shopxphyjia=rs("shopxphyjia")
	pro_color=rs("pro_color")
	pro_size=rs("pro_size")
	pro_color_id=rs("pro_color_id")
	pro_size_id=rs("pro_size_id")
%>
			
							
							
							<tr id="item_<%=bookiid%>-<%=pro_color_id%>-<%=pro_size_id%>">
								<td class="td-prod">
									<table border="0" cellpadding="0" cellspacing="0">
										<tbody>
											<tr>
												<td class="prod-pic">
													<a href="products_show.asp?typeid=<%=subcid%>&id=<%=subid%>" target="_blank">
														<img src="../<%=subbookpicm%>" width="80" height="80" border="0">
													</a>
												</td>
												<td class="prod-info">
												<a class="prod-name" href="products_show.asp?typeid=<%=subcid%>&id=<%=subid%>" target="_blank"><%=subtitle%></a>
													<p class="prod-attr">颜色:<%=pro_color%>，规格:<%=pro_size%></p>
												</td>
											</tr>
										</tbody>
									</table>
								</td>
								<td width="77" class="td-price-origin">¥ <%=Formatnumber(shichangjia,2,-1,-1,0)%></td>
								<td width="77" class="td-price-real">¥<span id="price_<%=bookiid%>-<%=pro_color_id%>-<%=pro_size_id%>"><%=Formatnumber(shopxphyjia,2,-1,-1,0)%></span></td>
								<td width="87" class="td-calculate">
									<table border="0" cellpadding="0" cellspacing="0">
										<tbody>
											<tr>
												<td><span class="subtration" id="reduceBtn_<%=bookiid%>-<%=pro_color_id%>-<%=pro_size_id%>"></span></td>
												<td class="inputext">
												<input value="<%=rs("productcount")%>" id="quantity_<%=bookiid%>-<%=pro_color_id%>-<%=pro_size_id%>" name="quantity_<%=bookiid%>-<%=pro_color_id%>-<%=pro_size_id%>" onblur="changeQuantity(&#39;<%=bookiid%>-<%=pro_color_id%>-<%=pro_size_id%>&#39;);" type="text">
												<input type="hidden" value="<%=rs("productcount")%>" id="original_quantity_<%=bookiid%>-<%=pro_color_id%>-<%=pro_size_id%>">
												</td>
												<td><span class="addition" id="addBtn_<%=bookiid%>-<%=pro_color_id%>-<%=pro_size_id%>"></span></td>
											</tr>
										</tbody>
									</table>
									<div class="messageinfo" style="display:none" id="quantityErrorTip_<%=bookiid%>-<%=pro_color_id%>-<%=pro_size_id%>"></div>
								</td>
								
								<td width="77">¥<span id="totalPrice_<%=bookiid%>-<%=pro_color_id%>-<%=pro_size_id%>"><%=Formatnumber(rs("zonger"),2,-1,-1,0)%></span></td>
								<td width="67">
<a class="butB" id="addFavorites_<%=bookiid%>-<%=pro_color_id%>-<%=pro_size_id%>" href="javascript:addFavorites('<%=bookiid%>','<%=pro_color_id%>', '<%=pro_size_id%>','<%=pro_color%>','<%=pro_size%>', '<%=bookiid%>-<%=pro_color_id%>-<%=pro_size_id%>')">收藏</a>
									<a class="butG" onclick="deleteSelectedItem(this, &#39;<%=bookiid%>&#39;,&#39;<%=pro_color_id%>&#39;, &#39;<%=pro_size_id%>&#39;)">删除</a>
								</td>
							</tr>
							
<%
rs.movenext
loop
showgo=1
%>
<%else
showgo=0
%>
	<tr><td valign="middle" height="80" bgcolor="#FFFFFF" colspan="7">您还没有挑选商品，现在就去挑选自己心爱的商品。</td></tr>				
<%
end if
rs.close
set rs=nothing
%>
</tbody></table>
		</div>
		<div class="tb-foot">
			<div class="footl">
				产品数量总计：<em id="totalQuantity"><%=jianshu%></em>件
			</div>
			<div class="footr">
				产品金额总计：<em>¥<span id="totalPrice"><%=Formatnumber(zongji,2,-1,-1,0)%></span></em>
			</div>
		</div>
	</div>
	<div class="div-con">
		<div class="btnbar">
			<%if showgo=1 then%><a onclick="deleteAllItem(this);" href="javascript:void(0);" class="btn-clear" id="deleteAllItem"><span>清空购物车</span></a><%end if%>
			<a href="../index.asp" class="btn-back"><span>继续购物</span></a>
			<%if showgo=1 then%><a href="javascript:forwardToNextStep('<%if session("user_xxx_name")<>"" then %>step_two.asp<%else%>login.asp?backurl=cart.asp<%end if%>')" class="btn-gouwu"><span>去结算</span></a><%end if%>
			
			
		</div>
	</div>
	
	<!-- 精品推荐 start-->
	<!--#include file="cart_tjPro.asp"--> 
	<!--精品推荐 end -->
	
	
	</form>
</div>
<!--end middle-->
	
	
   <div class="clear"></div>
   
  <div id="bg" class="bg" style="display: none;"></div>
	<iframe id="popIframe" class="popIframe" frameborder="0"></iframe>
	<div id="loadingTip" class="loadingTip" style="display: none;">
		数据处理中...
	</div> 
   
<!--#include file="foot.asp"--> 


<script>
/*设置浏览过的商品*/
withBroswerStore(function(broswerStore){
  broswerStore.get('history',function(history){
  history=JSON.decode(history);
  if(!history||$type(history)!=='array')history=[];
   if(history.length==40){history.pop()};
   var newhis={'goodsId':<%=request("id")%>,
			   'goodsCid':<%=request("cid")%>,
               'goodsName':<%=request("id")%>,
               'goodsImg':<%=request("id")%>,
               'viewTime':$time()
              };
   if(!history.some(function(i,index){


   if(i['goodsId']==newhis['goodsId']){
         history.erase(i);
         history.include(newhis)
         return true;
   }
      return false;

   })){
       history.include(newhis);
   }
   broswerStore.set('history',history);

  });
});


</script>


<%
sub title()
typeid=request("typeid")
if typeid="" then
response.write "商品信息"
elseif typeid=0 then
response.write "商品信息"
end if
if typeid<>"" and typeid<>0 then
set rstype=server.CreateObject("adodb.recordset")	
rstype.open "select * from com_class where id="&typeid&" order by pid asc,id desc",conn,1,1
response.write " "&rstype("ClassName"&language)&""
rstype.close
set rstype=nothing
end if
end sub


sub title1()
styleid=request("cid")
if styleid="" then
response.write ""
elseif styleid=0 then
response.write ""
end if
if styleid<>"" and styleid<>0 then
set rstype=server.CreateObject("adodb.recordset")	
rstype.open "select * from com_class where id="&styleid&" order by pid asc,id desc",conn,1,1
response.write " >> "&rstype("ClassName"&language)&" "
rstype.close
set rstype=nothing
end if
end sub

function pifn(proid)
if proid<>""then
set rstype=server.CreateObject("adodb.recordset")	
rstype.open "select * from com_message where proid="&proid&" and look"&Language&"=1 and type=1 order by ID desc",conn,1,1
if rstype.eof then
response.Write("0")
else
pi=0
xjb=0
while not rstype.eof
xjb=rstype("xjb")+xjb
pi=pi+1
rstype.movenext
Wend
end if
rstype.close
set rstype=nothing
pifn=Formatnumber(xjb/pi,1,-1,-1,0)
end if
end function
%>